gtfs 4.15.6 → 4.15.8
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/dist/bin/gtfs-export.js +116 -85
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +135 -131
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +43 -40
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.js +154 -134
- package/dist/index.js.map +1 -1
- package/dist/models/models.d.ts +56 -51
- package/dist/models/models.js +54 -42
- package/dist/models/models.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/gtfs-export.js
CHANGED
|
@@ -18,6 +18,48 @@ import { omit, snakeCase } from "lodash-es";
|
|
|
18
18
|
import sanitize from "sanitize-filename";
|
|
19
19
|
import untildify from "untildify";
|
|
20
20
|
import StreamZip from "node-stream-zip";
|
|
21
|
+
|
|
22
|
+
// src/lib/log-utils.ts
|
|
23
|
+
import { clearLine, cursorTo } from "node:readline";
|
|
24
|
+
import { noop } from "lodash-es";
|
|
25
|
+
import * as colors from "yoctocolors";
|
|
26
|
+
function log(config) {
|
|
27
|
+
if (config.verbose === false) {
|
|
28
|
+
return noop;
|
|
29
|
+
}
|
|
30
|
+
if (config.logFunction) {
|
|
31
|
+
return config.logFunction;
|
|
32
|
+
}
|
|
33
|
+
return (text, overwrite = false) => {
|
|
34
|
+
if (overwrite && process.stdout.isTTY) {
|
|
35
|
+
clearLine(process.stdout, 0);
|
|
36
|
+
cursorTo(process.stdout, 0);
|
|
37
|
+
} else {
|
|
38
|
+
process.stdout.write("\n");
|
|
39
|
+
}
|
|
40
|
+
process.stdout.write(text);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function logWarning(config) {
|
|
44
|
+
if (config.logFunction) {
|
|
45
|
+
return config.logFunction;
|
|
46
|
+
}
|
|
47
|
+
return (text) => {
|
|
48
|
+
process.stdout.write(`
|
|
49
|
+
${formatWarning(text)}
|
|
50
|
+
`);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function formatWarning(text) {
|
|
54
|
+
return colors.yellow(`${colors.underline("Warning")}: ${text}`);
|
|
55
|
+
}
|
|
56
|
+
function formatError(error) {
|
|
57
|
+
const messageText = error instanceof Error ? error.message : error;
|
|
58
|
+
const cleanMessage = messageText.replace(/^Error:\s*/i, "");
|
|
59
|
+
return colors.red(`${colors.underline("Error")}: ${cleanMessage}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/lib/file-utils.ts
|
|
21
63
|
async function getConfig(argv2) {
|
|
22
64
|
let config;
|
|
23
65
|
let data;
|
|
@@ -38,7 +80,7 @@ async function getConfig(argv2) {
|
|
|
38
80
|
} else if (existsSync(path.resolve("./config.json"))) {
|
|
39
81
|
data = await readFile(path.resolve("./config.json"), "utf8");
|
|
40
82
|
config = Object.assign(JSON.parse(data), argv2);
|
|
41
|
-
|
|
83
|
+
log(config)("Using configuration from ./config.json");
|
|
42
84
|
} else {
|
|
43
85
|
throw new Error(
|
|
44
86
|
"Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
|
|
@@ -65,46 +107,6 @@ function generateFolderName(folderName) {
|
|
|
65
107
|
return snakeCase(sanitize(folderName));
|
|
66
108
|
}
|
|
67
109
|
|
|
68
|
-
// src/lib/log-utils.ts
|
|
69
|
-
import { clearLine, cursorTo } from "node:readline";
|
|
70
|
-
import { noop } from "lodash-es";
|
|
71
|
-
import * as colors from "yoctocolors";
|
|
72
|
-
function log(config) {
|
|
73
|
-
if (!config.verbose) {
|
|
74
|
-
return noop;
|
|
75
|
-
}
|
|
76
|
-
if (config.logFunction) {
|
|
77
|
-
return config.logFunction;
|
|
78
|
-
}
|
|
79
|
-
return (text, overwrite = false) => {
|
|
80
|
-
if (overwrite && process.stdout.isTTY) {
|
|
81
|
-
clearLine(process.stdout, 0);
|
|
82
|
-
cursorTo(process.stdout, 0);
|
|
83
|
-
} else {
|
|
84
|
-
process.stdout.write("\n");
|
|
85
|
-
}
|
|
86
|
-
process.stdout.write(text);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function logWarning(config) {
|
|
90
|
-
if (config.logFunction) {
|
|
91
|
-
return config.logFunction;
|
|
92
|
-
}
|
|
93
|
-
return (text) => {
|
|
94
|
-
process.stdout.write(`
|
|
95
|
-
${formatWarning(text)}
|
|
96
|
-
`);
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function formatWarning(text) {
|
|
100
|
-
return colors.yellow(`${colors.underline("Warning")}: ${text}`);
|
|
101
|
-
}
|
|
102
|
-
function formatError(error) {
|
|
103
|
-
const messageText = error instanceof Error ? error.message : error;
|
|
104
|
-
const cleanMessage = messageText.replace(/^Error:\s*/i, "");
|
|
105
|
-
return colors.red(`${colors.underline("Error")}: ${cleanMessage}`);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
110
|
// src/lib/import-gtfs.ts
|
|
109
111
|
import { parse } from "csv-parse";
|
|
110
112
|
import pluralize2 from "pluralize";
|
|
@@ -250,7 +252,8 @@ var attributions = {
|
|
|
250
252
|
{
|
|
251
253
|
name: "attribution_id",
|
|
252
254
|
type: "text",
|
|
253
|
-
prefix: true
|
|
255
|
+
prefix: true,
|
|
256
|
+
primary: true
|
|
254
257
|
},
|
|
255
258
|
{
|
|
256
259
|
name: "agency_id",
|
|
@@ -683,26 +686,31 @@ var fareRules = {
|
|
|
683
686
|
name: "fare_id",
|
|
684
687
|
type: "text",
|
|
685
688
|
required: true,
|
|
689
|
+
primary: true,
|
|
686
690
|
prefix: true
|
|
687
691
|
},
|
|
688
692
|
{
|
|
689
693
|
name: "route_id",
|
|
690
694
|
type: "text",
|
|
695
|
+
primary: true,
|
|
691
696
|
prefix: true
|
|
692
697
|
},
|
|
693
698
|
{
|
|
694
699
|
name: "origin_id",
|
|
695
700
|
type: "text",
|
|
701
|
+
primary: true,
|
|
696
702
|
prefix: true
|
|
697
703
|
},
|
|
698
704
|
{
|
|
699
705
|
name: "destination_id",
|
|
700
706
|
type: "text",
|
|
707
|
+
primary: true,
|
|
701
708
|
prefix: true
|
|
702
709
|
},
|
|
703
710
|
{
|
|
704
711
|
name: "contains_id",
|
|
705
712
|
type: "text",
|
|
713
|
+
primary: true,
|
|
706
714
|
prefix: true
|
|
707
715
|
}
|
|
708
716
|
]
|
|
@@ -909,14 +917,16 @@ var locationGroupStops = {
|
|
|
909
917
|
type: "text",
|
|
910
918
|
prefix: true,
|
|
911
919
|
index: true,
|
|
912
|
-
required: true
|
|
920
|
+
required: true,
|
|
921
|
+
primary: true
|
|
913
922
|
},
|
|
914
923
|
{
|
|
915
924
|
name: "stop_id",
|
|
916
925
|
type: "text",
|
|
917
926
|
required: true,
|
|
918
927
|
prefix: true,
|
|
919
|
-
index: true
|
|
928
|
+
index: true,
|
|
929
|
+
primary: true
|
|
920
930
|
}
|
|
921
931
|
]
|
|
922
932
|
};
|
|
@@ -1177,12 +1187,14 @@ var stopAreas = {
|
|
|
1177
1187
|
name: "area_id",
|
|
1178
1188
|
type: "text",
|
|
1179
1189
|
required: true,
|
|
1190
|
+
primary: true,
|
|
1180
1191
|
prefix: true
|
|
1181
1192
|
},
|
|
1182
1193
|
{
|
|
1183
1194
|
name: "stop_id",
|
|
1184
1195
|
type: "text",
|
|
1185
1196
|
required: true,
|
|
1197
|
+
primary: true,
|
|
1186
1198
|
prefix: true
|
|
1187
1199
|
}
|
|
1188
1200
|
]
|
|
@@ -1406,16 +1418,19 @@ var timeframes = {
|
|
|
1406
1418
|
},
|
|
1407
1419
|
{
|
|
1408
1420
|
name: "start_time",
|
|
1409
|
-
type: "text"
|
|
1421
|
+
type: "text",
|
|
1422
|
+
primary: true
|
|
1410
1423
|
},
|
|
1411
1424
|
{
|
|
1412
1425
|
name: "end_time",
|
|
1413
|
-
type: "text"
|
|
1426
|
+
type: "text",
|
|
1427
|
+
primary: true
|
|
1414
1428
|
},
|
|
1415
1429
|
{
|
|
1416
1430
|
name: "service_id",
|
|
1417
1431
|
type: "text",
|
|
1418
1432
|
required: true,
|
|
1433
|
+
primary: true,
|
|
1419
1434
|
index: true,
|
|
1420
1435
|
prefix: true
|
|
1421
1436
|
}
|
|
@@ -1602,21 +1617,19 @@ var timetables = {
|
|
|
1602
1617
|
filenameExtension: "txt",
|
|
1603
1618
|
nonstandard: true,
|
|
1604
1619
|
schema: [
|
|
1605
|
-
{
|
|
1606
|
-
name: "id",
|
|
1607
|
-
type: "integer",
|
|
1608
|
-
primary: true,
|
|
1609
|
-
prefix: true
|
|
1610
|
-
},
|
|
1611
1620
|
{
|
|
1612
1621
|
name: "timetable_id",
|
|
1613
1622
|
type: "text",
|
|
1614
|
-
prefix: true
|
|
1623
|
+
prefix: true,
|
|
1624
|
+
required: true,
|
|
1625
|
+
primary: true
|
|
1615
1626
|
},
|
|
1616
1627
|
{
|
|
1617
1628
|
name: "route_id",
|
|
1618
1629
|
type: "text",
|
|
1619
|
-
prefix: true
|
|
1630
|
+
prefix: true,
|
|
1631
|
+
required: true,
|
|
1632
|
+
primary: true
|
|
1620
1633
|
},
|
|
1621
1634
|
{
|
|
1622
1635
|
name: "direction_id",
|
|
@@ -1750,6 +1763,7 @@ var timetablePages = {
|
|
|
1750
1763
|
name: "timetable_page_id",
|
|
1751
1764
|
type: "text",
|
|
1752
1765
|
primary: true,
|
|
1766
|
+
required: true,
|
|
1753
1767
|
prefix: true
|
|
1754
1768
|
},
|
|
1755
1769
|
{
|
|
@@ -1769,28 +1783,28 @@ var timetableStopOrder = {
|
|
|
1769
1783
|
filenameExtension: "txt",
|
|
1770
1784
|
nonstandard: true,
|
|
1771
1785
|
schema: [
|
|
1772
|
-
{
|
|
1773
|
-
name: "id",
|
|
1774
|
-
type: "integer",
|
|
1775
|
-
primary: true,
|
|
1776
|
-
prefix: true
|
|
1777
|
-
},
|
|
1778
1786
|
{
|
|
1779
1787
|
name: "timetable_id",
|
|
1780
1788
|
type: "text",
|
|
1781
1789
|
index: true,
|
|
1782
|
-
prefix: true
|
|
1790
|
+
prefix: true,
|
|
1791
|
+
required: true,
|
|
1792
|
+
primary: true
|
|
1783
1793
|
},
|
|
1784
1794
|
{
|
|
1785
1795
|
name: "stop_id",
|
|
1786
1796
|
type: "text",
|
|
1787
|
-
prefix: true
|
|
1797
|
+
prefix: true,
|
|
1798
|
+
required: true,
|
|
1799
|
+
primary: true
|
|
1788
1800
|
},
|
|
1789
1801
|
{
|
|
1790
1802
|
name: "stop_sequence",
|
|
1791
1803
|
type: "integer",
|
|
1792
1804
|
min: 0,
|
|
1793
|
-
index: true
|
|
1805
|
+
index: true,
|
|
1806
|
+
required: true,
|
|
1807
|
+
primary: true
|
|
1794
1808
|
}
|
|
1795
1809
|
]
|
|
1796
1810
|
};
|
|
@@ -1805,7 +1819,8 @@ var timetableNotes = {
|
|
|
1805
1819
|
name: "note_id",
|
|
1806
1820
|
type: "text",
|
|
1807
1821
|
primary: true,
|
|
1808
|
-
prefix: true
|
|
1822
|
+
prefix: true,
|
|
1823
|
+
required: true
|
|
1809
1824
|
},
|
|
1810
1825
|
{
|
|
1811
1826
|
name: "symbol",
|
|
@@ -1814,7 +1829,8 @@ var timetableNotes = {
|
|
|
1814
1829
|
{
|
|
1815
1830
|
name: "note",
|
|
1816
1831
|
type: "text",
|
|
1817
|
-
nocase: true
|
|
1832
|
+
nocase: true,
|
|
1833
|
+
required: true
|
|
1818
1834
|
}
|
|
1819
1835
|
]
|
|
1820
1836
|
};
|
|
@@ -1828,37 +1844,39 @@ var timetableNotesReferences = {
|
|
|
1828
1844
|
{
|
|
1829
1845
|
name: "note_id",
|
|
1830
1846
|
type: "text",
|
|
1831
|
-
prefix: true
|
|
1847
|
+
prefix: true,
|
|
1848
|
+
required: true,
|
|
1849
|
+
primary: true
|
|
1832
1850
|
},
|
|
1833
1851
|
{
|
|
1834
1852
|
name: "timetable_id",
|
|
1835
1853
|
type: "text",
|
|
1836
|
-
|
|
1837
|
-
|
|
1854
|
+
prefix: true,
|
|
1855
|
+
primary: true
|
|
1838
1856
|
},
|
|
1839
1857
|
{
|
|
1840
1858
|
name: "route_id",
|
|
1841
1859
|
type: "text",
|
|
1842
|
-
|
|
1843
|
-
|
|
1860
|
+
prefix: true,
|
|
1861
|
+
primary: true
|
|
1844
1862
|
},
|
|
1845
1863
|
{
|
|
1846
1864
|
name: "trip_id",
|
|
1847
1865
|
type: "text",
|
|
1848
|
-
|
|
1849
|
-
|
|
1866
|
+
prefix: true,
|
|
1867
|
+
primary: true
|
|
1850
1868
|
},
|
|
1851
1869
|
{
|
|
1852
1870
|
name: "stop_id",
|
|
1853
1871
|
type: "text",
|
|
1854
|
-
|
|
1855
|
-
|
|
1872
|
+
prefix: true,
|
|
1873
|
+
primary: true
|
|
1856
1874
|
},
|
|
1857
1875
|
{
|
|
1858
1876
|
name: "stop_sequence",
|
|
1859
1877
|
type: "integer",
|
|
1860
1878
|
min: 0,
|
|
1861
|
-
|
|
1879
|
+
primary: true
|
|
1862
1880
|
},
|
|
1863
1881
|
{
|
|
1864
1882
|
name: "show_on_stoptime",
|
|
@@ -2492,7 +2510,7 @@ var tripUpdates = {
|
|
|
2492
2510
|
extension: "gtfs-realtime",
|
|
2493
2511
|
schema: [
|
|
2494
2512
|
{
|
|
2495
|
-
name: "
|
|
2513
|
+
name: "id",
|
|
2496
2514
|
type: "text",
|
|
2497
2515
|
required: true,
|
|
2498
2516
|
primary: true,
|
|
@@ -2656,7 +2674,7 @@ var vehiclePositions = {
|
|
|
2656
2674
|
extension: "gtfs-realtime",
|
|
2657
2675
|
schema: [
|
|
2658
2676
|
{
|
|
2659
|
-
name: "
|
|
2677
|
+
name: "id",
|
|
2660
2678
|
type: "text",
|
|
2661
2679
|
required: true,
|
|
2662
2680
|
primary: true,
|
|
@@ -2895,17 +2913,12 @@ var deadheadTimes = {
|
|
|
2895
2913
|
nonstandard: true,
|
|
2896
2914
|
extension: "ods",
|
|
2897
2915
|
schema: [
|
|
2898
|
-
{
|
|
2899
|
-
name: "id",
|
|
2900
|
-
type: "integer",
|
|
2901
|
-
primary: true,
|
|
2902
|
-
prefix: true
|
|
2903
|
-
},
|
|
2904
2916
|
{
|
|
2905
2917
|
name: "deadhead_id",
|
|
2906
2918
|
type: "text",
|
|
2907
2919
|
required: true,
|
|
2908
2920
|
index: true,
|
|
2921
|
+
primary: true,
|
|
2909
2922
|
prefix: true
|
|
2910
2923
|
},
|
|
2911
2924
|
{
|
|
@@ -2942,6 +2955,7 @@ var deadheadTimes = {
|
|
|
2942
2955
|
name: "location_sequence",
|
|
2943
2956
|
type: "integer",
|
|
2944
2957
|
required: true,
|
|
2958
|
+
primary: true,
|
|
2945
2959
|
min: 0,
|
|
2946
2960
|
index: true
|
|
2947
2961
|
},
|
|
@@ -3253,13 +3267,23 @@ function setDefaultConfig(initialConfig) {
|
|
|
3253
3267
|
sqlitePath: ":memory:",
|
|
3254
3268
|
ignoreDuplicates: false,
|
|
3255
3269
|
ignoreErrors: false,
|
|
3256
|
-
gtfsRealtimeExpirationSeconds: 0
|
|
3270
|
+
gtfsRealtimeExpirationSeconds: 0,
|
|
3271
|
+
verbose: true
|
|
3257
3272
|
};
|
|
3258
3273
|
return {
|
|
3259
3274
|
...defaults,
|
|
3260
3275
|
...initialConfig
|
|
3261
3276
|
};
|
|
3262
3277
|
}
|
|
3278
|
+
function formatCurrency(value, currency) {
|
|
3279
|
+
const parts = new Intl.NumberFormat(void 0, {
|
|
3280
|
+
style: "currency",
|
|
3281
|
+
currency
|
|
3282
|
+
}).formatToParts(value);
|
|
3283
|
+
const integerPart = parts.find((part) => part.type === "integer")?.value ?? "0";
|
|
3284
|
+
const fractionPart = parts.find((part) => part.type === "fraction")?.value ?? "";
|
|
3285
|
+
return `${integerPart}${fractionPart !== "" ? `.${fractionPart}` : ""}`;
|
|
3286
|
+
}
|
|
3263
3287
|
|
|
3264
3288
|
// src/lib/import-gtfs.ts
|
|
3265
3289
|
var TIME_COLUMN_NAMES = [
|
|
@@ -3346,7 +3370,6 @@ var exportGtfs = async (initialConfig) => {
|
|
|
3346
3370
|
}
|
|
3347
3371
|
if (model.filenameExtension === "txt") {
|
|
3348
3372
|
const excludeColumns = [
|
|
3349
|
-
"id",
|
|
3350
3373
|
"arrival_timestamp",
|
|
3351
3374
|
"departure_timestamp",
|
|
3352
3375
|
"start_timestamp",
|
|
@@ -3365,6 +3388,14 @@ var exportGtfs = async (initialConfig) => {
|
|
|
3365
3388
|
if (!routesWithAgencyId || routesWithAgencyId.length === 0) {
|
|
3366
3389
|
excludeColumns.push("agency_id");
|
|
3367
3390
|
}
|
|
3391
|
+
} else if (model.filenameBase === "fare_attributes") {
|
|
3392
|
+
for (const line of lines) {
|
|
3393
|
+
line.price = formatCurrency(line.price, line.currency_type);
|
|
3394
|
+
}
|
|
3395
|
+
} else if (model.filenameBase === "fare_products") {
|
|
3396
|
+
for (const line of lines) {
|
|
3397
|
+
line.price = formatCurrency(line.amount, line.currency);
|
|
3398
|
+
}
|
|
3368
3399
|
}
|
|
3369
3400
|
const columns = without(
|
|
3370
3401
|
model.schema.map((column) => column.name),
|