gtfs 4.17.6 → 4.17.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/README.md +23 -2
- package/dist/bin/gtfs-export.js +14 -14
- package/dist/bin/gtfs-export.js.map +1 -1
- package/dist/bin/gtfs-import.js +86 -29
- package/dist/bin/gtfs-import.js.map +1 -1
- package/dist/bin/gtfsrealtime-update.js +13 -13
- package/dist/bin/gtfsrealtime-update.js.map +1 -1
- package/dist/index.js +165 -106
- package/dist/index.js.map +1 -1
- package/package.json +1 -6
package/dist/bin/gtfs-import.js
CHANGED
|
@@ -13,10 +13,10 @@ import PrettyError from "pretty-error";
|
|
|
13
13
|
// src/lib/file-utils.ts
|
|
14
14
|
import path from "path";
|
|
15
15
|
import { existsSync } from "fs";
|
|
16
|
+
import { homedir } from "os";
|
|
16
17
|
import { mkdir, readFile, rm } from "fs/promises";
|
|
17
18
|
import { omit, snakeCase } from "lodash-es";
|
|
18
19
|
import sanitize from "sanitize-filename";
|
|
19
|
-
import untildify from "untildify";
|
|
20
20
|
import StreamZip from "node-stream-zip";
|
|
21
21
|
|
|
22
22
|
// src/lib/log-utils.ts
|
|
@@ -70,6 +70,7 @@ function formatError(error) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// src/lib/file-utils.ts
|
|
73
|
+
var homeDirectory = homedir();
|
|
73
74
|
async function getConfig(argv2) {
|
|
74
75
|
let config;
|
|
75
76
|
let data;
|
|
@@ -117,17 +118,17 @@ async function unzip(zipfilePath, exportPath) {
|
|
|
117
118
|
);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
121
|
+
function untildify(pathWithTilde) {
|
|
122
|
+
return homeDirectory ? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory) : pathWithTilde;
|
|
123
|
+
}
|
|
120
124
|
|
|
121
125
|
// src/lib/import-gtfs.ts
|
|
122
126
|
import path2 from "path";
|
|
123
127
|
import { createReadStream, existsSync as existsSync2, lstatSync } from "fs";
|
|
124
128
|
import { cp, readdir, rename, readFile as readFile2, rm as rm2, writeFile } from "fs/promises";
|
|
125
129
|
import { parse } from "csv-parse";
|
|
126
|
-
import pluralize2 from "pluralize";
|
|
127
130
|
import stripBomStream from "strip-bom-stream";
|
|
128
131
|
import { temporaryDirectory } from "tempy";
|
|
129
|
-
import Timer from "timer-machine";
|
|
130
|
-
import untildify3 from "untildify";
|
|
131
132
|
import mapSeries2 from "promise-map-series";
|
|
132
133
|
|
|
133
134
|
// src/models/models.ts
|
|
@@ -4089,10 +4090,9 @@ var vehicles = {
|
|
|
4089
4090
|
|
|
4090
4091
|
// src/lib/db.ts
|
|
4091
4092
|
import Database from "better-sqlite3";
|
|
4092
|
-
import untildify2 from "untildify";
|
|
4093
4093
|
var dbs = {};
|
|
4094
4094
|
function setupDb(sqlitePath) {
|
|
4095
|
-
const db = new Database(
|
|
4095
|
+
const db = new Database(untildify(sqlitePath));
|
|
4096
4096
|
db.pragma("journal_mode = OFF");
|
|
4097
4097
|
db.pragma("synchronous = OFF");
|
|
4098
4098
|
db.pragma("temp_store = MEMORY");
|
|
@@ -4164,7 +4164,6 @@ function isValidJSON(string) {
|
|
|
4164
4164
|
}
|
|
4165
4165
|
|
|
4166
4166
|
// src/lib/import-gtfs-realtime.ts
|
|
4167
|
-
import pluralize from "pluralize";
|
|
4168
4167
|
import GtfsRealtimeBindings from "gtfs-realtime-bindings";
|
|
4169
4168
|
import mapSeries from "promise-map-series";
|
|
4170
4169
|
import { get } from "lodash-es";
|
|
@@ -4220,6 +4219,9 @@ function applyPrefixToValue(value, columnShouldBePrefixed, prefix) {
|
|
|
4220
4219
|
}
|
|
4221
4220
|
return `${prefix}${value}`;
|
|
4222
4221
|
}
|
|
4222
|
+
function pluralize(singularWord, pluralWord, count) {
|
|
4223
|
+
return count === 1 ? singularWord : pluralWord;
|
|
4224
|
+
}
|
|
4223
4225
|
|
|
4224
4226
|
// src/lib/import-gtfs-realtime.ts
|
|
4225
4227
|
async function fetchGtfsRealtimeData(urlConfig, task) {
|
|
@@ -4456,7 +4458,7 @@ var extractGtfsFiles = async (task) => {
|
|
|
4456
4458
|
if (!task.path) {
|
|
4457
4459
|
throw new Error("No `path` specified in config");
|
|
4458
4460
|
}
|
|
4459
|
-
const gtfsPath =
|
|
4461
|
+
const gtfsPath = untildify(task.path);
|
|
4460
4462
|
task.log(`Importing GTFS from ${task.path}\r`);
|
|
4461
4463
|
if (path2.extname(gtfsPath) === ".zip") {
|
|
4462
4464
|
try {
|
|
@@ -4708,7 +4710,12 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
4708
4710
|
}
|
|
4709
4711
|
}
|
|
4710
4712
|
} catch (error) {
|
|
4711
|
-
|
|
4713
|
+
if (task.ignoreErrors) {
|
|
4714
|
+
task.logError(`Error processing ${filename}: ${error.message}`);
|
|
4715
|
+
resolve();
|
|
4716
|
+
} else {
|
|
4717
|
+
reject(error);
|
|
4718
|
+
}
|
|
4712
4719
|
}
|
|
4713
4720
|
});
|
|
4714
4721
|
parser.on("end", () => {
|
|
@@ -4717,7 +4724,16 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
4717
4724
|
try {
|
|
4718
4725
|
insertLines(lines);
|
|
4719
4726
|
} catch (error) {
|
|
4720
|
-
|
|
4727
|
+
if (task.ignoreErrors) {
|
|
4728
|
+
task.logError(
|
|
4729
|
+
`Error inserting data for ${filename}: ${error.message}`
|
|
4730
|
+
);
|
|
4731
|
+
resolve();
|
|
4732
|
+
return;
|
|
4733
|
+
} else {
|
|
4734
|
+
reject(error);
|
|
4735
|
+
return;
|
|
4736
|
+
}
|
|
4721
4737
|
}
|
|
4722
4738
|
}
|
|
4723
4739
|
task.log(
|
|
@@ -4726,15 +4742,34 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
4726
4742
|
);
|
|
4727
4743
|
resolve();
|
|
4728
4744
|
} catch (error) {
|
|
4745
|
+
if (task.ignoreErrors) {
|
|
4746
|
+
task.logError(`Error finalizing ${filename}: ${error.message}`);
|
|
4747
|
+
resolve();
|
|
4748
|
+
} else {
|
|
4749
|
+
reject(error);
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
});
|
|
4753
|
+
parser.on("error", (error) => {
|
|
4754
|
+
if (task.ignoreErrors) {
|
|
4755
|
+
task.logError(`Parser error for ${filename}: ${error.message}`);
|
|
4756
|
+
resolve();
|
|
4757
|
+
} else {
|
|
4729
4758
|
reject(error);
|
|
4730
4759
|
}
|
|
4731
4760
|
});
|
|
4732
|
-
parser.on("error", reject);
|
|
4733
4761
|
createReadStream(filepath).pipe(stripBomStream()).pipe(parser);
|
|
4734
4762
|
} else if (model.filenameExtension === "geojson") {
|
|
4735
4763
|
readFile2(filepath, "utf8").then((data) => {
|
|
4736
4764
|
if (isValidJSON(data) === false) {
|
|
4737
|
-
|
|
4765
|
+
if (task.ignoreErrors) {
|
|
4766
|
+
task.logError(`Invalid JSON in ${filename}`);
|
|
4767
|
+
resolve();
|
|
4768
|
+
return;
|
|
4769
|
+
} else {
|
|
4770
|
+
reject(new Error(`Invalid JSON in ${filename}`));
|
|
4771
|
+
return;
|
|
4772
|
+
}
|
|
4738
4773
|
}
|
|
4739
4774
|
totalLineCount += 1;
|
|
4740
4775
|
const line = formatGtfsLine(
|
|
@@ -4742,30 +4777,54 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
4742
4777
|
model,
|
|
4743
4778
|
totalLineCount
|
|
4744
4779
|
);
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4780
|
+
try {
|
|
4781
|
+
insertLines([line]);
|
|
4782
|
+
task.log(
|
|
4783
|
+
`Importing - ${filename} - ${totalLineCount} lines imported\r`,
|
|
4784
|
+
true
|
|
4785
|
+
);
|
|
4786
|
+
resolve();
|
|
4787
|
+
} catch (error) {
|
|
4788
|
+
if (task.ignoreErrors) {
|
|
4789
|
+
task.logError(
|
|
4790
|
+
`Error inserting data for ${filename}: ${error.message}`
|
|
4791
|
+
);
|
|
4792
|
+
resolve();
|
|
4793
|
+
} else {
|
|
4794
|
+
reject(error);
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
}).catch((error) => {
|
|
4798
|
+
if (task.ignoreErrors) {
|
|
4799
|
+
task.logError(`Error reading ${filename}: ${error.message}`);
|
|
4800
|
+
resolve();
|
|
4801
|
+
} else {
|
|
4802
|
+
reject(error);
|
|
4803
|
+
}
|
|
4804
|
+
});
|
|
4805
|
+
} else {
|
|
4806
|
+
if (task.ignoreErrors) {
|
|
4807
|
+
task.logError(
|
|
4808
|
+
`Unsupported file type: ${model.filenameExtension} for ${filename}`
|
|
4749
4809
|
);
|
|
4750
4810
|
resolve();
|
|
4751
|
-
}
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4811
|
+
} else {
|
|
4812
|
+
reject(
|
|
4813
|
+
new Error(`Unsupported file type: ${model.filenameExtension}`)
|
|
4814
|
+
);
|
|
4815
|
+
}
|
|
4756
4816
|
}
|
|
4757
4817
|
})
|
|
4758
4818
|
);
|
|
4759
4819
|
async function importGtfs(initialConfig) {
|
|
4760
|
-
const
|
|
4761
|
-
timer.start();
|
|
4820
|
+
const startTime = process.hrtime.bigint();
|
|
4762
4821
|
const config = setDefaultConfig(initialConfig);
|
|
4763
4822
|
validateConfigForImport(config);
|
|
4764
4823
|
try {
|
|
4765
4824
|
const db = openDb(config);
|
|
4766
4825
|
const agencyCount = config.agencies.length;
|
|
4767
4826
|
log(config)(
|
|
4768
|
-
`Starting GTFS import for ${
|
|
4827
|
+
`Starting GTFS import for ${pluralize("file", "files", agencyCount)} using SQLite database at ${config.sqlitePath}`
|
|
4769
4828
|
);
|
|
4770
4829
|
createGtfsTables(db);
|
|
4771
4830
|
await mapSeries2(config.agencies, async (agency2) => {
|
|
@@ -4809,10 +4868,10 @@ async function importGtfs(initialConfig) {
|
|
|
4809
4868
|
});
|
|
4810
4869
|
log(config)(`Creating DB indexes`);
|
|
4811
4870
|
createGtfsIndexes(db);
|
|
4812
|
-
const
|
|
4813
|
-
|
|
4871
|
+
const endTime = process.hrtime.bigint();
|
|
4872
|
+
const elapsedSeconds = Number(endTime - startTime) / 1e9;
|
|
4814
4873
|
log(config)(
|
|
4815
|
-
`Completed GTFS import
|
|
4874
|
+
`Completed GTFS import in ${elapsedSeconds.toFixed(1)} seconds
|
|
4816
4875
|
`
|
|
4817
4876
|
);
|
|
4818
4877
|
} catch (error) {
|
|
@@ -4829,11 +4888,9 @@ async function importGtfs(initialConfig) {
|
|
|
4829
4888
|
import path3 from "path";
|
|
4830
4889
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
4831
4890
|
import { without, compact as compact2 } from "lodash-es";
|
|
4832
|
-
import pluralize3 from "pluralize";
|
|
4833
4891
|
import { stringify } from "csv-stringify";
|
|
4834
4892
|
import sqlString2 from "sqlstring-sqlite";
|
|
4835
4893
|
import mapSeries3 from "promise-map-series";
|
|
4836
|
-
import untildify4 from "untildify";
|
|
4837
4894
|
|
|
4838
4895
|
// src/lib/advancedQuery.ts
|
|
4839
4896
|
import sqlString3 from "sqlstring-sqlite";
|