gtfs 3.8.0 → 4.0.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.
Files changed (89) hide show
  1. package/@types/index.d.ts +35 -60
  2. package/@types/tests.ts +18 -13
  3. package/CHANGELOG.md +10 -0
  4. package/README.md +227 -207
  5. package/lib/advancedQuery.js +8 -17
  6. package/lib/db.js +29 -59
  7. package/lib/export.js +16 -10
  8. package/lib/gtfs/agencies.js +8 -6
  9. package/lib/gtfs/areas.js +8 -11
  10. package/lib/gtfs/attributions.js +8 -6
  11. package/lib/gtfs/calendar-dates.js +8 -6
  12. package/lib/gtfs/calendars.js +8 -6
  13. package/lib/gtfs/fare-attributes.js +8 -6
  14. package/lib/gtfs/fare-leg-rules.js +8 -6
  15. package/lib/gtfs/fare-products.js +8 -6
  16. package/lib/gtfs/fare-rules.js +8 -6
  17. package/lib/gtfs/fare-transfer-rules.js +8 -6
  18. package/lib/gtfs/feed-info.js +8 -6
  19. package/lib/gtfs/frequencies.js +8 -6
  20. package/lib/gtfs/levels.js +8 -11
  21. package/lib/gtfs/pathways.js +8 -6
  22. package/lib/gtfs/routes.js +8 -11
  23. package/lib/gtfs/shapes.js +34 -39
  24. package/lib/gtfs/stop-areas.js +8 -6
  25. package/lib/gtfs/stop-times.js +8 -6
  26. package/lib/gtfs/stops.js +27 -33
  27. package/lib/gtfs/transfers.js +8 -6
  28. package/lib/gtfs/translations.js +8 -6
  29. package/lib/gtfs/trips.js +8 -11
  30. package/lib/gtfs-realtime/service-alerts.js +9 -7
  31. package/lib/gtfs-realtime/stop-times-updates.js +9 -7
  32. package/lib/gtfs-realtime/trip-updates.js +9 -7
  33. package/lib/gtfs-realtime/vehicle-positions.js +9 -7
  34. package/lib/gtfs-ride/board-alights.js +8 -6
  35. package/lib/gtfs-ride/ride-feed-infos.js +8 -6
  36. package/lib/gtfs-ride/rider-trips.js +8 -6
  37. package/lib/gtfs-ride/riderships.js +8 -6
  38. package/lib/gtfs-ride/trip-capacities.js +8 -6
  39. package/lib/gtfs.js +3 -9
  40. package/lib/import.js +195 -202
  41. package/lib/non-standard/directions.js +8 -6
  42. package/lib/non-standard/stop-attributes.js +8 -6
  43. package/lib/non-standard/timetable-notes-references.js +8 -6
  44. package/lib/non-standard/timetable-notes.js +8 -6
  45. package/lib/non-standard/timetable-pages.js +8 -6
  46. package/lib/non-standard/timetable-stop-order.js +8 -6
  47. package/lib/non-standard/timetables.js +8 -6
  48. package/lib/non-standard/trips-dated-vehicle-journey.js +9 -7
  49. package/package.json +2 -3
  50. package/test/mocha/advanced-query.js +9 -15
  51. package/test/mocha/export-gtfs.js +5 -6
  52. package/test/mocha/fare-transfer-rules.js +32 -0
  53. package/test/mocha/get-agencies.js +13 -19
  54. package/test/mocha/get-areas.js +27 -0
  55. package/test/mocha/get-attributions.js +7 -13
  56. package/test/mocha/get-board-alights.js +7 -13
  57. package/test/mocha/get-calendar-dates.js +11 -17
  58. package/test/mocha/get-calendars.js +11 -17
  59. package/test/mocha/get-directions.js +7 -13
  60. package/test/mocha/get-fare-attributes.js +9 -15
  61. package/test/mocha/get-fare-leg-rules.js +27 -0
  62. package/test/mocha/get-fare-products.js +27 -0
  63. package/test/mocha/get-fare-rules.js +9 -15
  64. package/test/mocha/get-feed-info.js +7 -13
  65. package/test/mocha/get-frequencies.js +7 -13
  66. package/test/mocha/get-levels.js +7 -7
  67. package/test/mocha/get-pathways.js +7 -13
  68. package/test/mocha/get-ride-feed-infos.js +7 -13
  69. package/test/mocha/get-rider-trips.js +7 -13
  70. package/test/mocha/get-riderships.js +7 -13
  71. package/test/mocha/get-routes.js +13 -13
  72. package/test/mocha/get-shapes-as-geojson.js +14 -15
  73. package/test/mocha/get-shapes.js +25 -25
  74. package/test/mocha/get-stop-attributes.js +7 -13
  75. package/test/mocha/get-stops-as-geojson.js +13 -19
  76. package/test/mocha/get-stops.js +19 -19
  77. package/test/mocha/get-stoptimes.js +11 -17
  78. package/test/mocha/get-timetable-pages.js +7 -13
  79. package/test/mocha/get-timetable-stop-orders.js +6 -7
  80. package/test/mocha/get-timetables.js +7 -13
  81. package/test/mocha/get-transfers.js +7 -13
  82. package/test/mocha/get-translations.js +7 -13
  83. package/test/mocha/get-trip-capacities.js +7 -13
  84. package/test/mocha/get-trips.js +9 -9
  85. package/test/mocha/import-gtfs.js +11 -11
  86. package/test/mocha/{get-db.js → open-db.js} +37 -29
  87. package/test/mocha/raw-query.js +34 -0
  88. package/test/mocha/exec-raw-query.js +0 -39
  89. package/test/mocha/run-raw-query.js +0 -54
