gtfs 4.1.0 → 4.1.1

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 CHANGED
@@ -383,6 +383,17 @@ export function getStopAreas(
383
383
  options?: QueryOptions
384
384
  ): SqlResults;
385
385
 
386
+ /**
387
+ * Returns an array of calendar_attributes that match query parameters.
388
+ * This is for the non-standard `calendar_attributes.txt` file.
389
+ */
390
+ export function getCalendarAttributes(
391
+ query?: SqlWhere,
392
+ fields?: SqlSelect,
393
+ sortBy?: SqlOrderBy,
394
+ options?: QueryOptions
395
+ ): SqlResults;
396
+
386
397
  /**
387
398
  * Returns an array of directions that match query parameters.
388
399
  * This is for the non-standard `directions.txt` file.
@@ -394,6 +405,17 @@ export function getDirections(
394
405
  options?: QueryOptions
395
406
  ): SqlResults;
396
407
 
408
+ /**
409
+ * Returns an array of route_attributes that match query parameters.
410
+ * This is for the non-standard `route_attributes.txt` file.
411
+ */
412
+ export function getRouteAttributes(
413
+ query?: SqlWhere,
414
+ fields?: SqlSelect,
415
+ sortBy?: SqlOrderBy,
416
+ options?: QueryOptions
417
+ ): SqlResults;
418
+
397
419
  /**
398
420
  * Returns an array of stop_attributes that match query parameters.
399
421
  * This is for the non-standard `stop_attributes.txt` file.
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.1.1] - 2023-04-12
9
+
10
+ ### Added
11
+
12
+ - Support for GTFS+ Files
13
+
14
+ ### Updated
15
+
16
+ - Dependency updates
17
+
8
18
  ## [4.1.0] - 2023-02-25
9
19
 
10
20
  ### Added
package/README.md CHANGED
@@ -1162,8 +1162,82 @@ import { getVehiclePositions } from 'gtfs';
1162
1162
  const vehiclePositions = getVehiclePositions();
1163
1163
  ```
1164
1164
 
1165
+ ### GTFS+ Files
1166
+
1167
+ #### getCalendarAttributes(query, fields, sortBy, options)
1168
+
1169
+ Returns an array of calendar_attributes that match query parameters.
1170
+
1171
+ ```js
1172
+ import { getCalendarAttributes } from 'gtfs';
1173
+
1174
+ // Get all calendar attributes
1175
+ const calendarAttributes = getCalendarAttributes();
1176
+
1177
+ // Get calendar attributes for specific service
1178
+ const calendarAttributes = getCalendarAttributes({
1179
+ service_id: '1234',
1180
+ });
1181
+ ```
1182
+
1183
+ #### getDirections(query, fields, sortBy, options)
1184
+
1185
+ Returns an array of directions that match query parameters.
1186
+
1187
+ ```js
1188
+ import { getDirections } from 'gtfs';
1189
+
1190
+ // Get all directions
1191
+ const directions = getDirections();
1192
+
1193
+ // Get directions for a specific route
1194
+ const directions = getDirections({
1195
+ route_id: '1234',
1196
+ });
1197
+
1198
+ // Get directions for a specific route and direction
1199
+ const directions = getDirections({
1200
+ route_id: '1234',
1201
+ direction_id: 1,
1202
+ });
1203
+ ```
1204
+
1205
+ #### getRouteAttributes(query, fields, sortBy, options)
1206
+
1207
+ Returns an array of route_attributes that match query parameters.
1208
+
1209
+ ```js
1210
+ import { getRouteAttributes } from 'gtfs';
1211
+
1212
+ // Get all route attributes
1213
+ const routeAttributes = getRouteAttributes();
1214
+
1215
+ // Get route attributes for specific route
1216
+ const routeAttributes = getRouteAttributes({
1217
+ route_id: '1234',
1218
+ });
1219
+ ```
1220
+
1221
+ #### getStopAttributes(query, fields, sortBy, options)
1222
+
1223
+ Returns an array of stop_attributes that match query parameters.
1224
+
1225
+ ```js
1226
+ import { getStopAttributes } from 'gtfs';
1227
+
1228
+ // Get all stop attributes
1229
+ const stopAttributes = getStopAttributes();
1230
+
1231
+ // Get stop attributes for specific stop
1232
+ const stopAttributes = getStopAttributes({
1233
+ stop_id: '1234',
1234
+ });
1235
+ ```
1236
+
1165
1237
  ### GTFS-Ride Files
1166
1238
 
1239
+ See full [documentation of GTFS Ride](https://gtfsride.org).
1240
+
1167
1241
  #### getBoardAlights(query, fields, sortBy, options)
1168
1242
 
1169
1243
  Returns an array of board_alight that match query parameters. [Details on board_alight.txt](http://gtfsride.org/specification#board_alighttxt)
@@ -1316,45 +1390,7 @@ const runEvents = runEvents({
1316
1390
  });
1317
1391
  ```
1318
1392
 
1319
- ### Non-standard GTFS Files
1320
-
1321
- #### getDirections(query, fields, sortBy, options)
1322
-
1323
- Returns an array of directions that match query parameters. This is for the non-standard `directions.txt` file. [Details on directions.txt](https://trilliumtransit.com/gtfs/reference/#directions)
1324
-
1325
- ```js
1326
- import { getDirections } from 'gtfs';
1327
-
1328
- // Get all directions
1329
- const directions = getDirections();
1330
-
1331
- // Get directions for a specific route
1332
- const directions = getDirections({
1333
- route_id: '1234',
1334
- });
1335
-
1336
- // Get directions for a specific route and direction
1337
- const directions = getDirections({
1338
- route_id: '1234',
1339
- direction_id: 1,
1340
- });
1341
- ```
1342
-
1343
- #### getStopAttributes(query, fields, sortBy, options)
1344
-
1345
- Returns an array of stop_attributes that match query parameters. This is for the non-standard `stop_attributes.txt` file. [Details on stop_attributes.txt](https://trilliumtransit.com/gtfs/reference/#stop_attributes)
1346
-
1347
- ```js
1348
- import { getStopAttributes } from 'gtfs';
1349
-
1350
- // Get all stop attributes
1351
- const stopAttributes = getStopAttributes();
1352
-
1353
- // Get stop attributes for specific stop
1354
- const stopAttributes = getStopAttributes({
1355
- stop_id: '1234',
1356
- });
1357
- ```
1393
+ ### Other Non-standard GTFS Files
1358
1394
 
1359
1395
  #### getTripsDatedVehicleJourneys(query, fields, sortBy, options)
1360
1396
 
@@ -0,0 +1,32 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { openDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import calendarAttributes from '../../models/gtfs-plus/calendar-attributes.js';
11
+
12
+ /*
13
+ * Returns an array of all calendar_attributes that match the query parameters.
14
+ */
15
+ export function getCalendarAttributes(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? openDb();
22
+ const tableName = sqlString.escapeId(calendarAttributes.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
32
+ }
@@ -7,7 +7,7 @@ import {
7
7
  formatSelectClause,
8
8
  formatWhereClauses,
9
9
  } from '../utils.js';
10
- import directions from '../../models/non-standard/directions.js';
10
+ import directions from '../../models/gtfs-plus/directions.js';
11
11
 
12
12
  /*
13
13
  * Returns an array of all directions that match the query parameters.
@@ -0,0 +1,32 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { openDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import routeAttributes from '../../models/gtfs-plus/route-attributes.js';
11
+
12
+ /*
13
+ * Returns an array of all route_attributes that match the query parameters.
14
+ */
15
+ export function getRouteAttributes(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? openDb();
22
+ const tableName = sqlString.escapeId(routeAttributes.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db
28
+ .prepare(
29
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
30
+ )
31
+ .all();
32
+ }
@@ -7,7 +7,7 @@ import {
7
7
  formatSelectClause,
8
8
  formatWhereClauses,
9
9
  } from '../utils.js';
10
- import stopAttributes from '../../models/non-standard/stop-attributes.js';
10
+ import stopAttributes from '../../models/gtfs-plus/stop-attributes.js';
11
11
 
12
12
  /*
13
13
  * Returns an array of all stop attributes that match the query parameters.
package/lib/gtfs.js CHANGED
@@ -28,9 +28,13 @@ import { getTransfers } from './gtfs/transfers.js';
28
28
  import { getTranslations } from './gtfs/translations.js';
29
29
  import { getTrips } from './gtfs/trips.js';
30
30
 
31
+ // GTFS Plus Filenames
32
+ import { getCalendarAttributes } from './gtfs-plus/calendar-attributes.js';
33
+ import { getDirections } from './gtfs-plus/directions.js';
34
+ import { getRouteAttributes } from './gtfs-plus/route-attributes.js';
35
+ import { getStopAttributes } from './gtfs-plus/stop-attributes.js';
36
+
31
37
  // Non-standard GTFS Filenames
32
- import { getDirections } from './non-standard/directions.js';
33
- import { getStopAttributes } from './non-standard/stop-attributes.js';
34
38
  import { getTimetables } from './non-standard/timetables.js';
35
39
  import { getTimetableStopOrders } from './non-standard/timetable-stop-order.js';
36
40
  import { getTimetablePages } from './non-standard/timetable-pages.js';
@@ -139,9 +143,15 @@ export { _getTrips as getTrips };
139
143
  const _getTranslations = getTranslations;
140
144
  export { _getTranslations as getTranslations };
141
145
 
146
+ const _getCalendarAttributes = getCalendarAttributes;
147
+ export { _getCalendarAttributes as getCalendarAttributes };
148
+
142
149
  const _getDirections = getDirections;
143
150
  export { _getDirections as getDirections };
144
151
 
152
+ const _getRouteAttributes = getRouteAttributes;
153
+ export { _getRouteAttributes as getRouteAttributes };
154
+
145
155
  const _getStopAttributes = getStopAttributes;
146
156
  export { _getStopAttributes as getStopAttributes };
147
157
 
@@ -0,0 +1,20 @@
1
+ const model = {
2
+ filenameBase: 'calendar_attributes',
3
+ nonstandard: true,
4
+ extension: 'gtfs-plus',
5
+ schema: [
6
+ {
7
+ name: 'service_id',
8
+ type: 'varchar(255)',
9
+ primary: true,
10
+ },
11
+ {
12
+ name: 'service_description',
13
+ type: 'varchar(255)',
14
+ required: true,
15
+ nocase: true,
16
+ },
17
+ ],
18
+ };
19
+
20
+ export default model;
@@ -1,6 +1,7 @@
1
1
  const model = {
2
2
  filenameBase: 'directions',
3
3
  nonstandard: true,
4
+ extension: 'gtfs-plus',
4
5
  schema: [
5
6
  {
6
7
  name: 'id',
@@ -0,0 +1,32 @@
1
+ const model = {
2
+ filenameBase: 'route_attributes',
3
+ nonstandard: true,
4
+ extension: 'gtfs-plus',
5
+ schema: [
6
+ {
7
+ name: 'route_id',
8
+ type: 'varchar(255)',
9
+ primary: true,
10
+ },
11
+ {
12
+ name: 'category',
13
+ type: 'integer',
14
+ min: 0,
15
+ required: true,
16
+ },
17
+ {
18
+ name: 'subcategory',
19
+ type: 'integer',
20
+ min: 101,
21
+ required: true,
22
+ },
23
+ {
24
+ name: 'running_way',
25
+ type: 'integer',
26
+ min: 1,
27
+ required: true,
28
+ },
29
+ ],
30
+ };
31
+
32
+ export default model;
@@ -1,6 +1,7 @@
1
1
  const model = {
2
2
  filenameBase: 'stop_attributes',
3
3
  nonstandard: true,
4
+ extension: 'gtfs-plus',
4
5
  schema: [
5
6
  {
6
7
  name: 'id',
@@ -13,6 +14,19 @@ const model = {
13
14
  required: true,
14
15
  index: true,
15
16
  },
17
+ {
18
+ name: 'accessibility_id',
19
+ type: 'integer',
20
+ min: 0,
21
+ },
22
+ {
23
+ name: 'cardinal_direction',
24
+ type: 'varchar(255)',
25
+ },
26
+ {
27
+ name: 'relative_position',
28
+ type: 'varchar(255)',
29
+ },
16
30
  {
17
31
  name: 'stop_city',
18
32
  type: 'varchar(255)',
package/models/models.js CHANGED
@@ -21,8 +21,6 @@ import transfers from '../models/gtfs/transfers.js';
21
21
  import translations from '../models/gtfs/translations.js';
22
22
  import trips from '../models/gtfs/trips.js';
23
23
 
24
- import directions from '../models/non-standard/directions.js';
25
- import stopAttributes from '../models/non-standard/stop-attributes.js';
26
24
  import timetables from '../models/non-standard/timetables.js';
27
25
  import timetablePages from '../models/non-standard/timetable-pages.js';
28
26
  import timetableStopOrder from '../models/non-standard/timetable-stop-order.js';
@@ -30,6 +28,11 @@ import timetableNotes from '../models/non-standard/timetable-notes.js';
30
28
  import timetableNotesReferences from '../models/non-standard/timetable-notes-references.js';
31
29
  import tripsDatedVehicleJourney from '../models/non-standard/trips-dated-vehicle-journey.js';
32
30
 
31
+ import calendarAttributes from '../models/gtfs-plus/calendar-attributes.js';
32
+ import directions from '../models/gtfs-plus/directions.js';
33
+ import routeAttributes from '../models/gtfs-plus/route-attributes.js';
34
+ import stopAttributes from '../models/gtfs-plus/stop-attributes.js';
35
+
33
36
  import boardAlight from '../models/gtfs-ride/board-alight.js';
34
37
  import riderTrip from '../models/gtfs-ride/rider-trip.js';
35
38
  import ridership from '../models/gtfs-ride/ridership.js';
@@ -71,14 +74,16 @@ const models = [
71
74
  transfers,
72
75
  translations,
73
76
  trips,
74
- directions,
75
- stopAttributes,
76
77
  timetables,
77
78
  timetablePages,
78
79
  timetableStopOrder,
79
80
  timetableNotes,
80
81
  timetableNotesReferences,
81
82
  tripsDatedVehicleJourney,
83
+ calendarAttributes,
84
+ directions,
85
+ routeAttributes,
86
+ stopAttributes,
82
87
  boardAlight,
83
88
  rideFeedInfo,
84
89
  riderTrip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtfs",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
5
5
  "keywords": [
6
6
  "transit",
@@ -74,13 +74,13 @@
74
74
  },
75
75
  "dependencies": {
76
76
  "@turf/helpers": "^6.5.0",
77
- "better-sqlite3": "^8.1.0",
78
- "csv-parse": "^5.3.5",
79
- "csv-stringify": "^6.2.4",
77
+ "better-sqlite3": "^8.3.0",
78
+ "csv-parse": "^5.3.6",
79
+ "csv-stringify": "^6.3.0",
80
80
  "gtfs-realtime-bindings": "^1.1.1",
81
81
  "lodash-es": "^4.17.21",
82
82
  "long": "^5.2.1",
83
- "node-fetch": "^3.3.0",
83
+ "node-fetch": "^3.3.1",
84
84
  "pluralize": "^8.0.0",
85
85
  "pretty-error": "^4.0.0",
86
86
  "promise-map-series": "^0.3.0",
@@ -95,14 +95,14 @@
95
95
  "yoctocolors": "^1.0.0"
96
96
  },
97
97
  "devDependencies": {
98
- "@types/better-sqlite3": "^7.6.3",
98
+ "@types/better-sqlite3": "^7.6.4",
99
99
  "dtslint": "^4.2.1",
100
- "eslint": "^8.34.0",
101
- "eslint-config-prettier": "^8.6.0",
100
+ "eslint": "^8.38.0",
101
+ "eslint-config-prettier": "^8.8.0",
102
102
  "eslint-config-xo": "^0.43.1",
103
103
  "husky": "^8.0.3",
104
104
  "mocha": "^10.2.0",
105
- "prettier": "^2.8.4",
105
+ "prettier": "^2.8.7",
106
106
  "pretty-quick": "^3.1.3",
107
107
  "should": "^13.2.3"
108
108
  },
@@ -0,0 +1,33 @@
1
+ /* eslint-env mocha */
2
+
3
+ import should from 'should';
4
+
5
+ import config from '../test-config.js';
6
+ import {
7
+ openDb,
8
+ closeDb,
9
+ importGtfs,
10
+ getCalendarAttributes,
11
+ } from '../../index.js';
12
+
13
+ describe('getCalendarAttributes():', () => {
14
+ before(async () => {
15
+ openDb(config);
16
+ await importGtfs(config);
17
+ });
18
+
19
+ after(() => {
20
+ const db = openDb(config);
21
+ closeDb(db);
22
+ });
23
+
24
+ it('should return empty array if no calendar attributes', () => {
25
+ const serviceId = 'fake-service-id';
26
+
27
+ const results = getCalendarAttributes({
28
+ service_id: serviceId,
29
+ });
30
+ should.exists(results);
31
+ results.should.have.length(0);
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ /* eslint-env mocha */
2
+
3
+ import should from 'should';
4
+
5
+ import config from '../test-config.js';
6
+ import {
7
+ openDb,
8
+ closeDb,
9
+ importGtfs,
10
+ getRouteAttributes,
11
+ } from '../../index.js';
12
+
13
+ describe('getRouteAttributes():', () => {
14
+ before(async () => {
15
+ openDb(config);
16
+ await importGtfs(config);
17
+ });
18
+
19
+ after(() => {
20
+ const db = openDb(config);
21
+ closeDb(db);
22
+ });
23
+
24
+ it('should return empty array if no route attributes', () => {
25
+ const routeId = 'fake-route-id';
26
+
27
+ const results = getRouteAttributes({
28
+ route_id: routeId,
29
+ });
30
+ should.exists(results);
31
+ results.should.have.length(0);
32
+ });
33
+ });