gtfs 4.11.2 → 4.11.3
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/.github/workflows/nodejs.yml +1 -1
- package/CHANGELOG.md +7 -0
- package/lib/export.js +4 -0
- package/lib/import.js +44 -41
- package/package.json +1 -1
- package/test/mocha/get-locations.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [4.11.3] - 2024-06-13
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Better tests for locations.geojson
|
|
13
|
+
- Handle unknown filename extensions in models
|
|
14
|
+
|
|
8
15
|
## [4.11.2] - 2024-06-13
|
|
9
16
|
|
|
10
17
|
### Added
|
package/lib/export.js
CHANGED
|
@@ -117,6 +117,10 @@ const exportGtfs = async (initialConfig) => {
|
|
|
117
117
|
} else if (model.filenameExtension === 'geojson') {
|
|
118
118
|
const fileText = lines?.[0].geojson ?? '';
|
|
119
119
|
await writeFile(filePath, fileText);
|
|
120
|
+
} else {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`Unexpected filename extension: ${model.filenameExtension}`,
|
|
123
|
+
);
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
log(`Exporting - ${model.filenameBase}.${model.filenameExtension}\r`);
|
package/lib/import.js
CHANGED
|
@@ -604,8 +604,46 @@ const importFiles = (task) =>
|
|
|
604
604
|
`Importing - ${model.filenameBase}.${model.filenameExtension}\r`,
|
|
605
605
|
);
|
|
606
606
|
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
if (model.filenameExtension === 'txt') {
|
|
608
|
+
const parser = parse({
|
|
609
|
+
columns: true,
|
|
610
|
+
relax_quotes: true,
|
|
611
|
+
trim: true,
|
|
612
|
+
skip_empty_lines: true,
|
|
613
|
+
...task.csvOptions,
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
parser.on('readable', () => {
|
|
617
|
+
let record;
|
|
618
|
+
|
|
619
|
+
while ((record = parser.read())) {
|
|
620
|
+
try {
|
|
621
|
+
totalLineCount += 1;
|
|
622
|
+
lines.push(formatLine(record, model, totalLineCount));
|
|
623
|
+
// If we have a bunch of lines ready to insert, then do it
|
|
624
|
+
if (lines.length >= maxInsertVariables / model.schema.length) {
|
|
625
|
+
importLines(task, lines, model, totalLineCount);
|
|
626
|
+
}
|
|
627
|
+
} catch (error) {
|
|
628
|
+
reject(error);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
parser.on('end', () => {
|
|
634
|
+
try {
|
|
635
|
+
// Insert all remaining lines
|
|
636
|
+
importLines(task, lines, model, totalLineCount);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
reject(error);
|
|
639
|
+
}
|
|
640
|
+
resolve();
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
parser.on('error', reject);
|
|
644
|
+
|
|
645
|
+
createReadStream(filepath).pipe(stripBomStream()).pipe(parser);
|
|
646
|
+
} else if (model.filenameExtension === 'geojson') {
|
|
609
647
|
readFile(filepath, 'utf8')
|
|
610
648
|
.then((data) => {
|
|
611
649
|
if (isValidJSON(data) === false) {
|
|
@@ -620,46 +658,11 @@ const importFiles = (task) =>
|
|
|
620
658
|
resolve();
|
|
621
659
|
})
|
|
622
660
|
.catch(reject);
|
|
661
|
+
} else {
|
|
662
|
+
reject(
|
|
663
|
+
new Error(`Unsupported file type: ${model.filenameExtension}`),
|
|
664
|
+
);
|
|
623
665
|
}
|
|
624
|
-
|
|
625
|
-
const parser = parse({
|
|
626
|
-
columns: true,
|
|
627
|
-
relax_quotes: true,
|
|
628
|
-
trim: true,
|
|
629
|
-
skip_empty_lines: true,
|
|
630
|
-
...task.csvOptions,
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
parser.on('readable', () => {
|
|
634
|
-
let record;
|
|
635
|
-
|
|
636
|
-
while ((record = parser.read())) {
|
|
637
|
-
try {
|
|
638
|
-
totalLineCount += 1;
|
|
639
|
-
lines.push(formatLine(record, model, totalLineCount));
|
|
640
|
-
// If we have a bunch of lines ready to insert, then do it
|
|
641
|
-
if (lines.length >= maxInsertVariables / model.schema.length) {
|
|
642
|
-
importLines(task, lines, model, totalLineCount);
|
|
643
|
-
}
|
|
644
|
-
} catch (error) {
|
|
645
|
-
reject(error);
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
parser.on('end', () => {
|
|
651
|
-
try {
|
|
652
|
-
// Insert all remaining lines
|
|
653
|
-
importLines(task, lines, model, totalLineCount);
|
|
654
|
-
} catch (error) {
|
|
655
|
-
reject(error);
|
|
656
|
-
}
|
|
657
|
-
resolve();
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
parser.on('error', reject);
|
|
661
|
-
|
|
662
|
-
createReadStream(filepath).pipe(stripBomStream()).pipe(parser);
|
|
663
666
|
}),
|
|
664
667
|
);
|
|
665
668
|
|
package/package.json
CHANGED
|
@@ -17,7 +17,6 @@ const locationsConfig = {
|
|
|
17
17
|
},
|
|
18
18
|
],
|
|
19
19
|
verbose: false,
|
|
20
|
-
sqlitePath: '/tmp/locations',
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
describe('getLocations():', () => {
|
|
@@ -25,7 +24,6 @@ describe('getLocations():', () => {
|
|
|
25
24
|
openDb(locationsConfig);
|
|
26
25
|
|
|
27
26
|
// Add locations.geojson to test GTFS dataset
|
|
28
|
-
const temporaryDir = path.join(import.meta.dirname, '../fixture/tmp2/');
|
|
29
27
|
await prepDirectory(temporaryDir);
|
|
30
28
|
await unzip(config.agencies[0].path, temporaryDir);
|
|
31
29
|
|