package/@types/index.d.ts CHANGED
@@ -1,13 +1,9 @@
1
1
  import CsvParse = require('csv-parse');
2
- import * as Sqlite3 from 'sqlite';
2
+
3
3
  import { FeatureCollection, Geometry } from '@turf/helpers';
4
4
 
5
5
  export {}; // disable implicit exporting of types
6
6
 
7
- type Unpromise<T> = T extends Promise<infer U> ? U : T;
8
-
9
- export type SqlDatabase = Unpromise<ReturnType<typeof Sqlite3.open>>;
10
-
11
7
  export type SqlValue =
12
8
  | undefined
13
9
  | null
@@ -146,11 +142,6 @@ export function openDb(config: DbConfig): Promise<SqlDatabase>;
146
142
  */
147
143
  export function closeDb(db?: SqlDatabase): Promise<void>;
148
144
 
149
- /**
150
- * Get open database. Throws error if no database is open.
151
- */
152
- export function getDb(config?: DbConfig): Promise<SqlDatabase>;
153
-
154
145
  /**
155
146
  * Queries agencies and returns a promise for an array of agencies.
156
147
  */
@@ -159,7 +150,7 @@ export function getAgencies(
159
150
  fields?: SqlSelect,
160
151
  sortBy?: SqlOrderBy,
161
152
  options?: QueryOptions
162
- ): Promise<SqlResults>;
153
+ ): SqlResults;
163
154
 
