gtfs 4.12.0 → 4.13.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.
Files changed (199) hide show
  1. package/README.md +27 -5
  2. package/dist/bin/gtfs-export.d.ts +1 -0
  3. package/dist/bin/gtfs-export.js +3645 -0
  4. package/dist/bin/gtfs-export.js.map +1 -0
  5. package/dist/bin/gtfs-import.d.ts +1 -0
  6. package/dist/bin/gtfs-import.js +4143 -0
  7. package/dist/bin/gtfs-import.js.map +1 -0
  8. package/dist/bin/gtfsrealtime-update.d.ts +1 -0
  9. package/dist/bin/gtfsrealtime-update.js +3800 -0
  10. package/dist/bin/gtfsrealtime-update.js.map +1 -0
  11. package/dist/index.d.ts +172 -0
  12. package/dist/index.js +5202 -0
  13. package/dist/index.js.map +1 -0
  14. package/package.json +26 -12
  15. package/.eslintrc.json +0 -28
  16. package/.github/workflows/nodejs.yml +0 -21
  17. package/.husky/pre-commit +0 -4
  18. package/@types/index.d.ts +0 -606
  19. package/@types/tests.ts +0 -31
  20. package/@types/tsconfig.json +0 -17
  21. package/CHANGELOG.md +0 -905
  22. package/bin/gtfs-export.js +0 -42
  23. package/bin/gtfs-import.js +0 -52
  24. package/bin/gtfsrealtime-update.js +0 -35
  25. package/config-sample-full.json +0 -20
  26. package/config-sample-rtupdates.json +0 -16
  27. package/config-sample.json +0 -8
  28. package/docs/images/node-gtfs-logo.svg +0 -18
  29. package/index.js +0 -1
  30. package/lib/advancedQuery.js +0 -36
  31. package/lib/db.js +0 -92
  32. package/lib/export.js +0 -141
  33. package/lib/file-utils.js +0 -103
  34. package/lib/geojson-utils.js +0 -138
  35. package/lib/gtfs/agencies.js +0 -32
  36. package/lib/gtfs/areas.js +0 -27
  37. package/lib/gtfs/attributions.js +0 -32
  38. package/lib/gtfs/booking-rules.js +0 -32
  39. package/lib/gtfs/calendar-dates.js +0 -32
  40. package/lib/gtfs/calendars.js +0 -32
  41. package/lib/gtfs/fare-attributes.js +0 -32
  42. package/lib/gtfs/fare-leg-rules.js +0 -32
  43. package/lib/gtfs/fare-media.js +0 -32
  44. package/lib/gtfs/fare-products.js +0 -32
  45. package/lib/gtfs/fare-rules.js +0 -32
  46. package/lib/gtfs/fare-transfer-rules.js +0 -32
  47. package/lib/gtfs/feed-info.js +0 -32
  48. package/lib/gtfs/frequencies.js +0 -32
  49. package/lib/gtfs/levels.js +0 -27
  50. package/lib/gtfs/location-group-stops.js +0 -32
  51. package/lib/gtfs/location-groups.js +0 -32
  52. package/lib/gtfs/locations.js +0 -32
  53. package/lib/gtfs/networks.js +0 -32
  54. package/lib/gtfs/pathways.js +0 -32
  55. package/lib/gtfs/route-networks.js +0 -32
  56. package/lib/gtfs/routes.js +0 -72
  57. package/lib/gtfs/shapes.js +0 -119
  58. package/lib/gtfs/stop-areas.js +0 -32
  59. package/lib/gtfs/stop-times.js +0 -32
  60. package/lib/gtfs/stops.js +0 -136
  61. package/lib/gtfs/timeframes.js +0 -32
  62. package/lib/gtfs/transfers.js +0 -32
  63. package/lib/gtfs/translations.js +0 -32
  64. package/lib/gtfs/trips.js +0 -27
  65. package/lib/gtfs-plus/calendar-attributes.js +0 -32
  66. package/lib/gtfs-plus/directions.js +0 -32
  67. package/lib/gtfs-plus/route-attributes.js +0 -32
  68. package/lib/gtfs-plus/stop-attributes.js +0 -32
  69. package/lib/gtfs-realtime/service-alerts.js +0 -34
  70. package/lib/gtfs-realtime/stop-time-updates.js +0 -32
  71. package/lib/gtfs-realtime/trip-updates.js +0 -32
  72. package/lib/gtfs-realtime/vehicle-positions.js +0 -32
  73. package/lib/gtfs-ride/board-alights.js +0 -32
  74. package/lib/gtfs-ride/ride-feed-infos.js +0 -32
  75. package/lib/gtfs-ride/rider-trips.js +0 -32
  76. package/lib/gtfs-ride/riderships.js +0 -32
  77. package/lib/gtfs-ride/trip-capacities.js +0 -32
  78. package/lib/gtfs.js +0 -261
  79. package/lib/import.js +0 -803
  80. package/lib/log-utils.js +0 -73
  81. package/lib/non-standard/timetable-notes-references.js +0 -32
  82. package/lib/non-standard/timetable-notes.js +0 -32
  83. package/lib/non-standard/timetable-pages.js +0 -32
  84. package/lib/non-standard/timetable-stop-order.js +0 -32
  85. package/lib/non-standard/timetables.js +0 -32
  86. package/lib/non-standard/trips-dated-vehicle-journey.js +0 -32
  87. package/lib/ods/deadhead-times.js +0 -32
  88. package/lib/ods/deadheads.js +0 -32
  89. package/lib/ods/ops-locations.js +0 -32
  90. package/lib/ods/run-events.js +0 -32
  91. package/lib/ods/runs-pieces.js +0 -32
  92. package/lib/utils.js +0 -178
  93. package/models/gtfs/agency.js +0 -49
  94. package/models/gtfs/areas.js +0 -19
  95. package/models/gtfs/attributions.js +0 -68
  96. package/models/gtfs/booking-rules.js +0 -92
  97. package/models/gtfs/calendar-dates.js +0 -34
  98. package/models/gtfs/calendar.js +0 -76
  99. package/models/gtfs/fare-attributes.js +0 -48
  100. package/models/gtfs/fare-leg-rules.js +0 -55
  101. package/models/gtfs/fare-media.js +0 -26
  102. package/models/gtfs/fare-products.js +0 -35
  103. package/models/gtfs/fare-rules.js +0 -34
  104. package/models/gtfs/fare-transfer-rules.js +0 -56
  105. package/models/gtfs/feed-info.js +0 -50
  106. package/models/gtfs/frequencies.js +0 -46
  107. package/models/gtfs/levels.js +0 -25
  108. package/models/gtfs/location-group-stops.js +0 -22
  109. package/models/gtfs/location-groups.js +0 -19
  110. package/models/gtfs/locations.js +0 -12
  111. package/models/gtfs/networks.js +0 -20
  112. package/models/gtfs/pathways.js +0 -74
  113. package/models/gtfs/route-networks.js +0 -21
  114. package/models/gtfs/routes.js +0 -79
  115. package/models/gtfs/shapes.js +0 -41
  116. package/models/gtfs/stop-areas.js +0 -20
  117. package/models/gtfs/stop-times.js +0 -120
  118. package/models/gtfs/stops.js +0 -85
  119. package/models/gtfs/timeframes.js +0 -29
  120. package/models/gtfs/transfers.js +0 -56
  121. package/models/gtfs/translations.js +0 -48
  122. package/models/gtfs/trips.js +0 -70
  123. package/models/gtfs-plus/calendar-attributes.js +0 -22
  124. package/models/gtfs-plus/directions.js +0 -29
  125. package/models/gtfs-plus/route-attributes.js +0 -34
  126. package/models/gtfs-plus/stop-attributes.js +0 -35
  127. package/models/gtfs-realtime/service-alert-targets.js +0 -37
  128. package/models/gtfs-realtime/service-alerts.js +0 -60
  129. package/models/gtfs-realtime/stop-time-updates.js +0 -85
  130. package/models/gtfs-realtime/trip-updates.js +0 -75
  131. package/models/gtfs-realtime/vehicle-positions.js +0 -135
  132. package/models/gtfs-ride/board-alight.js +0 -132
  133. package/models/gtfs-ride/ride-feed-info.js +0 -40
  134. package/models/gtfs-ride/rider-trip.js +0 -113
  135. package/models/gtfs-ride/ridership.js +0 -127
  136. package/models/gtfs-ride/trip-capacity.js +0 -51
  137. package/models/models.js +0 -120
  138. package/models/non-standard/timetable-notes-references.js +0 -50
  139. package/models/non-standard/timetable-notes.js +0 -24
  140. package/models/non-standard/timetable-pages.js +0 -23
  141. package/models/non-standard/timetable-stop-order.js +0 -32
  142. package/models/non-standard/timetables.js +0 -144
  143. package/models/non-standard/trips-dated-vehicle-journey.js +0 -34
  144. package/models/ods/deadhead-times.js +0 -65
  145. package/models/ods/deadheads.js +0 -60
  146. package/models/ods/ops-locations.js +0 -46
  147. package/models/ods/run-events.js +0 -70
  148. package/models/ods/runs-pieces.js +0 -59
  149. package/test/fixture/caltrain_20160406.zip +0 -0
  150. package/test/mocha/advanced-query.js +0 -74
  151. package/test/mocha/delete-db.js +0 -62
  152. package/test/mocha/export-gtfs.js +0 -147
  153. package/test/mocha/fare-transfer-rules.js +0 -32
  154. package/test/mocha/get-agencies.js +0 -90
  155. package/test/mocha/get-areas.js +0 -27
  156. package/test/mocha/get-attributions.js +0 -27
  157. package/test/mocha/get-board-alights.js +0 -28
  158. package/test/mocha/get-booking-rules.js +0 -28
  159. package/test/mocha/get-calendar-attributes.js +0 -33
  160. package/test/mocha/get-calendar-dates.js +0 -107
  161. package/test/mocha/get-calendars.js +0 -94
  162. package/test/mocha/get-directions.js +0 -28
  163. package/test/mocha/get-fare-attributes.js +0 -51
  164. package/test/mocha/get-fare-leg-rules.js +0 -27
  165. package/test/mocha/get-fare-media.js +0 -27
  166. package/test/mocha/get-fare-products.js +0 -27
  167. package/test/mocha/get-fare-rules.js +0 -50
  168. package/test/mocha/get-feed-info.js +0 -28
  169. package/test/mocha/get-frequencies.js +0 -28
  170. package/test/mocha/get-levels.js +0 -28
  171. package/test/mocha/get-location-group-stops.js +0 -33
  172. package/test/mocha/get-location-groups.js +0 -28
  173. package/test/mocha/get-locations.js +0 -69
  174. package/test/mocha/get-networks.js +0 -28
  175. package/test/mocha/get-pathways.js +0 -28
  176. package/test/mocha/get-ride-feed-infos.js +0 -24
  177. package/test/mocha/get-rider-trips.js +0 -28
  178. package/test/mocha/get-riderships.js +0 -28
  179. package/test/mocha/get-route-attributes.js +0 -33
  180. package/test/mocha/get-route-networks.js +0 -28
  181. package/test/mocha/get-routes.js +0 -143
  182. package/test/mocha/get-shapes-as-geojson.js +0 -92
  183. package/test/mocha/get-shapes.js +0 -240
  184. package/test/mocha/get-stop-attributes.js +0 -28
  185. package/test/mocha/get-stops-as-geojson.js +0 -87
  186. package/test/mocha/get-stops.js +0 -343
  187. package/test/mocha/get-stoptimes.js +0 -67
  188. package/test/mocha/get-timeframes.js +0 -28
  189. package/test/mocha/get-timetable-pages.js +0 -28
  190. package/test/mocha/get-timetable-stop-orders.js +0 -33
  191. package/test/mocha/get-timetables.js +0 -28
  192. package/test/mocha/get-transfers.js +0 -28
  193. package/test/mocha/get-translations.js +0 -28
  194. package/test/mocha/get-trip-capacities.js +0 -28
  195. package/test/mocha/get-trips.js +0 -53
  196. package/test/mocha/import-gtfs.js +0 -173
  197. package/test/mocha/open-db.js +0 -149
  198. package/test/mocha/raw-query.js +0 -34
  199. package/test/test-config.js +0 -12
