gtfs 4.12.0 → 4.13.1
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/README.md +27 -5
- package/dist/bin/gtfs-export.d.ts +1 -0
- package/dist/bin/gtfs-export.js +3645 -0
- package/dist/bin/gtfs-export.js.map +1 -0
- package/dist/bin/gtfs-import.d.ts +1 -0
- package/dist/bin/gtfs-import.js +4143 -0
- package/dist/bin/gtfs-import.js.map +1 -0
- package/dist/bin/gtfsrealtime-update.d.ts +1 -0
- package/dist/bin/gtfsrealtime-update.js +3800 -0
- package/dist/bin/gtfsrealtime-update.js.map +1 -0
- package/dist/index.d.ts +172 -0
- package/dist/index.js +5202 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -12
- package/.eslintrc.json +0 -28
- package/.github/workflows/nodejs.yml +0 -21
- package/.husky/pre-commit +0 -4
- package/@types/index.d.ts +0 -606
- package/@types/tests.ts +0 -31
- package/@types/tsconfig.json +0 -17
- package/CHANGELOG.md +0 -905
- package/bin/gtfs-export.js +0 -42
- package/bin/gtfs-import.js +0 -52
- package/bin/gtfsrealtime-update.js +0 -35
- package/config-sample-full.json +0 -20
- package/config-sample-rtupdates.json +0 -16
- package/config-sample.json +0 -8
- package/docs/images/node-gtfs-logo.svg +0 -18
- package/index.js +0 -1
- package/lib/advancedQuery.js +0 -36
- package/lib/db.js +0 -92
- package/lib/export.js +0 -141
- package/lib/file-utils.js +0 -103
- package/lib/geojson-utils.js +0 -138
- package/lib/gtfs/agencies.js +0 -32
- package/lib/gtfs/areas.js +0 -27
- package/lib/gtfs/attributions.js +0 -32
- package/lib/gtfs/booking-rules.js +0 -32
- package/lib/gtfs/calendar-dates.js +0 -32
- package/lib/gtfs/calendars.js +0 -32
- package/lib/gtfs/fare-attributes.js +0 -32
- package/lib/gtfs/fare-leg-rules.js +0 -32
- package/lib/gtfs/fare-media.js +0 -32
- package/lib/gtfs/fare-products.js +0 -32
- package/lib/gtfs/fare-rules.js +0 -32
- package/lib/gtfs/fare-transfer-rules.js +0 -32
- package/lib/gtfs/feed-info.js +0 -32
- package/lib/gtfs/frequencies.js +0 -32
- package/lib/gtfs/levels.js +0 -27
- package/lib/gtfs/location-group-stops.js +0 -32
- package/lib/gtfs/location-groups.js +0 -32
- package/lib/gtfs/locations.js +0 -32
- package/lib/gtfs/networks.js +0 -32
- package/lib/gtfs/pathways.js +0 -32
- package/lib/gtfs/route-networks.js +0 -32
- package/lib/gtfs/routes.js +0 -72
- package/lib/gtfs/shapes.js +0 -119
- package/lib/gtfs/stop-areas.js +0 -32
- package/lib/gtfs/stop-times.js +0 -32
- package/lib/gtfs/stops.js +0 -136
- package/lib/gtfs/timeframes.js +0 -32
- package/lib/gtfs/transfers.js +0 -32
- package/lib/gtfs/translations.js +0 -32
- package/lib/gtfs/trips.js +0 -27
- package/lib/gtfs-plus/calendar-attributes.js +0 -32
- package/lib/gtfs-plus/directions.js +0 -32
- package/lib/gtfs-plus/route-attributes.js +0 -32
- package/lib/gtfs-plus/stop-attributes.js +0 -32
- package/lib/gtfs-realtime/service-alerts.js +0 -34
- package/lib/gtfs-realtime/stop-time-updates.js +0 -32
- package/lib/gtfs-realtime/trip-updates.js +0 -32
- package/lib/gtfs-realtime/vehicle-positions.js +0 -32
- package/lib/gtfs-ride/board-alights.js +0 -32
- package/lib/gtfs-ride/ride-feed-infos.js +0 -32
- package/lib/gtfs-ride/rider-trips.js +0 -32
- package/lib/gtfs-ride/riderships.js +0 -32
- package/lib/gtfs-ride/trip-capacities.js +0 -32
- package/lib/gtfs.js +0 -261
- package/lib/import.js +0 -803
- package/lib/log-utils.js +0 -73
- package/lib/non-standard/timetable-notes-references.js +0 -32
- package/lib/non-standard/timetable-notes.js +0 -32
- package/lib/non-standard/timetable-pages.js +0 -32
- package/lib/non-standard/timetable-stop-order.js +0 -32
- package/lib/non-standard/timetables.js +0 -32
- package/lib/non-standard/trips-dated-vehicle-journey.js +0 -32
- package/lib/ods/deadhead-times.js +0 -32
- package/lib/ods/deadheads.js +0 -32
- package/lib/ods/ops-locations.js +0 -32
- package/lib/ods/run-events.js +0 -32
- package/lib/ods/runs-pieces.js +0 -32
- package/lib/utils.js +0 -178
- package/models/gtfs/agency.js +0 -49
- package/models/gtfs/areas.js +0 -19
- package/models/gtfs/attributions.js +0 -68
- package/models/gtfs/booking-rules.js +0 -92
- package/models/gtfs/calendar-dates.js +0 -34
- package/models/gtfs/calendar.js +0 -76
- package/models/gtfs/fare-attributes.js +0 -48
- package/models/gtfs/fare-leg-rules.js +0 -55
- package/models/gtfs/fare-media.js +0 -26
- package/models/gtfs/fare-products.js +0 -35
- package/models/gtfs/fare-rules.js +0 -34
- package/models/gtfs/fare-transfer-rules.js +0 -56
- package/models/gtfs/feed-info.js +0 -50
- package/models/gtfs/frequencies.js +0 -46
- package/models/gtfs/levels.js +0 -25
- package/models/gtfs/location-group-stops.js +0 -22
- package/models/gtfs/location-groups.js +0 -19
- package/models/gtfs/locations.js +0 -12
- package/models/gtfs/networks.js +0 -20
- package/models/gtfs/pathways.js +0 -74
- package/models/gtfs/route-networks.js +0 -21
- package/models/gtfs/routes.js +0 -79
- package/models/gtfs/shapes.js +0 -41
- package/models/gtfs/stop-areas.js +0 -20
- package/models/gtfs/stop-times.js +0 -120
- package/models/gtfs/stops.js +0 -85
- package/models/gtfs/timeframes.js +0 -29
- package/models/gtfs/transfers.js +0 -56
- package/models/gtfs/translations.js +0 -48
- package/models/gtfs/trips.js +0 -70
- package/models/gtfs-plus/calendar-attributes.js +0 -22
- package/models/gtfs-plus/directions.js +0 -29
- package/models/gtfs-plus/route-attributes.js +0 -34
- package/models/gtfs-plus/stop-attributes.js +0 -35
- package/models/gtfs-realtime/service-alert-targets.js +0 -37
- package/models/gtfs-realtime/service-alerts.js +0 -60
- package/models/gtfs-realtime/stop-time-updates.js +0 -85
- package/models/gtfs-realtime/trip-updates.js +0 -75
- package/models/gtfs-realtime/vehicle-positions.js +0 -135
- package/models/gtfs-ride/board-alight.js +0 -132
- package/models/gtfs-ride/ride-feed-info.js +0 -40
- package/models/gtfs-ride/rider-trip.js +0 -113
- package/models/gtfs-ride/ridership.js +0 -127
- package/models/gtfs-ride/trip-capacity.js +0 -51
- package/models/models.js +0 -120
- package/models/non-standard/timetable-notes-references.js +0 -50
- package/models/non-standard/timetable-notes.js +0 -24
- package/models/non-standard/timetable-pages.js +0 -23
- package/models/non-standard/timetable-stop-order.js +0 -32
- package/models/non-standard/timetables.js +0 -144
- package/models/non-standard/trips-dated-vehicle-journey.js +0 -34
- package/models/ods/deadhead-times.js +0 -65
- package/models/ods/deadheads.js +0 -60
- package/models/ods/ops-locations.js +0 -46
- package/models/ods/run-events.js +0 -70
- package/models/ods/runs-pieces.js +0 -59
- package/test/fixture/caltrain_20160406.zip +0 -0
- package/test/mocha/advanced-query.js +0 -74
- package/test/mocha/delete-db.js +0 -62
- package/test/mocha/export-gtfs.js +0 -147
- package/test/mocha/fare-transfer-rules.js +0 -32
- package/test/mocha/get-agencies.js +0 -90
- package/test/mocha/get-areas.js +0 -27
- package/test/mocha/get-attributions.js +0 -27
- package/test/mocha/get-board-alights.js +0 -28
- package/test/mocha/get-booking-rules.js +0 -28
- package/test/mocha/get-calendar-attributes.js +0 -33
- package/test/mocha/get-calendar-dates.js +0 -107
- package/test/mocha/get-calendars.js +0 -94
- package/test/mocha/get-directions.js +0 -28
- package/test/mocha/get-fare-attributes.js +0 -51
- package/test/mocha/get-fare-leg-rules.js +0 -27
- package/test/mocha/get-fare-media.js +0 -27
- package/test/mocha/get-fare-products.js +0 -27
- package/test/mocha/get-fare-rules.js +0 -50
- package/test/mocha/get-feed-info.js +0 -28
- package/test/mocha/get-frequencies.js +0 -28
- package/test/mocha/get-levels.js +0 -28
- package/test/mocha/get-location-group-stops.js +0 -33
- package/test/mocha/get-location-groups.js +0 -28
- package/test/mocha/get-locations.js +0 -69
- package/test/mocha/get-networks.js +0 -28
- package/test/mocha/get-pathways.js +0 -28
- package/test/mocha/get-ride-feed-infos.js +0 -24
- package/test/mocha/get-rider-trips.js +0 -28
- package/test/mocha/get-riderships.js +0 -28
- package/test/mocha/get-route-attributes.js +0 -33
- package/test/mocha/get-route-networks.js +0 -28
- package/test/mocha/get-routes.js +0 -143
- package/test/mocha/get-shapes-as-geojson.js +0 -92
- package/test/mocha/get-shapes.js +0 -240
- package/test/mocha/get-stop-attributes.js +0 -28
- package/test/mocha/get-stops-as-geojson.js +0 -87
- package/test/mocha/get-stops.js +0 -343
- package/test/mocha/get-stoptimes.js +0 -67
- package/test/mocha/get-timeframes.js +0 -28
- package/test/mocha/get-timetable-pages.js +0 -28
- package/test/mocha/get-timetable-stop-orders.js +0 -33
- package/test/mocha/get-timetables.js +0 -28
- package/test/mocha/get-transfers.js +0 -28
- package/test/mocha/get-translations.js +0 -28
- package/test/mocha/get-trip-capacities.js +0 -28
- package/test/mocha/get-trips.js +0 -53
- package/test/mocha/import-gtfs.js +0 -173
- package/test/mocha/open-db.js +0 -149
- package/test/mocha/raw-query.js +0 -34
- package/test/test-config.js +0 -12
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getStoptimes } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getStoptimes():', () => {
|
|
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 an empty array if no stoptimes exist for given agency', () => {
|
|
20
|
-
const stopId = 'fake-stop-id';
|
|
21
|
-
|
|
22
|
-
const results = getStoptimes({
|
|
23
|
-
stop_id: stopId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return array of stoptimes for given stop_id', () => {
|
|
30
|
-
const stopId = '70011';
|
|
31
|
-
|
|
32
|
-
const results = getStoptimes({
|
|
33
|
-
stop_id: stopId,
|
|
34
|
-
});
|
|
35
|
-
should.exist(results);
|
|
36
|
-
results.should.have.length(80);
|
|
37
|
-
|
|
38
|
-
for (const result of results) {
|
|
39
|
-
result.stop_id.should.equal(stopId);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return array of stoptimes for given trip_id ordered by stop_sequence', () => {
|
|
44
|
-
const tripId = '421a';
|
|
45
|
-
|
|
46
|
-
const results = getStoptimes(
|
|
47
|
-
{
|
|
48
|
-
trip_id: tripId,
|
|
49
|
-
},
|
|
50
|
-
[],
|
|
51
|
-
[['stop_sequence', 'ASC']],
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
should.exist(results);
|
|
55
|
-
results.should.have.length(24);
|
|
56
|
-
|
|
57
|
-
let lastStopSequence;
|
|
58
|
-
for (const result of results) {
|
|
59
|
-
result.trip_id.should.equal(tripId);
|
|
60
|
-
if (lastStopSequence !== undefined) {
|
|
61
|
-
result.stop_sequence.should.be.greaterThan(lastStopSequence);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
lastStopSequence = result.stop_sequence;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTimetablePages } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTimetablePages():', () => {
|
|
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 timetable pages (GTFS-to-HTML timetables)', () => {
|
|
20
|
-
const timetablePageId = 'fake-timetable-page-id';
|
|
21
|
-
|
|
22
|
-
const results = getTimetablePages({
|
|
23
|
-
timetable_page_id: timetablePageId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import {
|
|
7
|
-
openDb,
|
|
8
|
-
closeDb,
|
|
9
|
-
importGtfs,
|
|
10
|
-
getTimetableStopOrders,
|
|
11
|
-
} from '../../index.js';
|
|
12
|
-
|
|
13
|
-
describe('getTimetableStopOrders():', () => {
|
|
14
|
-
before(async () => {
|
|
15
|
-
openDb(config);
|
|
16
|
-
await importGtfs(config);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
after(() => {
|
|
20
|
-
const db = openDb(config);
|
|
21
|
-
closeDb(db);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should return empty array if no timetable stop orders (GTFS-to-HTML timetables)', () => {
|
|
25
|
-
const timetableId = 'fake-timetable-id';
|
|
26
|
-
|
|
27
|
-
const results = getTimetableStopOrders({
|
|
28
|
-
timetable_id: timetableId,
|
|
29
|
-
});
|
|
30
|
-
should.exists(results);
|
|
31
|
-
results.should.have.length(0);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTimetables } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTimetables():', () => {
|
|
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 timetables (GTFS-to-HTML timetables)', () => {
|
|
20
|
-
const timetableId = 'fake-timetable-id';
|
|
21
|
-
|
|
22
|
-
const results = getTimetables({
|
|
23
|
-
timetable_id: timetableId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTransfers } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTransfers():', () => {
|
|
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 transfers', () => {
|
|
20
|
-
const fromStopId = 'fake-stop-id';
|
|
21
|
-
|
|
22
|
-
const results = getTransfers({
|
|
23
|
-
from_stop_id: fromStopId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTranslations } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTranslations():', () => {
|
|
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 translations', () => {
|
|
20
|
-
const fieldName = 'fake-field-name';
|
|
21
|
-
|
|
22
|
-
const results = getTranslations({
|
|
23
|
-
field_name: fieldName,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTripCapacities } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTripCapacities():', () => {
|
|
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 trip capacities (GTFS-ride)', () => {
|
|
20
|
-
const tripId = 'fake-trip-id';
|
|
21
|
-
|
|
22
|
-
const results = getTripCapacities({
|
|
23
|
-
trip_id: tripId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
});
|
package/test/mocha/get-trips.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs, getTrips } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('getTrips():', () => {
|
|
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 trips exist', () => {
|
|
20
|
-
const tripId = 'fake-trip-id';
|
|
21
|
-
|
|
22
|
-
const results = getTrips({
|
|
23
|
-
trip_id: tripId,
|
|
24
|
-
});
|
|
25
|
-
should.exists(results);
|
|
26
|
-
results.should.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should return expected trips', () => {
|
|
30
|
-
const routeId = 'Bu-16APR';
|
|
31
|
-
|
|
32
|
-
const results = getTrips({
|
|
33
|
-
route_id: routeId,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const expectedResult = {
|
|
37
|
-
trip_id: '329',
|
|
38
|
-
route_id: 'Bu-16APR',
|
|
39
|
-
service_id: 'CT-16APR-Caltrain-Weekday-01',
|
|
40
|
-
trip_headsign: 'SAN FRANCISCO STATION',
|
|
41
|
-
trip_short_name: '329',
|
|
42
|
-
direction_id: 0,
|
|
43
|
-
block_id: null,
|
|
44
|
-
shape_id: 'cal_tam_sf',
|
|
45
|
-
wheelchair_accessible: 1,
|
|
46
|
-
bikes_allowed: 1,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
should.exists(results);
|
|
50
|
-
results.length.should.equal(30);
|
|
51
|
-
results.should.containEql(expectedResult);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
/* eslint-disable max-nested-callbacks */
|
|
3
|
-
|
|
4
|
-
import { createReadStream, existsSync } from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import { parse } from 'csv-parse';
|
|
7
|
-
import should from 'should';
|
|
8
|
-
|
|
9
|
-
import { prepDirectory, unzip } from '../../lib/file-utils.js';
|
|
10
|
-
import config from '../test-config.js';
|
|
11
|
-
import {
|
|
12
|
-
openDb,
|
|
13
|
-
closeDb,
|
|
14
|
-
importGtfs,
|
|
15
|
-
getRoutes,
|
|
16
|
-
getStops,
|
|
17
|
-
} from '../../index.js';
|
|
18
|
-
import models from '../../models/models.js';
|
|
19
|
-
|
|
20
|
-
let db;
|
|
21
|
-
|
|
22
|
-
const agenciesFixturesRemote = [
|
|
23
|
-
{
|
|
24
|
-
url: 'http://transitfeeds.com/p/caltrain/122/20160406/download',
|
|
25
|
-
},
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
const agenciesFixturesLocal = [
|
|
29
|
-
{
|
|
30
|
-
path: path.join(import.meta.dirname, '../fixture/caltrain_20160406.zip'),
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
describe('importGtfs():', function () {
|
|
35
|
-
before(() => {
|
|
36
|
-
db = openDb(config);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
after(() => {
|
|
40
|
-
const db = openDb(config);
|
|
41
|
-
closeDb(db);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
this.timeout(10000);
|
|
45
|
-
describe('Download and import from different GTFS sources', () => {
|
|
46
|
-
it('should be able to download and import from HTTP', async () => {
|
|
47
|
-
await importGtfs({
|
|
48
|
-
...config,
|
|
49
|
-
agencies: agenciesFixturesRemote,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const routes = getRoutes();
|
|
53
|
-
should.exist(routes);
|
|
54
|
-
routes.length.should.equal(4);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should be able to download and import from HTTP with a downloadTimeout', async () => {
|
|
58
|
-
try {
|
|
59
|
-
await importGtfs({
|
|
60
|
-
...config,
|
|
61
|
-
agencies: agenciesFixturesRemote,
|
|
62
|
-
downloadTimeout: 1,
|
|
63
|
-
});
|
|
64
|
-
} catch (error) {
|
|
65
|
-
error.name.should.equal('AbortError');
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should be able to download and import from local filesystem', async () => {
|
|
70
|
-
await importGtfs({
|
|
71
|
-
...config,
|
|
72
|
-
agencies: agenciesFixturesLocal,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const routes = getRoutes();
|
|
76
|
-
should.exist(routes);
|
|
77
|
-
routes.length.should.equal(4);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should throw an error when importing from local filesystem which doesn't exist", async () =>
|
|
81
|
-
importGtfs({
|
|
82
|
-
...config,
|
|
83
|
-
agencies: [
|
|
84
|
-
{
|
|
85
|
-
path: '/does/not/exist',
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
}).should.be.rejected());
|
|
89
|
-
|
|
90
|
-
it('should add a prefix to imported data if present in config', async () => {
|
|
91
|
-
const prefix = 'test-prefix';
|
|
92
|
-
await importGtfs({
|
|
93
|
-
...config,
|
|
94
|
-
agencies: [
|
|
95
|
-
{
|
|
96
|
-
...agenciesFixturesLocal[0],
|
|
97
|
-
prefix,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const routes = getRoutes();
|
|
103
|
-
should.exist(routes);
|
|
104
|
-
routes[0].route_id.should.startWith(prefix);
|
|
105
|
-
|
|
106
|
-
const stops = getStops();
|
|
107
|
-
should.exist(stops);
|
|
108
|
-
stops[0].stop_id.should.startWith(prefix);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('Verify data imported into database', () => {
|
|
113
|
-
const countData = {};
|
|
114
|
-
const temporaryDir = path.join(import.meta.dirname, '../fixture/tmp/');
|
|
115
|
-
|
|
116
|
-
before(async () => {
|
|
117
|
-
await prepDirectory(temporaryDir);
|
|
118
|
-
await unzip(agenciesFixturesLocal[0].path, temporaryDir);
|
|
119
|
-
|
|
120
|
-
await Promise.all(
|
|
121
|
-
models.map((model) => {
|
|
122
|
-
const filePath = path.join(
|
|
123
|
-
temporaryDir,
|
|
124
|
-
`${model.filenameBase}.${model.filenameExtension}`,
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
// GTFS has optional files
|
|
128
|
-
if (!existsSync(filePath)) {
|
|
129
|
-
countData[model.filenameBase] = 0;
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const parser = parse(
|
|
134
|
-
{
|
|
135
|
-
columns: true,
|
|
136
|
-
relax_quotes: true,
|
|
137
|
-
trim: true,
|
|
138
|
-
skip_empty_lines: true,
|
|
139
|
-
},
|
|
140
|
-
(error, data) => {
|
|
141
|
-
if (error) {
|
|
142
|
-
throw new Error(error);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
countData[model.filenameBase] = data.length;
|
|
146
|
-
},
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
return createReadStream(filePath)
|
|
150
|
-
.pipe(parser)
|
|
151
|
-
.on('error', (error) => {
|
|
152
|
-
countData[model.collection] = 0;
|
|
153
|
-
throw new Error(error);
|
|
154
|
-
});
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
await importGtfs({
|
|
159
|
-
...config,
|
|
160
|
-
agencies: agenciesFixturesLocal,
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
for (const model of models) {
|
|
165
|
-
it(`should import the same number of ${model.filenameBase}`, async () => {
|
|
166
|
-
const result = await db
|
|
167
|
-
.prepare(`SELECT COUNT(*) FROM ${model.filenameBase};`)
|
|
168
|
-
.get();
|
|
169
|
-
result['COUNT(*)'].should.equal(countData[model.filenameBase]);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
package/test/mocha/open-db.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
|
|
6
|
-
import config from '../test-config.js';
|
|
7
|
-
import { openDb, closeDb, importGtfs, getShapes } from '../../index.js';
|
|
8
|
-
|
|
9
|
-
const db2Config = {
|
|
10
|
-
agencies: [
|
|
11
|
-
{
|
|
12
|
-
...config.agencies[0],
|
|
13
|
-
exclude: ['shapes'],
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
verbose: false,
|
|
17
|
-
sqlitePath: './tmpdb2',
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const db3Config = {
|
|
21
|
-
agencies: [
|
|
22
|
-
{
|
|
23
|
-
...config.agencies[0],
|
|
24
|
-
exclude: ['shapes'],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
verbose: false,
|
|
28
|
-
sqlitePath: './tmpdb3',
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('openDb():', () => {
|
|
32
|
-
before(async () => {
|
|
33
|
-
openDb(config);
|
|
34
|
-
await importGtfs(config);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
after(() => {
|
|
38
|
-
const db = openDb(config);
|
|
39
|
-
closeDb(db);
|
|
40
|
-
|
|
41
|
-
// Close db2 and then delete it
|
|
42
|
-
const db2 = openDb(db2Config);
|
|
43
|
-
closeDb(db2);
|
|
44
|
-
fs.unlinkSync(db2Config.sqlitePath);
|
|
45
|
-
|
|
46
|
-
// Close db3 and then delete it
|
|
47
|
-
const db3 = openDb(db3Config);
|
|
48
|
-
closeDb(db3);
|
|
49
|
-
fs.unlinkSync(db3Config.sqlitePath);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should allow raw db queries: calendar_dates', () => {
|
|
53
|
-
const serviceIds = ['CT-16APR-Caltrain-Weekday-01'];
|
|
54
|
-
const db = openDb();
|
|
55
|
-
const results = db
|
|
56
|
-
.prepare(
|
|
57
|
-
`SELECT * FROM calendar_dates WHERE exception_type = 1 AND service_id NOT IN (${serviceIds
|
|
58
|
-
.map((serviceId) => `'${serviceId}'`)
|
|
59
|
-
.join(', ')})`,
|
|
60
|
-
)
|
|
61
|
-
.all();
|
|
62
|
-
|
|
63
|
-
should.exists(results);
|
|
64
|
-
results.should.have.length(4);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should allow raw db queries: trips', () => {
|
|
68
|
-
// Find all trips between two stop ids
|
|
69
|
-
const startStopId = '70261';
|
|
70
|
-
const endStopId = '70131';
|
|
71
|
-
const db = openDb();
|
|
72
|
-
const results = db
|
|
73
|
-
.prepare(
|
|
74
|
-
'SELECT * from trips where trips.trip_id IN (SELECT start_stop_times.trip_id FROM stop_times as start_stop_times WHERE stop_id = ? AND start_stop_times.stop_sequence < (SELECT end_stop_times.stop_sequence FROM stop_times as end_stop_times WHERE end_stop_times.stop_sequence > start_stop_times.stop_sequence AND end_stop_times.trip_id = start_stop_times.trip_id AND end_stop_times.stop_id = ? ))',
|
|
75
|
-
)
|
|
76
|
-
.all(startStopId, endStopId);
|
|
77
|
-
should.exists(results);
|
|
78
|
-
results.should.have.length(62);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should allow multiple db connections', async () => {
|
|
82
|
-
const db2 = openDb(db2Config);
|
|
83
|
-
await importGtfs(db2Config);
|
|
84
|
-
|
|
85
|
-
const db1 = openDb(config);
|
|
86
|
-
|
|
87
|
-
db1.name.should.equal(':memory:');
|
|
88
|
-
db2.name.should.equal('./tmpdb2');
|
|
89
|
-
|
|
90
|
-
// Query db1 for shapes
|
|
91
|
-
const shapeId = 'cal_sf_tam';
|
|
92
|
-
const results1 = getShapes(
|
|
93
|
-
{
|
|
94
|
-
shape_id: shapeId,
|
|
95
|
-
},
|
|
96
|
-
[],
|
|
97
|
-
[],
|
|
98
|
-
{ db: db1 },
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const expectedResult = {
|
|
102
|
-
shape_id: 'cal_sf_tam',
|
|
103
|
-
shape_pt_lat: 37.45375587083584,
|
|
104
|
-
shape_pt_lon: -122.18063950538635,
|
|
105
|
-
shape_pt_sequence: 279,
|
|
106
|
-
shape_dist_traveled: null,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
should.exist(results1);
|
|
110
|
-
results1.length.should.equal(401);
|
|
111
|
-
results1.should.containEql(expectedResult);
|
|
112
|
-
|
|
113
|
-
// Query db2 for shapes, none should exist
|
|
114
|
-
const results2 = getShapes(
|
|
115
|
-
{
|
|
116
|
-
shape_id: shapeId,
|
|
117
|
-
},
|
|
118
|
-
[],
|
|
119
|
-
[],
|
|
120
|
-
{ db: db2 },
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
should.exist(results2);
|
|
124
|
-
results2.length.should.equal(0);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should allow `db` configuration option', async () => {
|
|
128
|
-
const db3 = openDb(db3Config);
|
|
129
|
-
|
|
130
|
-
await importGtfs({
|
|
131
|
-
...db3Config,
|
|
132
|
-
db: db3,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// Query db3 for shapes, none should exist
|
|
136
|
-
const shapeId = 'cal_sf_tam';
|
|
137
|
-
const results = getShapes(
|
|
138
|
-
{
|
|
139
|
-
shape_id: shapeId,
|
|
140
|
-
},
|
|
141
|
-
[],
|
|
142
|
-
[],
|
|
143
|
-
{ db: db3 },
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
should.exist(results);
|
|
147
|
-
results.length.should.equal(0);
|
|
148
|
-
});
|
|
149
|
-
});
|
package/test/mocha/raw-query.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/* eslint-env mocha */
|
|
2
|
-
|
|
3
|
-
import should from 'should';
|
|
4
|
-
|
|
5
|
-
import config from '../test-config.js';
|
|
6
|
-
import { openDb, closeDb, importGtfs } from '../../index.js';
|
|
7
|
-
|
|
8
|
-
describe('Raw Query:', () => {
|
|
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 DELETE a trip', () => {
|
|
20
|
-
const db = openDb(config);
|
|
21
|
-
|
|
22
|
-
const results = db.prepare('SELECT count(*) FROM trips').get();
|
|
23
|
-
|
|
24
|
-
should.exists(results);
|
|
25
|
-
results['count(*)'].should.equal(218);
|
|
26
|
-
|
|
27
|
-
db.exec("DELETE FROM trips where trip_id = '329';");
|
|
28
|
-
|
|
29
|
-
const newResults = db.prepare('SELECT count(*) FROM trips').get();
|
|
30
|
-
|
|
31
|
-
should.exists(newResults);
|
|
32
|
-
newResults['count(*)'].should.equal(217);
|
|
33
|
-
});
|
|
34
|
-
});
|