164
155
  /**
165
156
  * Queries attributions and returns a promise for an array of attributions.
@@ -169,7 +160,7 @@ export function getAttributions(
169
160
  fields?: SqlSelect,
170
161
  sortBy?: SqlOrderBy,
171
162
  options?: QueryOptions
172
- ): Promise<SqlResults>;
163
+ ): SqlResults;
173
164
 
174
165
  /**
175
166
  * Queries routes and returns a promise for an array of routes.
@@ -179,7 +170,7 @@ export function getRoutes(
179
170
  fields?: SqlSelect,
180
171
  sortBy?: SqlOrderBy,
181
172
  options?: QueryOptions
182
- ): Promise<SqlResults>;
173
+ ): SqlResults;
183
174
 
184
175
  /**
185
176
  * Queries stops and returns a promise for an array of stops.
@@ -189,7 +180,7 @@ export function getStops(
189
180
  fields?: SqlSelect,
190
181
  sortBy?: SqlOrderBy,
191
182
  options?: QueryOptions
192
- ): Promise<SqlResults>;
183
+ ): SqlResults;
193
184
 
194
185
  /**
195
186
  * Queries stops and returns a promise for an geoJSON object of stops.
@@ -208,7 +199,7 @@ export function getStoptimes(
208
199
  fields?: SqlSelect,
209
200
  sortBy?: SqlOrderBy,
210
201
  options?: QueryOptions
211
- ): Promise<SqlResults>;
202
+ ): SqlResults;
212
203
 
213
204
  /**
214
205
  * Queries trips and returns a promise for an array of trips.
@@ -218,7 +209,7 @@ export function getTrips(
218
209
  fields?: SqlSelect,
219
210
  sortBy?: SqlOrderBy,
220
211
  options?: QueryOptions
221
- ): Promise<SqlResults>;
212
+ ): SqlResults;
222
213
 
223
214
  /**
224
215
  * Queries shapes and returns a promise for an array of shapes.
@@ -228,7 +219,7 @@ export function getShapes(
228
219
  fields?: SqlSelect,
229
220
  sortBy?: SqlOrderBy,
230
221
  options?: QueryOptions
231
- ): Promise<SqlResults>;
222
+ ): SqlResults;
232
223
 
233
224
  /**
234
225
  * Queries shapes and returns a promise for an geoJSON object of shapes.
@@ -247,7 +238,7 @@ export function getCalendars(
247
238
  fields?: SqlSelect,
248
239
  sortBy?: SqlOrderBy,
249
240
  options?: QueryOptions
250
- ): Promise<SqlResults>;
241
+ ): SqlResults;
251
242
 
252
243
  /**
253
244
  * Queries calendar_dates and returns a promise for an array of calendar_dates.
@@ -257,7 +248,7 @@ export function getCalendarDates(
257
248
  fields?: SqlSelect,
258
249
  sortBy?: SqlOrderBy,
259
250
  options?: QueryOptions
260
- ): Promise<SqlResults>;
251
+ ): SqlResults;
261
252
 
262
253
  /**
263
254
  * Queries fare_attributes and returns a promise for an array of fare_attributes.
@@ -267,7 +258,7 @@ export function getFareAttributes(
267
258
  fields?: SqlSelect,
268
259
  sortBy?: SqlOrderBy,
269
260
  options?: QueryOptions
270
- ): Promise<SqlResults>;
261
+ ): SqlResults;
271
262
 
272
263
  /**
273
264
  * Queries fare_rules and returns a promise for an array of fare_rules.
@@ -277,7 +268,7 @@ export function getFareRules(
277
268
  fields?: SqlSelect,
278
269
  sortBy?: SqlOrderBy,
279
270
  options?: QueryOptions
280
- ): Promise<SqlResults>;
271
+ ): SqlResults;
281
272
 
282
273
  /**
283
274
  * Queries feed_info and returns a promise for an array of feed_infos.
@@ -287,7 +278,7 @@ export function getFeedInfo(
287
278
  fields?: SqlSelect,
288
279
  sortBy?: SqlOrderBy,
289
280
  options?: QueryOptions
290
- ): Promise<SqlResults>;
281
+ ): SqlResults;
291
282
 
292
283
  /**
293
284
  * Queries frequencies and returns a promise for an array of frequencies.
@@ -297,7 +288,7 @@ export function getFrequencies(
297
288
  fields?: SqlSelect,
298
289
  sortBy?: SqlOrderBy,
299
290
  options?: QueryOptions
300
- ): Promise<SqlResults>;
291
+ ): SqlResults;
301
292
 
302
293
  /**
303
294
  * Queries levels and returns a promise for an array of levels.
@@ -307,7 +298,7 @@ export function getLevels(
307
298
  fields?: SqlSelect,
308
299
  sortBy?: SqlOrderBy,
309
300
  options?: QueryOptions
310
- ): Promise<SqlResults>;
301
+ ): SqlResults;
311
302
 
312
303
  /**
313
304
  * Queries pathways and returns a promise for an array of pathways.
@@ -317,7 +308,7 @@ export function getPathways(
317
308
  fields?: SqlSelect,
318
309
  sortBy?: SqlOrderBy,
319
310
  options?: QueryOptions
320
- ): Promise<SqlResults>;
311
+ ): SqlResults;
321
312
 
322
313
  /**
323
314
  * Queries transfers and returns a promise for an array of transfers.
@@ -327,7 +318,7 @@ export function getTransfers(
327
318
  fields?: SqlSelect,
328
319
  sortBy?: SqlOrderBy,
329
320
  options?: QueryOptions
330
- ): Promise<SqlResults>;
321
+ ): SqlResults;
331
322
 
332
323
  /**
333
324
  * Queries translations and returns a promise for an array of translations.
@@ -337,7 +328,7 @@ export function getTranslations(
337
328
  fields?: SqlSelect,
338
329
  sortBy?: SqlOrderBy,
339
330
  options?: QueryOptions
340
- ): Promise<SqlResults>;
331
+ ): SqlResults;
341
332
 
342
333
  /**
343
334
  * Queries directions and returns a promise for an array of directions.
@@ -348,7 +339,7 @@ export function getDirections(
348
339
  fields?: SqlSelect,
349
340
  sortBy?: SqlOrderBy,
350
341
  options?: QueryOptions
351
- ): Promise<SqlResults>;
342
+ ): SqlResults;
352
343
 
353
344
  /**
354
345
  * Queries stop_attributes and returns a promise for an array of stop_attributes.
@@ -359,7 +350,7 @@ export function getStopAttributes(
359
350
  fields?: SqlSelect,
360
351
  sortBy?: SqlOrderBy,
361
352
  options?: QueryOptions
362
- ): Promise<SqlResults>;
353
+ ): SqlResults;
363
354
 
364
355
  /**
365
356
  * Queries timetables and returns a promise for an array of timetables.
@@ -370,7 +361,7 @@ export function getTimetables(
370
361
  fields?: SqlSelect,
371
362
  sortBy?: SqlOrderBy,
372
363
  options?: QueryOptions
373
- ): Promise<SqlResults>;
364
+ ): SqlResults;
374
365
 
375
366
  /**
376
367
  * Queries timetable_stop_orders and returns a promise for an array of timetable_stop_orders.
@@ -381,7 +372,7 @@ export function getTimetableStopOrders(
381
372
  fields?: SqlSelect,
382
373
  sortBy?: SqlOrderBy,
383
374
  options?: QueryOptions
384
- ): Promise<SqlResults>;
375
+ ): SqlResults;
385
376
 
386
377
  /**
387
378
  * Queries timetable_pages and returns a promise for an array of timetable_pages.
@@ -392,7 +383,7 @@ export function getTimetablePages(
392
383
  fields?: SqlSelect,
393
384
  sortBy?: SqlOrderBy,
394
385
  options?: QueryOptions
395
- ): Promise<SqlResults>;
386
+ ): SqlResults;
396
387
 
397
388
  /**
398
389
  * Queries timetable_notes and returns a promise for an array of timetable_notes.
@@ -403,7 +394,7 @@ export function getTimetableNotes(
403
394
  fields?: SqlSelect,
404
395
  sortBy?: SqlOrderBy,
405
396
  options?: QueryOptions
406
- ): Promise<SqlResults>;
397
+ ): SqlResults;
407
398
 
408
399
  /**
409
400
  * Queries timetable_notes_references and returns a promise for an array of timetable_notes references.
@@ -414,7 +405,7 @@ export function getTimetableNotesReferences(
414
405
  fields?: SqlSelect,
415
406
  sortBy?: SqlOrderBy,
416
407
  options?: QueryOptions
417
- ): Promise<SqlResults>;
408
+ ): SqlResults;
418
409
 
419
410
  /**
420
411
  * Queries board-alights and returns a promise for an array of board-alights.
@@ -424,7 +415,7 @@ export function getBoardAlights(
424
415
  fields?: SqlSelect,
425
416
  sortBy?: SqlOrderBy,
426
417
  options?: QueryOptions
427
- ): Promise<SqlResults>;
418
+ ): SqlResults;
428
419
 
429
420
  /**
430
421
  * Queries ride-feed-info and returns a promise for an array of ride-feed-info.
@@ -434,7 +425,7 @@ export function getRideFeedInfos(
434
425
  fields?: SqlSelect,
435
426
  sortBy?: SqlOrderBy,
436
427
  options?: QueryOptions
437
- ): Promise<SqlResults>;
428
+ ): SqlResults;
438
429
 
439
430
  /**
440
431
  * Queries rider trips and returns a promise for an array of rider trips.
@@ -444,7 +435,7 @@ export function getRiderTrips(
444
435
  fields?: SqlSelect,
445
436
  sortBy?: SqlOrderBy,
446
437
  options?: QueryOptions
447
- ): Promise<SqlResults>;
438
+ ): SqlResults;
448
439
 
449
440
  /**
450
441
  * Queries riderships and returns a promise for an array of riderships.
@@ -454,7 +445,7 @@ export function getRiderships(
454
445
  fields?: SqlSelect,
455
446
  sortBy?: SqlOrderBy,
456
447
  options?: QueryOptions
457
- ): Promise<SqlResults>;
448
+ ): SqlResults;
458
449
 
459
450
  /**
460
451
  * Queries trip-capacities and returns a promise for an array of trip-capacities.
@@ -464,7 +455,7 @@ export function getTripCapacities(
464
455
  fields?: SqlSelect,
465
456
  sortBy?: SqlOrderBy,
466
457
  options?: QueryOptions
467
- ): Promise<SqlResults>;
458
+ ): SqlResults;
468
459
 
469
460
  /**
470
461
  * Queries trip-capacities and returns a promise for an array of service-alerts.
@@ -474,7 +465,7 @@ export function getServiceAlerts(
474
465
  fields?: SqlSelect,
475
466
  sortBy?: SqlOrderBy,
476
467
  options?: QueryOptions
477
- ): Promise<SqlResults>;
468
+ ): SqlResults;
478
469
 
479
470
  /**
480
471
  * Queries trip-capacities and returns a promise for an array of trip-updates.
@@ -484,7 +475,7 @@ export function getTripUpdates(
484
475
  fields?: SqlSelect,
485
476
  sortBy?: SqlOrderBy,
486
477
  options?: QueryOptions
487
- ): Promise<SqlResults>;
478
+ ): SqlResults;
488
479
 
489
480
  /**
490
481
  * Queries trip-capacities and returns a promise for an array of vehicle-positions.
@@ -494,7 +485,7 @@ export function getVehiclePositions(
494
485
  fields?: SqlSelect,
495
486
  sortBy?: SqlOrderBy,
496
487
  options?: QueryOptions
497
- ): Promise<SqlResults>;
488
+ ): SqlResults;
498
489
 
499
490
  /**
500
491
  * Queries trip-capacities and returns a promise for an array of stop-times-updates.
@@ -504,7 +495,7 @@ export function getStopTimesUpdates(
504
495
  fields?: SqlSelect,
505
496
  sortBy?: SqlOrderBy,
506
497
  options?: QueryOptions
507
- ): Promise<SqlResults>;
498
+ ): SqlResults;
508
499
 
509
500
  /**
510
501
  * Runs an advanced query.
@@ -512,20 +503,4 @@ export function getStopTimesUpdates(
512
503
  export function advancedQuery(
513
504
  table?: SqlTableName,
514
505
  advancedQueryOptions?: AdvancedQueryOptions
515
- ): Promise<SqlResults>;
516
-
517
- /**
518
- * Runs an raw query retuning all rows.
519
- */
520
- export function runRawQuery(
521
- sql?: SqlQueryString,
522
- options?: QueryOptions
523
- ): Promise<SqlResults>;
524
-
525
- /**
526
- * Executing an raw query.
527
- */
528
- export function execRawQuery(
529
- sql?: SqlQueryString,
530
- options?: QueryOptions
531
- ): Promise<any>;
506
+ ): SqlResults;
package/@types/tests.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { Config, exportGtfs, getAgencies, getDb, getShapesAsGeoJSON, importGtfs, openDb } from "gtfs";
1
+ import {
2
+ Config,
3
+ exportGtfs,
4
+ getAgencies,
5
+ getShapesAsGeoJSON,
6
+ importGtfs,
7
+ openDb,
8
+ } from 'gtfs';
2
9
 
