gtfs 4.15.2 → 4.15.4

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 CHANGED
@@ -148,18 +148,18 @@ Copy `config-sample.json` to `config.json` and then add your projects configurat
148
148
 
149
149
  cp config-sample.json config.json
150
150
 
151
- | option | type | description |
152
- | --------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
153
- | [`agencies`](#agencies) | array | An array of GTFS files to be imported, and which files to exclude. |
154
- | [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
155
- | [`db`](#db) | database instance | An existing database instance to use instead of relying on node-gtfs to connect. Optional. |
156
- | [`downloadTimeout`](#downloadtimeout) | integer | The number of milliseconds to wait before throwing an error when downloading GTFS. Optional. |
157
- | [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
151
+ | option | type | description |
152
+ | ----------------------------------------------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
153
+ | [`agencies`](#agencies) | array | An array of GTFS files to be imported, and which files to exclude. |
154
+ | [`csvOptions`](#csvOptions) | object | Options passed to `csv-parse` for parsing GTFS CSV files. Optional. |
155
+ | [`db`](#db) | database instance | An existing database instance to use instead of relying on node-gtfs to connect. Optional. |
156
+ | [`downloadTimeout`](#downloadtimeout) | integer | The number of milliseconds to wait before throwing an error when downloading GTFS. Optional. |
157
+ | [`exportPath`](#exportPath) | string | A path to a directory to put exported GTFS files. Optional, defaults to `gtfs-export/<agency_name>`. |
158
158
  | [`gtfsRealtimeExpirationSeconds`](#gtfsrealtimeexpirationseconds) | integer | Amount of time in seconds to allow GTFS-Realtime data to be stored in database before allowing to be deleted. Optional, defaults to 0. |
159
- | [`ignoreDuplicates`](#ignoreduplicates) | boolean | Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`. Optional, defaults to false. |
160
- | [`ignoreErrors`](#ignoreerrors) | boolean | Whether or not to ignore errors during the import process. If true, when importing multiple agencies, failed agencies will be skipped. Optional, defaults to false. |
161
- | [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
162
- | [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
159
+ | [`ignoreDuplicates`](#ignoreduplicates) | boolean | Whether or not to ignore unique constraints on ids when importing GTFS, such as `trip_id`, `calendar_id`. Optional, defaults to false. |
160
+ | [`ignoreErrors`](#ignoreerrors) | boolean | Whether or not to ignore errors during the import process. If true, when importing multiple agencies, failed agencies will be skipped. Optional, defaults to false. |
161
+ | [`sqlitePath`](#sqlitePath) | string | A path to an SQLite database. Optional, defaults to using an in-memory database. |
162
+ | [`verbose`](#verbose) | boolean | Whether or not to print output to the console. Optional, defaults to true. |
163
163
 
164
164
  ### agencies
165
165
 
@@ -171,16 +171,16 @@ To find an agency's GTFS file, visit [transitfeeds.com](http://transitfeeds.com)
171
171
 
172
172
  #### agencies options
173
173
 
174
- | option | type | description |
175
- | ----------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
176
- | `url` | string | The URL to a zipped GTFS file. Required if `path` not present. |
177
- | `path` | string | A path to a zipped GTFS file or a directory of unzipped .txt files. Required if `url` is not present. |
178
- | `headers` | object | An object of HTTP headers in key:value format to use when fetching GTFS from the `url` specified. Optional. |
179
- | `prefix` | string | A prefix to be added to every ID field maintain uniqueness when importing multiple GTFS from multiple agencies. Optional. |
180
- | `exclude` | array | An array of GTFS file names (without `.txt`) to exclude when importing. Optional. |
181
- | `realtimeAlerts` | object | An object containing a `url` field for GTFS-Realtime alerts and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
182
- | `realtimeTripUpdates` | object | An object containing a `url` field for GTFS-Realtime trip updates and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
183
- | `realtimeVehiclePositions` | object | An object containing a `url` field for GTFS-Realtime vehicle positions and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
174
+ | option | type | description |
175
+ | -------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
176
+ | `url` | string | The URL to a zipped GTFS file. Required if `path` not present. |
177
+ | `path` | string | A path to a zipped GTFS file or a directory of unzipped .txt files. Required if `url` is not present. |
178
+ | `headers` | object | An object of HTTP headers in key:value format to use when fetching GTFS from the `url` specified. Optional. |
179
+ | `prefix` | string | A prefix to be added to every ID field maintain uniqueness when importing multiple GTFS from multiple agencies. Optional. |
180
+ | `exclude` | array | An array of GTFS file names (without `.txt`) to exclude when importing. Optional. |
181
+ | `realtimeAlerts` | object | An object containing a `url` field for GTFS-Realtime alerts and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
182
+ | `realtimeTripUpdates` | object | An object containing a `url` field for GTFS-Realtime trip updates and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
183
+ | `realtimeVehiclePositions` | object | An object containing a `url` field for GTFS-Realtime vehicle positions and a `headers` field in key:value format to use when fetching GTFS-Realtime data. Optional. |
184
184
 
185
185
  - Specify a `url` to download GTFS:
186
186
 
@@ -416,7 +416,6 @@ importGtfs({
416
416
  }
417
417
  ```
418
418
 
419
-
420
419
  ### ignoreDuplicates
421
420
 
422
421
  {Boolean} If you don't want node-GTFS to throw an error when it encounters a duplicate id on GTFS import. If `true`, it will skip importing duplicate records where unique constraints are violated, such as`trip_id`, `stop_id`, `calendar_id`. Useful if importing GTFS from multiple sources into one SQlite database that share routes or stops. Defaults to `false`.
@@ -952,6 +951,28 @@ const stoptimes = getStoptimes({
952
951
  stop_id: '70011',
953
952
  service_id: 'CT-16APR-Caltrain-Weekday-01',
954
953
  });
954
+
955
+ /*
956
+ * `getStoptimes` allows passing a `date` in the query to return
957
+ * only stoptimes for a specific day.
958
+ */
959
+ const stoptimes = getStoptimes({
960
+ stop_id: '70011',
961
+ date: 20160704
962
+ });
963
+
964
+ /*
965
+ * `getStoptimes` allows passing a `start_time` and/or and
966
+ * `end_time` in the query to return only stoptimes after
967
+ * start_time and before end_time. This can be combined with the
968
+ * `date` parameter to get upcoming stoptimes
969
+ */
970
+ const stoptimes = getStoptimes({
971
+ stop_id: '70011',
972
+ date: 20160704,
973
+ start_time: '11:30:00',
974
+ end_time: '11:45:00'
975
+ });
955
976
  ```
956
977
 
957
978
  #### getTrips(query, fields, sortBy, options)
@@ -1066,6 +1087,17 @@ const calendars = getCalendars({
1066
1087
  });
1067
1088
  ```
1068
1089
 
1090
+ #### getServiceIdsByDate(date, options)
1091
+
1092
+ Returns an array of service_ids for a specified date. It queries both calendars.txt and calendar_dates.txt to calculate which service_ids are effective for that date, including exceptions. The `date` field is an integer in yyyymmdd format.
1093
+
1094
+ ```js
1095
+ import { getServiceIdsByDate } from 'gtfs';
1096
+
1097
+ // Get service_ids for a specifc date
1098
+ const serviceIds = getServiceIdsByDate(20240704);
1099
+ ```
1100
+
1069
1101
  #### getCalendarDates(query, fields, sortBy, options)
1070
1102
 
1071
1103
  Returns an array of calendar_dates that match query parameters. [Details on calendar_dates.txt](https://gtfs.org/schedule/reference/#calendar_datestxt)
@@ -3323,8 +3323,6 @@ var getAgencies = (db, config) => {
3323
3323
  };
3324
3324
  var exportGtfs = async (initialConfig) => {
3325
3325
  const config = setDefaultConfig(initialConfig);
3326
- const log2 = log(config);
3327
- const logWarning2 = logWarning(config);
3328
3326
  const db = openDb(config);
3329
3327
  const agencies = getAgencies(db, config);
3330
3328
  const agencyCount = agencies.length;
@@ -3333,11 +3331,11 @@ var exportGtfs = async (initialConfig) => {
3333
3331
  "No agencies found in SQLite. Be sure to first import data into SQLite using `gtfs-import` or `importGtfs(config);`"
3334
3332
  );
3335
3333
  } else if (agencyCount > 1) {
3336
- logWarning2(
3334
+ logWarning(config)(
3337
3335
  "More than one agency is defined in config.json. Export will merge all into one GTFS file."
3338
3336
  );
3339
3337
  }
3340
- log2(
3338
+ log(config)(
3341
3339
  `Starting GTFS export for ${pluralize3(
3342
3340
  "agency",
3343
3341
  agencyCount,
@@ -3362,7 +3360,7 @@ var exportGtfs = async (initialConfig) => {
3362
3360
  const lines = db.prepare(`SELECT * FROM ${tableName};`).all();
3363
3361
  if (!lines || lines.length === 0) {
3364
3362
  if (!model.nonstandard) {
3365
- log2(
3363
+ log(config)(
3366
3364
  `Skipping (no data) - ${model.filenameBase}.${model.filenameExtension}\r`
3367
3365
  );
3368
3366
  }
@@ -3404,17 +3402,23 @@ var exportGtfs = async (initialConfig) => {
3404
3402
  `Unexpected filename extension: ${model.filenameExtension}`
3405
3403
  );
3406
3404
  }
3407
- log2(`Exporting - ${model.filenameBase}.${model.filenameExtension}\r`);
3405
+ log(config)(
3406
+ `Exporting - ${model.filenameBase}.${model.filenameExtension}\r`
3407
+ );
3408
3408
  return `${model.filenameBase}.${model.filenameExtension}`;
3409
3409
  }
3410
3410
  );
3411
3411
  if (compact2(exportedFiles).length === 0) {
3412
- log2("No GTFS data exported. Be sure to first import data into SQLite.");
3412
+ log(config)(
3413
+ "No GTFS data exported. Be sure to first import data into SQLite."
3414
+ );
3413
3415
  return;
3414
3416
  }
3415
- log2(`Completed GTFS export to ${exportPath}`);
3416
- log2(`Completed GTFS export for ${pluralize3("agency", agencyCount, true)}
3417
- `);
3417
+ log(config)(`Completed GTFS export to ${exportPath}`);
3418
+ log(config)(
3419
+ `Completed GTFS export for ${pluralize3("agency", agencyCount, true)}
3420
+ `
3421
+ );
3418
3422
  };
3419
3423
 
3420
3424
  // src/lib/advancedQuery.ts
@@ -3430,6 +3434,10 @@ import { featureCollection as featureCollection2 } from "@turf/helpers";
3430
3434
  // src/lib/gtfs/stops.ts
3431
3435
  import { omit as omit5, orderBy, pick as pick3 } from "lodash-es";
3432
3436
 
3437
+ // src/lib/gtfs/stop-times.ts
3438
+ import { omit as omit6 } from "lodash-es";
3439
+ import sqlString5 from "sqlstring-sqlite";
3440
+
3433
3441
  // src/bin/gtfs-export.ts
3434
3442
  var pe = new PrettyError();
3435
3443
  var argv = yargs(hideBin(process.argv)).usage("Usage: $0 --configPath ./config.json").help().option("c", {