gtfs-sqljs
    Preparing search index...

    Class GtfsSqlJs

    Index

    Methods

    • Build an ordered list of stops from multiple trips

      This is useful when you need to display a timetable for a route where different trips may stop at different sets of stops (e.g., express vs local service, or trips with different start/end points).

      The method intelligently merges stop sequences from all provided trips to create a comprehensive ordered list of all unique stops.

      Parameters

      • tripIds: string[]

        Array of trip IDs to analyze

      Returns Stop[]

      Ordered array of Stop objects representing all unique stops

      // Get all trips for a route going in one direction
      const trips = gtfs.getTrips({ routeId: 'ROUTE_1', directionId: 0 });
      const tripIds = trips.map(t => t.trip_id);

      // Build ordered stop list for all these trips
      const stops = gtfs.buildOrderedStopList(tripIds);

      // Now you can display a timetable with all possible stops
      stops.forEach(stop => {
      console.log(stop.stop_name);
      });
    • Clear all realtime data from the database

      Returns void

    • Export all alerts without staleness filtering (for debugging)

      Returns Alert[]

    • Export all stop time updates without staleness filtering (for debugging) Returns stop time updates with trip_id and rt_last_updated populated

      Returns StopTimeUpdate[]

    • Export database to ArrayBuffer

      Returns ArrayBuffer

    • Fetch and load GTFS Realtime data from configured feed URLs or provided URLs

      Parameters

      • Optionalurls: string[]

        Optional array of feed URLs. If not provided, uses configured feed URLs

      Returns Promise<void>

    • Get active service IDs for a given date (YYYYMMDD format)

      Parameters

      • date: string

      Returns string[]

    • Get calendar entry by service_id

      Parameters

      • serviceId: string

      Returns Calendar | null

    • Get direct access to the database (for advanced queries)

      Returns Database

    • Get timestamp of the last successful realtime data fetch and insertion

      Returns number | null

      Unix timestamp in seconds, or null if no realtime data has been fetched

    • Get currently configured GTFS-RT feed URLs

      Returns string[]

    • Get shapes with optional filters

      Parameters

      • Optionalfilters: ShapeFilters

        Optional filters

        • Optionallimit?: number
        • OptionalrouteId?: string | string[]
        • OptionalshapeId?: string | string[]
        • OptionaltripId?: string | string[]

      Returns Shape[]

      // Get all points for a specific shape
      const shapes = gtfs.getShapes({ shapeId: 'SHAPE_1' });
      // Get shapes for a specific route
      const shapes = gtfs.getShapes({ routeId: 'ROUTE_1' });
      // Get shapes for multiple trips
      const shapes = gtfs.getShapes({ tripId: ['TRIP_1', 'TRIP_2'] });
    • Get shapes as GeoJSON FeatureCollection

      Each shape is converted to a LineString Feature with route properties. Coordinates are in [longitude, latitude] format per GeoJSON spec.

      Parameters

      • Optionalfilters: ShapeFilters

        Optional filters (same as getShapes)

        • Optionallimit?: number
        • OptionalrouteId?: string | string[]
        • OptionalshapeId?: string | string[]
        • OptionaltripId?: string | string[]
      • precision: number = 6

        Number of decimal places for coordinates (default: 6, ~10cm precision)

      Returns GeoJsonFeatureCollection

      GeoJSON FeatureCollection with LineString features

      // Get all shapes as GeoJSON
      const geojson = gtfs.getShapesToGeojson();
      // Get shapes for a route with lower precision
      const geojson = gtfs.getShapesToGeojson({ routeId: 'ROUTE_1' }, 5);
      // Result structure:
      // {
      // type: 'FeatureCollection',
      // features: [{
      // type: 'Feature',
      // properties: {
      // shape_id: 'SHAPE_1',
      // route_id: 'ROUTE_1',
      // route_short_name: '1',
      // route_long_name: 'Main Street',
      // route_type: 3,
      // route_color: 'FF0000'
      // },
      // geometry: {
      // type: 'LineString',
      // coordinates: [[-122.123456, 37.123456], ...]
      // }
      // }]
      // }
    • Get current staleness threshold

      Returns number

    • Get stop times with optional filters

      Parameters

      • Optionalfilters: StopTimeFilters & { date?: string }

        Optional filters

        • OptionalagencyId?: string | string[]
        • OptionaldirectionId?: number | number[]
        • OptionaldropOffType?: PickupDropOffType | PickupDropOffType[]

          Filter by drop-off type. 0 = Regular, 1 = None, 2 = Phone agency, 3 = Coordinate with driver.

        • OptionalincludeRealtime?: boolean
        • Optionallimit?: number
        • OptionalpickupType?: PickupDropOffType | PickupDropOffType[]

          Filter by pickup type. 0 = Regular, 1 = None, 2 = Phone agency, 3 = Coordinate with driver.

        • OptionalrouteId?: string | string[]
        • OptionalserviceIds?: string | string[]
        • OptionalstopId?: string | string[]
        • OptionaltripId?: string | string[]
        • Optionaldate?: string

          Filter by date (YYYYMMDD format) - will get active services for that date

      Returns StopTime[]

      // Get stop times for a specific trip
      const stopTimes = gtfs.getStopTimes({ tripId: 'TRIP_123' });
      // Get stop times at a stop for a specific route on a date
      const stopTimes = gtfs.getStopTimes({
      stopId: 'STOP_123',
      routeId: 'ROUTE_1',
      date: '20240115'
      });
      // Get stop times with realtime data
      const stopTimes = gtfs.getStopTimes({
      tripId: 'TRIP_123',
      includeRealtime: true
      });
    • Get trips with optional filters Pass tripId filter to get a specific trip

      Parameters

      • Optionalfilters: TripFilters & { date?: string }

        Optional filters

        • OptionalagencyId?: string | string[]
        • OptionaldirectionId?: number | number[]
        • OptionalincludeRealtime?: boolean
        • Optionallimit?: number
        • OptionalrouteId?: string | string[]
        • OptionalserviceIds?: string | string[]
        • OptionaltripId?: string | string[]
        • Optionaldate?: string

          Filter by date (YYYYMMDD format) - will get active services for that date

      Returns Trip[]

      // Get all trips for a route on a specific date
      const trips = gtfs.getTrips({ routeId: 'ROUTE_1', date: '20240115' });
      // Get all trips for a route going in one direction
      const trips = gtfs.getTrips({ routeId: 'ROUTE_1', directionId: 0 });
      // Get a specific trip
      const trips = gtfs.getTrips({ tripId: 'TRIP_123' });
    • Set GTFS-RT feed URLs

      Parameters

      • urls: string[]

      Returns void

    • Set staleness threshold in seconds

      Parameters

      • seconds: number

      Returns void

    • Clean expired cache entries

      Parameters

      • cacheStore: CacheStore

        Cache store to clean (required)

      • expirationMs: number = DEFAULT_CACHE_EXPIRATION_MS

        Expiration time in milliseconds (default: 7 days)

      Returns Promise<number>

      Number of entries deleted

    • Get cache statistics

      Parameters

      • cacheStore: CacheStore

        Cache store to query (required)

      Returns Promise<
          {
              activeEntries: number;
              expiredEntries: number;
              newestEntry: number
              | null;
              oldestEntry: number | null;
              totalEntries: number;
              totalSize: number;
              totalSizeMB: string;
          },
      >

      Cache statistics including size, entry count, and age information

    • List all cache entries

      Parameters

      • cacheStore: CacheStore

        Cache store to query (required)

      • includeExpired: boolean = false

        Include expired entries (default: false)

      Returns Promise<CacheEntry[]>

      Array of cache entries with metadata