Skip to content

Commit

Permalink
Changed model exports
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Aug 6, 2024
1 parent 6cbca5c commit dc03c0b
Show file tree
Hide file tree
Showing 121 changed files with 228 additions and 572 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
### Fixed
- Correction to trips_dated_vehicle_journey

### Updated
- Changed model exports

## [4.13.3] - 2024-08-03

### Changed
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1565,15 +1565,15 @@ const boardAlights = getBoardAlights({
});
```
#### getRideFeedInfos(query, fields, sortBy, options)
#### getRideFeedInfo(query, fields, sortBy, options)
Returns an array of ride_feed_info that match query parameters. [Details on ride_feed_info.txt](http://gtfsride.org/specification#ride_feed_infotxt)
```js
import { getRideFeedInfos } from 'gtfs';
import { getRideFeedInfo } from 'gtfs';
// Get all ride_feed_info
const rideFeedInfos = getRideFeedInfos();
const rideFeedInfos = getRideFeedInfo();
```
#### getRiderTrips(query, fields, sortBy, options)
Expand All @@ -1592,18 +1592,18 @@ const riderTrips = getRiderTrips({
});
```
#### getRiderships(query, fields, sortBy, options)
#### getRidership(query, fields, sortBy, options)
Returns an array of ridership that match query parameters. [Details on ridership.txt](http://gtfsride.org/specification#ridershiptxt)
```js
import { getRiderships } from 'gtfs';
import { getRidership } from 'gtfs';
// Get all ridership
const riderships = getRiderships();
const riderships = getRidership();
// Get ridership for a specific route
const riderships = getRiderships({
const riderships = getRidership({
route_id: '123',
});
```
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"build": "tsup"
},
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./models": {
"import": "./dist/models/models.js",
"types": "./dist/models/models.d.ts"
}
},
"dependencies": {
"@turf/helpers": "^7.0.0",
"better-sqlite3": "^11.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export { getTripsDatedVehicleJourneys } from './lib/non-standard/trips-dated-veh

// GTFS-ride
export { getBoardAlights } from './lib/gtfs-ride/board-alights.ts';
export { getRideFeedInfos } from './lib/gtfs-ride/ride-feed-infos.ts';
export { getRideFeedInfo } from './lib/gtfs-ride/ride-feed-info.ts';
export { getRiderTrips } from './lib/gtfs-ride/rider-trips.ts';
export { getRiderships } from './lib/gtfs-ride/riderships.ts';
export { getRidership } from './lib/gtfs-ride/ridership.ts';
export { getTripCapacities } from './lib/gtfs-ride/trip-capacities.ts';

// GTFS-Realtime
Expand Down
6 changes: 3 additions & 3 deletions src/lib/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Database from 'better-sqlite3';
import mapSeries from 'promise-map-series';
import untildify from 'untildify';

import models from '../models/models.ts';
import * as models from '../models/models.ts';
import { openDb } from './db.ts';
import { prepDirectory, generateFolderName } from './file-utils.ts';
import { log as _log, logWarning as _logWarning } from './log-utils.ts';
Expand Down Expand Up @@ -70,8 +70,8 @@ export const exportGtfs = async (initialConfig: IConfig) => {
await prepDirectory(exportPath);

// Loop through each GTFS file
const modelsToExport = models.filter(
(model) => model.extension !== 'gtfs-realtime',
const modelsToExport = Object.values(models).filter(
(model: IModel) => model.extension !== 'gtfs-realtime',
);
const exportedFiles = await mapSeries(
modelsToExport,
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-plus/calendar-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import calendarAttributes from '../../models/gtfs-plus/calendar-attributes.ts';

/*
* Returns an array of all calendar_attributes that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getCalendarAttributes(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(calendarAttributes.filenameBase);
const tableName = 'calendar_attributes';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-plus/directions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import directions from '../../models/gtfs-plus/directions.ts';

/*
* Returns an array of all directions that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getDirections(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(directions.filenameBase);
const tableName = 'directions';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-plus/route-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import routeAttributes from '../../models/gtfs-plus/route-attributes.ts';

/*
* Returns an array of all route_attributes that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getRouteAttributes(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(routeAttributes.filenameBase);
const tableName = 'route_attributes';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-plus/stop-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import stopAttributes from '../../models/gtfs-plus/stop-attributes.ts';

/*
* Returns an array of all stop attributes that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getStopAttributes(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(stopAttributes.filenameBase);
const tableName = 'stop_attributes';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
10 changes: 3 additions & 7 deletions src/lib/gtfs-realtime/service-alerts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,8 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import serviceAlerts from '../../models/gtfs-realtime/service-alerts.ts';
import serviceAlertTargets from '../../models/gtfs-realtime/service-alert-targets.ts';

/*
* Returns an array of all service alerts that match the query parameters.
Expand All @@ -26,15 +22,15 @@ export function getServiceAlerts(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(serviceAlerts.filenameBase);
const joinTable = sqlString.escapeId(serviceAlertTargets.filenameBase);
const tableName = 'service_alerts';
const joinTableName = 'service_alert_targets';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);

return db
.prepare(
`${selectClause} FROM ${tableName} INNER JOIN ${joinTable} ON ${tableName}.id=${joinTable}.alert_id ${whereClause} ${orderByClause};`,
`${selectClause} FROM ${tableName} INNER JOIN ${joinTableName} ON ${tableName}.id=${joinTableName}.alert_id ${whereClause} ${orderByClause};`,
)
.all() as SqlResults;
}
5 changes: 1 addition & 4 deletions src/lib/gtfs-realtime/stop-time-updates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import stopTimeUpdates from '../../models/gtfs-realtime/stop-time-updates.ts';

/*
* Returns an array of all stop time updates that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getStopTimeUpdates(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(stopTimeUpdates.filenameBase);
const tableName = 'stop_time_updates';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-realtime/trip-updates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import tripUpdates from '../../models/gtfs-realtime/trip-updates.ts';

/*
* Returns an array of all trip updates that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getTripUpdates(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(tripUpdates.filenameBase);
const tableName = 'trip_updates';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-realtime/vehicle-positions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import vehiclePositions from '../../models/gtfs-realtime/vehicle-positions.ts';

/*
* Returns an array of all vehicle positions that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getVehiclePositions(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(vehiclePositions.filenameBase);
const tableName = 'vehicle_positions';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-ride/board-alights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import boardAlights from '../../models/gtfs-ride/board-alight.ts';

/*
* Returns an array of all board-alights that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getBoardAlights(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(boardAlights.filenameBase);
const tableName = 'board_alight';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,19 +11,18 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import rideFeedInfo from '../../models/gtfs-ride/ride-feed-info.ts';

/*
* Returns an array of all ride-feed-info that match the query parameters.
*/
export function getRideFeedInfos(
export function getRideFeedInfo(
query: SqlWhere = {},
fields: SqlSelect = [],
orderBy: SqlOrderBy = [],
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(rideFeedInfo.filenameBase);
const tableName = 'ride_feed_info';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
5 changes: 1 addition & 4 deletions src/lib/gtfs-ride/rider-trips.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sqlString from 'sqlstring-sqlite';

import {
QueryOptions,
SqlOrderBy,
Expand All @@ -13,7 +11,6 @@ import {
formatSelectClause,
formatWhereClauses,
} from '../utils.ts';
import riderTrip from '../../models/gtfs-ride/rider-trip.ts';

/*
* Returns an array of all rider trips that match the query parameters.
Expand All @@ -25,7 +22,7 @@ export function getRiderTrips(
options: QueryOptions = {},
): SqlResults {
const db = options.db ?? openDb();
const tableName = sqlString.escapeId(riderTrip.filenameBase);
const tableName = 'rider_trip';
const selectClause = formatSelectClause(fields);
const whereClause = formatWhereClauses(query);
const orderByClause = formatOrderByClause(orderBy);
Expand Down
Loading

0 comments on commit dc03c0b

Please sign in to comment.