gtfs 4.17.6 → 4.18.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/README.md +32 -11
- package/dist/bin/gtfs-export.js +25 -18
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +443 -316
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +253 -196
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +145 -7
- package/dist/index.js +568 -427
- package/dist/index.js.map +1 -1
- package/package.json +16 -16
package/dist/index.d.ts
CHANGED
|
@@ -3,36 +3,132 @@ import Database$1, { Database } from 'better-sqlite3';
|
|
|
3
3
|
import { FeatureCollection } from 'geojson';
|
|
4
4
|
|
|
5
5
|
type UnixTimestamp = number;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
type TableNames = 'agency' | 'stops' | 'routes' | 'trips' | 'stop_times' | 'calendar' | 'calendar_dates' | 'fare_attributes' | 'fare_rules' | 'timeframes' | 'rider_categories' | 'fare_media' | 'fare_products' | 'fare_leg_rules' | 'fare_leg_join_rules' | 'fare_transfer_rules' | 'areas' | 'stop_areas' | 'networks' | 'route_networks' | 'shapes' | 'frequencies' | 'transfers' | 'pathways' | 'levels' | 'location_groups' | 'location_group_stops' | 'locations' | 'booking_rules' | 'translations' | 'feed_info' | 'attributions';
|
|
7
|
+
interface BaseConfigAgency {
|
|
8
|
+
/**
|
|
9
|
+
* An array of GTFS file names (without .txt) to exclude when importing
|
|
10
|
+
*/
|
|
11
|
+
exclude?: TableNames[];
|
|
12
|
+
/**
|
|
13
|
+
* An object of HTTP headers in key:value format to use when fetching GTFS from the url specified
|
|
14
|
+
*/
|
|
10
15
|
headers?: Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Settings for fetching GTFS-Realtime alerts
|
|
18
|
+
*/
|
|
11
19
|
realtimeAlerts?: {
|
|
20
|
+
/**
|
|
21
|
+
* URL for fetching GTFS-Realtime alerts
|
|
22
|
+
*/
|
|
12
23
|
url: string;
|
|
24
|
+
/**
|
|
25
|
+
* Headers to use when fetching GTFS-Realtime alerts
|
|
26
|
+
*/
|
|
13
27
|
headers?: Record<string, string>;
|
|
14
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Settings for fetching GTFS-Realtime trip updates
|
|
31
|
+
*/
|
|
15
32
|
realtimeTripUpdates?: {
|
|
33
|
+
/**
|
|
34
|
+
* URL for fetching GTFS-Realtime trip updates
|
|
35
|
+
*/
|
|
16
36
|
url: string;
|
|
37
|
+
/**
|
|
38
|
+
* Headers to use when fetching GTFS-Realtime trip updates
|
|
39
|
+
*/
|
|
17
40
|
headers?: Record<string, string>;
|
|
18
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Settings for fetching GTFS-Realtime vehicle positions
|
|
44
|
+
*/
|
|
19
45
|
realtimeVehiclePositions?: {
|
|
46
|
+
/**
|
|
47
|
+
* URL for fetching GTFS-Realtime vehicle positions
|
|
48
|
+
*/
|
|
20
49
|
url: string;
|
|
50
|
+
/**
|
|
51
|
+
* Headers to use when fetching GTFS-Realtime vehicle positions
|
|
52
|
+
*/
|
|
21
53
|
headers?: Record<string, string>;
|
|
22
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* A prefix to be added to every ID field maintain uniqueness when importing multiple GTFS from multiple agencies
|
|
57
|
+
*/
|
|
23
58
|
prefix?: string;
|
|
24
59
|
}
|
|
60
|
+
type ConfigAgency = BaseConfigAgency & ({
|
|
61
|
+
/**
|
|
62
|
+
* The URL to a zipped GTFS file. Required if path not present
|
|
63
|
+
*/
|
|
64
|
+
url: string;
|
|
65
|
+
} | {
|
|
66
|
+
/**
|
|
67
|
+
* A path to a zipped GTFS file or a directory of unzipped .txt files. Required if url is not present
|
|
68
|
+
*/
|
|
69
|
+
path: string;
|
|
70
|
+
});
|
|
25
71
|
interface Config {
|
|
72
|
+
/**
|
|
73
|
+
* An existing database instance to use instead of relying on node-gtfs to connect.
|
|
74
|
+
*/
|
|
26
75
|
db?: Database;
|
|
76
|
+
/**
|
|
77
|
+
* A path to an SQLite database. Defaults to using an in-memory database.
|
|
78
|
+
*/
|
|
27
79
|
sqlitePath?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Amount of time in seconds to allow GTFS-Realtime data to be stored in database before allowing to be deleted.
|
|
82
|
+
*
|
|
83
|
+
* Note: is an integer
|
|
84
|
+
*
|
|
85
|
+
* @defaultValue 0
|
|
86
|
+
*/
|
|
28
87
|
gtfsRealtimeExpirationSeconds?: number;
|
|
88
|
+
/**
|
|
89
|
+
* The number of milliseconds to wait before throwing an error when downloading GTFS.
|
|
90
|
+
*
|
|
91
|
+
* Note: is an integer
|
|
92
|
+
*/
|
|
29
93
|
downloadTimeout?: number;
|
|
94
|
+
/**
|
|
95
|
+
* Options passed to `csv-parse` for parsing GTFS CSV files.
|
|
96
|
+
*/
|
|
30
97
|
csvOptions?: Options;
|
|
98
|
+
/**
|
|
99
|
+
* A path to a directory to put exported GTFS files.
|
|
100
|
+
*
|
|
101
|
+
* @defaultValue `gtfs-export/<agency_name>`
|
|
102
|
+
*/
|
|
31
103
|
exportPath?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`.
|
|
106
|
+
*
|
|
107
|
+
* @defaultValue false
|
|
108
|
+
*/
|
|
32
109
|
ignoreDuplicates?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Whether or not to ignore errors during the import process. If true, failed files will be skipped while the rest are processed.
|
|
112
|
+
*
|
|
113
|
+
* @defaultValue false
|
|
114
|
+
*/
|
|
33
115
|
ignoreErrors?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* An array of GTFS files to be imported, and which files to exclude.
|
|
118
|
+
*/
|
|
34
119
|
agencies: ConfigAgency[];
|
|
120
|
+
/**
|
|
121
|
+
* Whether or not to print output to the console.
|
|
122
|
+
*
|
|
123
|
+
* @defaulValue true
|
|
124
|
+
*/
|
|
35
125
|
verbose?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* An optional custom logger instead of the build in console.log
|
|
128
|
+
*
|
|
129
|
+
* @param message
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
36
132
|
logFunction?: (message: string) => void;
|
|
37
133
|
}
|
|
38
134
|
interface ModelColumn {
|
|
@@ -49,7 +145,7 @@ interface ModelColumn {
|
|
|
49
145
|
prefix?: boolean;
|
|
50
146
|
}
|
|
51
147
|
interface Model {
|
|
52
|
-
filenameBase:
|
|
148
|
+
filenameBase: TableNames;
|
|
53
149
|
filenameExtension?: string;
|
|
54
150
|
extension?: string;
|
|
55
151
|
nonstandard?: boolean;
|
|
@@ -623,8 +719,16 @@ interface StopAttribute {
|
|
|
623
719
|
stop_city?: string;
|
|
624
720
|
}
|
|
625
721
|
|
|
722
|
+
/**
|
|
723
|
+
* Function to import GTFS files into the database
|
|
724
|
+
*
|
|
725
|
+
* @param initialConfig
|
|
726
|
+
*/
|
|
626
727
|
declare function importGtfs(initialConfig: Config): Promise<void>;
|
|
627
728
|
|
|
729
|
+
/**
|
|
730
|
+
* Main function to update GTFS Realtime data
|
|
731
|
+
*/
|
|
628
732
|
declare function updateGtfsRealtime(initialConfig: Config): Promise<void>;
|
|
629
733
|
|
|
630
734
|
declare const exportGtfs: (initialConfig: Config) => Promise<void>;
|
|
@@ -643,7 +747,41 @@ declare function advancedQuery(table: string, advancedQueryOptions: {
|
|
|
643
747
|
orderBy?: SqlOrderBy;
|
|
644
748
|
join?: JoinOptions[];
|
|
645
749
|
options?: QueryOptions;
|
|
646
|
-
}): Array<Record<string,
|
|
750
|
+
}): Array<Record<string, SqlValue>>;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Prepares a directory for saving files by clearing its contents
|
|
754
|
+
* @param {string} exportPath - Path to the directory to prepare
|
|
755
|
+
* @returns {Promise<void>}
|
|
756
|
+
* @example
|
|
757
|
+
* await prepDirectory('./output');
|
|
758
|
+
*/
|
|
759
|
+
declare function prepDirectory(exportPath: string): Promise<void>;
|
|
760
|
+
/**
|
|
761
|
+
* Extracts contents of a zip file to specified directory
|
|
762
|
+
* @param {string} zipfilePath - Path to the zip file
|
|
763
|
+
* @param {string} exportPath - Directory to extract contents to
|
|
764
|
+
* @returns {Promise<void>}
|
|
765
|
+
* @throws {Error} If zip file cannot be opened or extracted
|
|
766
|
+
* @example
|
|
767
|
+
* await unzip('./data.zip', './extracted');
|
|
768
|
+
*/
|
|
769
|
+
declare function unzip(zipfilePath: string, exportPath: string): Promise<void>;
|
|
770
|
+
/**
|
|
771
|
+
* Generates a safe folder name from input string
|
|
772
|
+
* Converts to snake_case and removes unsafe characters
|
|
773
|
+
* @param {string} folderName - Input string to convert to folder name
|
|
774
|
+
* @returns {string} Sanitized folder name
|
|
775
|
+
* @example
|
|
776
|
+
* generateFolderName('My Folder!') // returns 'my_folder'
|
|
777
|
+
*/
|
|
778
|
+
declare function generateFolderName(folderName: string): string;
|
|
779
|
+
/**
|
|
780
|
+
* Converts a tilde path to a full path
|
|
781
|
+
* @param pathWithTilde The path to convert
|
|
782
|
+
* @returns The full path
|
|
783
|
+
*/
|
|
784
|
+
declare function untildify(pathWithTilde: string): string;
|
|
647
785
|
|
|
648
786
|
declare function getAgencies<Fields extends keyof Agency>(query?: SqlWhere, fields?: Fields[], orderBy?: SqlOrderBy, options?: QueryOptions): QueryResult<Agency, Fields>[];
|
|
649
787
|
|
|
@@ -758,4 +896,4 @@ declare function getRunEvents<Fields extends keyof RunEvent>(query?: SqlWhere, f
|
|
|
758
896
|
|
|
759
897
|
declare function getRunsPieces<Fields extends keyof RunPiece>(query?: SqlWhere, fields?: Fields[], orderBy?: SqlOrderBy, options?: QueryOptions): QueryResult<RunPiece, Fields>[];
|
|
760
898
|
|
|
761
|
-
export { type Agency, type Area, type Attribution, type BoardAlight, type BookingRule, type Calendar, type CalendarAttribute, type CalendarDate, type Config, type ConfigAgency, type Deadhead, type DeadheadTime, type Direction, type FareAttribute, type FareLegRule, type FareMedia, type FareProduct, type FareRule, type FareTransferRule, type FeedInfo, type Frequency, type JoinOptions, type Level, type Location, type LocationGroup, type LocationGroupStop, type Model, type ModelColumn, type Network, type OpsLocation, type Pathway, type QueryOptions, type QueryResult, type RideFeedInfo, type RiderCategory, type RiderTrip, type Ridership, type Route, type RouteAttribute, type RouteNetwork, type RunEvent, type RunPiece, type ServiceAlert, type Shape, type SqlOrderBy, type SqlValue, type SqlWhere, type Stop, type StopArea, type StopAttribute, type StopTime, type StopTimeUpdate, type Timeframe, type Timetable, type TimetableNote, type TimetableNotesReference, type TimetablePage, type TimetableStopOrder, type Transfer, type Translation, type Trip, type TripCapacity, type TripUpdate, type TripsDatedVehicleJourney, type UnixTimestamp, type VehiclePosition, advancedQuery, closeDb, deleteDb, exportGtfs, getAgencies, getAreas, getAttributions, getBoardAlights, getBookingRules, getCalendarAttributes, getCalendarDates, getCalendars, getDeadheadTimes, getDeadheads, getDirections, getFareAttributes, getFareLegRules, getFareMedia, getFareProducts, getFareRules, getFareTransferRules, getFeedInfo, getFrequencies, getLevels, getLocationGroupStops, getLocationGroups, getLocations, getNetworks, getOpsLocations, getPathways, getRideFeedInfo, getRiderCategories, getRiderTrips, getRidership, getRouteAttributes, getRouteNetworks, getRoutes, getRunEvents, getRunsPieces, getServiceAlerts, getServiceIdsByDate, getShapes, getShapesAsGeoJSON, getStopAreas, getStopAttributes, getStopTimeUpdates, getStops, getStopsAsGeoJSON, getStoptimes, getTimeframes, getTimetableNotes, getTimetableNotesReferences, getTimetablePages, getTimetableStopOrders, getTimetables, getTransfers, getTranslations, getTripCapacities, getTripUpdates, getTrips, getTripsDatedVehicleJourneys, getVehiclePositions, importGtfs, openDb, updateGtfsRealtime };
|
|
899
|
+
export { type Agency, type Area, type Attribution, type BoardAlight, type BookingRule, type Calendar, type CalendarAttribute, type CalendarDate, type Config, type ConfigAgency, type Deadhead, type DeadheadTime, type Direction, type FareAttribute, type FareLegRule, type FareMedia, type FareProduct, type FareRule, type FareTransferRule, type FeedInfo, type Frequency, type JoinOptions, type Level, type Location, type LocationGroup, type LocationGroupStop, type Model, type ModelColumn, type Network, type OpsLocation, type Pathway, type QueryOptions, type QueryResult, type RideFeedInfo, type RiderCategory, type RiderTrip, type Ridership, type Route, type RouteAttribute, type RouteNetwork, type RunEvent, type RunPiece, type ServiceAlert, type Shape, type SqlOrderBy, type SqlValue, type SqlWhere, type Stop, type StopArea, type StopAttribute, type StopTime, type StopTimeUpdate, type TableNames, type Timeframe, type Timetable, type TimetableNote, type TimetableNotesReference, type TimetablePage, type TimetableStopOrder, type Transfer, type Translation, type Trip, type TripCapacity, type TripUpdate, type TripsDatedVehicleJourney, type UnixTimestamp, type VehiclePosition, advancedQuery, closeDb, deleteDb, exportGtfs, generateFolderName, getAgencies, getAreas, getAttributions, getBoardAlights, getBookingRules, getCalendarAttributes, getCalendarDates, getCalendars, getDeadheadTimes, getDeadheads, getDirections, getFareAttributes, getFareLegRules, getFareMedia, getFareProducts, getFareRules, getFareTransferRules, getFeedInfo, getFrequencies, getLevels, getLocationGroupStops, getLocationGroups, getLocations, getNetworks, getOpsLocations, getPathways, getRideFeedInfo, getRiderCategories, getRiderTrips, getRidership, getRouteAttributes, getRouteNetworks, getRoutes, getRunEvents, getRunsPieces, getServiceAlerts, getServiceIdsByDate, getShapes, getShapesAsGeoJSON, getStopAreas, getStopAttributes, getStopTimeUpdates, getStops, getStopsAsGeoJSON, getStoptimes, getTimeframes, getTimetableNotes, getTimetableNotesReferences, getTimetablePages, getTimetableStopOrders, getTimetables, getTransfers, getTranslations, getTripCapacities, getTripUpdates, getTrips, getTripsDatedVehicleJourneys, getVehiclePositions, importGtfs, openDb, prepDirectory, untildify, unzip, updateGtfsRealtime };
|