gtfs-sqljs 0.1.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/LICENSE +21 -0
- package/README.md +1263 -0
- package/dist/index.d.ts +1089 -0
- package/dist/index.js +3154 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1089 @@
|
|
|
1
|
+
import { SqlJsStatic, Database } from 'sql.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GTFS Realtime TypeScript types
|
|
5
|
+
* Based on GTFS Realtime v2.0 specification
|
|
6
|
+
*/
|
|
7
|
+
declare enum ScheduleRelationship {
|
|
8
|
+
SCHEDULED = 0,
|
|
9
|
+
ADDED = 1,
|
|
10
|
+
UNSCHEDULED = 2,
|
|
11
|
+
CANCELED = 3,
|
|
12
|
+
SKIPPED = 4,
|
|
13
|
+
NO_DATA = 5
|
|
14
|
+
}
|
|
15
|
+
declare enum VehicleStopStatus {
|
|
16
|
+
INCOMING_AT = 0,
|
|
17
|
+
STOPPED_AT = 1,
|
|
18
|
+
IN_TRANSIT_TO = 2
|
|
19
|
+
}
|
|
20
|
+
declare enum CongestionLevel {
|
|
21
|
+
UNKNOWN_CONGESTION_LEVEL = 0,
|
|
22
|
+
RUNNING_SMOOTHLY = 1,
|
|
23
|
+
STOP_AND_GO = 2,
|
|
24
|
+
CONGESTION = 3,
|
|
25
|
+
SEVERE_CONGESTION = 4
|
|
26
|
+
}
|
|
27
|
+
declare enum OccupancyStatus {
|
|
28
|
+
EMPTY = 0,
|
|
29
|
+
MANY_SEATS_AVAILABLE = 1,
|
|
30
|
+
FEW_SEATS_AVAILABLE = 2,
|
|
31
|
+
STANDING_ROOM_ONLY = 3,
|
|
32
|
+
CRUSHED_STANDING_ROOM_ONLY = 4,
|
|
33
|
+
FULL = 5,
|
|
34
|
+
NOT_ACCEPTING_PASSENGERS = 6
|
|
35
|
+
}
|
|
36
|
+
declare enum AlertCause {
|
|
37
|
+
UNKNOWN_CAUSE = 1,
|
|
38
|
+
OTHER_CAUSE = 2,
|
|
39
|
+
TECHNICAL_PROBLEM = 3,
|
|
40
|
+
STRIKE = 4,
|
|
41
|
+
DEMONSTRATION = 5,
|
|
42
|
+
ACCIDENT = 6,
|
|
43
|
+
HOLIDAY = 7,
|
|
44
|
+
WEATHER = 8,
|
|
45
|
+
MAINTENANCE = 9,
|
|
46
|
+
CONSTRUCTION = 10,
|
|
47
|
+
POLICE_ACTIVITY = 11,
|
|
48
|
+
MEDICAL_EMERGENCY = 12
|
|
49
|
+
}
|
|
50
|
+
declare enum AlertEffect {
|
|
51
|
+
NO_SERVICE = 1,
|
|
52
|
+
REDUCED_SERVICE = 2,
|
|
53
|
+
SIGNIFICANT_DELAYS = 3,
|
|
54
|
+
DETOUR = 4,
|
|
55
|
+
ADDITIONAL_SERVICE = 5,
|
|
56
|
+
MODIFIED_SERVICE = 6,
|
|
57
|
+
OTHER_EFFECT = 7,
|
|
58
|
+
UNKNOWN_EFFECT = 8,
|
|
59
|
+
STOP_MOVED = 9,
|
|
60
|
+
NO_EFFECT = 10,
|
|
61
|
+
ACCESSIBILITY_ISSUE = 11
|
|
62
|
+
}
|
|
63
|
+
interface TranslatedString {
|
|
64
|
+
translation: Array<{
|
|
65
|
+
text: string;
|
|
66
|
+
language?: string;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
interface EntitySelector {
|
|
70
|
+
agency_id?: string;
|
|
71
|
+
route_id?: string;
|
|
72
|
+
route_type?: number;
|
|
73
|
+
trip?: {
|
|
74
|
+
trip_id?: string;
|
|
75
|
+
route_id?: string;
|
|
76
|
+
direction_id?: number;
|
|
77
|
+
start_time?: string;
|
|
78
|
+
start_date?: string;
|
|
79
|
+
schedule_relationship?: ScheduleRelationship;
|
|
80
|
+
};
|
|
81
|
+
stop_id?: string;
|
|
82
|
+
}
|
|
83
|
+
interface TimeRange {
|
|
84
|
+
start?: number;
|
|
85
|
+
end?: number;
|
|
86
|
+
}
|
|
87
|
+
interface Alert {
|
|
88
|
+
id: string;
|
|
89
|
+
active_period: TimeRange[];
|
|
90
|
+
informed_entity: EntitySelector[];
|
|
91
|
+
cause?: AlertCause;
|
|
92
|
+
effect?: AlertEffect;
|
|
93
|
+
url?: TranslatedString;
|
|
94
|
+
header_text?: TranslatedString;
|
|
95
|
+
description_text?: TranslatedString;
|
|
96
|
+
rt_last_updated: number;
|
|
97
|
+
}
|
|
98
|
+
interface Position {
|
|
99
|
+
latitude: number;
|
|
100
|
+
longitude: number;
|
|
101
|
+
bearing?: number;
|
|
102
|
+
odometer?: number;
|
|
103
|
+
speed?: number;
|
|
104
|
+
}
|
|
105
|
+
interface VehicleDescriptor {
|
|
106
|
+
id?: string;
|
|
107
|
+
label?: string;
|
|
108
|
+
license_plate?: string;
|
|
109
|
+
}
|
|
110
|
+
interface VehiclePosition {
|
|
111
|
+
trip_id: string;
|
|
112
|
+
route_id?: string;
|
|
113
|
+
vehicle?: VehicleDescriptor;
|
|
114
|
+
position?: Position;
|
|
115
|
+
current_stop_sequence?: number;
|
|
116
|
+
stop_id?: string;
|
|
117
|
+
current_status?: VehicleStopStatus;
|
|
118
|
+
timestamp?: number;
|
|
119
|
+
congestion_level?: CongestionLevel;
|
|
120
|
+
occupancy_status?: OccupancyStatus;
|
|
121
|
+
rt_last_updated: number;
|
|
122
|
+
}
|
|
123
|
+
interface StopTimeEvent {
|
|
124
|
+
delay?: number;
|
|
125
|
+
time?: number;
|
|
126
|
+
uncertainty?: number;
|
|
127
|
+
}
|
|
128
|
+
interface StopTimeUpdate {
|
|
129
|
+
stop_sequence?: number;
|
|
130
|
+
stop_id?: string;
|
|
131
|
+
arrival?: StopTimeEvent;
|
|
132
|
+
departure?: StopTimeEvent;
|
|
133
|
+
schedule_relationship?: ScheduleRelationship;
|
|
134
|
+
trip_id?: string;
|
|
135
|
+
rt_last_updated?: number;
|
|
136
|
+
}
|
|
137
|
+
interface TripUpdate {
|
|
138
|
+
trip_id: string;
|
|
139
|
+
route_id?: string;
|
|
140
|
+
vehicle?: VehicleDescriptor;
|
|
141
|
+
stop_time_update: StopTimeUpdate[];
|
|
142
|
+
timestamp?: number;
|
|
143
|
+
delay?: number;
|
|
144
|
+
schedule_relationship?: ScheduleRelationship;
|
|
145
|
+
rt_last_updated: number;
|
|
146
|
+
}
|
|
147
|
+
interface StopTimeRealtime {
|
|
148
|
+
arrival_delay?: number;
|
|
149
|
+
arrival_time?: number;
|
|
150
|
+
departure_delay?: number;
|
|
151
|
+
departure_time?: number;
|
|
152
|
+
schedule_relationship?: ScheduleRelationship;
|
|
153
|
+
}
|
|
154
|
+
interface TripRealtime {
|
|
155
|
+
vehicle_position?: VehiclePosition | null;
|
|
156
|
+
trip_update?: {
|
|
157
|
+
delay?: number;
|
|
158
|
+
schedule_relationship?: ScheduleRelationship;
|
|
159
|
+
} | null;
|
|
160
|
+
}
|
|
161
|
+
interface AlertFilters {
|
|
162
|
+
alertId?: string;
|
|
163
|
+
activeOnly?: boolean;
|
|
164
|
+
routeId?: string;
|
|
165
|
+
stopId?: string;
|
|
166
|
+
tripId?: string;
|
|
167
|
+
cause?: AlertCause;
|
|
168
|
+
effect?: AlertEffect;
|
|
169
|
+
limit?: number;
|
|
170
|
+
}
|
|
171
|
+
interface VehiclePositionFilters {
|
|
172
|
+
tripId?: string;
|
|
173
|
+
routeId?: string;
|
|
174
|
+
vehicleId?: string;
|
|
175
|
+
limit?: number;
|
|
176
|
+
}
|
|
177
|
+
interface RealtimeConfig {
|
|
178
|
+
feedUrls?: string[];
|
|
179
|
+
stalenessThreshold?: number;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Metadata stored with cached GTFS databases
|
|
184
|
+
*/
|
|
185
|
+
interface CacheMetadata {
|
|
186
|
+
/** Checksum of the source zip file (SHA-256) */
|
|
187
|
+
checksum: string;
|
|
188
|
+
/** Version number - cache is invalidated if this changes */
|
|
189
|
+
version: string;
|
|
190
|
+
/** Timestamp when the cache was created */
|
|
191
|
+
timestamp: number;
|
|
192
|
+
/** Source zip URL or path (for reference) */
|
|
193
|
+
source?: string;
|
|
194
|
+
/** Size of the cached database in bytes */
|
|
195
|
+
size: number;
|
|
196
|
+
/** Which files were skipped during import (affects cache validity) */
|
|
197
|
+
skipFiles?: string[];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* A single cache entry with its metadata
|
|
201
|
+
*/
|
|
202
|
+
interface CacheEntry {
|
|
203
|
+
/** Unique cache key */
|
|
204
|
+
key: string;
|
|
205
|
+
/** Cache metadata */
|
|
206
|
+
metadata: CacheMetadata;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* A cache entry with data and metadata
|
|
210
|
+
*/
|
|
211
|
+
interface CacheEntryWithData {
|
|
212
|
+
/** The cached database data */
|
|
213
|
+
data: ArrayBuffer;
|
|
214
|
+
/** Cache metadata */
|
|
215
|
+
metadata: CacheMetadata;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Interface for implementing custom cache storage backends.
|
|
219
|
+
*
|
|
220
|
+
* The library provides two implementations:
|
|
221
|
+
* - IndexedDBCacheStore (for browsers)
|
|
222
|
+
* - FileSystemCacheStore (for Node.js)
|
|
223
|
+
*
|
|
224
|
+
* You can implement this interface to use custom storage backends
|
|
225
|
+
* (e.g., Redis, S3, or any other storage system).
|
|
226
|
+
*/
|
|
227
|
+
interface CacheStore {
|
|
228
|
+
/**
|
|
229
|
+
* Retrieve a cached database by key
|
|
230
|
+
* @param key - Cache key (typically includes checksum and version)
|
|
231
|
+
* @returns The cached entry with data and metadata, or null if not found
|
|
232
|
+
*/
|
|
233
|
+
get(key: string): Promise<CacheEntryWithData | null>;
|
|
234
|
+
/**
|
|
235
|
+
* Store a database in the cache
|
|
236
|
+
* @param key - Cache key
|
|
237
|
+
* @param data - Database as ArrayBuffer
|
|
238
|
+
* @param metadata - Metadata about the cached database
|
|
239
|
+
*/
|
|
240
|
+
set(key: string, data: ArrayBuffer, metadata: CacheMetadata): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Check if a cache entry exists
|
|
243
|
+
* @param key - Cache key
|
|
244
|
+
* @returns true if the cache entry exists
|
|
245
|
+
*/
|
|
246
|
+
has(key: string): Promise<boolean>;
|
|
247
|
+
/**
|
|
248
|
+
* Delete a specific cache entry
|
|
249
|
+
* @param key - Cache key
|
|
250
|
+
*/
|
|
251
|
+
delete(key: string): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Clear all cache entries
|
|
254
|
+
*/
|
|
255
|
+
clear(): Promise<void>;
|
|
256
|
+
/**
|
|
257
|
+
* List all cached entries (optional)
|
|
258
|
+
* @returns Array of cache entries with their metadata
|
|
259
|
+
*/
|
|
260
|
+
list?(): Promise<CacheEntry[]>;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Options for cache stores
|
|
264
|
+
*/
|
|
265
|
+
interface CacheStoreOptions {
|
|
266
|
+
/** Cache directory path (for FileSystemCacheStore) */
|
|
267
|
+
dir?: string;
|
|
268
|
+
/** IndexedDB database name (for IndexedDBCacheStore) */
|
|
269
|
+
dbName?: string;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* GTFS Type Definitions
|
|
274
|
+
* Based on GTFS Reference: https://gtfs.org/schedule/reference/
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* Agency - One or more transit agencies that provide the data in this feed
|
|
278
|
+
*/
|
|
279
|
+
interface Agency {
|
|
280
|
+
agency_id: string;
|
|
281
|
+
agency_name: string;
|
|
282
|
+
agency_url: string;
|
|
283
|
+
agency_timezone: string;
|
|
284
|
+
agency_lang?: string;
|
|
285
|
+
agency_phone?: string;
|
|
286
|
+
agency_fare_url?: string;
|
|
287
|
+
agency_email?: string;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Stop - Individual locations where vehicles pick up or drop off riders
|
|
291
|
+
*/
|
|
292
|
+
interface Stop {
|
|
293
|
+
stop_id: string;
|
|
294
|
+
stop_name: string;
|
|
295
|
+
stop_lat: number;
|
|
296
|
+
stop_lon: number;
|
|
297
|
+
stop_code?: string;
|
|
298
|
+
stop_desc?: string;
|
|
299
|
+
zone_id?: string;
|
|
300
|
+
stop_url?: string;
|
|
301
|
+
location_type?: number;
|
|
302
|
+
parent_station?: string;
|
|
303
|
+
stop_timezone?: string;
|
|
304
|
+
wheelchair_boarding?: number;
|
|
305
|
+
level_id?: string;
|
|
306
|
+
platform_code?: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Route - Transit routes
|
|
310
|
+
*/
|
|
311
|
+
interface Route {
|
|
312
|
+
route_id: string;
|
|
313
|
+
route_short_name: string;
|
|
314
|
+
route_long_name: string;
|
|
315
|
+
route_type: number;
|
|
316
|
+
agency_id?: string;
|
|
317
|
+
route_desc?: string;
|
|
318
|
+
route_url?: string;
|
|
319
|
+
route_color?: string;
|
|
320
|
+
route_text_color?: string;
|
|
321
|
+
route_sort_order?: number;
|
|
322
|
+
continuous_pickup?: number;
|
|
323
|
+
continuous_drop_off?: number;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Trip - Trips for each route
|
|
327
|
+
*/
|
|
328
|
+
interface Trip {
|
|
329
|
+
route_id: string;
|
|
330
|
+
service_id: string;
|
|
331
|
+
trip_id: string;
|
|
332
|
+
trip_headsign?: string;
|
|
333
|
+
trip_short_name?: string;
|
|
334
|
+
direction_id?: number;
|
|
335
|
+
block_id?: string;
|
|
336
|
+
shape_id?: string;
|
|
337
|
+
wheelchair_accessible?: number;
|
|
338
|
+
bikes_allowed?: number;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* StopTime - Times that a vehicle arrives at and departs from stops for each trip
|
|
342
|
+
*/
|
|
343
|
+
interface StopTime {
|
|
344
|
+
trip_id: string;
|
|
345
|
+
arrival_time: string;
|
|
346
|
+
departure_time: string;
|
|
347
|
+
stop_id: string;
|
|
348
|
+
stop_sequence: number;
|
|
349
|
+
stop_headsign?: string;
|
|
350
|
+
pickup_type?: number;
|
|
351
|
+
drop_off_type?: number;
|
|
352
|
+
continuous_pickup?: number;
|
|
353
|
+
continuous_drop_off?: number;
|
|
354
|
+
shape_dist_traveled?: number;
|
|
355
|
+
timepoint?: number;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Calendar - Service dates specified using a weekly schedule with start and end dates
|
|
359
|
+
*/
|
|
360
|
+
interface Calendar {
|
|
361
|
+
service_id: string;
|
|
362
|
+
monday: number;
|
|
363
|
+
tuesday: number;
|
|
364
|
+
wednesday: number;
|
|
365
|
+
thursday: number;
|
|
366
|
+
friday: number;
|
|
367
|
+
saturday: number;
|
|
368
|
+
sunday: number;
|
|
369
|
+
start_date: string;
|
|
370
|
+
end_date: string;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* CalendarDate - Exceptions for the services defined in calendar.txt
|
|
374
|
+
*/
|
|
375
|
+
interface CalendarDate {
|
|
376
|
+
service_id: string;
|
|
377
|
+
date: string;
|
|
378
|
+
exception_type: number;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* FareAttribute - Fare information for a transit agency's routes
|
|
382
|
+
*/
|
|
383
|
+
interface FareAttribute {
|
|
384
|
+
fare_id: string;
|
|
385
|
+
price: number;
|
|
386
|
+
currency_type: string;
|
|
387
|
+
payment_method: number;
|
|
388
|
+
transfers: number;
|
|
389
|
+
agency_id?: string;
|
|
390
|
+
transfer_duration?: number;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* FareRule - Rules for applying fares for itineraries
|
|
394
|
+
*/
|
|
395
|
+
interface FareRule {
|
|
396
|
+
fare_id: string;
|
|
397
|
+
route_id?: string;
|
|
398
|
+
origin_id?: string;
|
|
399
|
+
destination_id?: string;
|
|
400
|
+
contains_id?: string;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Shape - Rules for mapping vehicle travel paths
|
|
404
|
+
*/
|
|
405
|
+
interface Shape {
|
|
406
|
+
shape_id: string;
|
|
407
|
+
shape_pt_lat: number;
|
|
408
|
+
shape_pt_lon: number;
|
|
409
|
+
shape_pt_sequence: number;
|
|
410
|
+
shape_dist_traveled?: number;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Frequency - Headway-based service patterns
|
|
414
|
+
*/
|
|
415
|
+
interface Frequency {
|
|
416
|
+
trip_id: string;
|
|
417
|
+
start_time: string;
|
|
418
|
+
end_time: string;
|
|
419
|
+
headway_secs: number;
|
|
420
|
+
exact_times?: number;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Transfer - Rules for making connections at transfer points
|
|
424
|
+
*/
|
|
425
|
+
interface Transfer {
|
|
426
|
+
from_stop_id: string;
|
|
427
|
+
to_stop_id: string;
|
|
428
|
+
transfer_type: number;
|
|
429
|
+
min_transfer_time?: number;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Pathway - Pathways linking together locations within stations
|
|
433
|
+
*/
|
|
434
|
+
interface Pathway {
|
|
435
|
+
pathway_id: string;
|
|
436
|
+
from_stop_id: string;
|
|
437
|
+
to_stop_id: string;
|
|
438
|
+
pathway_mode: number;
|
|
439
|
+
is_bidirectional: number;
|
|
440
|
+
length?: number;
|
|
441
|
+
traversal_time?: number;
|
|
442
|
+
stair_count?: number;
|
|
443
|
+
max_slope?: number;
|
|
444
|
+
min_width?: number;
|
|
445
|
+
signposted_as?: string;
|
|
446
|
+
reversed_signposted_as?: string;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Level - Levels within stations
|
|
450
|
+
*/
|
|
451
|
+
interface Level {
|
|
452
|
+
level_id: string;
|
|
453
|
+
level_index: number;
|
|
454
|
+
level_name?: string;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* FeedInfo - Information about the dataset itself
|
|
458
|
+
*/
|
|
459
|
+
interface FeedInfo {
|
|
460
|
+
feed_publisher_name: string;
|
|
461
|
+
feed_publisher_url: string;
|
|
462
|
+
feed_lang: string;
|
|
463
|
+
default_lang?: string;
|
|
464
|
+
feed_start_date?: string;
|
|
465
|
+
feed_end_date?: string;
|
|
466
|
+
feed_version?: string;
|
|
467
|
+
feed_contact_email?: string;
|
|
468
|
+
feed_contact_url?: string;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Attribution - Attribution information for the dataset
|
|
472
|
+
*/
|
|
473
|
+
interface Attribution {
|
|
474
|
+
attribution_id: string;
|
|
475
|
+
organization_name: string;
|
|
476
|
+
agency_id?: string;
|
|
477
|
+
route_id?: string;
|
|
478
|
+
trip_id?: string;
|
|
479
|
+
is_producer?: number;
|
|
480
|
+
is_operator?: number;
|
|
481
|
+
is_authority?: number;
|
|
482
|
+
attribution_url?: string;
|
|
483
|
+
attribution_email?: string;
|
|
484
|
+
attribution_phone?: string;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Agency Query Methods
|
|
489
|
+
*/
|
|
490
|
+
|
|
491
|
+
interface AgencyFilters {
|
|
492
|
+
agencyId?: string | string[];
|
|
493
|
+
limit?: number;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Stop Query Methods
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
interface StopFilters {
|
|
501
|
+
stopId?: string | string[];
|
|
502
|
+
stopCode?: string | string[];
|
|
503
|
+
name?: string;
|
|
504
|
+
tripId?: string | string[];
|
|
505
|
+
limit?: number;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Route Query Methods
|
|
510
|
+
*/
|
|
511
|
+
|
|
512
|
+
interface RouteFilters {
|
|
513
|
+
routeId?: string | string[];
|
|
514
|
+
agencyId?: string | string[];
|
|
515
|
+
limit?: number;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Trip Query Methods
|
|
520
|
+
*/
|
|
521
|
+
|
|
522
|
+
interface TripFilters {
|
|
523
|
+
tripId?: string | string[];
|
|
524
|
+
routeId?: string | string[];
|
|
525
|
+
serviceIds?: string | string[];
|
|
526
|
+
directionId?: number | number[];
|
|
527
|
+
agencyId?: string | string[];
|
|
528
|
+
includeRealtime?: boolean;
|
|
529
|
+
limit?: number;
|
|
530
|
+
}
|
|
531
|
+
interface TripWithRealtime extends Trip {
|
|
532
|
+
realtime?: TripRealtime;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Stop Time Query Methods
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
interface StopTimeFilters {
|
|
540
|
+
tripId?: string | string[];
|
|
541
|
+
stopId?: string | string[];
|
|
542
|
+
routeId?: string | string[];
|
|
543
|
+
serviceIds?: string | string[];
|
|
544
|
+
directionId?: number | number[];
|
|
545
|
+
agencyId?: string | string[];
|
|
546
|
+
includeRealtime?: boolean;
|
|
547
|
+
limit?: number;
|
|
548
|
+
}
|
|
549
|
+
interface StopTimeWithRealtime extends StopTime {
|
|
550
|
+
realtime?: StopTimeRealtime;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Shape Query Methods
|
|
555
|
+
*/
|
|
556
|
+
|
|
557
|
+
interface ShapeFilters {
|
|
558
|
+
shapeId?: string | string[];
|
|
559
|
+
routeId?: string | string[];
|
|
560
|
+
tripId?: string | string[];
|
|
561
|
+
limit?: number;
|
|
562
|
+
}
|
|
563
|
+
interface GeoJsonGeometry {
|
|
564
|
+
type: 'LineString';
|
|
565
|
+
coordinates: number[][];
|
|
566
|
+
}
|
|
567
|
+
interface GeoJsonFeature {
|
|
568
|
+
type: 'Feature';
|
|
569
|
+
properties: {
|
|
570
|
+
shape_id: string;
|
|
571
|
+
route_id?: string;
|
|
572
|
+
route_short_name?: string;
|
|
573
|
+
route_long_name?: string;
|
|
574
|
+
route_type?: number;
|
|
575
|
+
route_color?: string;
|
|
576
|
+
route_text_color?: string;
|
|
577
|
+
agency_id?: string;
|
|
578
|
+
};
|
|
579
|
+
geometry: GeoJsonGeometry;
|
|
580
|
+
}
|
|
581
|
+
interface GeoJsonFeatureCollection {
|
|
582
|
+
type: 'FeatureCollection';
|
|
583
|
+
features: GeoJsonFeature[];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
interface TripUpdateFilters {
|
|
587
|
+
tripId?: string;
|
|
588
|
+
routeId?: string;
|
|
589
|
+
vehicleId?: string;
|
|
590
|
+
limit?: number;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
interface StopTimeUpdateFilters {
|
|
594
|
+
tripId?: string | string[];
|
|
595
|
+
stopId?: string | string[];
|
|
596
|
+
stopSequence?: number | number[];
|
|
597
|
+
limit?: number;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Progress information for GTFS data loading
|
|
602
|
+
*/
|
|
603
|
+
interface ProgressInfo {
|
|
604
|
+
phase: 'checking_cache' | 'loading_from_cache' | 'downloading' | 'extracting' | 'creating_schema' | 'inserting_data' | 'creating_indexes' | 'analyzing' | 'loading_realtime' | 'saving_cache' | 'complete';
|
|
605
|
+
currentFile: string | null;
|
|
606
|
+
filesCompleted: number;
|
|
607
|
+
totalFiles: number;
|
|
608
|
+
rowsProcessed: number;
|
|
609
|
+
totalRows: number;
|
|
610
|
+
bytesDownloaded?: number;
|
|
611
|
+
totalBytes?: number;
|
|
612
|
+
percentComplete: number;
|
|
613
|
+
message: string;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Progress callback function type
|
|
617
|
+
*/
|
|
618
|
+
type ProgressCallback = (progress: ProgressInfo) => void;
|
|
619
|
+
interface GtfsSqlJsOptions {
|
|
620
|
+
/**
|
|
621
|
+
* Path or URL to GTFS ZIP file
|
|
622
|
+
*/
|
|
623
|
+
zipPath?: string;
|
|
624
|
+
/**
|
|
625
|
+
* Pre-loaded SQLite database as ArrayBuffer
|
|
626
|
+
*/
|
|
627
|
+
database?: ArrayBuffer;
|
|
628
|
+
/**
|
|
629
|
+
* Optional: Custom SQL.js instance
|
|
630
|
+
*/
|
|
631
|
+
SQL?: SqlJsStatic;
|
|
632
|
+
/**
|
|
633
|
+
* Optional: Path to SQL.js WASM file (for custom loading)
|
|
634
|
+
*/
|
|
635
|
+
locateFile?: (filename: string) => string;
|
|
636
|
+
/**
|
|
637
|
+
* Optional: Array of GTFS filenames to skip importing (e.g., ['shapes.txt'])
|
|
638
|
+
* Tables will be created but no data will be imported for these files
|
|
639
|
+
*/
|
|
640
|
+
skipFiles?: string[];
|
|
641
|
+
/**
|
|
642
|
+
* Optional: Array of GTFS-RT feed URLs for realtime data
|
|
643
|
+
*/
|
|
644
|
+
realtimeFeedUrls?: string[];
|
|
645
|
+
/**
|
|
646
|
+
* Optional: Staleness threshold in seconds (default: 120)
|
|
647
|
+
* Realtime data older than this will be excluded from queries
|
|
648
|
+
*/
|
|
649
|
+
stalenessThreshold?: number;
|
|
650
|
+
/**
|
|
651
|
+
* Optional: Progress callback for tracking load progress
|
|
652
|
+
* Useful for displaying progress in UI or web workers
|
|
653
|
+
*/
|
|
654
|
+
onProgress?: ProgressCallback;
|
|
655
|
+
/**
|
|
656
|
+
* Optional: Cache store for persisting processed GTFS databases
|
|
657
|
+
* Implement your own CacheStore or copy one from examples/cache/:
|
|
658
|
+
* - IndexedDBCacheStore (browser)
|
|
659
|
+
* - FileSystemCacheStore (Node.js only)
|
|
660
|
+
*
|
|
661
|
+
* If not provided, caching is disabled.
|
|
662
|
+
*/
|
|
663
|
+
cache?: CacheStore | null;
|
|
664
|
+
/**
|
|
665
|
+
* Optional: Data version string
|
|
666
|
+
* When changed, cached databases are invalidated and reprocessed
|
|
667
|
+
* Default: '1.0'
|
|
668
|
+
*/
|
|
669
|
+
cacheVersion?: string;
|
|
670
|
+
/**
|
|
671
|
+
* Optional: Cache expiration time in milliseconds
|
|
672
|
+
* Cached databases older than this will be invalidated
|
|
673
|
+
* Default: 7 days (604800000 ms)
|
|
674
|
+
*/
|
|
675
|
+
cacheExpirationMs?: number;
|
|
676
|
+
}
|
|
677
|
+
declare class GtfsSqlJs {
|
|
678
|
+
private db;
|
|
679
|
+
private SQL;
|
|
680
|
+
private realtimeFeedUrls;
|
|
681
|
+
private stalenessThreshold;
|
|
682
|
+
private lastRealtimeFetchTimestamp;
|
|
683
|
+
/**
|
|
684
|
+
* Private constructor - use static factory methods instead
|
|
685
|
+
*/
|
|
686
|
+
private constructor();
|
|
687
|
+
/**
|
|
688
|
+
* Create GtfsSqlJs instance from GTFS ZIP file
|
|
689
|
+
*/
|
|
690
|
+
static fromZip(zipPath: string, options?: Omit<GtfsSqlJsOptions, 'zipPath' | 'database'>): Promise<GtfsSqlJs>;
|
|
691
|
+
/**
|
|
692
|
+
* Create GtfsSqlJs instance from existing SQLite database
|
|
693
|
+
*/
|
|
694
|
+
static fromDatabase(database: ArrayBuffer, options?: Omit<GtfsSqlJsOptions, 'zipPath' | 'database'>): Promise<GtfsSqlJs>;
|
|
695
|
+
/**
|
|
696
|
+
* Initialize from ZIP file
|
|
697
|
+
*/
|
|
698
|
+
private initFromZip;
|
|
699
|
+
/**
|
|
700
|
+
* Helper method to load GTFS data from zip data (ArrayBuffer)
|
|
701
|
+
* Used by both cache-enabled and cache-disabled paths
|
|
702
|
+
*/
|
|
703
|
+
private loadFromZipData;
|
|
704
|
+
/**
|
|
705
|
+
* Initialize from existing database
|
|
706
|
+
*/
|
|
707
|
+
private initFromDatabase;
|
|
708
|
+
/**
|
|
709
|
+
* Export database to ArrayBuffer
|
|
710
|
+
*/
|
|
711
|
+
export(): ArrayBuffer;
|
|
712
|
+
/**
|
|
713
|
+
* Close the database connection
|
|
714
|
+
*/
|
|
715
|
+
close(): void;
|
|
716
|
+
/**
|
|
717
|
+
* Get direct access to the database (for advanced queries)
|
|
718
|
+
*/
|
|
719
|
+
getDatabase(): Database;
|
|
720
|
+
/**
|
|
721
|
+
* Get agencies with optional filters
|
|
722
|
+
* Pass agencyId filter to get a specific agency
|
|
723
|
+
*/
|
|
724
|
+
getAgencies(filters?: AgencyFilters): Agency[];
|
|
725
|
+
/**
|
|
726
|
+
* Get stops with optional filters
|
|
727
|
+
* Pass stopId filter to get a specific stop
|
|
728
|
+
*/
|
|
729
|
+
getStops(filters?: StopFilters): Stop[];
|
|
730
|
+
/**
|
|
731
|
+
* Get routes with optional filters
|
|
732
|
+
* Pass routeId filter to get a specific route
|
|
733
|
+
*/
|
|
734
|
+
getRoutes(filters?: RouteFilters): Route[];
|
|
735
|
+
/**
|
|
736
|
+
* Get active service IDs for a given date (YYYYMMDD format)
|
|
737
|
+
*/
|
|
738
|
+
getActiveServiceIds(date: string): string[];
|
|
739
|
+
/**
|
|
740
|
+
* Get calendar entry by service_id
|
|
741
|
+
*/
|
|
742
|
+
getCalendarByServiceId(serviceId: string): Calendar | null;
|
|
743
|
+
/**
|
|
744
|
+
* Get calendar date exceptions for a service
|
|
745
|
+
*/
|
|
746
|
+
getCalendarDates(serviceId: string): CalendarDate[];
|
|
747
|
+
/**
|
|
748
|
+
* Get calendar date exceptions for a specific date
|
|
749
|
+
*/
|
|
750
|
+
getCalendarDatesForDate(date: string): CalendarDate[];
|
|
751
|
+
/**
|
|
752
|
+
* Get trips with optional filters
|
|
753
|
+
* Pass tripId filter to get a specific trip
|
|
754
|
+
*
|
|
755
|
+
* @param filters - Optional filters
|
|
756
|
+
* @param filters.tripId - Filter by trip ID (single value or array)
|
|
757
|
+
* @param filters.routeId - Filter by route ID (single value or array)
|
|
758
|
+
* @param filters.date - Filter by date (YYYYMMDD format) - will get active services for that date
|
|
759
|
+
* @param filters.directionId - Filter by direction ID (single value or array)
|
|
760
|
+
* @param filters.agencyId - Filter by agency ID (single value or array)
|
|
761
|
+
* @param filters.limit - Limit number of results
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* // Get all trips for a route on a specific date
|
|
765
|
+
* const trips = gtfs.getTrips({ routeId: 'ROUTE_1', date: '20240115' });
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* // Get all trips for a route going in one direction
|
|
769
|
+
* const trips = gtfs.getTrips({ routeId: 'ROUTE_1', directionId: 0 });
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* // Get a specific trip
|
|
773
|
+
* const trips = gtfs.getTrips({ tripId: 'TRIP_123' });
|
|
774
|
+
*/
|
|
775
|
+
getTrips(filters?: TripFilters & {
|
|
776
|
+
date?: string;
|
|
777
|
+
}): Trip[];
|
|
778
|
+
/**
|
|
779
|
+
* Get shapes with optional filters
|
|
780
|
+
*
|
|
781
|
+
* @param filters - Optional filters
|
|
782
|
+
* @param filters.shapeId - Filter by shape ID (single value or array)
|
|
783
|
+
* @param filters.routeId - Filter by route ID (single value or array) - joins with trips table
|
|
784
|
+
* @param filters.tripId - Filter by trip ID (single value or array) - joins with trips table
|
|
785
|
+
* @param filters.limit - Limit number of results
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* // Get all points for a specific shape
|
|
789
|
+
* const shapes = gtfs.getShapes({ shapeId: 'SHAPE_1' });
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* // Get shapes for a specific route
|
|
793
|
+
* const shapes = gtfs.getShapes({ routeId: 'ROUTE_1' });
|
|
794
|
+
*
|
|
795
|
+
* @example
|
|
796
|
+
* // Get shapes for multiple trips
|
|
797
|
+
* const shapes = gtfs.getShapes({ tripId: ['TRIP_1', 'TRIP_2'] });
|
|
798
|
+
*/
|
|
799
|
+
getShapes(filters?: ShapeFilters): Shape[];
|
|
800
|
+
/**
|
|
801
|
+
* Get shapes as GeoJSON FeatureCollection
|
|
802
|
+
*
|
|
803
|
+
* Each shape is converted to a LineString Feature with route properties.
|
|
804
|
+
* Coordinates are in [longitude, latitude] format per GeoJSON spec.
|
|
805
|
+
*
|
|
806
|
+
* @param filters - Optional filters (same as getShapes)
|
|
807
|
+
* @param filters.shapeId - Filter by shape ID (single value or array)
|
|
808
|
+
* @param filters.routeId - Filter by route ID (single value or array)
|
|
809
|
+
* @param filters.tripId - Filter by trip ID (single value or array)
|
|
810
|
+
* @param filters.limit - Limit number of results
|
|
811
|
+
* @param precision - Number of decimal places for coordinates (default: 6, ~10cm precision)
|
|
812
|
+
*
|
|
813
|
+
* @returns GeoJSON FeatureCollection with LineString features
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* // Get all shapes as GeoJSON
|
|
817
|
+
* const geojson = gtfs.getShapesToGeojson();
|
|
818
|
+
*
|
|
819
|
+
* @example
|
|
820
|
+
* // Get shapes for a route with lower precision
|
|
821
|
+
* const geojson = gtfs.getShapesToGeojson({ routeId: 'ROUTE_1' }, 5);
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* // Result structure:
|
|
825
|
+
* // {
|
|
826
|
+
* // type: 'FeatureCollection',
|
|
827
|
+
* // features: [{
|
|
828
|
+
* // type: 'Feature',
|
|
829
|
+
* // properties: {
|
|
830
|
+
* // shape_id: 'SHAPE_1',
|
|
831
|
+
* // route_id: 'ROUTE_1',
|
|
832
|
+
* // route_short_name: '1',
|
|
833
|
+
* // route_long_name: 'Main Street',
|
|
834
|
+
* // route_type: 3,
|
|
835
|
+
* // route_color: 'FF0000'
|
|
836
|
+
* // },
|
|
837
|
+
* // geometry: {
|
|
838
|
+
* // type: 'LineString',
|
|
839
|
+
* // coordinates: [[-122.123456, 37.123456], ...]
|
|
840
|
+
* // }
|
|
841
|
+
* // }]
|
|
842
|
+
* // }
|
|
843
|
+
*/
|
|
844
|
+
getShapesToGeojson(filters?: ShapeFilters, precision?: number): GeoJsonFeatureCollection;
|
|
845
|
+
/**
|
|
846
|
+
* Get stop times with optional filters
|
|
847
|
+
*
|
|
848
|
+
* @param filters - Optional filters
|
|
849
|
+
* @param filters.tripId - Filter by trip ID (single value or array)
|
|
850
|
+
* @param filters.stopId - Filter by stop ID (single value or array)
|
|
851
|
+
* @param filters.routeId - Filter by route ID (single value or array)
|
|
852
|
+
* @param filters.date - Filter by date (YYYYMMDD format) - will get active services for that date
|
|
853
|
+
* @param filters.directionId - Filter by direction ID (single value or array)
|
|
854
|
+
* @param filters.agencyId - Filter by agency ID (single value or array)
|
|
855
|
+
* @param filters.includeRealtime - Include realtime data (delay and time fields)
|
|
856
|
+
* @param filters.limit - Limit number of results
|
|
857
|
+
*
|
|
858
|
+
* @example
|
|
859
|
+
* // Get stop times for a specific trip
|
|
860
|
+
* const stopTimes = gtfs.getStopTimes({ tripId: 'TRIP_123' });
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* // Get stop times at a stop for a specific route on a date
|
|
864
|
+
* const stopTimes = gtfs.getStopTimes({
|
|
865
|
+
* stopId: 'STOP_123',
|
|
866
|
+
* routeId: 'ROUTE_1',
|
|
867
|
+
* date: '20240115'
|
|
868
|
+
* });
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
* // Get stop times with realtime data
|
|
872
|
+
* const stopTimes = gtfs.getStopTimes({
|
|
873
|
+
* tripId: 'TRIP_123',
|
|
874
|
+
* includeRealtime: true
|
|
875
|
+
* });
|
|
876
|
+
*/
|
|
877
|
+
getStopTimes(filters?: StopTimeFilters & {
|
|
878
|
+
date?: string;
|
|
879
|
+
}): StopTime[];
|
|
880
|
+
/**
|
|
881
|
+
* Build an ordered list of stops from multiple trips
|
|
882
|
+
*
|
|
883
|
+
* This is useful when you need to display a timetable for a route where different trips
|
|
884
|
+
* may stop at different sets of stops (e.g., express vs local service, or trips with
|
|
885
|
+
* different start/end points).
|
|
886
|
+
*
|
|
887
|
+
* The method intelligently merges stop sequences from all provided trips to create
|
|
888
|
+
* a comprehensive ordered list of all unique stops.
|
|
889
|
+
*
|
|
890
|
+
* @param tripIds - Array of trip IDs to analyze
|
|
891
|
+
* @returns Ordered array of Stop objects representing all unique stops
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* // Get all trips for a route going in one direction
|
|
895
|
+
* const trips = gtfs.getTrips({ routeId: 'ROUTE_1', directionId: 0 });
|
|
896
|
+
* const tripIds = trips.map(t => t.trip_id);
|
|
897
|
+
*
|
|
898
|
+
* // Build ordered stop list for all these trips
|
|
899
|
+
* const stops = gtfs.buildOrderedStopList(tripIds);
|
|
900
|
+
*
|
|
901
|
+
* // Now you can display a timetable with all possible stops
|
|
902
|
+
* stops.forEach(stop => {
|
|
903
|
+
* console.log(stop.stop_name);
|
|
904
|
+
* });
|
|
905
|
+
*/
|
|
906
|
+
buildOrderedStopList(tripIds: string[]): Stop[];
|
|
907
|
+
/**
|
|
908
|
+
* Set GTFS-RT feed URLs
|
|
909
|
+
*/
|
|
910
|
+
setRealtimeFeedUrls(urls: string[]): void;
|
|
911
|
+
/**
|
|
912
|
+
* Get currently configured GTFS-RT feed URLs
|
|
913
|
+
*/
|
|
914
|
+
getRealtimeFeedUrls(): string[];
|
|
915
|
+
/**
|
|
916
|
+
* Set staleness threshold in seconds
|
|
917
|
+
*/
|
|
918
|
+
setStalenessThreshold(seconds: number): void;
|
|
919
|
+
/**
|
|
920
|
+
* Get current staleness threshold
|
|
921
|
+
*/
|
|
922
|
+
getStalenessThreshold(): number;
|
|
923
|
+
/**
|
|
924
|
+
* Get timestamp of the last successful realtime data fetch and insertion
|
|
925
|
+
* @returns Unix timestamp in seconds, or null if no realtime data has been fetched
|
|
926
|
+
*/
|
|
927
|
+
getLastRealtimeFetchTimestamp(): number | null;
|
|
928
|
+
/**
|
|
929
|
+
* Fetch and load GTFS Realtime data from configured feed URLs or provided URLs
|
|
930
|
+
* @param urls - Optional array of feed URLs. If not provided, uses configured feed URLs
|
|
931
|
+
*/
|
|
932
|
+
fetchRealtimeData(urls?: string[]): Promise<void>;
|
|
933
|
+
/**
|
|
934
|
+
* Clear all realtime data from the database
|
|
935
|
+
*/
|
|
936
|
+
clearRealtimeData(): void;
|
|
937
|
+
/**
|
|
938
|
+
* Get alerts with optional filters
|
|
939
|
+
* Pass alertId filter to get a specific alert
|
|
940
|
+
*/
|
|
941
|
+
getAlerts(filters?: AlertFilters): Alert[];
|
|
942
|
+
/**
|
|
943
|
+
* Get vehicle positions with optional filters
|
|
944
|
+
* Pass tripId filter to get vehicle position for a specific trip
|
|
945
|
+
*/
|
|
946
|
+
getVehiclePositions(filters?: VehiclePositionFilters): VehiclePosition[];
|
|
947
|
+
/**
|
|
948
|
+
* Get trip updates with optional filters
|
|
949
|
+
* Pass tripId filter to get trip update for a specific trip
|
|
950
|
+
*/
|
|
951
|
+
getTripUpdates(filters?: TripUpdateFilters): TripUpdate[];
|
|
952
|
+
/**
|
|
953
|
+
* Get stop time updates with optional filters
|
|
954
|
+
* Pass tripId filter to get stop time updates for a specific trip
|
|
955
|
+
*/
|
|
956
|
+
getStopTimeUpdates(filters?: StopTimeUpdateFilters): StopTimeUpdate[];
|
|
957
|
+
/**
|
|
958
|
+
* Export all alerts without staleness filtering (for debugging)
|
|
959
|
+
*/
|
|
960
|
+
debugExportAllAlerts(): Alert[];
|
|
961
|
+
/**
|
|
962
|
+
* Export all vehicle positions without staleness filtering (for debugging)
|
|
963
|
+
*/
|
|
964
|
+
debugExportAllVehiclePositions(): VehiclePosition[];
|
|
965
|
+
/**
|
|
966
|
+
* Export all trip updates without staleness filtering (for debugging)
|
|
967
|
+
*/
|
|
968
|
+
debugExportAllTripUpdates(): TripUpdate[];
|
|
969
|
+
/**
|
|
970
|
+
* Export all stop time updates without staleness filtering (for debugging)
|
|
971
|
+
* Returns stop time updates with trip_id and rt_last_updated populated
|
|
972
|
+
*/
|
|
973
|
+
debugExportAllStopTimeUpdates(): StopTimeUpdate[];
|
|
974
|
+
/**
|
|
975
|
+
* Get cache statistics
|
|
976
|
+
* @param cacheStore - Cache store to query (required)
|
|
977
|
+
* @returns Cache statistics including size, entry count, and age information
|
|
978
|
+
*/
|
|
979
|
+
static getCacheStats(cacheStore: CacheStore): Promise<{
|
|
980
|
+
totalEntries: number;
|
|
981
|
+
activeEntries: number;
|
|
982
|
+
expiredEntries: number;
|
|
983
|
+
totalSize: number;
|
|
984
|
+
totalSizeMB: string;
|
|
985
|
+
oldestEntry: number | null;
|
|
986
|
+
newestEntry: number | null;
|
|
987
|
+
}>;
|
|
988
|
+
/**
|
|
989
|
+
* Clean expired cache entries
|
|
990
|
+
* @param cacheStore - Cache store to clean (required)
|
|
991
|
+
* @param expirationMs - Expiration time in milliseconds (default: 7 days)
|
|
992
|
+
* @returns Number of entries deleted
|
|
993
|
+
*/
|
|
994
|
+
static cleanExpiredCache(cacheStore: CacheStore, expirationMs?: number): Promise<number>;
|
|
995
|
+
/**
|
|
996
|
+
* Clear all cache entries
|
|
997
|
+
* @param cacheStore - Cache store to clear (required)
|
|
998
|
+
*/
|
|
999
|
+
static clearCache(cacheStore: CacheStore): Promise<void>;
|
|
1000
|
+
/**
|
|
1001
|
+
* List all cache entries
|
|
1002
|
+
* @param cacheStore - Cache store to query (required)
|
|
1003
|
+
* @param includeExpired - Include expired entries (default: false)
|
|
1004
|
+
* @returns Array of cache entries with metadata
|
|
1005
|
+
*/
|
|
1006
|
+
static listCache(cacheStore: CacheStore, includeExpired?: boolean): Promise<CacheEntry[]>;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* SQLite Schema Definitions for GTFS Data
|
|
1011
|
+
* Matches required/optional fields from GTFS specification
|
|
1012
|
+
*/
|
|
1013
|
+
interface TableSchema {
|
|
1014
|
+
name: string;
|
|
1015
|
+
columns: ColumnDefinition[];
|
|
1016
|
+
indexes?: IndexDefinition[];
|
|
1017
|
+
}
|
|
1018
|
+
interface ColumnDefinition {
|
|
1019
|
+
name: string;
|
|
1020
|
+
type: 'TEXT' | 'INTEGER' | 'REAL';
|
|
1021
|
+
required: boolean;
|
|
1022
|
+
primaryKey?: boolean;
|
|
1023
|
+
}
|
|
1024
|
+
interface IndexDefinition {
|
|
1025
|
+
name: string;
|
|
1026
|
+
columns: string[];
|
|
1027
|
+
unique?: boolean;
|
|
1028
|
+
}
|
|
1029
|
+
declare const GTFS_SCHEMA: TableSchema[];
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Compute SHA-256 checksum of data
|
|
1033
|
+
* Uses Web Crypto API (available in both browser and Node.js 18+)
|
|
1034
|
+
*/
|
|
1035
|
+
declare function computeChecksum(data: ArrayBuffer | Uint8Array): Promise<string>;
|
|
1036
|
+
/**
|
|
1037
|
+
* Compute checksum for a zip file
|
|
1038
|
+
* @param zipData - The zip file data (ArrayBuffer or Uint8Array)
|
|
1039
|
+
* @returns SHA-256 checksum as hex string
|
|
1040
|
+
*/
|
|
1041
|
+
declare function computeZipChecksum(zipData: ArrayBuffer | Uint8Array): Promise<string>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Generate a cache key from checksum, version, filesize, source, and options
|
|
1044
|
+
* Format: v{libVersion}_{dataVersion}_{filesize}_{checksum}_{source}_{skipFiles}
|
|
1045
|
+
*
|
|
1046
|
+
* @param checksum - SHA-256 checksum of zip file
|
|
1047
|
+
* @param libVersion - Library version from package.json
|
|
1048
|
+
* @param dataVersion - User-specified data version
|
|
1049
|
+
* @param filesize - Size of the zip file in bytes
|
|
1050
|
+
* @param source - Source URL or filename (optional)
|
|
1051
|
+
* @param skipFiles - Files that were skipped during import
|
|
1052
|
+
* @returns Cache key string
|
|
1053
|
+
*/
|
|
1054
|
+
declare function generateCacheKey(checksum: string, libVersion: string, dataVersion: string, filesize: number, source?: string, skipFiles?: string[]): string;
|
|
1055
|
+
|
|
1056
|
+
/**
|
|
1057
|
+
* Default cache expiration time in milliseconds (7 days)
|
|
1058
|
+
*/
|
|
1059
|
+
declare const DEFAULT_CACHE_EXPIRATION_MS: number;
|
|
1060
|
+
/**
|
|
1061
|
+
* Check if a cache entry is expired
|
|
1062
|
+
* @param metadata - Cache metadata
|
|
1063
|
+
* @param expirationMs - Expiration time in milliseconds (default: 7 days)
|
|
1064
|
+
* @returns true if the cache entry is expired
|
|
1065
|
+
*/
|
|
1066
|
+
declare function isCacheExpired(metadata: CacheMetadata, expirationMs?: number): boolean;
|
|
1067
|
+
/**
|
|
1068
|
+
* Filter out expired cache entries
|
|
1069
|
+
* @param entries - Array of cache entries
|
|
1070
|
+
* @param expirationMs - Expiration time in milliseconds (default: 7 days)
|
|
1071
|
+
* @returns Filtered array of non-expired entries
|
|
1072
|
+
*/
|
|
1073
|
+
declare function filterExpiredEntries(entries: CacheEntry[], expirationMs?: number): CacheEntry[];
|
|
1074
|
+
/**
|
|
1075
|
+
* Get cache statistics
|
|
1076
|
+
* @param entries - Array of cache entries
|
|
1077
|
+
* @returns Cache statistics
|
|
1078
|
+
*/
|
|
1079
|
+
declare function getCacheStats(entries: CacheEntry[]): {
|
|
1080
|
+
totalEntries: number;
|
|
1081
|
+
activeEntries: number;
|
|
1082
|
+
expiredEntries: number;
|
|
1083
|
+
totalSize: number;
|
|
1084
|
+
totalSizeMB: string;
|
|
1085
|
+
oldestEntry: number | null;
|
|
1086
|
+
newestEntry: number | null;
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
export { type Agency, type AgencyFilters, type Alert, AlertCause, AlertEffect, type AlertFilters, type Attribution, type CacheEntry, type CacheEntryWithData, type CacheMetadata, type CacheStore, type CacheStoreOptions, type Calendar, type CalendarDate, type ColumnDefinition, CongestionLevel, DEFAULT_CACHE_EXPIRATION_MS, type EntitySelector, type FareAttribute, type FareRule, type FeedInfo, type Frequency, GTFS_SCHEMA, type GeoJsonFeatureCollection, GtfsSqlJs, type GtfsSqlJsOptions, type IndexDefinition, type Level, OccupancyStatus, type Pathway, type Position, type RealtimeConfig, type Route, type RouteFilters, ScheduleRelationship, type Shape, type ShapeFilters, type Stop, type StopFilters, type StopTime, type StopTimeEvent, type StopTimeFilters, type StopTimeRealtime, type StopTimeUpdate, type StopTimeUpdateFilters, type StopTimeWithRealtime, type TableSchema, type TimeRange, type Transfer, type TranslatedString, type Trip, type TripFilters, type TripRealtime, type TripUpdate, type TripUpdateFilters, type TripWithRealtime, type VehicleDescriptor, type VehiclePosition, type VehiclePositionFilters, VehicleStopStatus, computeChecksum, computeZipChecksum, filterExpiredEntries, generateCacheKey, getCacheStats, isCacheExpired };
|