@@ -41,6 +41,88 @@ Try the live demo to explore GTFS data, view routes with colors, and see trip sc
4141- ✅ Filter alerts and vehicle positions by route, stop, or trip
4242- ✅ Store RT data in SQLite for consistent querying
4343- ✅ Include RT data in database exports
44+ - ✅ Full support for both GTFS-RT ` time ` and ` delay ` fields in stop time updates
45+
46+ ## Migration Guide (v1.0.0+)
47+
48+ If you're upgrading from an earlier version, the API has been simplified and improved:
49+
50+ ### Unified Filter-Based API
51+
52+ All ` getXXXByYYYY ` methods have been removed in favor of unified ` getXXXX ` methods with optional filters. Filters now support both single values and arrays for maximum flexibility.
53+
54+ ** Migration examples:**
55+
56+ ``` typescript
57+ // ❌ Old API
58+ const stop = gtfs .getStopById (' STOP_123' );
59+ const route = gtfs .getRouteById (' ROUTE_1' );
60+ const trip = gtfs .getTripById (' TRIP_123' );
61+ const stopTimes = gtfs .getStopTimesByTrip (' TRIP_123' );
62+ const agency = gtfs .getAgencyById (' AGENCY_1' );
63+ const alert = gtfs .getAlertById (' alert:123' );
64+ const vehicle = gtfs .getVehiclePositionByTripId (' TRIP_123' );
65+
66+ // ✅ New API
67+ const stops = gtfs .getStops ({ stopId: ' STOP_123' });
68+ const stop = stops .length > 0 ? stops [0 ] : null ;
69+
70+ const routes = gtfs .getRoutes ({ routeId: ' ROUTE_1' });
71+ const route = routes .length > 0 ? routes [0 ] : null ;
72+
73+ const trips = gtfs .getTrips ({ tripId: ' TRIP_123' });
74+ const trip = trips .length > 0 ? trips [0 ] : null ;
75+
76+ const stopTimes = gtfs .getStopTimes ({ tripId: ' TRIP_123' });
77+
78+ const agencies = gtfs .getAgencies ({ agencyId: ' AGENCY_1' });
79+ const agency = agencies .length > 0 ? agencies [0 ] : null ;
80+
81+ const alerts = gtfs .getAlerts ({ alertId: ' alert:123' });
82+ const alert = alerts .length > 0 ? alerts [0 ] : null ;
83+
84+ const vehicles = gtfs .getVehiclePositions ({ tripId: ' TRIP_123' });
85+ const vehicle = vehicles .length > 0 ? vehicles [0 ] : null ;
86+ ```
87+
88+ ** Benefits of the new API:**
89+ - ✅ Support for filtering by multiple IDs at once (arrays)
90+ - ✅ More consistent API surface
91+ - ✅ Easier to combine multiple filters
92+ - ✅ Better TypeScript inference
93+
94+ ** Array filtering example:**
95+ ``` typescript
96+ // Get multiple stops at once
97+ const stops = gtfs .getStops ({ stopId: [' STOP_1' , ' STOP_2' , ' STOP_3' ] });
98+
99+ // Get trips for multiple routes
100+ const trips = gtfs .getTrips ({ routeId: [' ROUTE_1' , ' ROUTE_2' ], date: ' 20240115' });
101+
102+ // Get stop times for multiple trips
103+ const stopTimes = gtfs .getStopTimes ({ tripId: [' TRIP_1' , ' TRIP_2' ] });
104+ ```
105+
106+ ### GTFS-RT Time/Delay Support
107+
108+ Stop time updates now include both ` time ` and ` delay ` fields:
109+
110+ ``` typescript
111+ const stopTimes = gtfs .getStopTimes ({
112+ tripId: ' TRIP_123' ,
113+ includeRealtime: true
114+ });
115+
116+ for (const st of stopTimes ) {
117+ if (st .realtime ) {
118+ // Both delay (relative to schedule) and time (absolute) are now available
119+ console .log (' Arrival delay:' , st .realtime .arrival_delay , ' seconds' );
120+ console .log (' Arrival time:' , st .realtime .arrival_time , ' (UNIX timestamp)' );
121+ console .log (' Departure delay:' , st .realtime .departure_delay , ' seconds' );
122+ console .log (' Departure time:' , st .realtime .departure_time , ' (UNIX timestamp)' );
123+ }
124+ }
125+ ```
44126
45127## Installation
46128
@@ -222,7 +304,8 @@ const stopTimes = gtfs.getStopTimes({
222304
223305``` typescript
224306// Get stop by ID
225- const stop = gtfs .getStopById (' STOP_123' );
307+ const stops = gtfs .getStops ({ stopId: ' STOP_123' });
308+ const stop = stops .length > 0 ? stops [0 ] : null ;
226309console .log (stop ?.stop_name );
227310
228311// Get stop by code (using filters)
@@ -246,7 +329,8 @@ const stops = gtfs.getStops({ tripId: 'TRIP_123' });
246329
247330``` typescript
248331// Get route by ID
249- const route = gtfs .getRouteById (' ROUTE_1' );
332+ const routes = gtfs .getRoutes ({ routeId: ' ROUTE_1' });
333+ const route = routes .length > 0 ? routes [0 ] : null ;
250334
251335// Get all routes (using filters with no parameters)
252336const routes = gtfs .getRoutes ();
@@ -262,10 +346,11 @@ const routes = gtfs.getRoutes({ limit: 10 });
262346
263347``` typescript
264348// Get agency by ID
265- const agency = gtfs .getAgencyById (' AGENCY_1' );
349+ const agencies = gtfs .getAgencies ({ agencyId: ' AGENCY_1' });
350+ const agency = agencies .length > 0 ? agencies [0 ] : null ;
266351
267352// Get all agencies
268- const agencies = gtfs .getAgencies ();
353+ const allAgencies = gtfs .getAgencies ();
269354
270355// Get agencies with limit
271356const agencies = gtfs .getAgencies ({ limit: 5 });
@@ -288,7 +373,8 @@ const exceptions = gtfs.getCalendarDates('WEEKDAY');
288373
289374``` typescript
290375// Get trip by ID
291- const trip = gtfs .getTripById (' TRIP_123' );
376+ const trips = gtfs .getTrips ({ tripId: ' TRIP_123' });
377+ const trip = trips .length > 0 ? trips [0 ] : null ;
292378
293379// Get trips by route (using filters)
294380const trips = gtfs .getTrips ({ routeId: ' ROUTE_1' });
@@ -314,7 +400,7 @@ const trips = gtfs.getTrips({ agencyId: 'AGENCY_1' });
314400
315401``` typescript
316402// Get stop times for a trip (ordered by stop_sequence)
317- const stopTimes = gtfs .getStopTimesByTrip ( ' TRIP_123' );
403+ const stopTimes = gtfs .getStopTimes ({ tripId: ' TRIP_123' } );
318404
319405// Get stop times for a stop (using filters)
320406const stopTimes = gtfs .getStopTimes ({ stopId: ' STOP_123' });
@@ -404,7 +490,8 @@ const tripAlerts = gtfs.getAlerts({
404490});
405491
406492// Get alert by ID
407- const alert = gtfs .getAlertById (' alert:12345' );
493+ const alerts = gtfs .getAlerts ({ alertId: ' alert:12345' });
494+ const alert = alerts .length > 0 ? alerts [0 ] : null ;
408495
409496// Alert structure
410497console .log (alert .header_text ); // TranslatedString
@@ -427,12 +514,10 @@ const routeVehicles = gtfs.getVehiclePositions({
427514});
428515
429516// Filter by trip
430- const tripVehicle = gtfs .getVehiclePositions ({
517+ const tripVehicles = gtfs .getVehiclePositions ({
431518 tripId: ' TRIP_123'
432519});
433-
434- // Get vehicle by trip ID
435- const vehicle = gtfs .getVehiclePositionByTripId (' TRIP_123' );
520+ const vehicle = tripVehicles .length > 0 ? tripVehicles [0 ] : null ;
436521
437522// Vehicle structure
438523console .log (vehicle .position ); // { latitude, longitude, bearing, speed }
@@ -568,15 +653,16 @@ async function example() {
568653 const allStopTimes = gtfs .getStopTimes ({ stopId: stop .stop_id });
569654 const routeIds = new Set (
570655 allStopTimes .map (st => {
571- const trip = gtfs .getTripById ( st .trip_id );
572- return trip ? .route_id ;
656+ const trips = gtfs .getTrips ({ tripId: st .trip_id } );
657+ return trips . length > 0 ? trips [ 0 ] .route_id : null ;
573658 })
574659 );
575660
576661 // Get route details
577662 for (const routeId of routeIds ) {
578663 if (! routeId ) continue ;
579- const route = gtfs .getRouteById (routeId );
664+ const routes = gtfs .getRoutes ({ routeId });
665+ const route = routes .length > 0 ? routes [0 ] : null ;
580666 console .log (` Route: ${route ?.route_short_name } - ${route ?.route_long_name } ` );
581667 }
582668
@@ -589,10 +675,11 @@ async function example() {
589675 console .log (` Found ${trips .length } trips for today ` );
590676
591677 // Get stop times for a specific trip
592- const stopTimes = gtfs .getStopTimesByTrip ( trips [0 ].trip_id );
678+ const stopTimes = gtfs .getStopTimes ({ tripId: trips [0 ].trip_id } );
593679 console .log (' Trip schedule:' );
594680 for (const st of stopTimes ) {
595- const stop = gtfs .getStopById (st .stop_id );
681+ const stops = gtfs .getStops ({ stopId: st .stop_id });
682+ const stop = stops .length > 0 ? stops [0 ] : null ;
596683 console .log (` ${st .arrival_time } - ${stop ?.stop_name } ` );
597684 }
598685
@@ -616,45 +703,44 @@ example();
616703
617704### Instance Methods
618705
619- #### Flexible Filter-Based Methods (Recommended)
620- - ` getStops(filters?) ` - Get stops with optional filters (stopId, stopCode, name, tripId, limit)
621- - ` getRoutes(filters?) ` - Get routes with optional filters (routeId, agencyId, limit)
622- - ` getTrips(filters?) ` - Get trips with optional filters (tripId, routeId, date, directionId, agencyId, limit)
623- - ` getStopTimes(filters?) ` - Get stop times with optional filters (tripId, stopId, routeId, date, directionId, agencyId, limit)
624- - ` getAgencies(filters?) ` - Get agencies with optional filters (agencyId, limit)
706+ #### GTFS Static Data Methods
707+ All methods support flexible filtering with both single values and arrays:
625708
626- #### Direct Lookup Methods
627- - ` getStopById(stopId )` - Get stop by stop_id
628- - ` getRouteById(routeId )` - Get route by route_id
629- - ` getTripById(tripId )` - Get trip by trip_id
630- - ` getAgencyById(agencyId )` - Get agency by agency_id
709+ - ` getAgencies(filters?) ` - Get agencies (filters: agencyId, limit)
710+ - ` getStops(filters? )` - Get stops (filters: stopId, stopCode, name, tripId, limit)
711+ - ` getRoutes(filters? )` - Get routes (filters: routeId, agencyId, limit)
712+ - ` getTrips(filters? )` - Get trips (filters: tripId, routeId, serviceIds, directionId, agencyId, includeRealtime, limit, date)
713+ - ` getStopTimes(filters? )` - Get stop times (filters: tripId, stopId, routeId, serviceIds, directionId, agencyId, includeRealtime, limit, date)
631714
632715#### Calendar Methods
633- - ` getActiveServiceIds(date) ` - Get active service IDs for a date
716+ - ` getActiveServiceIds(date) ` - Get active service IDs for a date (YYYYMMDD format)
634717- ` getCalendarByServiceId(serviceId) ` - Get calendar by service_id
635- - ` getCalendarDates(serviceId) ` - Get calendar date exceptions
636- - ` getCalendarDatesForDate(date) ` - Get exceptions for a specific date
637-
638- #### Special Methods
639- - ` getStopTimesByTrip(tripId) ` - Get stop times for a trip (ordered by stop_sequence)
718+ - ` getCalendarDates(serviceId) ` - Get calendar date exceptions for a service
719+ - ` getCalendarDatesForDate(date) ` - Get calendar exceptions for a specific date
640720
641721#### GTFS Realtime Methods
642722- ` fetchRealtimeData(urls?) ` - Fetch and load RT data from protobuf feeds
643723- ` clearRealtimeData() ` - Clear all realtime data from database
644724- ` setRealtimeFeedUrls(urls) ` - Configure RT feed URLs
645725- ` getRealtimeFeedUrls() ` - Get configured RT feed URLs
646- - ` setStalenessThreshold(seconds) ` - Set staleness threshold (default: 120)
647- - ` getStalenessThreshold() ` - Get staleness threshold
648- - ` getAlerts(filters?) ` - Get alerts with optional filters ( routeId, stopId, tripId, activeOnly)
649- - ` getAlertById(alertId )` - Get alert by ID
650- - ` getVehiclePositions (filters?)` - Get vehicle positions with optional filters (routeId, tripId, vehicleId )
651- - ` getVehiclePositionByTripId(tripId )` - Get vehicle position by trip ID
726+ - ` setStalenessThreshold(seconds) ` - Set staleness threshold (default: 120 seconds )
727+ - ` getStalenessThreshold() ` - Get current staleness threshold
728+ - ` getAlerts(filters?) ` - Get alerts ( filters: alertId, routeId, stopId, tripId, activeOnly, cause, effect, limit )
729+ - ` getVehiclePositions(filters? )` - Get vehicle positions (filters: tripId, routeId, vehicleId, limit)
730+ - ` getTripUpdates (filters?)` - Get trip updates ( filters: tripId, routeId, limit )
731+ - ` getStopTimeUpdates(filters? )` - Get stop time updates (filters: tripId, stopId, stopSequence, limit)
652732
653733#### Database Methods
654734- ` export() ` - Export database to ArrayBuffer (includes RT data)
655- - ` getDatabase() ` - Get direct access to sql.js database
735+ - ` getDatabase() ` - Get direct access to sql.js database for advanced queries
656736- ` close() ` - Close database connection
657737
738+ #### Debug Methods
739+ - ` debugExportAllAlerts() ` - Export all alerts without staleness filtering
740+ - ` debugExportAllVehiclePositions() ` - Export all vehicle positions without staleness filtering
741+ - ` debugExportAllTripUpdates() ` - Export all trip updates without staleness filtering
742+ - ` debugExportAllStopTimeUpdates() ` - Export all stop time updates without staleness filtering
743+
658744## TypeScript Support
659745
660746This library is written in TypeScript and provides full type definitions for all GTFS entities, filter options, and GTFS-RT types:
0 commit comments