gtfs 3.1.4 → 3.2.3
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/@types/index.d.ts +269 -0
- package/@types/tests.ts +26 -0
- package/@types/tsconfig.json +17 -0
- package/CHANGELOG.md +35 -0
- package/README.md +54 -22
- package/docs/images/node-gtfs-logo.svg +18 -0
- package/lib/db.js +63 -14
- package/lib/export.js +1 -4
- package/lib/gtfs/agencies.js +7 -2
- package/lib/gtfs/attributions.js +7 -2
- package/lib/gtfs/calendar-dates.js +7 -2
- package/lib/gtfs/calendars.js +7 -2
- package/lib/gtfs/fare-attributes.js +7 -2
- package/lib/gtfs/fare-rules.js +7 -2
- package/lib/gtfs/feed-info.js +7 -2
- package/lib/gtfs/frequencies.js +7 -2
- package/lib/gtfs/levels.js +7 -2
- package/lib/gtfs/pathways.js +7 -2
- package/lib/gtfs/routes.js +7 -2
- package/lib/gtfs/shapes.js +16 -11
- package/lib/gtfs/stop-times.js +7 -2
- package/lib/gtfs/stops.js +11 -6
- package/lib/gtfs/transfers.js +7 -2
- package/lib/gtfs/translations.js +7 -2
- package/lib/gtfs/trips.js +7 -2
- package/lib/gtfs-ride/board-alights.js +7 -2
- package/lib/gtfs-ride/ride-feed-infos.js +7 -2
- package/lib/gtfs-ride/rider-trips.js +7 -2
- package/lib/gtfs-ride/riderships.js +7 -2
- package/lib/gtfs-ride/trip-capacities.js +7 -2
- package/lib/import.js +5 -4
- package/lib/non-standard/directions.js +7 -2
- package/lib/non-standard/stop-attributes.js +7 -2
- package/lib/non-standard/timetable-notes-references.js +3 -2
- package/lib/non-standard/timetable-notes.js +7 -2
- package/lib/non-standard/timetable-pages.js +7 -2
- package/lib/non-standard/timetable-stop-order.js +3 -2
- package/lib/non-standard/timetables.js +7 -2
- package/lib/utils.js +4 -1
- package/models/gtfs/agency.js +4 -0
- package/models/gtfs/attributions.js +3 -0
- package/models/gtfs/calendar-dates.js +1 -0
- package/models/gtfs/feed-info.js +3 -0
- package/models/gtfs/levels.js +1 -0
- package/models/gtfs/pathways.js +2 -0
- package/models/gtfs/routes.js +5 -0
- package/models/gtfs/stop-times.js +1 -0
- package/models/gtfs/stops.js +3 -0
- package/models/gtfs/trips.js +2 -0
- package/models/non-standard/stop-attributes.js +1 -0
- package/models/non-standard/timetable-notes.js +1 -0
- package/models/non-standard/timetable-pages.js +1 -0
- package/models/non-standard/timetables.js +2 -0
- package/package.json +20 -15
- package/test/mocha/export-gtfs.js +11 -4
- package/test/mocha/get-agencies.js +9 -3
- package/test/mocha/get-attributions.js +9 -3
- package/test/mocha/get-board-alights.js +9 -3
- package/test/mocha/get-calendar-dates.js +9 -3
- package/test/mocha/get-calendars.js +9 -3
- package/test/mocha/get-db.js +62 -3
- package/test/mocha/get-directions.js +9 -3
- package/test/mocha/get-fare-attributes.js +9 -3
- package/test/mocha/get-fare-rules.js +9 -3
- package/test/mocha/get-feed-info.js +9 -3
- package/test/mocha/get-frequencies.js +9 -3
- package/test/mocha/get-levels.js +3 -3
- package/test/mocha/get-pathways.js +9 -3
- package/test/mocha/get-ride-feed-infos.js +9 -3
- package/test/mocha/get-rider-trips.js +9 -3
- package/test/mocha/get-riderships.js +9 -3
- package/test/mocha/get-routes.js +3 -3
- package/test/mocha/get-shapes-as-geojson.js +9 -3
- package/test/mocha/get-shapes.js +3 -3
- package/test/mocha/get-stop-attributes.js +9 -3
- package/test/mocha/get-stops-as-geojson.js +9 -3
- package/test/mocha/get-stops.js +3 -3
- package/test/mocha/get-stoptimes.js +9 -3
- package/test/mocha/get-timetable-pages.js +9 -3
- package/test/mocha/get-timetable-stop-orders.js +9 -3
- package/test/mocha/get-timetables.js +9 -3
- package/test/mocha/get-transfers.js +9 -3
- package/test/mocha/get-translations.js +9 -3
- package/test/mocha/get-trip-capacities.js +9 -3
- package/test/mocha/get-trips.js +3 -3
- package/test/mocha/import-gtfs.js +4 -4
- package/.prettierrc.js +0 -4
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import CsvParse = require("csv-parse");
|
|
2
|
+
import * as Sqlite3 from "sqlite";
|
|
3
|
+
import { FeatureCollection, Geometry } from "@turf/helpers";
|
|
4
|
+
|
|
5
|
+
export {}; // disable implicit exporting of types
|
|
6
|
+
|
|
7
|
+
type Unpromise<T> = T extends Promise<infer U> ? U : T;
|
|
8
|
+
|
|
9
|
+
export type SqlDatabase = Unpromise<ReturnType<typeof Sqlite3.open>>;
|
|
10
|
+
|
|
11
|
+
export type SqlValue = undefined | null | string | number | boolean | Date | SqlValue[];
|
|
12
|
+
|
|
13
|
+
export type SqlWhere = Record<string, null | SqlValue | SqlValue[]>;
|
|
14
|
+
|
|
15
|
+
export type SqlSelect = string[];
|
|
16
|
+
|
|
17
|
+
export type SqlOrderBy = Array<[string, "ASC" | "DESC"]>;
|
|
18
|
+
|
|
19
|
+
export type SqlResults = Array<Record<string, any>>;
|
|
20
|
+
|
|
21
|
+
export type Config = ExportConfig & ImportConfig;
|
|
22
|
+
|
|
23
|
+
interface VerboseConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Whether or not to print output to the console. Defaults to true.
|
|
26
|
+
*/
|
|
27
|
+
verbose?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DbConfig {
|
|
31
|
+
/**
|
|
32
|
+
* A path to an SQLite database. Defaults to using an in-memory database.
|
|
33
|
+
*/
|
|
34
|
+
sqlitePath?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ExportConfig extends DbConfig, VerboseConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Path to a directory to store exported GTFS files. Defaults to `gtfs-export/<agency_name>`.
|
|
40
|
+
*/
|
|
41
|
+
exportPath?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ImportConfig extends DbConfig, VerboseConfig {
|
|
45
|
+
/**
|
|
46
|
+
* An array of GTFS files to be imported.
|
|
47
|
+
*/
|
|
48
|
+
agencies: Array<{
|
|
49
|
+
/**
|
|
50
|
+
* Exclude files - if you don't want all GTFS files to be imported,
|
|
51
|
+
* you can specify an array of files to exclude.
|
|
52
|
+
*/
|
|
53
|
+
exclude?: string[];
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Specify custom headers for download URL.
|
|
57
|
+
*/
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Specify a path to a zipped GTFS file or an unzipped GTFS directory.
|
|
62
|
+
* One of `url` or `path` must be provided.
|
|
63
|
+
*/
|
|
64
|
+
path?: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Specify a download URL. One of `url` or `path` must be provided.
|
|
68
|
+
*/
|
|
69
|
+
url?: string;
|
|
70
|
+
}>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Options passed to csv-parse for parsing GTFS CSV files.
|
|
74
|
+
*/
|
|
75
|
+
csvOptions?: CsvParse.Options;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface QueryOptions {
|
|
79
|
+
db?: SqlDatabase;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Use exportGtfs() in your code to run an export of a GTFS file specified in a config.json file.
|
|
84
|
+
*/
|
|
85
|
+
export function exportGtfs(config: ExportConfig): Promise<void>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Use importGtfs() in your code to run an import of a GTFS file specified in a config.json file.
|
|
89
|
+
*/
|
|
90
|
+
export function importGtfs(config: ImportConfig): Promise<void>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Open database before making any queries.
|
|
94
|
+
*/
|
|
95
|
+
export function openDb(config: DbConfig): Promise<SqlDatabase>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Closes open database.
|
|
99
|
+
*/
|
|
100
|
+
export function closeDb(db?: SqlDatabase): Promise<void>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get open database. Throws error if no database is open.
|
|
104
|
+
*/
|
|
105
|
+
export function getDb(config?: DbConfig): Promise<SqlDatabase>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Queries agencies and returns a promise for an array of agencies.
|
|
109
|
+
*/
|
|
110
|
+
export function getAgencies(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Queries attributions and returns a promise for an array of attributions.
|
|
114
|
+
*/
|
|
115
|
+
export function getAttributions(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Queries routes and returns a promise for an array of routes.
|
|
119
|
+
*/
|
|
120
|
+
export function getRoutes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Queries stops and returns a promise for an array of stops.
|
|
124
|
+
*/
|
|
125
|
+
export function getStops(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Queries stops and returns a promise for an geoJSON object of stops.
|
|
129
|
+
* All valid queries for `getStops()` work for `getStopsAsGeoJSON()`.
|
|
130
|
+
*/
|
|
131
|
+
export function getStopsAsGeoJSON(query?: SqlWhere, options?: QueryOptions): Promise<FeatureCollection<Geometry, { [name: string]: any; }>>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Queries `stop_times` and returns a promise for an array of stop_times.
|
|
135
|
+
*/
|
|
136
|
+
export function getStoptimes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Queries trips and returns a promise for an array of trips.
|
|
140
|
+
*/
|
|
141
|
+
export function getTrips(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Queries shapes and returns a promise for an array of shapes.
|
|
145
|
+
*/
|
|
146
|
+
export function getShapes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Queries shapes and returns a promise for an geoJSON object of shapes.
|
|
150
|
+
* All valid queries for `getShapes()` work for `getShapesAsGeoJSON()`.
|
|
151
|
+
*/
|
|
152
|
+
export function getShapesAsGeoJSON(query?: SqlWhere, options?: QueryOptions): Promise<FeatureCollection<Geometry, { [name: string]: any; }>>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Queries calendars and returns a promise for an array of calendars.
|
|
156
|
+
*/
|
|
157
|
+
export function getCalendars(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Queries calendar_dates and returns a promise for an array of calendar_dates.
|
|
161
|
+
*/
|
|
162
|
+
export function getCalendarDates(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Queries fare_attributes and returns a promise for an array of fare_attributes.
|
|
166
|
+
*/
|
|
167
|
+
export function getFareAttributes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Queries fare_rules and returns a promise for an array of fare_rules.
|
|
171
|
+
*/
|
|
172
|
+
export function getFareRules(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Queries feed_info and returns a promise for an array of feed_infos.
|
|
176
|
+
*/
|
|
177
|
+
export function getFeedInfo(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Queries frequencies and returns a promise for an array of frequencies.
|
|
181
|
+
*/
|
|
182
|
+
export function getFrequencies(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Queries levels and returns a promise for an array of levels.
|
|
186
|
+
*/
|
|
187
|
+
export function getLevels(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Queries pathways and returns a promise for an array of pathways.
|
|
191
|
+
*/
|
|
192
|
+
export function getPathways(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Queries transfers and returns a promise for an array of transfers.
|
|
196
|
+
*/
|
|
197
|
+
export function getTransfers(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Queries translations and returns a promise for an array of translations.
|
|
201
|
+
*/
|
|
202
|
+
export function getTranslations(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Queries directions and returns a promise for an array of directions.
|
|
206
|
+
* These are from the non-standard `directions.txt` file.
|
|
207
|
+
*/
|
|
208
|
+
export function getDirections(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Queries stop_attributes and returns a promise for an array of stop_attributes.
|
|
212
|
+
* These are from the non-standard `stop_attributes.txt` file.
|
|
213
|
+
*/
|
|
214
|
+
export function getStopAttributes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Queries timetables and returns a promise for an array of timetables.
|
|
218
|
+
* These are from the non-standard `timetables.txt` file.
|
|
219
|
+
*/
|
|
220
|
+
export function getTimetables(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Queries timetable_stop_orders and returns a promise for an array of timetable_stop_orders.
|
|
224
|
+
* These are from the non-standard `timetable_stop_order.txt` file.
|
|
225
|
+
*/
|
|
226
|
+
export function getTimetableStopOrders(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Queries timetable_pages and returns a promise for an array of timetable_pages.
|
|
230
|
+
* These are from the non-standard `timetable_pages.txt` file.
|
|
231
|
+
*/
|
|
232
|
+
export function getTimetablePages(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Queries timetable_notes and returns a promise for an array of timetable_notes.
|
|
236
|
+
* These are from the non-standard `timetable_notes.txt` file.
|
|
237
|
+
*/
|
|
238
|
+
export function getTimetableNotes(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Queries timetable_notes_references and returns a promise for an array of timetable_notes references.
|
|
242
|
+
* These are from the non-standard `timetable_notes_references.txt` file.
|
|
243
|
+
*/
|
|
244
|
+
export function getTimetableNotesReferences(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Queries board-alights and returns a promise for an array of board-alights.
|
|
248
|
+
*/
|
|
249
|
+
export function getBoardAlights(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Queries ride-feed-info and returns a promise for an array of ride-feed-info.
|
|
253
|
+
*/
|
|
254
|
+
export function getRideFeedInfos(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Queries rider trips and returns a promise for an array of rider trips.
|
|
258
|
+
*/
|
|
259
|
+
export function getRiderTrips(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Queries riderships and returns a promise for an array of riderships.
|
|
263
|
+
*/
|
|
264
|
+
export function getRiderships(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Queries trip-capacities and returns a promise for an array of trip-capacities.
|
|
268
|
+
*/
|
|
269
|
+
export function getTripCapacities(query?: SqlWhere, fields?: SqlSelect, sortBy?: SqlOrderBy, options?: QueryOptions): Promise<SqlResults>;
|
package/@types/tests.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Config, exportGtfs, getAgencies, getDb, getShapesAsGeoJSON, importGtfs, openDb } from "gtfs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is type-checked (but not executed) by dtslint.
|
|
5
|
+
* `npm run dtslint`
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const config: Config = {
|
|
10
|
+
agencies: [{ path: "example.zip" }],
|
|
11
|
+
verbose: false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
await importGtfs(config); // $ExpectType void
|
|
15
|
+
|
|
16
|
+
await exportGtfs(config); // $ExpectType void
|
|
17
|
+
|
|
18
|
+
await openDb(config); // $ExpectType Database<Database, Statement>
|
|
19
|
+
|
|
20
|
+
await getDb(); // $ExpectType Database<Database, Statement>
|
|
21
|
+
|
|
22
|
+
const results = await getAgencies();
|
|
23
|
+
results[0]; // $ExpectType Record<string, any>
|
|
24
|
+
|
|
25
|
+
await getShapesAsGeoJSON(); // $ExpectType FeatureCollection<Geometry, { [name: string]: any; }>
|
|
26
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"lib": ["es6"],
|
|
5
|
+
"noImplicitAny": true,
|
|
6
|
+
"noImplicitThis": true,
|
|
7
|
+
"strictFunctionTypes": true,
|
|
8
|
+
"strictNullChecks": true,
|
|
9
|
+
"types": [],
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
|
|
13
|
+
// This allows test file to import "gtfs" instead of "./index".
|
|
14
|
+
"baseUrl": ".",
|
|
15
|
+
"paths": { "gtfs": ["."] }
|
|
16
|
+
}
|
|
17
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,41 @@ 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
|
+
## [3.2.3] - 2022-01-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Implemented case-insensitive columns on import
|
|
13
|
+
|
|
14
|
+
### Updated
|
|
15
|
+
|
|
16
|
+
- Dependency Updates
|
|
17
|
+
|
|
18
|
+
## [3.2.2] - 2021-12-28
|
|
19
|
+
|
|
20
|
+
### Updated
|
|
21
|
+
|
|
22
|
+
- Dependency Updates
|
|
23
|
+
|
|
24
|
+
## [3.2.1] - 2021-11-26
|
|
25
|
+
|
|
26
|
+
### Updated
|
|
27
|
+
|
|
28
|
+
- Updated sqlite3 dependency to use @vscode/sqlite3 for npm audit warning
|
|
29
|
+
- Downgraded dtslint to 3.4.2 for npm audit warning
|
|
30
|
+
|
|
31
|
+
## [3.2.0] - 2021-11-21
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- Support for opening multiple sqlite databases
|
|
36
|
+
- Basic TypeScript support (Matt Moran)
|
|
37
|
+
|
|
38
|
+
### Updated
|
|
39
|
+
|
|
40
|
+
- Readme updates
|
|
41
|
+
- Dependency updates
|
|
42
|
+
|
|
8
43
|
## [3.1.4] - 2021-10-17
|
|
9
44
|
|
|
10
45
|
### Added
|
package/README.md
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
➡️
|
|
3
|
+
<a href="#installation">Installation</a> |
|
|
4
|
+
<a href="#quick-start">Quick Start</a> |
|
|
5
|
+
<a href="#typescript-support">TypeScript Support</a> |
|
|
6
|
+
<a href="#configuration">Configuration</a> |
|
|
7
|
+
<a href="#query-methods">Query Methods</a>
|
|
8
|
+
⬅️
|
|
9
|
+
<br /><br />
|
|
10
|
+
<img src="docs/images/node-gtfs-logo.svg" alt="node-GTFS" />
|
|
11
|
+
<br /><br />
|
|
12
|
+
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/v/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/gtfs" rel="nofollow"><img src="https://img.shields.io/npm/dm/gtfs.svg?style=flat" style="max-width: 100%;"></a>
|
|
14
|
+
<a href="https://github.com/BlinkTagInc/node-gtfs/actions?query=workflow%3A%22Node+CI%22"><img src="https://img.shields.io/github/workflow/status/BlinkTagInc/node-gtfs/Node%20CI.svg" alt="CircleCI" style="max-width: 100%;"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
16
|
+
<br /><br />
|
|
17
|
+
Import and Export GTFS transit data into SQLite. Query or change routes, stops, times, fares and more.
|
|
18
|
+
<br /><br />
|
|
19
|
+
<a href="https://nodei.co/npm/gtfs/" rel="nofollow"><img src="https://nodei.co/npm/gtfs.png?downloads=true" alt="NPM" style="max-width: 100%;"></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<hr>
|
|
10
23
|
|
|
11
24
|
`node-GTFS` loads transit data in [GTFS format](https://developers.google.com/transit/) into a SQLite database and provides some methods to query for agencies, routes, stops, times, fares, calendars and other GTFS data. It also offers spatial queries to find nearby stops, routes and agencies and can convert stops and shapes to geoJSON format.
|
|
12
25
|
|
|
13
26
|
Additionally, this library can export data from the SQLite database back into GTFS (csv) format.
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Example Application
|
|
18
|
-
|
|
19
|
-
The [GTFS-to-HTML](https://gtfstohtml.com) app uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library and is used by over a dozen transit agencies to generate the timetables on their websites.
|
|
20
|
-
|
|
21
|
-
The [GTFS-to-geojson](https://github.com/blinktaginc/gtfs-to-geojson) app creates geoJSON files for transit routes for use in mapping. It uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library.
|
|
28
|
+
You can use it as a [command-line tool](#command-line-examples) or as a [node.js module](#code-example).
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
The [GTFS-Text-to-Speech](https://github.com/blinktaginc/node-gtfs-tts) app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.
|
|
30
|
+
This library has three parts: the [GTFS import script](#gtfs-import-script), the [query methods](#query-methods) and the [GTFS export script](#gtfs-export-script)
|
|
26
31
|
|
|
27
32
|
## Installation
|
|
28
33
|
|
|
@@ -32,7 +37,9 @@ If you would like to use this library as a command-line utility, you can install
|
|
|
32
37
|
|
|
33
38
|
If you are using this as a node module as part of an application, you can include it in your project's `package.json` file.
|
|
34
39
|
|
|
35
|
-
##
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### Command-line examples
|
|
36
43
|
|
|
37
44
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
38
45
|
|
|
@@ -50,7 +57,7 @@ or
|
|
|
50
57
|
|
|
51
58
|
gtfs-export --configPath /path/to/your/custom-config.json
|
|
52
59
|
|
|
53
|
-
|
|
60
|
+
### Code example
|
|
54
61
|
|
|
55
62
|
```js
|
|
56
63
|
import { importGtfs } from 'gtfs';
|
|
@@ -68,6 +75,27 @@ importGtfs(config)
|
|
|
68
75
|
});
|
|
69
76
|
```
|
|
70
77
|
|
|
78
|
+
### Example Applications
|
|
79
|
+
|
|
80
|
+
<table>
|
|
81
|
+
<tr>
|
|
82
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-html/raw/master/www/static/img/gtfs-to-html-logo.svg" alt="GTFS-to-HTML" width="200"></td>
|
|
83
|
+
<td><a href="https://gtfstohtml.com">GTFS-to-HTML</a> uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library and is used by over a dozen transit agencies to generate the timetables on their websites.</td>
|
|
84
|
+
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-geojson/raw/master/docs/images/gtfs-to-geojson-logo.svg" alt="GTFS-to-geojson" width="200"></td>
|
|
87
|
+
<td><a href="https://github.com/blinktaginc/gtfs-to-geojson">GTFS-to-geojson</a> creates geoJSON files for transit routes for use in mapping. It uses `node-gtfs` for downloading, importing and querying GTFS data. It provides a good example of how to use this library.</td>
|
|
88
|
+
</tr>
|
|
89
|
+
<tr>
|
|
90
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-to-chart/raw/master/docs/images/gtfs-to-chart-logo.svg" alt="GTFS-to-Chart" width="200"></td>
|
|
91
|
+
<td><a href="https://github.com/blinktaginc/gtfs-to-chart">GTFS-to-chart</a> generates a stringline chart in D3 for all trips for a specific route using data from an agency's GTFS. It uses `node-gtfs` for downloading, importing and querying GTFS data.</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td><img src="https://github.com/BlinkTagInc/gtfs-tts/raw/main/docs/images/gtfs-tts-logo.svg" alt="GTFS-TTS" width="200"></td>
|
|
95
|
+
<td><a href="https://github.com/blinktaginc/gtfs-tts">GTFS-Text-to-Speech</a> app tests GTFS stop name pronunciation for text-to-speech. It uses `node-gtfs` for loading stop names from GTFS data.</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</table>
|
|
98
|
+
|
|
71
99
|
## Command Line Usage
|
|
72
100
|
|
|
73
101
|
The `gtfs-import` command-line utility will import GTFS into SQLite3.
|
|
@@ -98,7 +126,11 @@ Specify a URL to a zipped GTFS file.
|
|
|
98
126
|
|
|
99
127
|
gtfs-import --gtfsUrl http://www.bart.gov/dev/schedules/google_transit.zip
|
|
100
128
|
|
|
101
|
-
##
|
|
129
|
+
## TypeScript Support
|
|
130
|
+
|
|
131
|
+
Basic TypeScript typings are included with this library. Please [open an issue](https://github.com/blinktaginc/node-gtfs/issues) if you find any inconsistencies between the declared types and underlying code.
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
102
134
|
|
|
103
135
|
Copy `config-sample.json` to `config.json` and then add your projects configuration to `config.json`.
|
|
104
136
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg width="280" height="311" viewBox="0 0 280 311" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M279.142 216.458V95.0263C279.142 82.9559 272.684 71.822 262.162 65.7868L156.951 5.01874C146.43 -1.01645 133.617 -1.01645 123.096 5.01874L17.8843 65.6828C7.36316 71.718 0.904633 82.8518 0.904633 95.0263V216.458C0.904633 228.529 7.36316 239.663 17.8843 245.698L123.096 306.362C133.617 312.397 146.43 312.397 156.951 306.362L262.267 245.594C272.684 239.663 279.142 228.529 279.142 216.458Z" fill="#B43052"/>
|
|
3
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M140.075 292.21C137.471 292.21 134.867 291.482 132.471 290.233L27.2596 229.465C22.5719 226.76 19.6552 221.765 19.6552 216.354V95.0263C19.6552 89.6154 22.5719 84.6208 27.1554 81.9154L132.471 21.1473C134.763 19.7945 137.367 19.1702 140.075 19.1702C142.784 19.1702 145.284 19.8986 147.68 21.1473L252.995 81.9154C257.683 84.6208 260.6 89.6154 260.6 95.0263V216.458C260.6 221.869 257.683 226.864 252.995 229.569L147.68 290.337C145.284 291.482 142.68 292.21 140.075 292.21Z" fill="#FCC761"/>
|
|
4
|
+
<mask id="mask0_4_20" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="10" y="133" width="259" height="61">
|
|
5
|
+
<path d="M10.6457 133.301H268.646V193.301H10.6457V133.301Z" fill="white"/>
|
|
6
|
+
</mask>
|
|
7
|
+
<g mask="url(#mask0_4_20)">
|
|
8
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.6457 34.2317H268.646V292.232H10.6457V34.2317Z" fill="#B43052"/>
|
|
9
|
+
</g>
|
|
10
|
+
<mask id="mask1_4_20" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="122" y="244" width="36" height="35">
|
|
11
|
+
<path d="M122 244H157.139V278.037H122V244Z" fill="white"/>
|
|
12
|
+
</mask>
|
|
13
|
+
<g mask="url(#mask1_4_20)">
|
|
14
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M144.917 255.167L157.139 256.912L148.335 265.657L150.471 277.948L139.523 272.186L128.621 278.037L130.658 265.73L121.785 257.056L133.992 255.212L139.41 244L144.917 255.167Z" fill="white"/>
|
|
15
|
+
</g>
|
|
16
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M178.87 65.8803C178.87 64.6713 178.312 63.7413 177.289 63.0903C177.103 62.9973 176.824 62.8113 176.638 62.7183C176.638 59.6494 176.545 56.4875 176.359 53.3256C175.987 46.0718 172.174 42.5378 165.013 42.4448C158.782 42.4448 152.551 42.4448 146.32 42.4448C136.183 42.4448 126.139 42.3518 116.002 42.5378C106.702 42.7238 102.982 46.6297 102.982 55.9295C102.982 58.1614 102.982 60.3934 102.982 62.7183C102.424 62.9043 101.959 63.3693 101.587 63.8343C100.936 64.3923 100.75 65.2293 100.75 66.1592C100.75 70.4371 100.75 74.715 100.75 79.0859C100.75 80.3879 101.215 81.4109 102.331 82.0618C102.61 82.2478 102.796 82.3408 103.075 82.4338C103.075 91.6406 103.075 100.754 103.075 109.961C103.075 111.263 102.889 112.751 103.54 113.867C104.935 116.099 104.656 118.517 104.749 120.935C104.842 123.911 106.795 125.957 109.771 126.05C111.91 126.143 114.049 126.143 116.188 126.05C119.257 125.957 121.21 124.19 121.303 121.121C121.396 119.819 121.582 119.354 123.07 119.354C134.23 119.447 145.483 119.447 156.643 119.354C158.038 119.354 158.41 119.726 158.41 121.121C158.503 124.376 160.456 126.05 163.711 126.05C165.571 126.05 167.431 126.05 169.291 126.05C173.104 126.05 174.964 124.097 175.057 120.284C175.057 118.796 174.592 117.122 175.429 115.727C176.452 113.867 176.731 112.007 176.731 109.961C176.731 101.312 176.731 92.6636 176.731 82.4338C177.382 82.3408 177.94 81.7829 178.312 81.2249C178.777 80.6669 178.963 79.9229 178.963 79.1789C178.87 74.808 178.87 70.3441 178.87 65.8803ZM124.279 49.1407C129.859 49.1407 135.439 49.1407 140.926 49.1407C146.32 49.1407 151.714 49.1407 157.201 49.1407C159.619 49.1407 159.898 49.5127 159.991 52.3026C159.991 55.3715 159.712 55.8365 157.387 55.8365C146.32 55.8365 135.253 55.8365 124.279 55.8365C121.861 55.8365 121.396 55.2785 121.396 52.4886C121.303 49.6987 121.768 49.1407 124.279 49.1407ZM117.304 111.077C114.049 111.077 111.352 108.38 111.352 105.125C111.445 101.963 114.142 99.3594 117.211 99.3594C120.466 99.3594 122.884 101.87 122.884 105.218C122.977 108.473 120.466 111.077 117.304 111.077ZM116.467 90.9896C112.933 90.9896 111.352 89.3157 111.352 85.6888C111.352 79.1789 111.352 72.6691 111.352 66.1592C111.352 62.5323 112.84 61.0444 116.467 61.0444C124.279 61.0444 131.998 61.0444 139.81 61.0444C147.436 61.0444 155.062 61.0444 162.688 61.0444C166.78 61.0444 168.175 62.4393 168.175 66.4382C168.175 72.6691 168.175 78.8999 168.175 85.1308C168.175 88.8507 166.129 90.8966 162.409 90.9896C147.157 90.9896 131.812 90.9896 116.467 90.9896ZM162.409 111.077C159.247 111.077 156.736 108.566 156.643 105.311C156.643 101.963 159.061 99.4524 162.316 99.4524C165.571 99.4524 168.268 102.149 168.268 105.404C168.175 108.38 165.571 111.077 162.409 111.077Z" fill="white"/>
|
|
17
|
+
<path d="M69.2254 147.5H75.4354L80.2504 166.355H80.3404V147.5H84.7504V179H79.6654L73.7254 156.005H73.6354V179H69.2254V147.5ZM95.5845 179.45C93.1545 179.45 91.2945 178.76 90.0045 177.38C88.7145 176 88.0695 174.05 88.0695 171.53V154.97C88.0695 152.45 88.7145 150.5 90.0045 149.12C91.2945 147.74 93.1545 147.05 95.5845 147.05C98.0145 147.05 99.8745 147.74 101.164 149.12C102.454 150.5 103.099 152.45 103.099 154.97V171.53C103.099 174.05 102.454 176 101.164 177.38C99.8745 178.76 98.0145 179.45 95.5845 179.45ZM95.5845 174.95C97.2945 174.95 98.1495 173.915 98.1495 171.845V154.655C98.1495 152.585 97.2945 151.55 95.5845 151.55C93.8745 151.55 93.0195 152.585 93.0195 154.655V171.845C93.0195 173.915 93.8745 174.95 95.5845 174.95ZM106.447 147.5H114.007C116.467 147.5 118.312 148.16 119.542 149.48C120.772 150.8 121.387 152.735 121.387 155.285V171.215C121.387 173.765 120.772 175.7 119.542 177.02C118.312 178.34 116.467 179 114.007 179H106.447V147.5ZM113.917 174.5C114.727 174.5 115.342 174.26 115.762 173.78C116.212 173.3 116.437 172.52 116.437 171.44V155.06C116.437 153.98 116.212 153.2 115.762 152.72C115.342 152.24 114.727 152 113.917 152H111.397V174.5H113.917ZM124.728 147.5H138.228V152H129.678V160.325H136.473V164.825H129.678V174.5H138.228V179H124.728V147.5ZM155.303 179.45C152.903 179.45 151.073 178.775 149.813 177.425C148.553 176.045 147.923 174.08 147.923 171.53V154.97C147.923 152.42 148.553 150.47 149.813 149.12C151.073 147.74 152.903 147.05 155.303 147.05C157.703 147.05 159.533 147.74 160.793 149.12C162.053 150.47 162.683 152.42 162.683 154.97V157.67H158.003V154.655C158.003 152.585 157.148 151.55 155.438 151.55C153.728 151.55 152.873 152.585 152.873 154.655V171.89C152.873 173.93 153.728 174.95 155.438 174.95C157.148 174.95 158.003 173.93 158.003 171.89V165.725H155.528V161.225H162.683V171.53C162.683 174.08 162.053 176.045 160.793 177.425C159.533 178.775 157.703 179.45 155.303 179.45ZM169.731 152H164.556V147.5H179.856V152H174.681V179H169.731V152ZM182.253 147.5H195.348V152H187.203V160.775H193.593V165.275H187.203V179H182.253V147.5ZM204.156 179.45C201.756 179.45 199.941 178.775 198.711 177.425C197.481 176.045 196.866 174.08 196.866 171.53V169.73H201.546V171.89C201.546 173.93 202.401 174.95 204.111 174.95C204.951 174.95 205.581 174.71 206.001 174.23C206.451 173.72 206.676 172.91 206.676 171.8C206.676 170.48 206.376 169.325 205.776 168.335C205.176 167.315 204.066 166.1 202.446 164.69C200.406 162.89 198.981 161.27 198.171 159.83C197.361 158.36 196.956 156.71 196.956 154.88C196.956 152.39 197.586 150.47 198.846 149.12C200.106 147.74 201.936 147.05 204.336 147.05C206.706 147.05 208.491 147.74 209.691 149.12C210.921 150.47 211.536 152.42 211.536 154.97V156.275H206.856V154.655C206.856 153.575 206.646 152.795 206.226 152.315C205.806 151.805 205.191 151.55 204.381 151.55C202.731 151.55 201.906 152.555 201.906 154.565C201.906 155.705 202.206 156.77 202.806 157.76C203.436 158.75 204.561 159.95 206.181 161.36C208.251 163.16 209.676 164.795 210.456 166.265C211.236 167.735 211.626 169.46 211.626 171.44C211.626 174.02 210.981 176 209.691 177.38C208.431 178.76 206.586 179.45 204.156 179.45Z" fill="white"/>
|
|
18
|
+
</svg>
|
package/lib/db.js
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import sqlite3 from 'sqlite3';
|
|
1
|
+
import sqlite3 from '@vscode/sqlite3';
|
|
2
2
|
import { open } from 'sqlite';
|
|
3
3
|
import { setDefaultConfig } from './utils.js';
|
|
4
|
-
|
|
4
|
+
const dbs = {};
|
|
5
5
|
|
|
6
6
|
export async function openDb(initialConfig) {
|
|
7
7
|
const config = setDefaultConfig(initialConfig);
|
|
8
|
-
if (!
|
|
9
|
-
|
|
8
|
+
if (!dbs[config.sqlitePath]) {
|
|
9
|
+
dbs[config.sqlitePath] = await open({
|
|
10
10
|
filename: config.sqlitePath,
|
|
11
11
|
driver: sqlite3.Database,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
return
|
|
15
|
+
return dbs[config.sqlitePath];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export async function setupDb() {
|
|
18
|
+
export async function setupDb(db) {
|
|
19
|
+
if (Object.keys(dbs).length === 0) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'No database connection. Call `openDb(config)` before using any methods.'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!db) {
|
|
26
|
+
if (Object.keys(dbs).length > 1) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
'Multiple database connections. Pass the db you want to close as a parameter to `setupDb`.'
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const filename = Object.keys(dbs)[0];
|
|
33
|
+
db = dbs[filename];
|
|
34
|
+
}
|
|
35
|
+
|
|
19
36
|
await db.run('PRAGMA journal_mode = OFF;');
|
|
20
37
|
await db.run('PRAGMA synchronous = 0;');
|
|
21
38
|
await db.run('PRAGMA locking_mode = EXCLUSIVE;');
|
|
@@ -23,17 +40,49 @@ export async function setupDb() {
|
|
|
23
40
|
await db.run('VACUUM;');
|
|
24
41
|
}
|
|
25
42
|
|
|
26
|
-
export async function closeDb() {
|
|
43
|
+
export async function closeDb(db) {
|
|
44
|
+
if (Object.keys(dbs).length === 0) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
'No database connection. Call `openDb(config)` before using any methods.'
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!db) {
|
|
51
|
+
if (Object.keys(dbs).length > 1) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'Multiple database connections. Pass the db you want to close as a parameter to `closeDb`.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
db = dbs[Object.keys(dbs)[0]];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const { filename } = db.config;
|
|
61
|
+
|
|
27
62
|
await db.close();
|
|
28
|
-
|
|
63
|
+
delete dbs[filename];
|
|
29
64
|
}
|
|
30
65
|
|
|
31
|
-
export function getDb() {
|
|
32
|
-
if (
|
|
33
|
-
|
|
66
|
+
export function getDb(initialConfig) {
|
|
67
|
+
if (Object.keys(dbs).length === 0) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
'No database connection. Call `openDb(config)` before using any methods.'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const config = setDefaultConfig(initialConfig);
|
|
74
|
+
if (dbs[config.sqlitePath]) {
|
|
75
|
+
return dbs[config.sqlitePath];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* Fall back to using the only open database connection if only
|
|
80
|
+
* one exists for backwards compatibility
|
|
81
|
+
*/
|
|
82
|
+
if (Object.keys(dbs).length === 1) {
|
|
83
|
+
const filename = Object.keys(dbs)[0];
|
|
84
|
+
return dbs[filename];
|
|
34
85
|
}
|
|
35
86
|
|
|
36
|
-
throw new Error(
|
|
37
|
-
'No database connection. Call `openDb(config)` before using any methods.'
|
|
38
|
-
);
|
|
87
|
+
throw new Error('Unable to find database connection.');
|
|
39
88
|
}
|
package/lib/export.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import { promisify } from 'node:util';
|
|
4
3
|
|
|
5
4
|
import { without, compact } from 'lodash-es';
|
|
6
5
|
import pluralize from 'pluralize';
|
|
7
|
-
import
|
|
6
|
+
import { stringify } from 'csv-stringify';
|
|
8
7
|
import sqlString from 'sqlstring-sqlite';
|
|
9
8
|
import mapSeries from 'promise-map-series';
|
|
10
9
|
import untildify from 'untildify';
|
|
@@ -15,8 +14,6 @@ import { prepDirectory, generateFolderName } from './file-utils.js';
|
|
|
15
14
|
import { log as _log, logWarning as _logWarning } from './log-utils.js';
|
|
16
15
|
import { setDefaultConfig } from './utils.js';
|
|
17
16
|
|
|
18
|
-
const stringify = promisify(csvStringify);
|
|
19
|
-
|
|
20
17
|
const exportGtfs = async (initialConfig) => {
|
|
21
18
|
const config = setDefaultConfig(initialConfig);
|
|
22
19
|
const log = _log(config);
|
package/lib/gtfs/agencies.js
CHANGED
|
@@ -12,8 +12,13 @@ import agency from '../../models/gtfs/agency.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all agencies that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getAgencies(
|
|
16
|
-
|
|
15
|
+
export async function getAgencies(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(agency.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|
package/lib/gtfs/attributions.js
CHANGED
|
@@ -12,8 +12,13 @@ import attributions from '../../models/gtfs/attributions.js';
|
|
|
12
12
|
/*
|
|
13
13
|
* Returns an array of all attributions that match the query parameters.
|
|
14
14
|
*/
|
|
15
|
-
export async function getAttributions(
|
|
16
|
-
|
|
15
|
+
export async function getAttributions(
|
|
16
|
+
query = {},
|
|
17
|
+
fields = [],
|
|
18
|
+
orderBy = [],
|
|
19
|
+
options = {}
|
|
20
|
+
) {
|
|
21
|
+
const db = options.db ?? (await getDb());
|
|
17
22
|
const tableName = sqlString.escapeId(attributions.filenameBase);
|
|
18
23
|
const selectClause = formatSelectClause(fields);
|
|
19
24
|
const whereClause = formatWhereClauses(query);
|