gtfs 4.16.0 → 4.17.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/dist/bin/gtfs-export.js +60 -23
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +165 -132
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +159 -130
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.js +171 -137
- package/dist/index.js.map +1 -1
- package/dist/models/models.d.ts +44 -3
- package/dist/models/models.js +55 -18
- package/dist/models/models.js.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ __export(models_exports, {
|
|
|
54
54
|
routes: () => routes,
|
|
55
55
|
runEvents: () => runEvents,
|
|
56
56
|
runsPieces: () => runsPieces,
|
|
57
|
-
|
|
57
|
+
serviceAlertInformedEntities: () => serviceAlertInformedEntities,
|
|
58
58
|
serviceAlerts: () => serviceAlerts,
|
|
59
59
|
shapes: () => shapes,
|
|
60
60
|
stopAreas: () => stopAreas,
|
|
@@ -1285,7 +1285,8 @@ var stops = {
|
|
|
1285
1285
|
{
|
|
1286
1286
|
name: "parent_station",
|
|
1287
1287
|
type: "text",
|
|
1288
|
-
index: true
|
|
1288
|
+
index: true,
|
|
1289
|
+
prefix: true
|
|
1289
1290
|
},
|
|
1290
1291
|
{
|
|
1291
1292
|
name: "stop_timezone",
|
|
@@ -2381,21 +2382,24 @@ var tripUpdates = {
|
|
|
2381
2382
|
required: true,
|
|
2382
2383
|
primary: true,
|
|
2383
2384
|
index: true,
|
|
2384
|
-
source: "id"
|
|
2385
|
+
source: "id",
|
|
2386
|
+
prefix: true
|
|
2385
2387
|
},
|
|
2386
2388
|
{
|
|
2387
2389
|
name: "vehicle_id",
|
|
2388
2390
|
type: "text",
|
|
2389
2391
|
index: true,
|
|
2390
2392
|
source: "tripUpdate.vehicle.id",
|
|
2391
|
-
default: null
|
|
2393
|
+
default: null,
|
|
2394
|
+
prefix: true
|
|
2392
2395
|
},
|
|
2393
2396
|
{
|
|
2394
2397
|
name: "trip_id",
|
|
2395
2398
|
type: "text",
|
|
2396
2399
|
index: true,
|
|
2397
2400
|
source: "tripUpdate.trip.tripId",
|
|
2398
|
-
default: null
|
|
2401
|
+
default: null,
|
|
2402
|
+
prefix: true
|
|
2399
2403
|
},
|
|
2400
2404
|
{
|
|
2401
2405
|
name: "trip_start_time",
|
|
@@ -2414,7 +2418,8 @@ var tripUpdates = {
|
|
|
2414
2418
|
type: "text",
|
|
2415
2419
|
index: true,
|
|
2416
2420
|
source: "tripUpdate.trip.routeId",
|
|
2417
|
-
default: null
|
|
2421
|
+
default: null,
|
|
2422
|
+
prefix: true
|
|
2418
2423
|
},
|
|
2419
2424
|
{
|
|
2420
2425
|
name: "start_date",
|
|
@@ -2457,7 +2462,8 @@ var stopTimeUpdates = {
|
|
|
2457
2462
|
type: "text",
|
|
2458
2463
|
index: true,
|
|
2459
2464
|
source: "parent.tripUpdate.trip.tripId",
|
|
2460
|
-
default: null
|
|
2465
|
+
default: null,
|
|
2466
|
+
prefix: true
|
|
2461
2467
|
},
|
|
2462
2468
|
{
|
|
2463
2469
|
name: "trip_start_time",
|
|
@@ -2476,14 +2482,16 @@ var stopTimeUpdates = {
|
|
|
2476
2482
|
type: "text",
|
|
2477
2483
|
index: true,
|
|
2478
2484
|
source: "parent.tripUpdate.trip.routeId",
|
|
2479
|
-
default: null
|
|
2485
|
+
default: null,
|
|
2486
|
+
prefix: true
|
|
2480
2487
|
},
|
|
2481
2488
|
{
|
|
2482
2489
|
name: "stop_id",
|
|
2483
2490
|
type: "text",
|
|
2484
2491
|
index: true,
|
|
2485
2492
|
source: "stopId",
|
|
2486
|
-
default: null
|
|
2493
|
+
default: null,
|
|
2494
|
+
prefix: true
|
|
2487
2495
|
},
|
|
2488
2496
|
{
|
|
2489
2497
|
name: "stop_sequence",
|
|
@@ -2545,7 +2553,8 @@ var vehiclePositions = {
|
|
|
2545
2553
|
required: true,
|
|
2546
2554
|
primary: true,
|
|
2547
2555
|
index: true,
|
|
2548
|
-
source: "id"
|
|
2556
|
+
source: "id",
|
|
2557
|
+
prefix: true
|
|
2549
2558
|
},
|
|
2550
2559
|
{
|
|
2551
2560
|
name: "bearing",
|
|
@@ -2587,7 +2596,8 @@ var vehiclePositions = {
|
|
|
2587
2596
|
type: "text",
|
|
2588
2597
|
index: true,
|
|
2589
2598
|
source: "vehicle.trip.tripId",
|
|
2590
|
-
default: null
|
|
2599
|
+
default: null,
|
|
2600
|
+
prefix: true
|
|
2591
2601
|
},
|
|
2592
2602
|
{
|
|
2593
2603
|
name: "trip_start_date",
|
|
@@ -2632,7 +2642,8 @@ var vehiclePositions = {
|
|
|
2632
2642
|
type: "text",
|
|
2633
2643
|
index: true,
|
|
2634
2644
|
source: "vehicle.vehicle.id",
|
|
2635
|
-
default: null
|
|
2645
|
+
default: null,
|
|
2646
|
+
prefix: true
|
|
2636
2647
|
},
|
|
2637
2648
|
{
|
|
2638
2649
|
name: "vehicle_label",
|
|
@@ -2682,7 +2693,8 @@ var serviceAlerts = {
|
|
|
2682
2693
|
required: true,
|
|
2683
2694
|
primary: true,
|
|
2684
2695
|
index: true,
|
|
2685
|
-
source: "id"
|
|
2696
|
+
source: "id",
|
|
2697
|
+
prefix: true
|
|
2686
2698
|
},
|
|
2687
2699
|
{
|
|
2688
2700
|
name: "active_period",
|
|
@@ -2761,9 +2773,9 @@ var serviceAlerts = {
|
|
|
2761
2773
|
]
|
|
2762
2774
|
};
|
|
2763
2775
|
|
|
2764
|
-
// src/models/gtfs-realtime/service-alert-
|
|
2765
|
-
var
|
|
2766
|
-
filenameBase: "
|
|
2776
|
+
// src/models/gtfs-realtime/service-alert-informed_entities.ts
|
|
2777
|
+
var serviceAlertInformedEntities = {
|
|
2778
|
+
filenameBase: "service_alert_informed_entities",
|
|
2767
2779
|
extension: "gtfs-realtime",
|
|
2768
2780
|
schema: [
|
|
2769
2781
|
{
|
|
@@ -2771,20 +2783,45 @@ var serviceAlertTargets = {
|
|
|
2771
2783
|
type: "text",
|
|
2772
2784
|
required: true,
|
|
2773
2785
|
primary: true,
|
|
2774
|
-
source: "parent.id"
|
|
2786
|
+
source: "parent.id",
|
|
2787
|
+
prefix: true
|
|
2775
2788
|
},
|
|
2776
2789
|
{
|
|
2777
2790
|
name: "stop_id",
|
|
2778
2791
|
type: "text",
|
|
2779
2792
|
index: true,
|
|
2780
2793
|
source: "stopId",
|
|
2781
|
-
default: null
|
|
2794
|
+
default: null,
|
|
2795
|
+
prefix: true
|
|
2782
2796
|
},
|
|
2783
2797
|
{
|
|
2784
2798
|
name: "route_id",
|
|
2785
2799
|
type: "text",
|
|
2786
2800
|
index: true,
|
|
2787
2801
|
source: "routeId",
|
|
2802
|
+
default: null,
|
|
2803
|
+
prefix: true
|
|
2804
|
+
},
|
|
2805
|
+
{
|
|
2806
|
+
name: "route_type",
|
|
2807
|
+
type: "integer",
|
|
2808
|
+
index: true,
|
|
2809
|
+
source: "routeType",
|
|
2810
|
+
default: null
|
|
2811
|
+
},
|
|
2812
|
+
{
|
|
2813
|
+
name: "trip_id",
|
|
2814
|
+
type: "text",
|
|
2815
|
+
index: true,
|
|
2816
|
+
source: "trip.tripId",
|
|
2817
|
+
default: null,
|
|
2818
|
+
prefix: true
|
|
2819
|
+
},
|
|
2820
|
+
{
|
|
2821
|
+
name: "direction_id",
|
|
2822
|
+
type: "integer",
|
|
2823
|
+
index: true,
|
|
2824
|
+
source: "directionId",
|
|
2788
2825
|
default: null
|
|
2789
2826
|
},
|
|
2790
2827
|
{
|
|
@@ -3362,8 +3399,8 @@ function stopsToGeoJSONFeatureCollection(stops2) {
|
|
|
3362
3399
|
// src/lib/import-gtfs-realtime.ts
|
|
3363
3400
|
import pluralize from "pluralize";
|
|
3364
3401
|
import GtfsRealtimeBindings from "gtfs-realtime-bindings";
|
|
3365
|
-
import sqlString2 from "sqlstring-sqlite";
|
|
3366
3402
|
import mapSeries from "promise-map-series";
|
|
3403
|
+
import { get } from "lodash-es";
|
|
3367
3404
|
|
|
3368
3405
|
// src/lib/utils.ts
|
|
3369
3406
|
import sqlString from "sqlstring-sqlite";
|
|
@@ -3524,39 +3561,14 @@ function formatCurrency(value, currency) {
|
|
|
3524
3561
|
function getTimestampColumnName(columnName) {
|
|
3525
3562
|
return columnName.endsWith("time") ? `${columnName}stamp` : `${columnName}_timestamp`;
|
|
3526
3563
|
}
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
if (path3 === void 0) return defaultValue;
|
|
3531
|
-
const arr = path3.split(".");
|
|
3532
|
-
while (arr.length) {
|
|
3533
|
-
const nextKey = arr.shift();
|
|
3534
|
-
if (nextKey === void 0) {
|
|
3535
|
-
return defaultValue;
|
|
3536
|
-
} else if (obj == null) {
|
|
3537
|
-
return defaultValue;
|
|
3538
|
-
} else if (nextKey?.includes("[")) {
|
|
3539
|
-
const arrayKey = nextKey.match(/(\w*)\[(\d+)\]/);
|
|
3540
|
-
if (arrayKey === null) {
|
|
3541
|
-
return defaultValue;
|
|
3542
|
-
}
|
|
3543
|
-
if (obj[arrayKey[1]] === void 0) {
|
|
3544
|
-
return defaultValue;
|
|
3545
|
-
}
|
|
3546
|
-
if (obj[arrayKey[1]][arrayKey[2]] === void 0) {
|
|
3547
|
-
return defaultValue;
|
|
3548
|
-
}
|
|
3549
|
-
obj = obj[arrayKey[1]][arrayKey[2]];
|
|
3550
|
-
} else {
|
|
3551
|
-
if (obj[nextKey] === void 0) {
|
|
3552
|
-
return defaultValue;
|
|
3553
|
-
}
|
|
3554
|
-
obj = obj[nextKey];
|
|
3555
|
-
}
|
|
3564
|
+
function applyPrefixToValue(value, columnShouldBePrefixed, prefix) {
|
|
3565
|
+
if (!columnShouldBePrefixed || prefix === void 0 || value === null) {
|
|
3566
|
+
return value;
|
|
3556
3567
|
}
|
|
3557
|
-
|
|
3558
|
-
return obj;
|
|
3568
|
+
return `${prefix}${value}`;
|
|
3559
3569
|
}
|
|
3570
|
+
|
|
3571
|
+
// src/lib/import-gtfs-realtime.ts
|
|
3560
3572
|
async function fetchGtfsRealtimeData(urlConfig, task) {
|
|
3561
3573
|
task.log(`Downloading GTFS-Realtime from ${urlConfig.url}`);
|
|
3562
3574
|
const response = await fetch(urlConfig.url, {
|
|
@@ -3581,7 +3593,7 @@ async function fetchGtfsRealtimeData(urlConfig, task) {
|
|
|
3581
3593
|
enums: String,
|
|
3582
3594
|
longs: String,
|
|
3583
3595
|
bytes: String,
|
|
3584
|
-
defaults:
|
|
3596
|
+
defaults: false,
|
|
3585
3597
|
arrays: true,
|
|
3586
3598
|
objects: true,
|
|
3587
3599
|
oneofs: true
|
|
@@ -3603,7 +3615,7 @@ function removeExpiredRealtimeData(config) {
|
|
|
3603
3615
|
`DELETE FROM service_alerts WHERE expiration_timestamp <= strftime('%s','now')`
|
|
3604
3616
|
).run();
|
|
3605
3617
|
db.prepare(
|
|
3606
|
-
`DELETE FROM
|
|
3618
|
+
`DELETE FROM service_alert_informed_entities WHERE expiration_timestamp <= strftime('%s','now')`
|
|
3607
3619
|
).run();
|
|
3608
3620
|
log(config)(`Removed expired GTFS-Realtime data\r`, true);
|
|
3609
3621
|
}
|
|
@@ -3614,100 +3626,117 @@ function prepareRealtimeFieldValue(entity, column, task) {
|
|
|
3614
3626
|
if (column.name === "expiration_timestamp") {
|
|
3615
3627
|
return task.currentTimestamp + task.gtfsRealtimeExpirationSeconds;
|
|
3616
3628
|
}
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3629
|
+
const baseValue = column.source === void 0 ? column.default : get(entity, column.source, column.default);
|
|
3630
|
+
const timeAdjustedValue = baseValue?.__isLong__ ? convertLongTimeToDate(baseValue) : baseValue;
|
|
3631
|
+
const prefixedValue = applyPrefixToValue(
|
|
3632
|
+
timeAdjustedValue,
|
|
3633
|
+
column.prefix,
|
|
3634
|
+
task.prefix
|
|
3635
|
+
);
|
|
3636
|
+
return column.type === "json" ? JSON.stringify(prefixedValue) : prefixedValue;
|
|
3622
3637
|
}
|
|
3623
3638
|
async function processRealtimeAlerts(db, gtfsRealtimeData, task) {
|
|
3624
|
-
|
|
3639
|
+
const alertStmt = db.prepare(
|
|
3640
|
+
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(
|
|
3641
|
+
", "
|
|
3642
|
+
)}) VALUES (${serviceAlerts.schema.map(() => "?").join(", ")})`
|
|
3643
|
+
);
|
|
3644
|
+
const informedEntityStmt = db.prepare(
|
|
3645
|
+
`REPLACE INTO ${serviceAlertInformedEntities.filenameBase} (${serviceAlertInformedEntities.schema.map((column) => column.name).join(
|
|
3646
|
+
", "
|
|
3647
|
+
)}) VALUES (${serviceAlertInformedEntities.schema.map(() => "?").join(", ")})`
|
|
3648
|
+
);
|
|
3625
3649
|
let totalLineCount = 0;
|
|
3626
|
-
|
|
3627
|
-
const
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
try {
|
|
3631
|
-
db.prepare(
|
|
3632
|
-
`REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
|
|
3633
|
-
).run();
|
|
3634
|
-
} catch (error) {
|
|
3635
|
-
task.logWarning(`Import error: ${error.message}`);
|
|
3636
|
-
}
|
|
3637
|
-
if (!entity.alert.informedEntity || entity.alert.informedEntity.length === 0) {
|
|
3638
|
-
task.logWarning(
|
|
3639
|
-
`Import error: No informed entities found for alert id=${entity.id}`
|
|
3650
|
+
db.transaction(() => {
|
|
3651
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3652
|
+
const fieldValues = serviceAlerts.schema.map(
|
|
3653
|
+
(column) => prepareRealtimeFieldValue(entity, column, task)
|
|
3640
3654
|
);
|
|
3641
|
-
} else {
|
|
3642
|
-
const alertTargetArray = [];
|
|
3643
|
-
for (const informedEntity of entity.alert.informedEntity) {
|
|
3644
|
-
informedEntity.parent = entity;
|
|
3645
|
-
const subValues = serviceAlertTargets.schema.map(
|
|
3646
|
-
(column) => prepareRealtimeFieldValue(informedEntity, column, task)
|
|
3647
|
-
);
|
|
3648
|
-
alertTargetArray.push(`(${subValues.join(", ")})`);
|
|
3649
|
-
totalLineCount++;
|
|
3650
|
-
}
|
|
3651
3655
|
try {
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3656
|
+
alertStmt.run(fieldValues);
|
|
3657
|
+
if (entity.alert.informedEntity?.length) {
|
|
3658
|
+
const informedEntities = entity.alert.informedEntity.map(
|
|
3659
|
+
(informedEntity) => {
|
|
3660
|
+
informedEntity.parent = entity;
|
|
3661
|
+
return serviceAlertInformedEntities.schema.map(
|
|
3662
|
+
(column) => prepareRealtimeFieldValue(informedEntity, column, task)
|
|
3663
|
+
);
|
|
3664
|
+
}
|
|
3665
|
+
);
|
|
3666
|
+
for (const values of informedEntities) {
|
|
3667
|
+
informedEntityStmt.run(values);
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
totalLineCount++;
|
|
3655
3671
|
} catch (error) {
|
|
3656
3672
|
task.logWarning(`Import error: ${error.message}`);
|
|
3657
3673
|
}
|
|
3658
3674
|
}
|
|
3659
|
-
task.log(
|
|
3660
|
-
|
|
3675
|
+
task.log(
|
|
3676
|
+
`Importing - GTFS-Realtime service alerts - ${totalLineCount} entries imported\r`,
|
|
3677
|
+
true
|
|
3678
|
+
);
|
|
3679
|
+
})();
|
|
3661
3680
|
}
|
|
3662
3681
|
async function processRealtimeTripUpdates(db, gtfsRealtimeData, task) {
|
|
3663
|
-
task.log(`Download successful`);
|
|
3664
3682
|
let totalLineCount = 0;
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
)
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
const
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3683
|
+
const tripUpdateStmt = db.prepare(
|
|
3684
|
+
`REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(
|
|
3685
|
+
", "
|
|
3686
|
+
)}) VALUES (${tripUpdates.schema.map(() => "?").join(", ")})`
|
|
3687
|
+
);
|
|
3688
|
+
const stopTimeStmt = db.prepare(
|
|
3689
|
+
`REPLACE INTO ${stopTimeUpdates.filenameBase} (${stopTimeUpdates.schema.map((column) => column.name).join(
|
|
3690
|
+
", "
|
|
3691
|
+
)}) VALUES (${stopTimeUpdates.schema.map(() => "?").join(", ")})`
|
|
3692
|
+
);
|
|
3693
|
+
db.transaction(() => {
|
|
3694
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3695
|
+
try {
|
|
3696
|
+
const fieldValues = tripUpdates.schema.map(
|
|
3697
|
+
(column) => prepareRealtimeFieldValue(entity, column, task)
|
|
3698
|
+
);
|
|
3699
|
+
tripUpdateStmt.run(fieldValues);
|
|
3700
|
+
for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
|
|
3701
|
+
stopTimeUpdate.parent = entity;
|
|
3702
|
+
const values = stopTimeUpdates.schema.map(
|
|
3703
|
+
(column) => prepareRealtimeFieldValue(stopTimeUpdate, column, task)
|
|
3704
|
+
);
|
|
3705
|
+
stopTimeStmt.run(values);
|
|
3706
|
+
}
|
|
3707
|
+
totalLineCount++;
|
|
3708
|
+
} catch (error) {
|
|
3709
|
+
task.logWarning(`Import error: ${error.message}`);
|
|
3710
|
+
}
|
|
3691
3711
|
}
|
|
3692
|
-
task.log(
|
|
3693
|
-
|
|
3712
|
+
task.log(
|
|
3713
|
+
`Importing - GTFS-Realtime trip updates - ${totalLineCount} entries imported\r`,
|
|
3714
|
+
true
|
|
3715
|
+
);
|
|
3716
|
+
})();
|
|
3694
3717
|
}
|
|
3695
3718
|
async function processRealtimeVehiclePositions(db, gtfsRealtimeData, task) {
|
|
3696
|
-
task.log(`Download successful`);
|
|
3697
3719
|
let totalLineCount = 0;
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
)
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3720
|
+
const vehiclePositionStmt = db.prepare(
|
|
3721
|
+
`REPLACE INTO ${vehiclePositions.filenameBase} (${vehiclePositions.schema.map((column) => column.name).join(
|
|
3722
|
+
", "
|
|
3723
|
+
)}) VALUES (${vehiclePositions.schema.map(() => "?").join(", ")})`
|
|
3724
|
+
);
|
|
3725
|
+
db.transaction(() => {
|
|
3726
|
+
for (const entity of gtfsRealtimeData.entity) {
|
|
3727
|
+
try {
|
|
3728
|
+
const fieldValues = vehiclePositions.schema.map((column) => prepareRealtimeFieldValue(entity, column, task));
|
|
3729
|
+
vehiclePositionStmt.run(fieldValues);
|
|
3730
|
+
totalLineCount++;
|
|
3731
|
+
} catch (error) {
|
|
3732
|
+
task.logWarning(`Import error: ${error.message}`);
|
|
3733
|
+
}
|
|
3708
3734
|
}
|
|
3709
|
-
task.log(
|
|
3710
|
-
|
|
3735
|
+
task.log(
|
|
3736
|
+
`Importing - GTFS-Realtime vehicle positions - ${totalLineCount} entries imported\r`,
|
|
3737
|
+
true
|
|
3738
|
+
);
|
|
3739
|
+
})();
|
|
3711
3740
|
}
|
|
3712
3741
|
async function updateGtfsRealtimeData(task) {
|
|
3713
3742
|
if (task.realtimeAlerts === void 0 && task.realtimeTripUpdates === void 0 && task.realtimeVehiclePositions === void 0) {
|
|
@@ -3788,6 +3817,7 @@ async function updateGtfsRealtime(initialConfig) {
|
|
|
3788
3817
|
gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
|
|
3789
3818
|
ignoreErrors: config.ignoreErrors,
|
|
3790
3819
|
sqlitePath: config.sqlitePath,
|
|
3820
|
+
prefix: agency2.prefix,
|
|
3791
3821
|
currentTimestamp: Math.floor(Date.now() / 1e3),
|
|
3792
3822
|
log: log(config),
|
|
3793
3823
|
logWarning: logWarning(config),
|
|
@@ -4071,7 +4101,11 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
4071
4101
|
line
|
|
4072
4102
|
).map(([columnName, value]) => [
|
|
4073
4103
|
columnName,
|
|
4074
|
-
|
|
4104
|
+
applyPrefixToValue(
|
|
4105
|
+
value,
|
|
4106
|
+
prefixedColumns.has(columnName),
|
|
4107
|
+
task.prefix
|
|
4108
|
+
)
|
|
4075
4109
|
])
|
|
4076
4110
|
);
|
|
4077
4111
|
insert.run(prefixedLine);
|
|
@@ -4240,7 +4274,7 @@ import { writeFile as writeFile2 } from "node:fs/promises";
|
|
|
4240
4274
|
import { without, compact as compact2 } from "lodash-es";
|
|
4241
4275
|
import pluralize3 from "pluralize";
|
|
4242
4276
|
import { stringify } from "csv-stringify";
|
|
4243
|
-
import
|
|
4277
|
+
import sqlString2 from "sqlstring-sqlite";
|
|
4244
4278
|
import mapSeries3 from "promise-map-series";
|
|
4245
4279
|
import untildify4 from "untildify";
|
|
4246
4280
|
var getAgencies = (db, config) => {
|
|
@@ -4292,7 +4326,7 @@ var exportGtfs = async (initialConfig) => {
|
|
|
4292
4326
|
exportPath,
|
|
4293
4327
|
`${model.filenameBase}.${model.filenameExtension}`
|
|
4294
4328
|
);
|
|
4295
|
-
const tableName =
|
|
4329
|
+
const tableName = sqlString2.escapeId(model.filenameBase);
|
|
4296
4330
|
const lines = db.prepare(`SELECT * FROM ${tableName};`).all();
|
|
4297
4331
|
if (!lines || lines.length === 0) {
|
|
4298
4332
|
if (!model.nonstandard) {
|
|
@@ -4354,7 +4388,7 @@ var exportGtfs = async (initialConfig) => {
|
|
|
4354
4388
|
};
|
|
4355
4389
|
|
|
4356
4390
|
// src/lib/advancedQuery.ts
|
|
4357
|
-
import
|
|
4391
|
+
import sqlString3 from "sqlstring-sqlite";
|
|
4358
4392
|
function advancedQuery(table, advancedQueryOptions) {
|
|
4359
4393
|
const defaultOptions = {
|
|
4360
4394
|
query: {},
|
|
@@ -4365,7 +4399,7 @@ function advancedQuery(table, advancedQueryOptions) {
|
|
|
4365
4399
|
};
|
|
4366
4400
|
const queryOptions = { ...defaultOptions, ...advancedQueryOptions };
|
|
4367
4401
|
const db = queryOptions.options.db ?? openDb();
|
|
4368
|
-
const tableName =
|
|
4402
|
+
const tableName = sqlString3.escapeId(table);
|
|
4369
4403
|
const selectClause = formatSelectClause(queryOptions.fields);
|
|
4370
4404
|
const whereClause = formatWhereClauses(queryOptions.query);
|
|
4371
4405
|
const joinClause = formatJoinClause(queryOptions.join);
|
|
@@ -4907,7 +4941,7 @@ function getStopsAsGeoJSON(query = {}, options = {}) {
|
|
|
4907
4941
|
|
|
4908
4942
|
// src/lib/gtfs/stop-times.ts
|
|
4909
4943
|
import { omit as omit6 } from "lodash-es";
|
|
4910
|
-
import
|
|
4944
|
+
import sqlString4 from "sqlstring-sqlite";
|
|
4911
4945
|
function getStoptimes(query = {}, fields = [], orderBy2 = [], options = {}) {
|
|
4912
4946
|
const db = options.db ?? openDb();
|
|
4913
4947
|
const tableName = "stop_times";
|
|
@@ -4924,7 +4958,7 @@ function getStoptimes(query = {}, fields = [], orderBy2 = [], options = {}) {
|
|
|
4924
4958
|
throw new Error("`date` must be a number in yyyymmdd format");
|
|
4925
4959
|
}
|
|
4926
4960
|
const serviceIds = getServiceIdsByDate(query.date);
|
|
4927
|
-
const tripSubquery = `SELECT DISTINCT trip_id FROM trips WHERE service_id IN (${serviceIds.map((id) =>
|
|
4961
|
+
const tripSubquery = `SELECT DISTINCT trip_id FROM trips WHERE service_id IN (${serviceIds.map((id) => sqlString4.escape(id)).join(",")})`;
|
|
4928
4962
|
whereClauses.push(`trip_id IN (${tripSubquery})`);
|
|
4929
4963
|
}
|
|
4930
4964
|
if (query.start_time) {
|
|
@@ -5195,7 +5229,7 @@ function getVehiclePositions(query = {}, fields = [], orderBy2 = [], options = {
|
|
|
5195
5229
|
function getServiceAlerts(query = {}, fields = [], orderBy2 = [], options = {}) {
|
|
5196
5230
|
const db = options.db ?? openDb();
|
|
5197
5231
|
const tableName = "service_alerts";
|
|
5198
|
-
const joinTableName = "
|
|
5232
|
+
const joinTableName = "service_alert_informed_entities";
|
|
5199
5233
|
const selectClause = formatSelectClause(fields);
|
|
5200
5234
|
const whereClause = formatWhereClauses(query);
|
|
5201
5235
|
const orderByClause = formatOrderByClause(orderBy2);
|