gtfs 4.13.4 → 4.14.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/README.md +36 -20
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +90 -59
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +86 -195
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +20 -9
- package/dist/index.js +94 -65
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -3480,31 +3480,34 @@ function formatOrderByClause(orderBy2) {
|
|
|
3480
3480
|
|
|
3481
3481
|
// src/lib/import.ts
|
|
3482
3482
|
var downloadFiles = async (task) => {
|
|
3483
|
-
task.log(`Downloading GTFS from ${task.
|
|
3483
|
+
task.log(`Downloading GTFS from ${task.url}`);
|
|
3484
3484
|
task.path = `${task.downloadDir}/gtfs.zip`;
|
|
3485
|
-
const response = await fetch(task.
|
|
3485
|
+
const response = await fetch(task.url, {
|
|
3486
3486
|
method: "GET",
|
|
3487
3487
|
headers: task.headers || {},
|
|
3488
3488
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3489
3489
|
});
|
|
3490
3490
|
if (response.status !== 200) {
|
|
3491
|
-
throw new Error(`Unable to download GTFS from ${task.
|
|
3491
|
+
throw new Error(`Unable to download GTFS from ${task.url}`);
|
|
3492
3492
|
}
|
|
3493
3493
|
const buffer = await response.arrayBuffer();
|
|
3494
3494
|
await writeFile(task.path, Buffer.from(buffer));
|
|
3495
3495
|
task.log("Download successful");
|
|
3496
3496
|
};
|
|
3497
|
-
var downloadGtfsRealtimeData = async (
|
|
3498
|
-
|
|
3497
|
+
var downloadGtfsRealtimeData = async (urlAndHeaders, task) => {
|
|
3498
|
+
task.log(`Downloading GTFS-Realtime from ${urlAndHeaders.url}`);
|
|
3499
|
+
const response = await fetch(urlAndHeaders.url, {
|
|
3499
3500
|
method: "GET",
|
|
3500
3501
|
headers: {
|
|
3501
|
-
...
|
|
3502
|
+
...urlAndHeaders.headers ?? {},
|
|
3502
3503
|
"Accept-Encoding": "gzip"
|
|
3503
3504
|
},
|
|
3504
3505
|
signal: task.downloadTimeout ? AbortSignal.timeout(task.downloadTimeout) : void 0
|
|
3505
3506
|
});
|
|
3506
3507
|
if (response.status !== 200) {
|
|
3507
|
-
task.logWarning(
|
|
3508
|
+
task.logWarning(
|
|
3509
|
+
`Unable to download GTFS-Realtime from ${urlAndHeaders.url}`
|
|
3510
|
+
);
|
|
3508
3511
|
return null;
|
|
3509
3512
|
}
|
|
3510
3513
|
const buffer = await response.arrayBuffer();
|
|
@@ -3585,48 +3588,70 @@ var prepareRealtimeValue = (entity, column, task) => {
|
|
|
3585
3588
|
);
|
|
3586
3589
|
};
|
|
3587
3590
|
var updateRealtimeData = async (task) => {
|
|
3588
|
-
if (
|
|
3591
|
+
if (task.realtimeAlerts === void 0 && task.realtimeTripUpdates === void 0 && task.realtimeVehiclePositions === void 0) {
|
|
3589
3592
|
return;
|
|
3590
3593
|
}
|
|
3591
3594
|
const db = openDb({
|
|
3592
3595
|
sqlitePath: task.sqlitePath
|
|
3593
3596
|
});
|
|
3594
|
-
task.
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3597
|
+
if (task.realtimeAlerts?.url) {
|
|
3598
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3599
|
+
task.realtimeAlerts,
|
|
3600
|
+
task
|
|
3601
|
+
);
|
|
3602
|
+
if (gtfsRealtimeData?.entity) {
|
|
3603
|
+
task.log(`Download successful`);
|
|
3604
|
+
let totalLineCount = 0;
|
|
3605
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3606
|
+
const fieldValues = serviceAlerts.schema.map(
|
|
3607
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3608
|
+
);
|
|
3609
|
+
try {
|
|
3610
|
+
db.prepare(
|
|
3611
|
+
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3612
|
+
).run();
|
|
3613
|
+
} catch (error) {
|
|
3614
|
+
task.logWarning("Import error: " + error.message);
|
|
3615
|
+
}
|
|
3616
|
+
const alertTargetArray = [];
|
|
3617
|
+
for (const informedEntity of entity.alert.informedEntity) {
|
|
3618
|
+
informedEntity.parent = entity;
|
|
3619
|
+
const subValues = serviceAlertTargets.schema.map(
|
|
3620
|
+
(column) => prepareRealtimeValue(informedEntity, column, task)
|
|
3621
|
+
);
|
|
3622
|
+
alertTargetArray.push(`(${subValues.join(", ")})`);
|
|
3623
|
+
totalLineCount++;
|
|
3624
|
+
}
|
|
3625
|
+
try {
|
|
3626
|
+
db.prepare(
|
|
3627
|
+
`REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
|
|
3628
|
+
).run();
|
|
3629
|
+
} catch (error) {
|
|
3630
|
+
task.logWarning("Import error: " + error.message);
|
|
3631
|
+
}
|
|
3632
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3628
3633
|
}
|
|
3629
|
-
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
if (task.realtimeTripUpdates?.url) {
|
|
3637
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3638
|
+
task.realtimeTripUpdates,
|
|
3639
|
+
task
|
|
3640
|
+
);
|
|
3641
|
+
if (gtfsRealtimeData?.entity) {
|
|
3642
|
+
task.log(`Download successful`);
|
|
3643
|
+
let totalLineCount = 0;
|
|
3644
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3645
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3646
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3647
|
+
);
|
|
3648
|
+
try {
|
|
3649
|
+
db.prepare(
|
|
3650
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3651
|
+
).run();
|
|
3652
|
+
} catch (error) {
|
|
3653
|
+
task.logWarning("Import error: " + error.message);
|
|
3654
|
+
}
|
|
3630
3655
|
const stopTimeUpdateArray = [];
|
|
3631
3656
|
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
3632
3657
|
stopTimeUpdate.parent = entity;
|
|
@@ -3643,26 +3668,31 @@ var updateRealtimeData = async (task) => {
|
|
|
3643
3668
|
} catch (error) {
|
|
3644
3669
|
task.logWarning("Import error: " + error.message);
|
|
3645
3670
|
}
|
|
3671
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3646
3672
|
}
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
if (task.realtimeVehiclePositions?.url) {
|
|
3676
|
+
const gtfsRealtimeData = await downloadGtfsRealtimeData(
|
|
3677
|
+
task.realtimeVehiclePositions,
|
|
3678
|
+
task
|
|
3679
|
+
);
|
|
3680
|
+
if (gtfsRealtimeData?.entity) {
|
|
3681
|
+
task.log(`Download successful`);
|
|
3682
|
+
let totalLineCount = 0;
|
|
3683
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3684
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3685
|
+
(column) => prepareRealtimeValue(entity, column, task)
|
|
3686
|
+
);
|
|
3657
3687
|
try {
|
|
3658
3688
|
db.prepare(
|
|
3659
|
-
`REPLACE INTO ${
|
|
3689
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3660
3690
|
).run();
|
|
3661
3691
|
} catch (error) {
|
|
3662
3692
|
task.logWarning("Import error: " + error.message);
|
|
3663
3693
|
}
|
|
3694
|
+
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3664
3695
|
}
|
|
3665
|
-
task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
|
|
3666
3696
|
}
|
|
3667
3697
|
}
|
|
3668
3698
|
task.log(`GTFS-Realtime data import complete`);
|
|
@@ -3974,10 +4004,11 @@ async function importGtfs(initialConfig) {
|
|
|
3974
4004
|
const tempPath = temporaryDirectory();
|
|
3975
4005
|
const task = {
|
|
3976
4006
|
exclude: agency2.exclude,
|
|
3977
|
-
|
|
4007
|
+
url: agency2.url,
|
|
3978
4008
|
headers: agency2.headers,
|
|
3979
|
-
|
|
3980
|
-
|
|
4009
|
+
realtimeAlerts: agency2.realtimeAlerts,
|
|
4010
|
+
realtimeTripUpdates: agency2.realtimeTripUpdates,
|
|
4011
|
+
realtimeVehiclePositions: agency2.realtimeVehiclePositions,
|
|
3981
4012
|
downloadDir: tempPath,
|
|
3982
4013
|
downloadTimeout: config.downloadTimeout,
|
|
3983
4014
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
@@ -3992,7 +4023,7 @@ async function importGtfs(initialConfig) {
|
|
|
3992
4023
|
logError: logError2
|
|
3993
4024
|
};
|
|
3994
4025
|
try {
|
|
3995
|
-
if (task.
|
|
4026
|
+
if (task.url) {
|
|
3996
4027
|
await downloadFiles(task);
|
|
3997
4028
|
}
|
|
3998
4029
|
await readFiles(task);
|
|
@@ -4040,12 +4071,10 @@ async function updateGtfsRealtime(initialConfig) {
|
|
|
4040
4071
|
deleteExpiredRealtimeData(config);
|
|
4041
4072
|
await Promise.all(
|
|
4042
4073
|
config.agencies.map(async (agency2) => {
|
|
4043
|
-
if (agency2.realtimeUrls === void 0) {
|
|
4044
|
-
return;
|
|
4045
|
-
}
|
|
4046
4074
|
const task = {
|
|
4047
|
-
|
|
4048
|
-
|
|
4075
|
+
realtimeAlerts: agency2.realtimeAlerts,
|
|
4076
|
+
realtimeTripUpdates: agency2.realtimeTripUpdates,
|
|
4077
|
+
realtimeVehiclePositions: agency2.realtimeVehiclePositions,
|
|
4049
4078
|
downloadTimeout: config.downloadTimeout,
|
|
4050
4079
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
4051
4080
|
sqlitePath: config.sqlitePath,
|
|
@@ -4068,7 +4097,7 @@ async function updateGtfsRealtime(initialConfig) {
|
|
|
4068
4097
|
} catch (error) {
|
|
4069
4098
|
if (error?.code === "SQLITE_CANTOPEN") {
|
|
4070
4099
|
logError2(
|
|
4071
|
-
`
|
|
4100
|
+
`Unable to open sqlite database "${config.sqlitePath}" defined as \`sqlitePath\` config.json. Ensure the parent directory exists or remove \`sqlitePath\` from config.json.`
|
|
4072
4101
|
);
|
|
4073
4102
|
}
|
|
4074
4103
|
throw error;
|