gtfs 4.15.5 → 4.15.7
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 +105 -108
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +140 -147
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +48 -68
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.d.ts +332 -58
- package/dist/index.js +204 -183
- package/dist/index.js.map +1 -1
- package/dist/models/models.d.ts +49 -36
- package/dist/models/models.js +50 -34
- package/dist/models/models.js.map +1 -1
- package/package.json +3 -2
package/dist/bin/gtfs-export.js
CHANGED
|
@@ -18,70 +18,6 @@ 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
|
-
async function getConfig(argv2) {
|
|
22
|
-
let config;
|
|
23
|
-
let data;
|
|
24
|
-
if (argv2.configPath) {
|
|
25
|
-
try {
|
|
26
|
-
data = await readFile(path.resolve(untildify(argv2.configPath)), "utf8");
|
|
27
|
-
} catch (error) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Cannot find configuration file at \`${argv2.configPath}\`. Use config-sample.json as a starting point.`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
config = Object.assign(JSON.parse(data), argv2);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
`Cannot parse configuration file at \`${argv2.configPath}\`. Check to ensure that it is valid JSON.`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
} else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
|
|
40
|
-
const agencies = [];
|
|
41
|
-
if (argv2.gtfsPath) {
|
|
42
|
-
agencies.push({
|
|
43
|
-
path: argv2.gtfsPath
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (argv2.gtfsUrl) {
|
|
47
|
-
agencies.push({
|
|
48
|
-
url: argv2.gtfsUrl
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
config = {
|
|
52
|
-
agencies,
|
|
53
|
-
...omit(argv2, ["path", "url"])
|
|
54
|
-
};
|
|
55
|
-
} else if (existsSync(path.resolve("./config.json"))) {
|
|
56
|
-
try {
|
|
57
|
-
data = await readFile(path.resolve("./config.json"), "utf8");
|
|
58
|
-
} catch (error) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`Cannot open configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it exists. Use config-sample.json as a starting point.`
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
config = Object.assign(JSON.parse(data), argv2);
|
|
65
|
-
console.log("Using configuration from ./config.json");
|
|
66
|
-
} catch (error) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Cannot parse configuration file at \`${path.resolve("./config.json")}\`. Check to ensure that it is valid JSON.`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
throw new Error(
|
|
73
|
-
"Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
return config;
|
|
77
|
-
}
|
|
78
|
-
async function prepDirectory(exportPath) {
|
|
79
|
-
await rm(exportPath, { recursive: true, force: true });
|
|
80
|
-
await mkdir(exportPath, { recursive: true });
|
|
81
|
-
}
|
|
82
|
-
function generateFolderName(folderName) {
|
|
83
|
-
return snakeCase(sanitize(folderName));
|
|
84
|
-
}
|
|
85
21
|
|
|
86
22
|
// src/lib/log-utils.ts
|
|
87
23
|
import { clearLine, cursorTo } from "node:readline";
|
|
@@ -94,8 +30,8 @@ function log(config) {
|
|
|
94
30
|
if (config.logFunction) {
|
|
95
31
|
return config.logFunction;
|
|
96
32
|
}
|
|
97
|
-
return (text, overwrite) => {
|
|
98
|
-
if (overwrite
|
|
33
|
+
return (text, overwrite = false) => {
|
|
34
|
+
if (overwrite && process.stdout.isTTY) {
|
|
99
35
|
clearLine(process.stdout, 0);
|
|
100
36
|
cursorTo(process.stdout, 0);
|
|
101
37
|
} else {
|
|
@@ -115,16 +51,60 @@ ${formatWarning(text)}
|
|
|
115
51
|
};
|
|
116
52
|
}
|
|
117
53
|
function formatWarning(text) {
|
|
118
|
-
|
|
119
|
-
return colors.yellow(warningMessage);
|
|
54
|
+
return colors.yellow(`${colors.underline("Warning")}: ${text}`);
|
|
120
55
|
}
|
|
121
56
|
function formatError(error) {
|
|
122
57
|
const messageText = error instanceof Error ? error.message : error;
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
58
|
+
const cleanMessage = messageText.replace(/^Error:\s*/i, "");
|
|
59
|
+
return colors.red(`${colors.underline("Error")}: ${cleanMessage}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/lib/file-utils.ts
|
|
63
|
+
async function getConfig(argv2) {
|
|
64
|
+
let config;
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
if (argv2.configPath) {
|
|
68
|
+
const configPath = path.resolve(untildify(argv2.configPath));
|
|
69
|
+
data = await readFile(configPath, "utf8");
|
|
70
|
+
config = Object.assign(JSON.parse(data), argv2);
|
|
71
|
+
} else if (argv2.gtfsPath || argv2.gtfsUrl || argv2.sqlitePath) {
|
|
72
|
+
const agencies = [
|
|
73
|
+
...argv2.gtfsPath ? [{ path: argv2.gtfsPath }] : [],
|
|
74
|
+
...argv2.gtfsUrl ? [{ url: argv2.gtfsUrl }] : []
|
|
75
|
+
];
|
|
76
|
+
config = {
|
|
77
|
+
agencies,
|
|
78
|
+
...omit(argv2, ["path", "url"])
|
|
79
|
+
};
|
|
80
|
+
} else if (existsSync(path.resolve("./config.json"))) {
|
|
81
|
+
data = await readFile(path.resolve("./config.json"), "utf8");
|
|
82
|
+
config = Object.assign(JSON.parse(data), argv2);
|
|
83
|
+
log(config)("Using configuration from ./config.json");
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(
|
|
86
|
+
"Cannot find configuration file. Use config-sample.json as a starting point, pass --configPath option."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return config;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof SyntaxError) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Cannot parse configuration file. Check to ensure that it is valid JSON. Error: ${error.message}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function prepDirectory(exportPath) {
|
|
100
|
+
await rm(exportPath, { recursive: true, force: true });
|
|
101
|
+
await mkdir(exportPath, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
function generateFolderName(folderName) {
|
|
104
|
+
if (!folderName || typeof folderName !== "string") {
|
|
105
|
+
throw new Error("Folder name must be a non-empty string");
|
|
106
|
+
}
|
|
107
|
+
return snakeCase(sanitize(folderName));
|
|
128
108
|
}
|
|
129
109
|
|
|
130
110
|
// src/lib/import-gtfs.ts
|
|
@@ -272,7 +252,8 @@ var attributions = {
|
|
|
272
252
|
{
|
|
273
253
|
name: "attribution_id",
|
|
274
254
|
type: "text",
|
|
275
|
-
prefix: true
|
|
255
|
+
prefix: true,
|
|
256
|
+
primary: true
|
|
276
257
|
},
|
|
277
258
|
{
|
|
278
259
|
name: "agency_id",
|
|
@@ -705,26 +686,31 @@ var fareRules = {
|
|
|
705
686
|
name: "fare_id",
|
|
706
687
|
type: "text",
|
|
707
688
|
required: true,
|
|
689
|
+
primary: true,
|
|
708
690
|
prefix: true
|
|
709
691
|
},
|
|
710
692
|
{
|
|
711
693
|
name: "route_id",
|
|
712
694
|
type: "text",
|
|
695
|
+
primary: true,
|
|
713
696
|
prefix: true
|
|
714
697
|
},
|
|
715
698
|
{
|
|
716
699
|
name: "origin_id",
|
|
717
700
|
type: "text",
|
|
701
|
+
primary: true,
|
|
718
702
|
prefix: true
|
|
719
703
|
},
|
|
720
704
|
{
|
|
721
705
|
name: "destination_id",
|
|
722
706
|
type: "text",
|
|
707
|
+
primary: true,
|
|
723
708
|
prefix: true
|
|
724
709
|
},
|
|
725
710
|
{
|
|
726
711
|
name: "contains_id",
|
|
727
712
|
type: "text",
|
|
713
|
+
primary: true,
|
|
728
714
|
prefix: true
|
|
729
715
|
}
|
|
730
716
|
]
|
|
@@ -931,14 +917,16 @@ var locationGroupStops = {
|
|
|
931
917
|
type: "text",
|
|
932
918
|
prefix: true,
|
|
933
919
|
index: true,
|
|
934
|
-
required: true
|
|
920
|
+
required: true,
|
|
921
|
+
primary: true
|
|
935
922
|
},
|
|
936
923
|
{
|
|
937
924
|
name: "stop_id",
|
|
938
925
|
type: "text",
|
|
939
926
|
required: true,
|
|
940
927
|
prefix: true,
|
|
941
|
-
index: true
|
|
928
|
+
index: true,
|
|
929
|
+
primary: true
|
|
942
930
|
}
|
|
943
931
|
]
|
|
944
932
|
};
|
|
@@ -1199,12 +1187,14 @@ var stopAreas = {
|
|
|
1199
1187
|
name: "area_id",
|
|
1200
1188
|
type: "text",
|
|
1201
1189
|
required: true,
|
|
1190
|
+
primary: true,
|
|
1202
1191
|
prefix: true
|
|
1203
1192
|
},
|
|
1204
1193
|
{
|
|
1205
1194
|
name: "stop_id",
|
|
1206
1195
|
type: "text",
|
|
1207
1196
|
required: true,
|
|
1197
|
+
primary: true,
|
|
1208
1198
|
prefix: true
|
|
1209
1199
|
}
|
|
1210
1200
|
]
|
|
@@ -1428,16 +1418,19 @@ var timeframes = {
|
|
|
1428
1418
|
},
|
|
1429
1419
|
{
|
|
1430
1420
|
name: "start_time",
|
|
1431
|
-
type: "text"
|
|
1421
|
+
type: "text",
|
|
1422
|
+
primary: true
|
|
1432
1423
|
},
|
|
1433
1424
|
{
|
|
1434
1425
|
name: "end_time",
|
|
1435
|
-
type: "text"
|
|
1426
|
+
type: "text",
|
|
1427
|
+
primary: true
|
|
1436
1428
|
},
|
|
1437
1429
|
{
|
|
1438
1430
|
name: "service_id",
|
|
1439
1431
|
type: "text",
|
|
1440
1432
|
required: true,
|
|
1433
|
+
primary: true,
|
|
1441
1434
|
index: true,
|
|
1442
1435
|
prefix: true
|
|
1443
1436
|
}
|
|
@@ -1624,21 +1617,19 @@ var timetables = {
|
|
|
1624
1617
|
filenameExtension: "txt",
|
|
1625
1618
|
nonstandard: true,
|
|
1626
1619
|
schema: [
|
|
1627
|
-
{
|
|
1628
|
-
name: "id",
|
|
1629
|
-
type: "integer",
|
|
1630
|
-
primary: true,
|
|
1631
|
-
prefix: true
|
|
1632
|
-
},
|
|
1633
1620
|
{
|
|
1634
1621
|
name: "timetable_id",
|
|
1635
1622
|
type: "text",
|
|
1636
|
-
prefix: true
|
|
1623
|
+
prefix: true,
|
|
1624
|
+
required: true,
|
|
1625
|
+
primary: true
|
|
1637
1626
|
},
|
|
1638
1627
|
{
|
|
1639
1628
|
name: "route_id",
|
|
1640
1629
|
type: "text",
|
|
1641
|
-
prefix: true
|
|
1630
|
+
prefix: true,
|
|
1631
|
+
required: true,
|
|
1632
|
+
primary: true
|
|
1642
1633
|
},
|
|
1643
1634
|
{
|
|
1644
1635
|
name: "direction_id",
|
|
@@ -1772,6 +1763,7 @@ var timetablePages = {
|
|
|
1772
1763
|
name: "timetable_page_id",
|
|
1773
1764
|
type: "text",
|
|
1774
1765
|
primary: true,
|
|
1766
|
+
required: true,
|
|
1775
1767
|
prefix: true
|
|
1776
1768
|
},
|
|
1777
1769
|
{
|
|
@@ -1791,28 +1783,28 @@ var timetableStopOrder = {
|
|
|
1791
1783
|
filenameExtension: "txt",
|
|
1792
1784
|
nonstandard: true,
|
|
1793
1785
|
schema: [
|
|
1794
|
-
{
|
|
1795
|
-
name: "id",
|
|
1796
|
-
type: "integer",
|
|
1797
|
-
primary: true,
|
|
1798
|
-
prefix: true
|
|
1799
|
-
},
|
|
1800
1786
|
{
|
|
1801
1787
|
name: "timetable_id",
|
|
1802
1788
|
type: "text",
|
|
1803
1789
|
index: true,
|
|
1804
|
-
prefix: true
|
|
1790
|
+
prefix: true,
|
|
1791
|
+
required: true,
|
|
1792
|
+
primary: true
|
|
1805
1793
|
},
|
|
1806
1794
|
{
|
|
1807
1795
|
name: "stop_id",
|
|
1808
1796
|
type: "text",
|
|
1809
|
-
prefix: true
|
|
1797
|
+
prefix: true,
|
|
1798
|
+
required: true,
|
|
1799
|
+
primary: true
|
|
1810
1800
|
},
|
|
1811
1801
|
{
|
|
1812
1802
|
name: "stop_sequence",
|
|
1813
1803
|
type: "integer",
|
|
1814
1804
|
min: 0,
|
|
1815
|
-
index: true
|
|
1805
|
+
index: true,
|
|
1806
|
+
required: true,
|
|
1807
|
+
primary: true
|
|
1816
1808
|
}
|
|
1817
1809
|
]
|
|
1818
1810
|
};
|
|
@@ -1827,7 +1819,8 @@ var timetableNotes = {
|
|
|
1827
1819
|
name: "note_id",
|
|
1828
1820
|
type: "text",
|
|
1829
1821
|
primary: true,
|
|
1830
|
-
prefix: true
|
|
1822
|
+
prefix: true,
|
|
1823
|
+
required: true
|
|
1831
1824
|
},
|
|
1832
1825
|
{
|
|
1833
1826
|
name: "symbol",
|
|
@@ -1836,7 +1829,8 @@ var timetableNotes = {
|
|
|
1836
1829
|
{
|
|
1837
1830
|
name: "note",
|
|
1838
1831
|
type: "text",
|
|
1839
|
-
nocase: true
|
|
1832
|
+
nocase: true,
|
|
1833
|
+
required: true
|
|
1840
1834
|
}
|
|
1841
1835
|
]
|
|
1842
1836
|
};
|
|
@@ -1850,37 +1844,39 @@ var timetableNotesReferences = {
|
|
|
1850
1844
|
{
|
|
1851
1845
|
name: "note_id",
|
|
1852
1846
|
type: "text",
|
|
1853
|
-
prefix: true
|
|
1847
|
+
prefix: true,
|
|
1848
|
+
required: true,
|
|
1849
|
+
primary: true
|
|
1854
1850
|
},
|
|
1855
1851
|
{
|
|
1856
1852
|
name: "timetable_id",
|
|
1857
1853
|
type: "text",
|
|
1858
|
-
|
|
1859
|
-
|
|
1854
|
+
prefix: true,
|
|
1855
|
+
primary: true
|
|
1860
1856
|
},
|
|
1861
1857
|
{
|
|
1862
1858
|
name: "route_id",
|
|
1863
1859
|
type: "text",
|
|
1864
|
-
|
|
1865
|
-
|
|
1860
|
+
prefix: true,
|
|
1861
|
+
primary: true
|
|
1866
1862
|
},
|
|
1867
1863
|
{
|
|
1868
1864
|
name: "trip_id",
|
|
1869
1865
|
type: "text",
|
|
1870
|
-
|
|
1871
|
-
|
|
1866
|
+
prefix: true,
|
|
1867
|
+
primary: true
|
|
1872
1868
|
},
|
|
1873
1869
|
{
|
|
1874
1870
|
name: "stop_id",
|
|
1875
1871
|
type: "text",
|
|
1876
|
-
|
|
1877
|
-
|
|
1872
|
+
prefix: true,
|
|
1873
|
+
primary: true
|
|
1878
1874
|
},
|
|
1879
1875
|
{
|
|
1880
1876
|
name: "stop_sequence",
|
|
1881
1877
|
type: "integer",
|
|
1882
1878
|
min: 0,
|
|
1883
|
-
|
|
1879
|
+
primary: true
|
|
1884
1880
|
},
|
|
1885
1881
|
{
|
|
1886
1882
|
name: "show_on_stoptime",
|
|
@@ -3275,7 +3271,8 @@ function setDefaultConfig(initialConfig) {
|
|
|
3275
3271
|
sqlitePath: ":memory:",
|
|
3276
3272
|
ignoreDuplicates: false,
|
|
3277
3273
|
ignoreErrors: false,
|
|
3278
|
-
gtfsRealtimeExpirationSeconds: 0
|
|
3274
|
+
gtfsRealtimeExpirationSeconds: 0,
|
|
3275
|
+
verbose: true
|
|
3279
3276
|
};
|
|
3280
3277
|
return {
|
|
3281
3278
|
...defaults,
|