gtfs 4.13.4 → 4.14.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 +36 -20
- package/dist/bin/gtfs-export.js +4 -8
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +93 -66
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +89 -197
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +325 -43
- package/dist/index.js +116 -88
- package/dist/index.js.map +1 -1
- package/dist/models/models.d.ts +0 -8
- package/dist/models/models.js +0 -5
- package/dist/models/models.js.map +1 -1
- package/package.json +8 -8
package/dist/bin/gtfs-import.js
CHANGED
|
@@ -765,11 +765,6 @@ var fareTransferRules = {
|
|
|
765
765
|
min: -1,
|
|
766
766
|
primary: true
|
|
767
767
|
},
|
|
768
|
-
{
|
|
769
|
-
name: "transfer_id",
|
|
770
|
-
type: "text",
|
|
771
|
-
prefix: true
|
|
772
|
-
},
|
|
773
768
|
{
|
|
774
769
|
name: "duration_limit",
|
|
775
770
|
type: "integer",
|
|
@@ -3285,6 +3280,7 @@ function closeDb(db = null) {
|
|
|
3285
3280
|
// src/lib/geojson-utils.ts
|
|
3286
3281
|
import {
|
|
3287
3282
|
cloneDeep,
|
|
3283
|
+
compact,
|
|
3288
3284
|
filter,
|
|
3289
3285
|
groupBy,
|
|
3290
3286
|
last,
|
|
@@ -3350,31 +3346,34 @@ function padLeadingZeros(time) {
|
|
|
3350
3346
|
|
|
3351
3347
|
// src/lib/import.ts
|
|
3352
3348
|
var downloadFiles = async (task) => {
|
|
3353
|
-
task.log(`Downloading GTFS from ${task.
|
|
3349
|
+
task.log(`Downloading GTFS from ${task.url}`);
|
|
3354
3350
|
task.path = `${task.downloadDir}/gtfs.zip`;
|
|
3355
|
-
const response = await fetch(task.
|
|
3351
|
+
const response = await fetch(task.url, {
|
|
3356
3352
|
method: "GET",
|
|
3357
3353
|
headers: task.headers || {},
|
|
3358
3354
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3359
3355
|
});
|
|
3360
3356
|
if (response.status !== 200) {
|
|
3361
|
-
throw new Error(`Unable to download GTFS from ${task.
|
|
3357
|
+
throw new Error(`Unable to download GTFS from ${task.url}`);
|
|
3362
3358
|
}
|
|
3363
3359
|
const buffer = await response.arrayBuffer();
|
|
3364
3360
|
await writeFile(task.path, Buffer.from(buffer));
|
|
3365
3361
|
task.log("Download successful");
|
|
3366
3362
|
};
|
|
3367
|
-
var downloadGtfsRealtimeData = async (
|
|
3368
|
-
|
|
3363
|
+
var downloadGtfsRealtimeData = async (urlAndHeaders, task) => {
|
|
3364
|
+
task.log(`Downloading GTFS-Realtime from ${urlAndHeaders.url}`);
|
|
3365
|
+
const response = await fetch(urlAndHeaders.url, {
|
|
3369
3366
|
method: "GET",
|
|
3370
3367
|
headers: {
|
|
3371
|
-
...
|
|
3368
|
+
...urlAndHeaders.headers ?? {},
|
|
3372
3369
|
"Accept-Encoding": "gzip"
|
|
3373
3370
|
},
|
|
3374
3371
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3375
3372
|
});
|
|
3376
3373
|
if (response.status !== 200) {
|
|
3377
|
-
task.logWarning(
|
|
3374
|
+
task.logWarning(
|
|
3375
|
+
`Unable to download GTFS-Realtime from ${urlAndHeaders.url}`
|
|
3376
|
+
);
|
|
3378
3377
|
return null;
|
|
3379
3378
|
}
|
|
3380
3379
|
const buffer = await response.arrayBuffer();
|
|
@@ -3434,48 +3433,70 @@ var prepareRealtimeValue = (entity, column, task) => {
|
|
|
3434
3433
|
);
|
|
3435
3434
|
};
|
|
3436
3435
|
var updateRealtimeData = async (task) => {
|
|
3437
|
-
if (
|
|
3436
|
+
if (task.realtimeAlerts === void 0 && task.realtimeTripUpdates === void 0 && task.realtimeVehiclePositions === void 0) {
|
|
3438
3437
|
return;
|
|
3439
3438
|
}
|
|
3440
3439
|
const db = openDb({
|
|
3441
3440
|
sqlitePath: task.sqlitePath
|
|
3442
3441
|
});
|
|
3443
|
-
task.
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3442
|
+
if (task.realtimeAlerts?.url) {
|
|
3443
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3444
|
+
task.realtimeAlerts,
|
|
3445
|
+
task
|
|
3446
|
+
);
|
|
3447
|
+
if (gtfsRealtimeData?.entity) {
|
|
3448
|
+
task.log(`Download successful`);
|
|
3449
|
+
let totalLineCount = 0;
|
|
3450
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3451
|
+
const fieldValues = serviceAlerts.schema.map(
|
|
3452
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3453
|
+
);
|
|
3454
|
+
try {
|
|
3455
|
+
db.prepare(
|
|
3456
|
+
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3457
|
+
).run();
|
|
3458
|
+
} catch (error) {
|
|
3459
|
+
task.logWarning("Import error: " + error.message);
|
|
3460
|
+
}
|
|
3461
|
+
const alertTargetArray = [];
|
|
3462
|
+
for (const informedEntity of entity.alert.informedEntity) {
|
|
3463
|
+
informedEntity.parent = entity;
|
|
3464
|
+
const subValues = serviceAlertTargets.schema.map(
|
|
3465
|
+
(column) => prepareRealtimeValue(informedEntity, column, task)
|
|
3466
|
+
);
|
|
3467
|
+
alertTargetArray.push(`(${subValues.join(", ")})`);
|
|
3468
|
+
totalLineCount++;
|
|
3469
|
+
}
|
|
3470
|
+
try {
|
|
3471
|
+
db.prepare(
|
|
3472
|
+
`REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
|
|
3473
|
+
).run();
|
|
3474
|
+
} catch (error) {
|
|
3475
|
+
task.logWarning("Import error: " + error.message);
|
|
3476
|
+
}
|
|
3477
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3477
3478
|
}
|
|
3478
|
-
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
if (task.realtimeTripUpdates?.url) {
|
|
3482
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3483
|
+
task.realtimeTripUpdates,
|
|
3484
|
+
task
|
|
3485
|
+
);
|
|
3486
|
+
if (gtfsRealtimeData?.entity) {
|
|
3487
|
+
task.log(`Download successful`);
|
|
3488
|
+
let totalLineCount = 0;
|
|
3489
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3490
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3491
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3492
|
+
);
|
|
3493
|
+
try {
|
|
3494
|
+
db.prepare(
|
|
3495
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3496
|
+
).run();
|
|
3497
|
+
} catch (error) {
|
|
3498
|
+
task.logWarning("Import error: " + error.message);
|
|
3499
|
+
}
|
|
3479
3500
|
const stopTimeUpdateArray = [];
|
|
3480
3501
|
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
3481
3502
|
stopTimeUpdate.parent = entity;
|
|
@@ -3492,26 +3513,31 @@ var updateRealtimeData = async (task) => {
|
|
|
3492
3513
|
} catch (error) {
|
|
3493
3514
|
task.logWarning("Import error: " + error.message);
|
|
3494
3515
|
}
|
|
3516
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3495
3517
|
}
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
if (task.realtimeVehiclePositions?.url) {
|
|
3521
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3522
|
+
task.realtimeVehiclePositions,
|
|
3523
|
+
task
|
|
3524
|
+
);
|
|
3525
|
+
if (gtfsRealtimeData?.entity) {
|
|
3526
|
+
task.log(`Download successful`);
|
|
3527
|
+
let totalLineCount = 0;
|
|
3528
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3529
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3530
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3531
|
+
);
|
|
3506
3532
|
try {
|
|
3507
3533
|
db.prepare(
|
|
3508
|
-
`REPLACE INTO ${
|
|
3534
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3509
3535
|
).run();
|
|
3510
3536
|
} catch (error) {
|
|
3511
3537
|
task.logWarning("Import error: " + error.message);
|
|
3512
3538
|
}
|
|
3539
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3513
3540
|
}
|
|
3514
|
-
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3515
3541
|
}
|
|
3516
3542
|
}
|
|
3517
3543
|
task.log(`GTFS-Realtime data import complete`);
|
|
@@ -3823,10 +3849,11 @@ async function importGtfs(initialConfig) {
|
|
|
3823
3849
|
const tempPath = temporaryDirectory();
|
|
3824
3850
|
const task = {
|
|
3825
3851
|
exclude: agency2.exclude,
|
|
3826
|
-
|
|
3852
|
+
url: agency2.url,
|
|
3827
3853
|
headers: agency2.headers,
|
|
3828
|
-
|
|
3829
|
-
|
|
3854
|
+
realtimeAlerts: agency2.realtimeAlerts,
|
|
3855
|
+
realtimeTripUpdates: agency2.realtimeTripUpdates,
|
|
3856
|
+
realtimeVehiclePositions: agency2.realtimeVehiclePositions,
|
|
3830
3857
|
downloadDir: tempPath,
|
|
3831
3858
|
downloadTimeout: config.downloadTimeout,
|
|
3832
3859
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
@@ -3841,7 +3868,7 @@ async function importGtfs(initialConfig) {
|
|
|
3841
3868
|
logError: logError2
|
|
3842
3869
|
};
|
|
3843
3870
|
try {
|
|
3844
|
-
if (task.
|
|
3871
|
+
if (task.url) {
|
|
3845
3872
|
await downloadFiles(task);
|
|
3846
3873
|
}
|
|
3847
3874
|
await readFiles(task);
|
|
@@ -3872,7 +3899,7 @@ async function importGtfs(initialConfig) {
|
|
|
3872
3899
|
}
|
|
3873
3900
|
|
|
3874
3901
|
// src/lib/export.ts
|
|
3875
|
-
import { without, compact } from "lodash-es";
|
|
3902
|
+
import { without, compact as compact2 } from "lodash-es";
|
|
3876
3903
|
import pluralize2 from "pluralize";
|
|
3877
3904
|
import { stringify } from "csv-stringify";
|
|
3878
3905
|
import sqlString3 from "sqlstring-sqlite";
|
|
@@ -3886,7 +3913,7 @@ import sqlString4 from "sqlstring-sqlite";
|
|
|
3886
3913
|
import { omit as omit3, pick } from "lodash-es";
|
|
3887
3914
|
|
|
3888
3915
|
// src/lib/gtfs/shapes.ts
|
|
3889
|
-
import { compact as
|
|
3916
|
+
import { compact as compact3, omit as omit4, pick as pick2 } from "lodash-es";
|
|
3890
3917
|
import { featureCollection as featureCollection2 } from "@turf/helpers";
|
|
3891
3918
|
|
|
3892
3919
|
// src/lib/gtfs/stops.ts
|