gtfs 3.4.0 → 3.6.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/lib/db.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import sqlite3 from 'sqlite3';
2
2
  import { open } from 'sqlite';
3
3
  import { setDefaultConfig } from './utils.js';
4
+ import untildify from 'untildify';
4
5
  const dbs = {};
5
6
 
6
7
  export async function openDb(initialConfig) {
7
8
  const config = setDefaultConfig(initialConfig);
8
9
  if (!dbs[config.sqlitePath]) {
9
10
  dbs[config.sqlitePath] = await open({
10
- filename: config.sqlitePath,
11
+ filename: untildify(config.sqlitePath),
11
12
  driver: sqlite3.Database,
12
13
  });
13
14
  }
@@ -0,0 +1,30 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { getDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import areas from '../../models/gtfs/areas.js';
11
+
12
+ /*
13
+ * Returns an array of all areas that match the query parameters.
14
+ */
15
+ export async function getAreas(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? (await getDb());
22
+ const tableName = sqlString.escapeId(areas.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db.all(
28
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
+ );
30
+ }
@@ -0,0 +1,30 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { getDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import fareLegRules from '../../models/gtfs/fare-leg-rules.js';
11
+
12
+ /*
13
+ * Returns an array of all fare leg rules that match the query parameters.
14
+ */
15
+ export async function getFareLegRules(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? (await getDb());
22
+ const tableName = sqlString.escapeId(fareLegRules.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db.all(
28
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
+ );
30
+ }
@@ -0,0 +1,30 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { getDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import fareProducts from '../../models/gtfs/fare-products.js';
11
+
12
+ /*
13
+ * Returns an array of all fare products that match the query parameters.
14
+ */
15
+ export async function getFareProducts(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? (await getDb());
22
+ const tableName = sqlString.escapeId(fareProducts.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db.all(
28
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
+ );
30
+ }
@@ -0,0 +1,30 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { getDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import fareTransferRules from '../../models/gtfs/fare-transfer-rules.js';
11
+
12
+ /*
13
+ * Returns an array of all fare transfer rules that match the query parameters.
14
+ */
15
+ export async function getFareTransferRules(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? (await getDb());
22
+ const tableName = sqlString.escapeId(fareTransferRules.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db.all(
28
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
+ );
30
+ }
@@ -0,0 +1,30 @@
1
+ import sqlString from 'sqlstring-sqlite';
2
+
3
+ import { getDb } from '../db.js';
4
+
5
+ import {
6
+ formatOrderByClause,
7
+ formatSelectClause,
8
+ formatWhereClauses,
9
+ } from '../utils.js';
10
+ import stopAreas from '../../models/gtfs/stop-areas.js';
11
+
12
+ /*
13
+ * Returns an array of all stop areas that match the query parameters.
14
+ */
15
+ export async function getStopAreas(
16
+ query = {},
17
+ fields = [],
18
+ orderBy = [],
19
+ options = {}
20
+ ) {
21
+ const db = options.db ?? (await getDb());
22
+ const tableName = sqlString.escapeId(stopAreas.filenameBase);
23
+ const selectClause = formatSelectClause(fields);
24
+ const whereClause = formatWhereClauses(query);
25
+ const orderByClause = formatOrderByClause(orderBy);
26
+
27
+ return db.all(
28
+ `${selectClause} FROM ${tableName} ${whereClause} ${orderByClause};`
29
+ );
30
+ }
package/lib/gtfs.js CHANGED
@@ -6,17 +6,22 @@ import exportGtfs from './export.js';
6
6
 
7
7
  // Standard GTFS Filenames
8
8
  import { getAgencies } from './gtfs/agencies.js';
9
+ import { getAreas } from './gtfs/areas.js';
9
10
  import { getAttributions } from './gtfs/attributions.js';
10
11
  import { getCalendarDates } from './gtfs/calendar-dates.js';
11
12
  import { getCalendars } from './gtfs/calendars.js';
12
13
  import { getFareAttributes } from './gtfs/fare-attributes.js';
14
+ import { getFareLegRules } from './gtfs/fare-leg-rules.js';
15
+ import { getFareProducts } from './gtfs/fare-products.js';
13
16
  import { getFareRules } from './gtfs/fare-rules.js';
17
+ import { getFareTransferRules } from './gtfs/fare-transfer-rules.js';
14
18
  import { getFeedInfo } from './gtfs/feed-info.js';
15
19
  import { getFrequencies } from './gtfs/frequencies.js';
16
20
  import { getLevels } from './gtfs/levels.js';
17
21
  import { getPathways } from './gtfs/pathways.js';
18
22
  import { getRoutes } from './gtfs/routes.js';
19
23
  import { getShapes, getShapesAsGeoJSON } from './gtfs/shapes.js';
24
+ import { getStopAreas } from './gtfs/stop-areas.js';
20
25
  import { getStops, getStopsAsGeoJSON } from './gtfs/stops.js';
21
26
  import { getStoptimes } from './gtfs/stop-times.js';
22
27
  import { getTransfers } from './gtfs/transfers.js';
@@ -60,6 +65,9 @@ export { _exportGtfs as exportGtfs };
60
65
  const _getAgencies = getAgencies;
61
66
  export { _getAgencies as getAgencies };
62
67
 
68
+ const _getAreas = getAreas;
69
+ export { _getAreas as getAreas };
70
+
63
71
  const _getAttributions = getAttributions;
64
72
  export { _getAttributions as getAttributions };
65
73
 
@@ -72,9 +80,18 @@ export { _getCalendars as getCalendars };
72
80
  const _getFareAttributes = getFareAttributes;
73
81
  export { _getFareAttributes as getFareAttributes };
74
82
 
83
+ const _getFareLegRules = getFareLegRules;
84
+ export { _getFareLegRules as getFareLegRules };
85
+
86
+ const _getFareProducts = getFareProducts;
87
+ export { _getFareProducts as getFareProducts };
88
+
75
89
  const _getFareRules = getFareRules;
76
90
  export { _getFareRules as getFareRules };
77
91
 
92
+ const _getFareTransferRules = getFareTransferRules;
93
+ export { _getFareTransferRules as getFareTransferRules };
94
+
78
95
  const _getFeedInfo = getFeedInfo;
79
96
  export { _getFeedInfo as getFeedInfo };
80
97
 
@@ -95,6 +112,9 @@ export { _getShapes as getShapes };
95
112
  const _getShapesAsGeoJSON = getShapesAsGeoJSON;
96
113
  export { _getShapesAsGeoJSON as getShapesAsGeoJSON };
97
114
 
115
+ const _getStopAreas = getStopAreas;
116
+ export { _getStopAreas as getStopAreas };
117
+
98
118
  const _getStops = getStops;
99
119
  export { _getStops as getStops };
100
120
  const _getStopsAsGeoJSON = getStopsAsGeoJSON;
package/lib/log-utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { clearLine, cursorTo } from 'node:readline';
2
2
  import PrettyError from 'pretty-error';
3
3
  import { noop } from 'lodash-es';
4
- import chalk from 'chalk';
4
+ import * as colors from 'yoctocolors';
5
5
 
6
6
  const pe = new PrettyError();
7
7
  pe.start();
@@ -60,17 +60,18 @@ export function logError(config) {
60
60
  * Format console warning text
61
61
  */
62
62
  export function formatWarning(text) {
63
- return `${chalk.yellow.underline('Warning')}${chalk.yellow(
64
- ':'
65
- )} ${chalk.yellow(text)}`;
63
+ const warningMessage = `${colors.underline('Warning')}: ${text}`;
64
+ return colors.yellow(warningMessage);
66
65
  }
67
66
 
68
67
  /*
69
68
  * Format console error text
70
69
  */
71
70
  export function formatError(error) {
72
- const message = error instanceof Error ? error.message : error;
73
- return `${chalk.red.underline('Error')}${chalk.red(':')} ${chalk.red(
74
- message.replace('Error: ', '')
71
+ const messageText = error instanceof Error ? error.message : error;
72
+ const errorMessage = `${colors.underline('Error')}: ${messageText.replace(
73
+ 'Error: ',
74
+ ''
75
75
  )}`;
76
+ return colors.red(errorMessage);
76
77
  }
@@ -0,0 +1,17 @@
1
+ const model = {
2
+ filenameBase: 'areas',
3
+ schema: [
4
+ {
5
+ name: 'area_id',
6
+ type: 'varchar(255)',
7
+ required: true,
8
+ primary: true,
9
+ },
10
+ {
11
+ name: 'area_name',
12
+ type: 'varchar(255)',
13
+ },
14
+ ],
15
+ };
16
+
17
+ export default model;
@@ -1,14 +1,10 @@
1
1
  const model = {
2
2
  filenameBase: 'attributions',
3
3
  schema: [
4
- {
5
- name: 'id',
6
- type: 'integer',
7
- primary: true,
8
- },
9
4
  {
10
5
  name: 'attribution_id',
11
6
  type: 'varchar(255)',
7
+ primary: true,
12
8
  },
13
9
  {
14
10
  name: 'agency_id',
@@ -0,0 +1,28 @@
1
+ const model = {
2
+ filenameBase: 'fare_leg_rules',
3
+ schema: [
4
+ {
5
+ name: 'leg_group_id',
6
+ type: 'varchar(255)',
7
+ },
8
+ {
9
+ name: 'network_id',
10
+ type: 'varchar(255)',
11
+ },
12
+ {
13
+ name: 'from_area_id',
14
+ type: 'varchar(255)',
15
+ },
16
+ {
17
+ name: 'to_area_id',
18
+ type: 'varchar(255)',
19
+ },
20
+ {
21
+ name: 'fare_product_id',
22
+ type: 'varchar(255)',
23
+ required: true,
24
+ },
25
+ ],
26
+ };
27
+
28
+ export default model;
@@ -0,0 +1,27 @@
1
+ const model = {
2
+ filenameBase: 'fare_products',
3
+ schema: [
4
+ {
5
+ name: 'fare_product_id',
6
+ type: 'varchar(255)',
7
+ required: true,
8
+ primary: true,
9
+ },
10
+ {
11
+ name: 'fare_product_name',
12
+ type: 'varchar(255)',
13
+ },
14
+ {
15
+ name: 'amount',
16
+ type: 'real',
17
+ required: true,
18
+ },
19
+ {
20
+ name: 'currency',
21
+ type: 'varchar(255)',
22
+ required: true,
23
+ },
24
+ ],
25
+ };
26
+
27
+ export default model;
@@ -10,12 +10,10 @@ const model = {
10
10
  name: 'fare_id',
11
11
  type: 'varchar(255)',
12
12
  required: true,
13
- index: true,
14
13
  },
15
14
  {
16
15
  name: 'route_id',
17
16
  type: 'varchar(255)',
18
- index: true,
19
17
  },
20
18
  {
21
19
  name: 'origin_id',
@@ -0,0 +1,45 @@
1
+ const model = {
2
+ filenameBase: 'fare_transfer_rules',
3
+ schema: [
4
+ {
5
+ name: 'from_leg_group_id',
6
+ type: 'varchar(255)',
7
+ },
8
+ {
9
+ name: 'to_leg_group_id',
10
+ type: 'varchar(255)',
11
+ },
12
+ {
13
+ name: 'transfer_count',
14
+ type: 'integer',
15
+ min: -1,
16
+ },
17
+ {
18
+ name: 'transfer_id',
19
+ type: 'varchar(255)',
20
+ },
21
+ {
22
+ name: 'duration_limit',
23
+ type: 'integer',
24
+ min: 0,
25
+ },
26
+ {
27
+ name: 'duration_limit_type',
28
+ type: 'integer',
29
+ min: 0,
30
+ max: 3,
31
+ },
32
+ {
33
+ name: 'fare_transfer_type',
34
+ type: 'integer',
35
+ min: 0,
36
+ max: 2,
37
+ },
38
+ {
39
+ name: 'fare_product_id',
40
+ type: 'varchar(255)',
41
+ },
42
+ ],
43
+ };
44
+
45
+ export default model;
@@ -5,6 +5,7 @@ const model = {
5
5
  name: 'level_id',
6
6
  type: 'varchar(255)',
7
7
  primary: true,
8
+ required: true,
8
9
  },
9
10
  {
10
11
  name: 'level_index',
@@ -5,6 +5,7 @@ const model = {
5
5
  name: 'pathway_id',
6
6
  type: 'varchar(255)',
7
7
  primary: true,
8
+ required: true,
8
9
  },
9
10
  {
10
11
  name: 'from_stop_id',
@@ -33,6 +34,7 @@ const model = {
33
34
  {
34
35
  name: 'length',
35
36
  type: 'real',
37
+ min: 0,
36
38
  },
37
39
  {
38
40
  name: 'traversal_time',
@@ -5,6 +5,7 @@ const model = {
5
5
  name: 'route_id',
6
6
  type: 'varchar(255)',
7
7
  primary: true,
8
+ required: true,
8
9
  },
9
10
  {
10
11
  name: 'agency_id',
@@ -64,6 +65,10 @@ const model = {
64
65
  min: 0,
65
66
  max: 3,
66
67
  },
68
+ {
69
+ name: 'network_id',
70
+ type: 'varchar(255)',
71
+ },
67
72
  ],
68
73
  };
69
74
 
@@ -0,0 +1,17 @@
1
+ const model = {
2
+ filenameBase: 'stop_areas',
3
+ schema: [
4
+ {
5
+ name: 'area_id',
6
+ type: 'varchar(255)',
7
+ required: true,
8
+ },
9
+ {
10
+ name: 'stop_id',
11
+ type: 'varchar(255)',
12
+ required: true,
13
+ },
14
+ ],
15
+ };
16
+
17
+ export default model;
@@ -5,6 +5,7 @@ const model = {
5
5
  name: 'stop_id',
6
6
  type: 'varchar(255)',
7
7
  primary: true,
8
+ required: true,
8
9
  },
9
10
  {
10
11
  name: 'stop_code',
@@ -9,20 +9,35 @@ const model = {
9
9
  {
10
10
  name: 'from_stop_id',
11
11
  type: 'varchar(255)',
12
- required: true,
13
12
  index: true,
14
13
  },
15
14
  {
16
15
  name: 'to_stop_id',
17
16
  type: 'varchar(255)',
18
- required: true,
19
17
  index: true,
20
18
  },
19
+ {
20
+ name: 'from_route_id',
21
+ type: 'varchar(255)',
22
+ },
23
+ {
24
+ name: 'to_route_id',
25
+ type: 'varchar(255)',
26
+ },
27
+ {
28
+ name: 'from_trip_id',
29
+ type: 'varchar(255)',
30
+ },
31
+ {
32
+ name: 'to_trip_id',
33
+ type: 'varchar(255)',
34
+ },
21
35
  {
22
36
  name: 'transfer_type',
23
37
  type: 'integer',
24
38
  min: 0,
25
- max: 3,
39
+ max: 5,
40
+ required: true,
26
41
  },
27
42
  {
28
43
  name: 'min_transfer_time',
@@ -1,11 +1,6 @@
1
1
  const model = {
2
2
  filenameBase: 'trips',
3
3
  schema: [
4
- {
5
- name: 'trip_id',
6
- type: 'varchar(255)',
7
- primary: true,
8
- },
9
4
  {
10
5
  name: 'route_id',
11
6
  type: 'varchar(255)',
@@ -18,6 +13,12 @@ const model = {
18
13
  required: true,
19
14
  index: true,
20
15
  },
16
+ {
17
+ name: 'trip_id',
18
+ type: 'varchar(255)',
19
+ primary: true,
20
+ required: true,
21
+ },
21
22
  {
22
23
  name: 'trip_headsign',
23
24
  type: 'varchar(255)',
package/models/models.js CHANGED
@@ -1,15 +1,20 @@
1
1
  import agency from '../models/gtfs/agency.js';
2
+ import areas from '../models/gtfs/areas.js';
2
3
  import attributions from '../models/gtfs/attributions.js';
3
4
  import calendarDates from '../models/gtfs/calendar-dates.js';
4
5
  import calendar from '../models/gtfs/calendar.js';
5
6
  import fareAttributes from '../models/gtfs/fare-attributes.js';
7
+ import fareLegRules from '../models/gtfs/fare-leg-rules.js';
8
+ import fareProducts from '../models/gtfs/fare-products.js';
6
9
  import fareRules from '../models/gtfs/fare-rules.js';
10
+ import fareTransferRules from '../models/gtfs/fare-transfer-rules.js';
7
11
  import feedInfo from '../models/gtfs/feed-info.js';
8
12
  import frequencies from '../models/gtfs/frequencies.js';
9
13
  import levels from '../models/gtfs/levels.js';
10
14
  import pathways from '../models/gtfs/pathways.js';
11
15
  import routes from '../models/gtfs/routes.js';
12
16
  import shapes from '../models/gtfs/shapes.js';
17
+ import stopAreas from '../models/gtfs/stop-areas.js';
13
18
  import stopTimes from '../models/gtfs/stop-times.js';
14
19
  import stops from '../models/gtfs/stops.js';
15
20
  import transfers from '../models/gtfs/transfers.js';
@@ -39,17 +44,22 @@ import serviceAlertTargets from './gtfs-realtime/service-alert-targets.js';
39
44
 
40
45
  const models = [
41
46
  agency,
47
+ areas,
42
48
  attributions,
43
49
  calendarDates,
44
50
  calendar,
45
51
  fareAttributes,
52
+ fareLegRules,
53
+ fareProducts,
46
54
  fareRules,
55
+ fareTransferRules,
47
56
  feedInfo,
48
57
  frequencies,
49
58
  levels,
50
59
  pathways,
51
60
  routes,
52
61
  shapes,
62
+ stopAreas,
53
63
  stopTimes,
54
64
  stops,
55
65
  transfers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtfs",
3
- "version": "3.4.0",
3
+ "version": "3.6.0",
4
4
  "description": "Import GTFS transit data into SQLite and query routes, stops, times, fares and more",
5
5
  "keywords": [
6
6
  "transit",
@@ -72,35 +72,35 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@turf/helpers": "^6.5.0",
75
- "chalk": "^5.0.1",
76
- "csv-parse": "^5.1.0",
77
- "csv-stringify": "^6.1.0",
75
+ "csv-parse": "^5.3.0",
76
+ "csv-stringify": "^6.2.0",
78
77
  "gtfs-realtime-bindings": "^0.0.6",
79
78
  "lodash-es": "^4.17.21",
80
79
  "long": "^5.2.0",
81
- "node-fetch": "^3.2.6",
80
+ "node-fetch": "^3.2.10",
82
81
  "pluralize": "^8.0.0",
83
82
  "pretty-error": "^4.0.0",
84
83
  "promise-map-series": "^0.3.0",
85
84
  "recursive-copy": "^2.0.14",
86
85
  "sanitize-filename": "^1.6.3",
87
- "sqlite": "^4.1.1",
88
- "sqlite3": "^5.0.8",
86
+ "sqlite": "^4.1.2",
87
+ "sqlite3": "^5.0.11",
89
88
  "sqlstring-sqlite": "^0.1.1",
90
89
  "strip-bom-stream": "^5.0.0",
91
90
  "tmp-promise": "^3.0.3",
92
91
  "untildify": "^4.0.0",
93
92
  "unzipper": "^0.10.11",
94
- "yargs": "^17.5.1"
93
+ "yargs": "^17.5.1",
94
+ "yoctocolors": "^1.0.0"
95
95
  },
96
96
  "devDependencies": {
97
97
  "dtslint": "^4.2.1",
98
- "eslint": "^8.17.0",
98
+ "eslint": "^8.21.0",
99
99
  "eslint-config-prettier": "^8.5.0",
100
100
  "eslint-config-xo": "^0.41.0",
101
101
  "husky": "^8.0.1",
102
102
  "mocha": "^10.0.0",
103
- "prettier": "^2.6.2",
103
+ "prettier": "^2.7.1",
104
104
  "pretty-quick": "^3.1.3",
105
105
  "should": "^13.2.3"
106
106
  },