3
10
  /**
4
11
  * This is type-checked (but not executed) by dtslint.
@@ -6,21 +13,19 @@ import { Config, exportGtfs, getAgencies, getDb, getShapesAsGeoJSON, importGtfs,
6
13
  */
7
14
 
8
15
  (async () => {
9
- const config: Config = {
10
- agencies: [{ path: "example.zip" }],
11
- verbose: false,
12
- };
16
+ const config: Config = {
17
+ agencies: [{ path: 'example.zip' }],
18
+ verbose: false,
19
+ };
13
20
 
14
- await importGtfs(config); // $ExpectType void
21
+ await importGtfs(config); // $ExpectType void
15
22
 
16
- await exportGtfs(config); // $ExpectType void
23
+ await exportGtfs(config); // $ExpectType void
17
24
 
18
- await openDb(config); // $ExpectType Database<Database, Statement>
25
+ openDb(config); // $ExpectType Database<Database, Statement>
19
26
 
20
- await getDb(); // $ExpectType Database<Database, Statement>
27
+ const results = getAgencies();
28
+ results[0]; // $ExpectType Record<string, any>
21
29
 
22
- const results = await getAgencies();
23
- results[0]; // $ExpectType Record<string, any>
24
-
25
- await getShapesAsGeoJSON(); // $ExpectType FeatureCollection<Geometry, { [name: string]: any; }>
30
+ getShapesAsGeoJSON(); // $ExpectType FeatureCollection<Geometry, { [name: string]: any; }>
26
31
  })();
package/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [4.0.0] - 2022-12-30
9
+
10
+ ### Changed
11
+
12
+ - Use better-sqlite3 library
13
+ - Make all query methods synchronous
14
+ - Remove `runRawQuery` (use Raw SQLite query instead)
15
+ - Remove `execRawQuery` (use Raw SQLite query instead)
16
+ - Remove `getDb` (use `openDb` instead)
17
+
8
18
  ## [3.8.0] - 2022-12-22
9
19
 
10
20
  ### Updated