gtfs 4.9.0 → 4.10.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 +40 -0
- package/CHANGELOG.md +9 -0
- package/README.md +79 -7
- package/lib/gtfs/fare-media.js +32 -0
- package/lib/gtfs/networks.js +32 -0
- package/lib/gtfs/route-networks.js +32 -0
- package/lib/gtfs/timeframes.js +32 -0
- package/lib/gtfs.js +16 -0
- package/models/gtfs/fare-leg-rules.js +12 -0
- package/models/gtfs/fare-media.js +25 -0
- package/models/gtfs/networks.js +19 -0
- package/models/gtfs/route-networks.js +20 -0
- package/models/gtfs/timeframes.js +28 -0
- package/models/models.js +8 -0
- package/package.json +4 -3
- package/test/mocha/export-gtfs.js +7 -11
- package/test/mocha/get-fare-media.js +27 -0
- package/test/mocha/get-networks.js +28 -0
- package/test/mocha/get-route-networks.js +28 -0
- package/test/mocha/get-timeframes.js +28 -0
- package/test/mocha/import-gtfs.js +2 -9
- package/test/test-config.js +1 -5
package/@types/index.d.ts
CHANGED
|
@@ -298,6 +298,16 @@ export function getFareLegRules(
|
|
|
298
298
|
options?: QueryOptions,
|
|
299
299
|
): SqlResults;
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Returns an array of fare_media that match query parameters.
|
|
303
|
+
*/
|
|
304
|
+
export function getFareMedia(
|
|
305
|
+
query?: SqlWhere,
|
|
306
|
+
fields?: SqlSelect,
|
|
307
|
+
sortBy?: SqlOrderBy,
|
|
308
|
+
options?: QueryOptions,
|
|
309
|
+
): SqlResults;
|
|
310
|
+
|
|
301
311
|
/**
|
|
302
312
|
* Returns an array of fare_products that match query parameters.
|
|
303
313
|
*/
|
|
@@ -368,6 +378,16 @@ export function getPathways(
|
|
|
368
378
|
options?: QueryOptions,
|
|
369
379
|
): SqlResults;
|
|
370
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Returns an array of timeframes that match query parameters.
|
|
383
|
+
*/
|
|
384
|
+
export function getTimeframes(
|
|
385
|
+
query?: SqlWhere,
|
|
386
|
+
fields?: SqlSelect,
|
|
387
|
+
sortBy?: SqlOrderBy,
|
|
388
|
+
options?: QueryOptions,
|
|
389
|
+
): SqlResults;
|
|
390
|
+
|
|
371
391
|
/**
|
|
372
392
|
* Returns an array of transfers that match query parameters.
|
|
373
393
|
*/
|
|
@@ -398,6 +418,26 @@ export function getStopAreas(
|
|
|
398
418
|
options?: QueryOptions,
|
|
399
419
|
): SqlResults;
|
|
400
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Returns an array of networks that match query parameters.
|
|
423
|
+
*/
|
|
424
|
+
export function getNetworks(
|
|
425
|
+
query?: SqlWhere,
|
|
426
|
+
fields?: SqlSelect,
|
|
427
|
+
sortBy?: SqlOrderBy,
|
|
428
|
+
options?: QueryOptions,
|
|
429
|
+
): SqlResults;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Returns an array of route_networks that match query parameters.
|
|
433
|
+
*/
|
|
434
|
+
export function getRouteNetworks(
|
|
435
|
+
query?: SqlWhere,
|
|
436
|
+
fields?: SqlSelect,
|
|
437
|
+
sortBy?: SqlOrderBy,
|
|
438
|
+
options?: QueryOptions,
|
|
439
|
+
): SqlResults;
|
|
440
|
+
|
|
401
441
|
/**
|
|
402
442
|
* Returns an array of calendar_attributes that match query parameters.
|
|
403
443
|
* This is for the non-standard `calendar_attributes.txt` file.
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ 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.0] - 2024-03-29
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Support for [fare_media.txt](https://gtfs.org/schedule/reference/#fare_mediatxt)
|
|
13
|
+
- Support for [networks.txt](https://gtfs.org/schedule/reference/#networkstxt)
|
|
14
|
+
- Support for [route_networks.txt](https://gtfs.org/schedule/reference/#route_networkstxt)
|
|
15
|
+
- Support for [timeframes.txt](https://gtfs.org/schedule/reference/#timeframestxt)
|
|
16
|
+
|
|
8
17
|
## [4.9.0] - 2024-03-12
|
|
9
18
|
|
|
10
19
|
### Updated
|
package/README.md
CHANGED
|
@@ -84,9 +84,10 @@ or
|
|
|
84
84
|
```js
|
|
85
85
|
import { importGtfs } from 'gtfs';
|
|
86
86
|
import { readFile } from 'fs/promises';
|
|
87
|
+
import path from 'node:path';
|
|
87
88
|
|
|
88
89
|
const config = JSON.parse(
|
|
89
|
-
await readFile(
|
|
90
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
90
91
|
);
|
|
91
92
|
|
|
92
93
|
try {
|
|
@@ -485,9 +486,10 @@ Use `importGtfs()` in your code to run an import of a GTFS file specified in a c
|
|
|
485
486
|
```js
|
|
486
487
|
import { importGtfs } from 'gtfs';
|
|
487
488
|
import { readFile } from 'fs/promises';
|
|
489
|
+
import path from 'node:path';
|
|
488
490
|
|
|
489
491
|
const config = JSON.parse(
|
|
490
|
-
await readFile(
|
|
492
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
491
493
|
);
|
|
492
494
|
|
|
493
495
|
await importGtfs(config);
|
|
@@ -530,9 +532,10 @@ Use `updateGtfsRealtime()` in your code to run an update of a GTFS-Realtime data
|
|
|
530
532
|
```js
|
|
531
533
|
import { updateGtfsRealtime } from 'gtfs';
|
|
532
534
|
import { readFile } from 'fs/promises';
|
|
535
|
+
import path from 'node:path';
|
|
533
536
|
|
|
534
537
|
const config = JSON.parse(
|
|
535
|
-
await readFile(
|
|
538
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
536
539
|
);
|
|
537
540
|
|
|
538
541
|
await updateGtfsRealtime(config);
|
|
@@ -612,9 +615,12 @@ To use any of the query methods, first open the database using `openDb` before m
|
|
|
612
615
|
```js
|
|
613
616
|
import { openDb } from 'gtfs';
|
|
614
617
|
import { readFile } from 'fs/promises';
|
|
618
|
+
import path from 'node:path';
|
|
619
|
+
|
|
615
620
|
const config = JSON.parse(
|
|
616
|
-
await readFile(
|
|
621
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
617
622
|
);
|
|
623
|
+
|
|
618
624
|
const db = openDb(config);
|
|
619
625
|
```
|
|
620
626
|
|
|
@@ -637,8 +643,10 @@ For example, to get a list of all routes with just `route_id`, `route_short_name
|
|
|
637
643
|
```js
|
|
638
644
|
import { closeDb, openDb, getRoutes } from 'gtfs';
|
|
639
645
|
import { readFile } from 'fs/promises';
|
|
646
|
+
import path from 'node:path';
|
|
647
|
+
|
|
640
648
|
const config = JSON.parse(
|
|
641
|
-
await readFile(
|
|
649
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
642
650
|
);
|
|
643
651
|
|
|
644
652
|
const db = openDb(config);
|
|
@@ -657,8 +665,10 @@ To get a list of all trip_ids for a specific route:
|
|
|
657
665
|
```js
|
|
658
666
|
import { closeDb, openDb, getTrips } from 'gtfs';
|
|
659
667
|
import { readFile } from 'fs/promises';
|
|
668
|
+
import path from 'node:path';
|
|
669
|
+
|
|
660
670
|
const config = JSON.parse(
|
|
661
|
-
await readFile(
|
|
671
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
662
672
|
);
|
|
663
673
|
|
|
664
674
|
const db = openDb(config);
|
|
@@ -677,8 +687,11 @@ To get a few stops by specific stop_ids:
|
|
|
677
687
|
```js
|
|
678
688
|
import { closeDb, openDb, getStops } from 'gtfs';
|
|
679
689
|
import { readFile } from 'fs/promises';
|
|
680
|
-
|
|
690
|
+
import path from 'node:path';
|
|
681
691
|
|
|
692
|
+
const config = JSON.parse(
|
|
693
|
+
await readFile(path.join(import.meta.dirname, 'config.json'))
|
|
694
|
+
);
|
|
682
695
|
const db = openDb(config);
|
|
683
696
|
const stops = getStops(
|
|
684
697
|
{
|
|
@@ -1047,6 +1060,22 @@ const fareLegRules = getFareLegRules({
|
|
|
1047
1060
|
});
|
|
1048
1061
|
```
|
|
1049
1062
|
|
|
1063
|
+
#### getFareMedia(query, fields, sortBy, options)
|
|
1064
|
+
|
|
1065
|
+
Returns an array of fare_media that match query parameters. [Details on fare_media.txt](https://gtfs.org/schedule/reference/#fare_mediatxt)
|
|
1066
|
+
|
|
1067
|
+
```js
|
|
1068
|
+
import { getFareMedia } from 'gtfs';
|
|
1069
|
+
|
|
1070
|
+
// Get all fare media
|
|
1071
|
+
const getFareMedia = getFareMedia();
|
|
1072
|
+
|
|
1073
|
+
// Get a specific fare media
|
|
1074
|
+
const fareMedia = getFareMedia({
|
|
1075
|
+
fare_media_id: 'media1',
|
|
1076
|
+
});
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1050
1079
|
#### getFareProducts(query, fields, sortBy, options)
|
|
1051
1080
|
|
|
1052
1081
|
Returns an array of fare_products that match query parameters. [Details on fare_products.txt](https://gtfs.org/schedule/reference/#fare_productstxt)
|
|
@@ -1144,6 +1173,17 @@ import { getPathways } from 'gtfs';
|
|
|
1144
1173
|
const pathways = getPathways();
|
|
1145
1174
|
```
|
|
1146
1175
|
|
|
1176
|
+
#### getTimeframes(query, fields, sortBy, options)
|
|
1177
|
+
|
|
1178
|
+
Returns an array of timeframes that match query parameters. [Details on timeframes.txt](https://gtfs.org/schedule/reference/#timeframestxt)
|
|
1179
|
+
|
|
1180
|
+
```js
|
|
1181
|
+
import { getTimeframes } from 'gtfs';
|
|
1182
|
+
|
|
1183
|
+
// Get all timeframes
|
|
1184
|
+
const timeframes = getTimeframes();
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1147
1187
|
#### getTransfers(query, fields, sortBy, options)
|
|
1148
1188
|
|
|
1149
1189
|
Returns an array of transfers that match query parameters. [Details on transfers.txt](https://gtfs.org/schedule/reference/#transferstxt)
|
|
@@ -1182,6 +1222,38 @@ import { getStopAreas } from 'gtfs';
|
|
|
1182
1222
|
const stopAreas = getStopAreas();
|
|
1183
1223
|
```
|
|
1184
1224
|
|
|
1225
|
+
#### getNetworks(query, fields, sortBy, options)
|
|
1226
|
+
|
|
1227
|
+
Returns an array of networks that match query parameters. [Details on networks.txt](https://gtfs.org/schedule/reference/#networkstxt)
|
|
1228
|
+
|
|
1229
|
+
```js
|
|
1230
|
+
import { getNetworks } from 'gtfs';
|
|
1231
|
+
|
|
1232
|
+
// Get all networks
|
|
1233
|
+
const networks = getNetworks();
|
|
1234
|
+
|
|
1235
|
+
// Get networks for a specific network_id
|
|
1236
|
+
const networks = getNetworks({
|
|
1237
|
+
network_id: '1234',
|
|
1238
|
+
});
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
#### getRouteNetworks(query, fields, sortBy, options)
|
|
1242
|
+
|
|
1243
|
+
Returns an array of route_networks that match query parameters. [Details on route_networks.txt](https://gtfs.org/schedule/reference/#route_networkstxt)
|
|
1244
|
+
|
|
1245
|
+
```js
|
|
1246
|
+
import { getRouteNetworks } from 'gtfs';
|
|
1247
|
+
|
|
1248
|
+
// Get all route_networks
|
|
1249
|
+
const routeNetworks = getRouteNetworks();
|
|
1250
|
+
|
|
1251
|
+
// Get route_networks for a specific network_id
|
|
1252
|
+
const routeNetworks = getRouteNetworks({
|
|
1253
|
+
network_id: '1234',
|
|
1254
|
+
});
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1185
1257
|
### GTFS-Timetables files
|
|
1186
1258
|
|
|
1187
1259
|
#### getTimetables(query, fields, sortBy, options)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import fareMedia from '../../models/gtfs/fare-media.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all fare media that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getFareMedia(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {},
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(fareMedia.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import networks from '../../models/gtfs/networks.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all networks that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getNetworks(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {},
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(networks.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import routeNetworks from '../../models/gtfs/route-networks.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all route_networks that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getRouteNetworks(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {},
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(routeNetworks.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import sqlString from 'sqlstring-sqlite';
|
|
2
|
+
|
|
3
|
+
import { openDb } from '../db.js';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatOrderByClause,
|
|
7
|
+
formatSelectClause,
|
|
8
|
+
formatWhereClauses,
|
|
9
|
+
} from '../utils.js';
|
|
10
|
+
import timeframes from '../../models/gtfs/timeframes.js';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Returns an array of all timeframes that match the query parameters.
|
|
14
|
+
*/
|
|
15
|
+
export function getTimeframes(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {},
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? openDb();
|
|
22
|
+
const tableName = sqlString.escapeId(timeframes.filenameBase);
|
|
23
|
+
const selectClause = formatSelectClause(fields);
|
|
24
|
+
const whereClause = formatWhereClauses(query);
|
|
25
|
+
const orderByClause = formatOrderByClause(orderBy);
|
|
26
|
+
|
|
27
|
+
return db
|
|
28
|
+
.prepare(
|
|
29
|
+
`${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`,
|
|
30
|
+
)
|
|
31
|
+
.all();
|
|
32
|
+
}
|
package/lib/gtfs.js
CHANGED
|
@@ -12,18 +12,22 @@ import { getCalendarDates } from './gtfs/calendar-dates.js';
|
|
|
12
12
|
import { getCalendars } from './gtfs/calendars.js';
|
|
13
13
|
import { getFareAttributes } from './gtfs/fare-attributes.js';
|
|
14
14
|
import { getFareLegRules } from './gtfs/fare-leg-rules.js';
|
|
15
|
+
import { getFareMedia } from './gtfs/fare-media.js';
|
|
15
16
|
import { getFareProducts } from './gtfs/fare-products.js';
|
|
16
17
|
import { getFareRules } from './gtfs/fare-rules.js';
|
|
17
18
|
import { getFareTransferRules } from './gtfs/fare-transfer-rules.js';
|
|
18
19
|
import { getFeedInfo } from './gtfs/feed-info.js';
|
|
19
20
|
import { getFrequencies } from './gtfs/frequencies.js';
|
|
20
21
|
import { getLevels } from './gtfs/levels.js';
|
|
22
|
+
import { getNetworks } from './gtfs/networks.js';
|
|
21
23
|
import { getPathways } from './gtfs/pathways.js';
|
|
24
|
+
import { getRouteNetworks } from './gtfs/route-networks.js';
|
|
22
25
|
import { getRoutes } from './gtfs/routes.js';
|
|
23
26
|
import { getShapes, getShapesAsGeoJSON } from './gtfs/shapes.js';
|
|
24
27
|
import { getStopAreas } from './gtfs/stop-areas.js';
|
|
25
28
|
import { getStops, getStopsAsGeoJSON } from './gtfs/stops.js';
|
|
26
29
|
import { getStoptimes } from './gtfs/stop-times.js';
|
|
30
|
+
import { getTimeframes } from './gtfs/timeframes.js';
|
|
27
31
|
import { getTransfers } from './gtfs/transfers.js';
|
|
28
32
|
import { getTranslations } from './gtfs/translations.js';
|
|
29
33
|
import { getTrips } from './gtfs/trips.js';
|
|
@@ -94,6 +98,9 @@ export { _getFareAttributes as getFareAttributes };
|
|
|
94
98
|
const _getFareLegRules = getFareLegRules;
|
|
95
99
|
export { _getFareLegRules as getFareLegRules };
|
|
96
100
|
|
|
101
|
+
const _getFareMedia = getFareMedia;
|
|
102
|
+
export { _getFareMedia as getFareMedia };
|
|
103
|
+
|
|
97
104
|
const _getFareProducts = getFareProducts;
|
|
98
105
|
export { _getFareProducts as getFareProducts };
|
|
99
106
|
|
|
@@ -112,9 +119,15 @@ export { _getFrequencies as getFrequencies };
|
|
|
112
119
|
const _getLevels = getLevels;
|
|
113
120
|
export { _getLevels as getLevels };
|
|
114
121
|
|
|
122
|
+
const _getNetworks = getNetworks;
|
|
123
|
+
export { _getNetworks as getNetworks };
|
|
124
|
+
|
|
115
125
|
const _getPathways = getPathways;
|
|
116
126
|
export { _getPathways as getPathways };
|
|
117
127
|
|
|
128
|
+
const _getRouteNetworks = getRouteNetworks;
|
|
129
|
+
export { _getRouteNetworks as getRouteNetworks };
|
|
130
|
+
|
|
118
131
|
const _getRoutes = getRoutes;
|
|
119
132
|
export { _getRoutes as getRoutes };
|
|
120
133
|
|
|
@@ -134,6 +147,9 @@ export { _getStopsAsGeoJSON as getStopsAsGeoJSON };
|
|
|
134
147
|
const _getStoptimes = getStoptimes;
|
|
135
148
|
export { _getStoptimes as getStoptimes };
|
|
136
149
|
|
|
150
|
+
const _getTimeframes = getTimeframes;
|
|
151
|
+
export { _getTimeframes as getTimeframes };
|
|
152
|
+
|
|
137
153
|
const _getTransfers = getTransfers;
|
|
138
154
|
export { _getTransfers as getTransfers };
|
|
139
155
|
|
|
@@ -24,6 +24,18 @@ const model = {
|
|
|
24
24
|
primary: true,
|
|
25
25
|
prefix: true,
|
|
26
26
|
},
|
|
27
|
+
{
|
|
28
|
+
name: 'from_timeframe_group_id',
|
|
29
|
+
type: 'varchar(255)',
|
|
30
|
+
primary: true,
|
|
31
|
+
prefix: true,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'to_timeframe_group_id',
|
|
35
|
+
type: 'varchar(255)',
|
|
36
|
+
primary: true,
|
|
37
|
+
prefix: true,
|
|
38
|
+
},
|
|
27
39
|
{
|
|
28
40
|
name: 'fare_product_id',
|
|
29
41
|
type: 'varchar(255)',
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'fare_media',
|
|
3
|
+
schema: [
|
|
4
|
+
{
|
|
5
|
+
name: 'fare_media_id',
|
|
6
|
+
type: 'varchar(255)',
|
|
7
|
+
required: true,
|
|
8
|
+
primary: true,
|
|
9
|
+
prefix: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'fare_media_name',
|
|
13
|
+
type: 'varchar(255)',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'fare_media_type',
|
|
17
|
+
type: 'integer',
|
|
18
|
+
required: true,
|
|
19
|
+
min: 0,
|
|
20
|
+
max: 4,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default model;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'networks',
|
|
3
|
+
schema: [
|
|
4
|
+
{
|
|
5
|
+
name: 'network_id',
|
|
6
|
+
type: 'varchar(255)',
|
|
7
|
+
primary: true,
|
|
8
|
+
required: true,
|
|
9
|
+
prefix: true,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: 'network_name',
|
|
13
|
+
type: 'varchar(255)',
|
|
14
|
+
nocase: true,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default model;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'route_networks',
|
|
3
|
+
schema: [
|
|
4
|
+
{
|
|
5
|
+
name: 'network_id',
|
|
6
|
+
type: 'varchar(255)',
|
|
7
|
+
required: true,
|
|
8
|
+
prefix: true,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'route_id',
|
|
12
|
+
type: 'varchar(255)',
|
|
13
|
+
primary: true,
|
|
14
|
+
index: true,
|
|
15
|
+
prefix: true,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default model;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const model = {
|
|
2
|
+
filenameBase: 'timeframes',
|
|
3
|
+
schema: [
|
|
4
|
+
{
|
|
5
|
+
name: 'timeframe_group_id',
|
|
6
|
+
type: 'varchar(255)',
|
|
7
|
+
primary: true,
|
|
8
|
+
prefix: true,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'start_time',
|
|
12
|
+
type: 'varchar(255)',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'end_time',
|
|
16
|
+
type: 'varchar(255)',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'service_id',
|
|
20
|
+
type: 'varchar(255)',
|
|
21
|
+
required: true,
|
|
22
|
+
index: true,
|
|
23
|
+
prefix: true,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default model;
|
package/models/models.js
CHANGED
|
@@ -5,18 +5,22 @@ import calendarDates from '../models/gtfs/calendar-dates.js';
|
|
|
5
5
|
import calendar from '../models/gtfs/calendar.js';
|
|
6
6
|
import fareAttributes from '../models/gtfs/fare-attributes.js';
|
|
7
7
|
import fareLegRules from '../models/gtfs/fare-leg-rules.js';
|
|
8
|
+
import fareMedia from '../models/gtfs/fare-media.js';
|
|
8
9
|
import fareProducts from '../models/gtfs/fare-products.js';
|
|
9
10
|
import fareRules from '../models/gtfs/fare-rules.js';
|
|
10
11
|
import fareTransferRules from '../models/gtfs/fare-transfer-rules.js';
|
|
11
12
|
import feedInfo from '../models/gtfs/feed-info.js';
|
|
12
13
|
import frequencies from '../models/gtfs/frequencies.js';
|
|
13
14
|
import levels from '../models/gtfs/levels.js';
|
|
15
|
+
import networks from '../models/gtfs/networks.js';
|
|
14
16
|
import pathways from '../models/gtfs/pathways.js';
|
|
17
|
+
import routeNetworks from '../models/gtfs/route-networks.js';
|
|
15
18
|
import routes from '../models/gtfs/routes.js';
|
|
16
19
|
import shapes from '../models/gtfs/shapes.js';
|
|
17
20
|
import stopAreas from '../models/gtfs/stop-areas.js';
|
|
18
21
|
import stopTimes from '../models/gtfs/stop-times.js';
|
|
19
22
|
import stops from '../models/gtfs/stops.js';
|
|
23
|
+
import timeframes from '../models/gtfs/timeframes.js';
|
|
20
24
|
import transfers from '../models/gtfs/transfers.js';
|
|
21
25
|
import translations from '../models/gtfs/translations.js';
|
|
22
26
|
import trips from '../models/gtfs/trips.js';
|
|
@@ -59,18 +63,22 @@ const models = [
|
|
|
59
63
|
calendar,
|
|
60
64
|
fareAttributes,
|
|
61
65
|
fareLegRules,
|
|
66
|
+
fareMedia,
|
|
62
67
|
fareProducts,
|
|
63
68
|
fareRules,
|
|
64
69
|
fareTransferRules,
|
|
65
70
|
feedInfo,
|
|
66
71
|
frequencies,
|
|
67
72
|
levels,
|
|
73
|
+
networks,
|
|
68
74
|
pathways,
|
|
75
|
+
routeNetworks,
|
|
69
76
|
routes,
|
|
70
77
|
shapes,
|
|
71
78
|
stopAreas,
|
|
72
79
|
stopTimes,
|
|
73
80
|
stops,
|
|
81
|
+
timeframes,
|
|
74
82
|
transfers,
|
|
75
83
|
translations,
|
|
76
84
|
trips,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtfs",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0",
|
|
4
4
|
"description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"transit",
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"Matthias Feist <matze@matf.de>",
|
|
62
62
|
"Oliv4945",
|
|
63
63
|
"Kyle Ramey",
|
|
64
|
-
"Anton Bracke"
|
|
64
|
+
"Anton Bracke",
|
|
65
|
+
"Emma K Alexandra <emma@emma.sh>"
|
|
65
66
|
],
|
|
66
67
|
"type": "module",
|
|
67
68
|
"main": "index.js",
|
|
@@ -104,7 +105,7 @@
|
|
|
104
105
|
"should": "^13.2.3"
|
|
105
106
|
},
|
|
106
107
|
"engines": {
|
|
107
|
-
"node": ">=
|
|
108
|
+
"node": ">= 20.11.0"
|
|
108
109
|
},
|
|
109
110
|
"release-it": {
|
|
110
111
|
"github": {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
/* eslint-disable max-nested-callbacks */
|
|
3
3
|
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
5
|
import { createReadStream, existsSync } from 'node:fs';
|
|
7
6
|
import { rm } from 'node:fs/promises';
|
|
8
7
|
import { parse } from 'csv-parse';
|
|
@@ -43,10 +42,7 @@ describe('exportGtfs():', function () {
|
|
|
43
42
|
|
|
44
43
|
describe('Verify data exported', () => {
|
|
45
44
|
const countData = {};
|
|
46
|
-
const temporaryDir = path.join(
|
|
47
|
-
path.dirname(fileURLToPath(import.meta.url)),
|
|
48
|
-
'../fixture/tmp/'
|
|
49
|
-
);
|
|
45
|
+
const temporaryDir = path.join(import.meta.dirname, '../fixture/tmp/');
|
|
50
46
|
|
|
51
47
|
before(async () => {
|
|
52
48
|
await prepDirectory(temporaryDir);
|
|
@@ -75,7 +71,7 @@ describe('exportGtfs():', function () {
|
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
countData[model.filenameBase] = data.length;
|
|
78
|
-
}
|
|
74
|
+
},
|
|
79
75
|
);
|
|
80
76
|
|
|
81
77
|
return createReadStream(filePath)
|
|
@@ -84,7 +80,7 @@ describe('exportGtfs():', function () {
|
|
|
84
80
|
countData[model.collection] = 0;
|
|
85
81
|
throw new Error(error);
|
|
86
82
|
});
|
|
87
|
-
})
|
|
83
|
+
}),
|
|
88
84
|
);
|
|
89
85
|
|
|
90
86
|
await importGtfs(config);
|
|
@@ -96,9 +92,9 @@ describe('exportGtfs():', function () {
|
|
|
96
92
|
path.join(
|
|
97
93
|
process.cwd(),
|
|
98
94
|
'gtfs-export',
|
|
99
|
-
generateFolderName(agencies[0].agency_name)
|
|
95
|
+
generateFolderName(agencies[0].agency_name),
|
|
100
96
|
),
|
|
101
|
-
{ recursive: true, force: true }
|
|
97
|
+
{ recursive: true, force: true },
|
|
102
98
|
);
|
|
103
99
|
});
|
|
104
100
|
|
|
@@ -109,7 +105,7 @@ describe('exportGtfs():', function () {
|
|
|
109
105
|
process.cwd(),
|
|
110
106
|
'gtfs-export',
|
|
111
107
|
generateFolderName(agencies[0].agency_name),
|
|
112
|
-
`${model.filenameBase}.txt
|
|
108
|
+
`${model.filenameBase}.txt`,
|
|
113
109
|
);
|
|
114
110
|
|
|
115
111
|
// GTFS has optional files
|
|
@@ -134,7 +130,7 @@ describe('exportGtfs():', function () {
|
|
|
134
130
|
should.not.exist(error);
|
|
135
131
|
|
|
136
132
|
data.length.should.equal(countData[model.filenameBase]);
|
|
137
|
-
}
|
|
133
|
+
},
|
|
138
134
|
);
|
|
139
135
|
|
|
140
136
|
return createReadStream(filePath)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import should from 'should';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { openDb, closeDb, importGtfs, getFareMedia } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
describe('getFareMedia():', () => {
|
|
9
|
+
before(async () => {
|
|
10
|
+
openDb(config);
|
|
11
|
+
await importGtfs(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
after(() => {
|
|
15
|
+
const db = openDb(config);
|
|
16
|
+
closeDb(db);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return empty array if no fare_media exist', () => {
|
|
20
|
+
const fareMediaId = 'fake-fare-media-id';
|
|
21
|
+
const results = getFareMedia({
|
|
22
|
+
fare_media_id: fareMediaId,
|
|
23
|
+
});
|
|
24
|
+
should.exists(results);
|
|
25
|
+
results.should.have.length(0);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import should from 'should';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { openDb, closeDb, importGtfs, getNetworks } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
describe('getNetworks():', () => {
|
|
9
|
+
before(async () => {
|
|
10
|
+
openDb(config);
|
|
11
|
+
await importGtfs(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
after(() => {
|
|
15
|
+
const db = openDb(config);
|
|
16
|
+
closeDb(db);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return empty array if no networks', () => {
|
|
20
|
+
const networkId = 'not_real';
|
|
21
|
+
|
|
22
|
+
const results = getNetworks({
|
|
23
|
+
network_id: networkId,
|
|
24
|
+
});
|
|
25
|
+
should.exists(results);
|
|
26
|
+
results.should.have.length(0);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import should from 'should';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { openDb, closeDb, importGtfs, getRouteNetworks } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
describe('getRouteNetworks():', () => {
|
|
9
|
+
before(async () => {
|
|
10
|
+
openDb(config);
|
|
11
|
+
await importGtfs(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
after(() => {
|
|
15
|
+
const db = openDb(config);
|
|
16
|
+
closeDb(db);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return empty array if no route_networks', () => {
|
|
20
|
+
const networkId = 'not_real';
|
|
21
|
+
|
|
22
|
+
const results = getRouteNetworks({
|
|
23
|
+
network_id: networkId,
|
|
24
|
+
});
|
|
25
|
+
should.exists(results);
|
|
26
|
+
results.should.have.length(0);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-env mocha */
|
|
2
|
+
|
|
3
|
+
import should from 'should';
|
|
4
|
+
|
|
5
|
+
import config from '../test-config.js';
|
|
6
|
+
import { openDb, closeDb, importGtfs, getTimeframes } from '../../index.js';
|
|
7
|
+
|
|
8
|
+
describe('getTimeframes():', () => {
|
|
9
|
+
before(async () => {
|
|
10
|
+
openDb(config);
|
|
11
|
+
await importGtfs(config);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
after(() => {
|
|
15
|
+
const db = openDb(config);
|
|
16
|
+
closeDb(db);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('should return empty array if no timeframes', () => {
|
|
20
|
+
const timeframeGroupId = 'not_real';
|
|
21
|
+
|
|
22
|
+
const results = getTimeframes({
|
|
23
|
+
timeframe_group_id: timeframeGroupId,
|
|
24
|
+
});
|
|
25
|
+
should.exists(results);
|
|
26
|
+
results.should.have.length(0);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { createReadStream, existsSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
6
|
import { parse } from 'csv-parse';
|
|
8
7
|
import should from 'should';
|
|
9
8
|
|
|
@@ -28,10 +27,7 @@ const agenciesFixturesRemote = [
|
|
|
28
27
|
|
|
29
28
|
const agenciesFixturesLocal = [
|
|
30
29
|
{
|
|
31
|
-
path: path.join(
|
|
32
|
-
path.dirname(fileURLToPath(import.meta.url)),
|
|
33
|
-
'../fixture/caltrain_20160406.zip',
|
|
34
|
-
),
|
|
30
|
+
path: path.join(import.meta.dirname, '../fixture/caltrain_20160406.zip'),
|
|
35
31
|
},
|
|
36
32
|
];
|
|
37
33
|
|
|
@@ -115,10 +111,7 @@ describe('importGtfs():', function () {
|
|
|
115
111
|
|
|
116
112
|
describe('Verify data imported into database', () => {
|
|
117
113
|
const countData = {};
|
|
118
|
-
const temporaryDir = path.join(
|
|
119
|
-
path.dirname(fileURLToPath(import.meta.url)),
|
|
120
|
-
'../fixture/tmp/',
|
|
121
|
-
);
|
|
114
|
+
const temporaryDir = path.join(import.meta.dirname, '../fixture/tmp/');
|
|
122
115
|
|
|
123
116
|
before(async () => {
|
|
124
117
|
await prepDirectory(temporaryDir);
|
package/test/test-config.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
2
|
|
|
4
3
|
const config = {
|
|
5
4
|
agencies: [
|
|
6
5
|
{
|
|
7
|
-
path: path.join(
|
|
8
|
-
path.dirname(fileURLToPath(import.meta.url)),
|
|
9
|
-
'fixture/caltrain_20160406.zip'
|
|
10
|
-
),
|
|
6
|
+
path: path.join(import.meta.dirname, 'fixture/caltrain_20160406.zip'),
|
|
11
7
|
},
|
|
12
8
|
],
|
|
13
9
|
verbose: false,
|