From 6feb9224ef92069b4c7076362421165734de2645 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 27 Nov 2025 18:21:24 +0000 Subject: [PATCH 1/2] Add getLastRealtimeFetchTimestamp method Track and expose the timestamp of the last successful realtime data fetch and insertion. Returns Unix timestamp in seconds, or null if no realtime data has been fetched yet. --- src/gtfs-sqljs.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/gtfs-sqljs.ts b/src/gtfs-sqljs.ts index 3e2c1f5..4006d86 100644 --- a/src/gtfs-sqljs.ts +++ b/src/gtfs-sqljs.ts @@ -142,6 +142,7 @@ export class GtfsSqlJs { private SQL: SqlJsStatic | null = null; private realtimeFeedUrls: string[] = []; private stalenessThreshold: number = 120; + private lastRealtimeFetchTimestamp: number | null = null; /** * Private constructor - use static factory methods instead @@ -875,6 +876,14 @@ export class GtfsSqlJs { return this.stalenessThreshold; } + /** + * Get timestamp of the last successful realtime data fetch and insertion + * @returns Unix timestamp in seconds, or null if no realtime data has been fetched + */ + getLastRealtimeFetchTimestamp(): number | null { + return this.lastRealtimeFetchTimestamp; + } + /** * Fetch and load GTFS Realtime data from configured feed URLs or provided URLs * @param urls - Optional array of feed URLs. If not provided, uses configured feed URLs @@ -888,6 +897,7 @@ export class GtfsSqlJs { } await loadRealtimeData(this.db, feedUrls); + this.lastRealtimeFetchTimestamp = Math.floor(Date.now() / 1000); } /** From 128d0ab1e93ec2051aca15927a7edd3e992802b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 27 Nov 2025 19:02:14 +0000 Subject: [PATCH 2/2] Add unit tests and README documentation for shape methods --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 9f906f3..9b0ed07 100644 --- a/README.md +++ b/README.md @@ -727,6 +727,15 @@ await gtfs.fetchRealtimeData(['./path/to/feed.pb']); // Update configuration gtfs.setRealtimeFeedUrls(['https://example.com/new-feed']); gtfs.setStalenessThreshold(60); // 60 seconds + +// Check when realtime data was last fetched +const lastFetch = gtfs.getLastRealtimeFetchTimestamp(); +if (lastFetch) { + const ageSeconds = Math.floor(Date.now() / 1000) - lastFetch; + console.log(`RT data is ${ageSeconds} seconds old`); +} else { + console.log('No RT data has been fetched yet'); +} ``` #### Querying Alerts @@ -1164,6 +1173,7 @@ All methods support flexible filtering with both single values and arrays: - `getRealtimeFeedUrls()` - Get configured RT feed URLs - `setStalenessThreshold(seconds)` - Set staleness threshold (default: 120 seconds) - `getStalenessThreshold()` - Get current staleness threshold +- `getLastRealtimeFetchTimestamp()` - Get Unix timestamp (seconds) of last successful RT fetch, or null if never fetched - `getAlerts(filters?)` - Get alerts (filters: alertId, routeId, stopId, tripId, activeOnly, cause, effect, limit) - `getVehiclePositions(filters?)` - Get vehicle positions (filters: tripId, routeId, vehicleId, limit) - `getTripUpdates(filters?)` - Get trip updates (filters: tripId, routeId, limit)