package/lib/log-utils.js DELETED
@@ -1,73 +0,0 @@
1
- import { clearLine, cursorTo } from 'node:readline';
2
- import { noop } from 'lodash-es';
3
- import * as colors from 'yoctocolors';
4
-
5
- /*
6
- * Returns a log function based on config settings
7
- */
8
- export function log(config) {
9
- if (config.verbose === false) {
10
- return noop;
11
- }
12
-
13
- if (config.logFunction) {
14
- return config.logFunction;
15
- }
16
-
17
- return (text, overwrite) => {
18
- if (overwrite === true && process.stdout.isTTY) {
19
- clearLine(process.stdout, 0);
20
- cursorTo(process.stdout, 0);
21
- } else {
22
- process.stdout.write('\n');
23
- }
24
-
25
- process.stdout.write(text);
26
- };
27
- }
28
-
29
- /*
30
- * Returns an warning log function based on config settings
31
- */
32
- export function logWarning(config) {
33
- if (config.logFunction) {
34
- return config.logFunction;
35
- }
36
-
37
- return (text) => {
38
- process.stdout.write(`\n${formatWarning(text)}\n`);
39
- };
40
- }
41
-
42
- /*
43
- * Returns an error log function based on config settings
44
- */
45
- export function logError(config) {
46
- if (config.logFunction) {
47
- return config.logFunction;
48
- }
49
-
50
- return (text) => {
51
- process.stdout.write(`\n${formatError(text)}\n`);
52
- };
53
- }
54
-
55
- /*
56
- * Format console warning text
57
- */
58
- export function formatWarning(text) {
59
- const warningMessage = `${colors.underline('Warning')}: ${text}`;
60
- return colors.yellow(warningMessage);
61
- }
62
-
63
- /*
64
- * Format console error text
65
- */
66
- export function formatError(error) {
67
- const messageText = error instanceof Error ? error.message : error;
68
- const errorMessage = `${colors.underline('Error')}: ${messageText.replace(
69
- 'Error: ',
70
- '',
71
- )}`;
72
- return colors.red(errorMessage);
73
- }
@@ -1,32 +0,0 @@
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 timetableNotesReferences from '../../models/non-standard/timetable-notes-references.js';
11
-
12
- /*
13
- * Returns an array of all timetable notes references that match the query parameters.
14
- */
15
- export function getTimetableNotesReferences(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(timetableNotesReferences.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
- }
@@ -1,32 +0,0 @@
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 timetableNotes from '../../models/non-standard/timetable-notes.js';
11
-
12
- /*
13
- * Returns an array of all timetable notes that match the query parameters.
14
- */
15
- export function getTimetableNotes(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(timetableNotes.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
- }
@@ -1,32 +0,0 @@
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 timetablePages from '../../models/non-standard/timetable-pages.js';
11
-
12
- /*
13
- * Returns an array of all timetable pages that match the query parameters.
14
- */
15
- export function getTimetablePages(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(timetablePages.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
- }
@@ -1,32 +0,0 @@
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 timetableStopOrder from '../../models/non-standard/timetable-stop-order.js';
11
-
12
- /*
13
- * Returns an array of all timetable stop orders that match the query parameters.
14
- */
15
- export function getTimetableStopOrders(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(timetableStopOrder.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
- }
@@ -1,32 +0,0 @@
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 timetables from '../../models/non-standard/timetables.js';
11
-
12
- /*
13
- * Returns an array of all timetables that match the query parameters.
14
- */
15
- export function getTimetables(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(timetables.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
- }
@@ -1,32 +0,0 @@
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 directions from '../../models/non-standard/trips-dated-vehicle-journey.js';
11
-
12
- /*
13
- * Returns an array of all trips dated vehicle journeys that match the query parameters.
14
- */
15
- export function getTripsDatedVehicleJourneys(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(directions.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
- }
@@ -1,32 +0,0 @@
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 deadheadTimes from '../../models/ods/deadhead-times.js';
11
-
12
- /*
13
- * Returns an array of all deadhead_times that match the query parameters.
14
- */
15
- export function getDeadheadTimes(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(deadheadTimes.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
- }
@@ -1,32 +0,0 @@
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 deadheads from '../../models/ods/deadheads.js';
11
-
12
- /*
13
- * Returns an array of all deadheads that match the query parameters.
14
- */
15
- export function getDeadheads(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(deadheads.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
- }
@@ -1,32 +0,0 @@
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 opsLocations from '../../models/ods/ops-locations.js';
11
-
12
- /*
13
- * Returns an array of all ops_locations that match the query parameters.
14
- */
15
- export function getOpsLocations(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(opsLocations.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
- }
@@ -1,32 +0,0 @@
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 runEvents from '../../models/ods/run-events.js';
11
-
12
- /*
13
- * Returns an array of all run_events that match the query parameters.
14
- */
15
- export function getRunEvents(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(runEvents.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
- }
@@ -1,32 +0,0 @@
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 runsPieces from '../../models/ods/runs-pieces.js';
11
-
12
- /*
13
- * Returns an array of all runs_pieces that match the query parameters.
14
- */
15
- export function getRunsPieces(
16
- query = {},
17
- fields = [],
18
- orderBy = [],
19
- options = {},
20
- ) {
21
- const db = options.db ?? openDb();
22
- const tableName = sqlString.escapeId(runsPieces.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
- }
package/lib/utils.js DELETED
@@ -1,178 +0,0 @@
1
- import sqlString from 'sqlstring-sqlite';
2
- import Long from 'long';
3
-
4
- /*
5
- * Validate configuration.
6
- */
7
- export function validateConfigForImport(config) {
8
- if (!config.agencies || config.agencies.length === 0) {
9
- throw new Error('No `agencies` specified in config');
10
- }
11
-
12
- for (const [index, agency] of config.agencies.entries()) {
13
- if (!agency.path && !agency.url) {
14
- throw new Error(
15
- `No Agency \`url\` or \`path\` specified in config for agency index ${index}.`,
16
- );
17
- }
18
- }
19
-
20
- return config;
21
- }
22
-
23
- /*
24
- * Initialize configuration with defaults.
25
- */
26
- export function setDefaultConfig(initialConfig) {
27
- const defaults = {
28
- sqlitePath: ':memory:',
29
- ignoreDuplicates: false,
30
- };
31
-
32
- return {
33
- ...defaults,
34
- ...initialConfig,
35
- };
36
- }
37
-
38
- export function convertLongTimeToDate(longDate) {
39
- const { high, low, unsigned } = longDate;
40
- return new Date(new Long(low, high, unsigned).toInt() * 1000).toISOString();
41
- }
42
-
43
- /*
44
- * Calculate seconds from midnight for HH:mm:ss
45
- */
46
- export function calculateSecondsFromMidnight(time) {
47
- const split = time.split(':').map((d) => Number.parseInt(d, 10));
48
- if (split.length !== 3) {
49
- return null;
50
- }
51
-
52
- return split[0] * 3600 + split[1] * 60 + split[2];
53
- }
54
-
55
- /*
56
- * Adds leading zeros to HH:mm:ss timestamps
57
- */
58
- export function padLeadingZeros(time) {
59
- const split = time.split(':').map((d) => String(Number(d)).padStart(2, '0'));
60
- if (split.length !== 3) {
61
- return null;
62
- }
63
-
64
- return split.join(':');
65
- }
66
-
67
- export function formatSelectClause(fields) {
68
- if (Array.isArray(fields)) {
69
- const selectItem =
70
- fields.length > 0
71
- ? fields.map((fieldName) => sqlString.escapeId(fieldName)).join(', ')
72
- : '*';
73
- return `SELECT ${selectItem}`;
74
- }
75
-
76
- const selectItem = Object.entries(fields)
77
- .map(
78
- (key) => `${sqlString.escapeId(key[0])} AS ${sqlString.escapeId(key[1])}`,
79
- )
80
- .join(', ');
81
- return `SELECT ${selectItem}`;
82
- }
83
-
84
- export function formatJoinClause(joinObject) {
85
- return joinObject
86
- .map(
87
- (data) =>
88
- `${data.type ? data.type + ' JOIN' : 'INNER JOIN'} ${sqlString.escapeId(
89
- data.table,
90
- )} ON ${data.on}`,
91
- )
92
- .join(' ');
93
- }
94
-
95
- function degree2radian(angle) {
96
- return (angle * Math.PI) / 180;
97
- }
98
-
99
- function radian2degree(angle) {
100
- return (angle / Math.PI) * 180;
101
- }
102
-
103
- /*
104
- * Search inside GPS coordinates boundary box
105
- * Distance unit: meters
106
- * */
107
- export function formatWhereClauseBoundingBox(
108
- latitudeDegree,
109
- longitudeDegree,
110
- boundingBoxSideMeters,
111
- ) {
112
- const earthRadius = 6371000;
113
- latitudeDegree = parseFloat(latitudeDegree);
114
- longitudeDegree = parseFloat(longitudeDegree);
115
-
116
- const latitudeRadian = degree2radian(latitudeDegree);
117
- const radiusFromLatitude = Math.cos(latitudeRadian) * earthRadius;
118
-
119
- // `boundingBoxSideMeters` is divided by 2 we are centering the coordinates in the middle of this square
120
- const deltaLatitude = radian2degree(boundingBoxSideMeters / 2 / earthRadius);
121
- const deltaLongitude = radian2degree(
122
- boundingBoxSideMeters / 2 / radiusFromLatitude,
123
- );
124
-
125
- let query = `stop_lat BETWEEN ${latitudeDegree - deltaLatitude} AND ${latitudeDegree + deltaLatitude}`;
126
- query += ` AND stop_lon BETWEEN ${longitudeDegree - deltaLongitude} AND ${longitudeDegree + deltaLongitude}`;
127
-
128
- return query;
129
- }
130
-
131
- export function formatWhereClause(key, value) {
132
- if (Array.isArray(value)) {
133
- let whereClause = `${sqlString.escapeId(key)} IN (${value
134
- .filter((v) => v !== null)
135
- .map((v) => sqlString.escape(v))
136
- .join(', ')})`;
137
-
138
- if (value.includes(null)) {
139
- whereClause = `(${whereClause} OR ${sqlString.escapeId(key)} IS NULL)`;
140
- }
141
-
142
- return whereClause;
143
- }
144
-
145
- if (value === null) {
146
- return `${sqlString.escapeId(key)} IS NULL`;
147
- }
148
-
149
- return `${sqlString.escapeId(key)} = ${sqlString.escape(value)}`;
150
- }
151
-
152
- export function formatWhereClauses(query) {
153
- if (Object.keys(query).length === 0) {
154
- return '';
155
- }
156
-
157
- const whereClauses = Object.entries(query).map(([key, value]) =>
158
- formatWhereClause(key, value),
159
- );
160
- return `WHERE ${whereClauses.join(' AND ')}`;
161
- }
162
-
163
- export function formatOrderByClause(orderBy) {
164
- let orderByClause = '';
165
-
166
- if (orderBy.length > 0) {
167
- orderByClause += 'ORDER BY ';
168
-
169
- orderByClause += orderBy
170
- .map(([key, value]) => {
171
- const direction = value === 'DESC' ? 'DESC' : 'ASC';
172
- return `${sqlString.escapeId(key)} ${direction}`;
173
- })
174
- .join(', ');
175
- }
176
-
177
- return orderByClause;
178
- }
@@ -1,49 +0,0 @@
1
- const model = {
2
- filenameBase: 'agency',
3
- filenameExtension: 'txt',
4
- schema: [
5
- {
6
- name: 'agency_id',
7
- type: 'text',
8
- primary: true,
9
- prefix: true,
10
- },
11
- {
12
- name: 'agency_name',
13
- type: 'text',
14
- required: true,
15
- nocase: true,
16
- },
17
- {
18
- name: 'agency_url',
19
- type: 'text',
20
- required: true,
21
- },
22
- {
23
- name: 'agency_timezone',
24
- type: 'text',
25
- required: true,
26
- },
27
- {
28
- name: 'agency_lang',
29
- type: 'text',
30
- nocase: true,
31
- },
32
- {
33
- name: 'agency_phone',
34
- type: 'text',
35
- nocase: true,
36
- },
37
- {
38
- name: 'agency_fare_url',
39
- type: 'text',
40
- },
41
- {
42
- name: 'agency_email',
43
- type: 'text',
44
- nocase: true,
45
- },
46
- ],
47
- };
48
-
49
- export default model;
@@ -1,19 +0,0 @@
1
- const model = {
2
- filenameBase: 'areas',
3
- filenameExtension: 'txt',
4
- schema: [
5
- {
6
- name: 'area_id',
7
- type: 'text',
8
- required: true,
9
- primary: true,
10
- prefix: true,
11
- },
12
- {
13
- name: 'area_name',
14
- type: 'text',
15
- },
16
- ],
17
- };
18
-
19
- export default model;