text-to-map 1.0.8 → 1.1.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.
- package/dist/bin/clear-all.js +21 -4
- package/dist/bin/init-db.d.ts +1 -0
- package/dist/bin/init-db.js +18 -0
- package/dist/bin/parse-ordinance.js +55 -42
- package/dist/bin/schools.js +1 -1
- package/dist/db/address-points.d.ts +11 -11
- package/dist/db/address-points.js +88 -76
- package/dist/db/db.d.ts +19 -10
- package/dist/db/db.js +124 -52
- package/dist/db/founders.d.ts +6 -6
- package/dist/db/founders.js +165 -134
- package/dist/db/meta.d.ts +3 -4
- package/dist/db/meta.js +23 -16
- package/dist/db/migrations/20230704125715_initial.d.ts +3 -0
- package/dist/db/migrations/20230704125715_initial.js +251 -0
- package/dist/db/regions.d.ts +5 -5
- package/dist/db/regions.js +40 -28
- package/dist/db/schools.d.ts +1 -1
- package/dist/db/schools.js +24 -12
- package/dist/db/street-sync.d.ts +4 -4
- package/dist/db/street-sync.js +26 -17
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/open-data-sync/address-points.d.ts +0 -1
- package/dist/open-data-sync/address-points.js +35 -25
- package/dist/open-data-sync/regions.js +13 -5
- package/dist/open-data-sync/schools.js +19 -15
- package/dist/open-data-sync/streets.js +46 -33
- package/dist/street-markdown/municipality.d.ts +2 -2
- package/dist/street-markdown/municipality.js +18 -9
- package/dist/street-markdown/smd-line-parser.js +8 -5
- package/dist/street-markdown/smd.d.ts +4 -5
- package/dist/street-markdown/smd.js +72 -78
- package/dist/utils/helpers.d.ts +0 -1
- package/dist/utils/helpers.js +1 -8
- package/package.json +9 -5
package/dist/bin/clear-all.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { clearDb, disconnectKnex } from "../db/db";
|
|
2
11
|
import { deleteSchoolsXmlFile } from "../open-data-sync/schools";
|
|
3
12
|
import { defaultBinOptions } from "./constants";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
console.log("
|
|
13
|
+
function main() {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
console.log("Clearing all data...");
|
|
16
|
+
yield clearDb();
|
|
17
|
+
console.log("DB cleared. Now deleting schools XML file...");
|
|
18
|
+
deleteSchoolsXmlFile(defaultBinOptions);
|
|
19
|
+
yield disconnectKnex();
|
|
20
|
+
console.log("Everything cleared, ready for a new sync.");
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
main();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { disconnectKnex, initDb } from "../db/db";
|
|
11
|
+
function main() {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
yield initDb();
|
|
14
|
+
console.log("Database ready to use.");
|
|
15
|
+
yield disconnectKnex();
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
main();
|
|
@@ -1,46 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { readFileSync, writeFileSync } from "fs";
|
|
2
11
|
import { getNewMunicipality, parseOrdinanceToAddressPoints, } from "../street-markdown/smd";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
function main() {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
// take first node argument as a file name
|
|
15
|
+
if (process.argv.length < 3) {
|
|
16
|
+
console.error("Missing file name argument");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const fileName = process.argv[2];
|
|
20
|
+
const fileContent = readFileSync(fileName);
|
|
21
|
+
const lines = fileContent.toString().split("\n");
|
|
22
|
+
let errorCount = 0;
|
|
23
|
+
const errorLines = [];
|
|
24
|
+
let warningCount = 0;
|
|
25
|
+
const reportErrors = ({ lineNumber, line, errors, }) => {
|
|
26
|
+
errors.forEach((error) => console.error(error));
|
|
27
|
+
console.error(`Invalid street definition on line ${lineNumber}: ${line}`);
|
|
28
|
+
errorCount++;
|
|
29
|
+
errorLines.push(`line ${lineNumber}: ${line}`);
|
|
30
|
+
};
|
|
31
|
+
const reportWarnings = ({ lineNumber, errors: warnings, }) => {
|
|
32
|
+
warnings.forEach((error) => {
|
|
33
|
+
console.error(`Line ${lineNumber}: ${error.message}`);
|
|
34
|
+
});
|
|
35
|
+
warningCount++;
|
|
36
|
+
};
|
|
37
|
+
console.time("downloadAndImportAllLatestAddressPoints");
|
|
38
|
+
const { municipality } = yield getNewMunicipality("Česká Lípa");
|
|
39
|
+
const addressPoints = yield parseOrdinanceToAddressPoints(lines, {
|
|
40
|
+
// currentMunicipality: municipality,
|
|
41
|
+
}, reportErrors, reportWarnings);
|
|
42
|
+
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
43
|
+
console.log(`Parsed ${lines.length} lines, ${errorCount} errors, ${warningCount} warnings.`);
|
|
44
|
+
if (errorCount > 0) {
|
|
45
|
+
console.log("Errors:");
|
|
46
|
+
errorLines.forEach((line) => console.log(line));
|
|
47
|
+
}
|
|
48
|
+
if (process.argv.length >= 4) {
|
|
49
|
+
const outputFileName = process.argv[3];
|
|
50
|
+
const output = JSON.stringify(addressPoints);
|
|
51
|
+
console.log(`Writing output to ${outputFileName}`);
|
|
52
|
+
writeFileSync(outputFileName, output);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log(JSON.stringify(addressPoints));
|
|
56
|
+
}
|
|
24
57
|
});
|
|
25
|
-
warningCount++;
|
|
26
|
-
};
|
|
27
|
-
console.time("downloadAndImportAllLatestAddressPoints");
|
|
28
|
-
const { municipality } = getNewMunicipality("Česká Lípa", defaultBinOptions);
|
|
29
|
-
const addressPoints = parseOrdinanceToAddressPoints(lines, defaultBinOptions, {
|
|
30
|
-
// currentMunicipality: municipality,
|
|
31
|
-
}, reportErrors, reportWarnings);
|
|
32
|
-
console.timeEnd("downloadAndImportAllLatestAddressPoints");
|
|
33
|
-
console.log(`Parsed ${lines.length} lines, ${errorCount} errors, ${warningCount} warnings.`);
|
|
34
|
-
if (errorCount > 0) {
|
|
35
|
-
console.log("Errors:");
|
|
36
|
-
errorLines.forEach((line) => console.log(line));
|
|
37
|
-
}
|
|
38
|
-
if (process.argv.length >= 4) {
|
|
39
|
-
const outputFileName = process.argv[3];
|
|
40
|
-
const output = JSON.stringify(addressPoints);
|
|
41
|
-
console.log(`Writing output to ${outputFileName}`);
|
|
42
|
-
writeFileSync(outputFileName, output);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log(JSON.stringify(addressPoints));
|
|
46
58
|
}
|
|
59
|
+
main();
|
package/dist/bin/schools.js
CHANGED
|
@@ -21,19 +21,19 @@ export declare const Column: {
|
|
|
21
21
|
xCoordinate: number;
|
|
22
22
|
validFrom: number;
|
|
23
23
|
};
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const getAddressPointById: (addressPointId: number) => AddressPoint | null
|
|
32
|
-
export declare const checkStreetExists: (streetName: string, founder: Founder) => {
|
|
24
|
+
export declare const commitAddressPoints: (buffer: string[][]) => Promise<number>;
|
|
25
|
+
export declare const insertCities: (buffer: string[][]) => Promise<number>;
|
|
26
|
+
export declare const insertDistricts: (buffer: string[][]) => Promise<number>;
|
|
27
|
+
export declare const insertMunicipalityParts: (buffer: string[][]) => Promise<number>;
|
|
28
|
+
export declare const insertPragueDistricts: (buffer: string[][]) => Promise<number>;
|
|
29
|
+
export declare const insertStreets: (buffer: string[][]) => Promise<number>;
|
|
30
|
+
export declare const areAddressPointsSynced: () => Promise<boolean>;
|
|
31
|
+
export declare const getAddressPointById: (addressPointId: number) => Promise<AddressPoint | null>;
|
|
32
|
+
export declare const checkStreetExists: (streetName: string, founder: Founder) => Promise<{
|
|
33
33
|
exists: boolean;
|
|
34
34
|
errors: SmdError[];
|
|
35
|
-
}
|
|
36
|
-
export declare const findAddressPoints: (smdLine: SmdLine | WholeMunicipalitySmdLine, municipality: Municipality) => AddressPoint[]
|
|
35
|
+
}>;
|
|
36
|
+
export declare const findAddressPoints: (smdLine: SmdLine | WholeMunicipalitySmdLine, municipality: Municipality) => Promise<AddressPoint[]>;
|
|
37
37
|
export declare const isInRange: (number: number | null, letter: string | null, range: RangeSpec) => boolean;
|
|
38
38
|
export declare const fitsType: (number: number | null, type: SeriesType) => boolean;
|
|
39
39
|
export declare const equalsFullStreetNumber: (fullStreetNumber: FullStreetNumber, addressPoint: AddressPoint) => boolean;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
2
10
|
import { AddressPointType, createSingleLineAddress } from "czech-address";
|
|
3
11
|
import { SeriesType, isNegativeSeriesSpec, isRange, isSeriesSpecArray, isWholeMunicipalitySmdLine, } from "../street-markdown/types";
|
|
4
12
|
import { findClosestString } from "../utils/helpers";
|
|
5
|
-
import
|
|
13
|
+
import jtsk2wgs84 from "../utils/jtsk2wgs84";
|
|
14
|
+
import { extractKeyValuesPairs, generate2DPlaceholders, getKnexDb, insertMultipleRows, isSqlite, nonEmptyOrNull } from "./db";
|
|
6
15
|
import { getFounderCityCode } from "./founders";
|
|
7
16
|
import { MunicipalityType } from "./types";
|
|
8
|
-
const buffer = [];
|
|
9
|
-
const MaxBufferSize = 1000;
|
|
10
17
|
const DescriptiveType = "č.p.";
|
|
11
18
|
const RegistrationType = "č.ev.";
|
|
12
19
|
const ObjectTypes = {
|
|
@@ -34,27 +41,32 @@ export const Column = {
|
|
|
34
41
|
xCoordinate: 17,
|
|
35
42
|
validFrom: 18,
|
|
36
43
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const columnNames = [
|
|
45
|
+
"id",
|
|
46
|
+
"street_code",
|
|
47
|
+
"object_type_id",
|
|
48
|
+
"descriptive_number",
|
|
49
|
+
"orientational_number",
|
|
50
|
+
"orientational_number_letter",
|
|
51
|
+
"city_code",
|
|
52
|
+
"city_district_code",
|
|
53
|
+
"municipality_part_code",
|
|
54
|
+
"prague_district_code",
|
|
55
|
+
"postal_code",
|
|
56
|
+
"jtsk_x",
|
|
57
|
+
"jtsk_y",
|
|
58
|
+
"wgs84_latitude",
|
|
59
|
+
"wgs84_longitude",
|
|
60
|
+
];
|
|
61
|
+
export const commitAddressPoints = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
62
|
if (buffer.length === 0) {
|
|
46
63
|
return 0;
|
|
47
64
|
}
|
|
48
|
-
insertCities(buffer);
|
|
49
|
-
insertDistricts(buffer);
|
|
50
|
-
insertMunicipalityParts(buffer);
|
|
51
|
-
insertStreets(buffer);
|
|
52
|
-
insertPragueDistricts(buffer);
|
|
53
|
-
const db = getDb();
|
|
54
|
-
const placeHolders = generate2DPlaceholders(15, buffer.length);
|
|
55
|
-
const insertStatement = db.prepare(`INSERT OR IGNORE INTO address_point
|
|
56
|
-
(id, street_code, object_type_id, descriptive_number, orientational_number, orientational_number_letter, city_code, city_district_code, municipality_part_code, prague_district_code, postal_code, jtsk_x, jtsk_y, wgs84_latitude, wgs84_longitude)
|
|
57
|
-
VALUES ${placeHolders}`);
|
|
65
|
+
yield insertCities(buffer);
|
|
66
|
+
yield insertDistricts(buffer);
|
|
67
|
+
yield insertMunicipalityParts(buffer);
|
|
68
|
+
yield insertStreets(buffer);
|
|
69
|
+
yield insertPragueDistricts(buffer);
|
|
58
70
|
const params = [];
|
|
59
71
|
buffer.forEach((data) => {
|
|
60
72
|
let latOrNull, lonOrNull;
|
|
@@ -66,34 +78,39 @@ export const commitAddressPoints = () => {
|
|
|
66
78
|
}
|
|
67
79
|
params.push(data[Column.admCode], nonEmptyOrNull(data[Column.streetCode]), ObjectTypes[data[Column.objectType]], nonEmptyOrNull(data[Column.houseNumber]), nonEmptyOrNull(data[Column.orientationalNumber]), nonEmptyOrNull(data[Column.orientationalNumberLetter]), data[Column.cityCode], nonEmptyOrNull(data[Column.districtCode]), nonEmptyOrNull(data[Column.municipalityPartCode]), nonEmptyOrNull(data[Column.pragueDistrictCode]), data[Column.postalCode], nonEmptyOrNull(data[Column.xCoordinate]), nonEmptyOrNull(data[Column.yCoordinate]), latOrNull, lonOrNull);
|
|
68
80
|
});
|
|
69
|
-
buffer.length
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
const placeHolders = generate2DPlaceholders(columnNames.length, buffer.length);
|
|
82
|
+
yield getKnexDb().raw(`INSERT INTO address_point (${columnNames.join(",")}) VALUES ${placeHolders} ON CONFLICT (id) DO NOTHING`, params);
|
|
83
|
+
return buffer.length;
|
|
84
|
+
});
|
|
85
|
+
export const insertCities = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, Column.cityCode, [Column.cityName]), "city", ["code", "name"]);
|
|
87
|
+
});
|
|
88
|
+
export const insertDistricts = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, Column.districtCode, [
|
|
77
90
|
Column.cityCode,
|
|
78
91
|
Column.districtName,
|
|
79
92
|
]), "city_district", ["code", "city_code", "name"]);
|
|
80
|
-
};
|
|
81
|
-
export const insertMunicipalityParts = (buffer) => {
|
|
82
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.municipalityPartCode, [
|
|
93
|
+
});
|
|
94
|
+
export const insertMunicipalityParts = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, Column.municipalityPartCode, [
|
|
83
96
|
Column.municipalityPartName,
|
|
84
97
|
]), "municipality_part", ["code", "name"]);
|
|
85
|
-
};
|
|
86
|
-
export const insertPragueDistricts = (buffer) => {
|
|
87
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.pragueDistrictCode, [
|
|
98
|
+
});
|
|
99
|
+
export const insertPragueDistricts = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, Column.pragueDistrictCode, [
|
|
88
101
|
Column.pragueDistrictName,
|
|
89
102
|
]), "prague_district", ["code", "name"]);
|
|
90
|
-
};
|
|
91
|
-
export const insertStreets = (buffer) => {
|
|
92
|
-
return insertMultipleRows(extractKeyValuesPairs(buffer, Column.streetCode, [
|
|
103
|
+
});
|
|
104
|
+
export const insertStreets = (buffer) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
return yield insertMultipleRows(extractKeyValuesPairs(buffer, Column.streetCode, [
|
|
93
106
|
Column.cityCode,
|
|
94
107
|
Column.streetName,
|
|
95
108
|
]), "street", ["code", "city_code", "name"]);
|
|
96
|
-
};
|
|
109
|
+
});
|
|
110
|
+
export const areAddressPointsSynced = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const result = yield getKnexDb().count("*", { as: "countAll" }).from("address_point").first();
|
|
112
|
+
return Number(result.countAll) >= 2900000; // total is almost 3 million
|
|
113
|
+
});
|
|
97
114
|
const addressPointSelect = `
|
|
98
115
|
SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
99
116
|
a.orientational_number, a.orientational_number_letter, c.name AS city_name,
|
|
@@ -106,29 +123,27 @@ const addressPointSelect = `
|
|
|
106
123
|
LEFT JOIN city_district d ON a.city_district_code = d.code
|
|
107
124
|
LEFT JOIN prague_district p ON a.prague_district_code = p.code
|
|
108
125
|
LEFT JOIN municipality_part m ON a.municipality_part_code = m.code`;
|
|
109
|
-
export const getAddressPointById = (addressPointId) => {
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
WHERE a.id =
|
|
113
|
-
const row = statement.get(addressPointId);
|
|
126
|
+
export const getAddressPointById = (addressPointId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
const knex = getKnexDb();
|
|
128
|
+
const row = yield knex.raw(`${addressPointSelect}
|
|
129
|
+
WHERE a.id = ?`, [addressPointId]);
|
|
114
130
|
if (!row) {
|
|
115
131
|
return null;
|
|
116
132
|
}
|
|
117
133
|
return rowToAddressPoint(row);
|
|
118
|
-
};
|
|
134
|
+
});
|
|
119
135
|
let lastFounder = null;
|
|
120
136
|
let allStreets = [];
|
|
121
|
-
export const checkStreetExists = (streetName, founder) => {
|
|
122
|
-
const
|
|
137
|
+
export const checkStreetExists = (streetName, founder) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
+
const knex = getKnexDb();
|
|
123
139
|
const errors = [];
|
|
124
140
|
// we check the whole city
|
|
125
|
-
const cityCode = getFounderCityCode(founder);
|
|
126
|
-
const
|
|
127
|
-
SELECT name AS street_name
|
|
141
|
+
const cityCode = yield getFounderCityCode(founder);
|
|
142
|
+
const rowList = yield knex.raw(`SELECT name AS street_name
|
|
128
143
|
FROM street
|
|
129
|
-
WHERE city_code = ? AND name = ? COLLATE NOCASE
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
WHERE city_code = ? AND name = ? ${isSqlite() ? "COLLATE NOCASE" : ""}`, [cityCode, streetName]);
|
|
145
|
+
if (rowList.length > 0) {
|
|
146
|
+
const row = rowList[0];
|
|
132
147
|
if (row.street_name !== streetName) {
|
|
133
148
|
// errors.push(
|
|
134
149
|
// `Street '${streetName}' has wrong case, correct case: '${row.street_name}'.`
|
|
@@ -137,7 +152,7 @@ export const checkStreetExists = (streetName, founder) => {
|
|
|
137
152
|
return { exists: true, errors };
|
|
138
153
|
}
|
|
139
154
|
if (lastFounder !== founder) {
|
|
140
|
-
allStreets = getAllStreets(cityCode);
|
|
155
|
+
allStreets = yield getAllStreets(cityCode);
|
|
141
156
|
lastFounder = founder;
|
|
142
157
|
}
|
|
143
158
|
const match = allStreets.find((s) => s.toLocaleLowerCase("cs-CZ") === streetName.toLocaleLowerCase("cs-CZ"));
|
|
@@ -160,23 +175,23 @@ export const checkStreetExists = (streetName, founder) => {
|
|
|
160
175
|
});
|
|
161
176
|
}
|
|
162
177
|
return { exists: false, errors };
|
|
163
|
-
};
|
|
164
|
-
const getAllStreets = (cityCode) => {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
});
|
|
179
|
+
const getAllStreets = (cityCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
+
const knex = getKnexDb();
|
|
181
|
+
return yield knex
|
|
182
|
+
.pluck("name")
|
|
183
|
+
.from("street")
|
|
184
|
+
.where("city_code", cityCode);
|
|
185
|
+
});
|
|
186
|
+
export const findAddressPoints = (smdLine, municipality) => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
const knex = getKnexDb();
|
|
188
|
+
const params = isWholeMunicipalitySmdLine(smdLine)
|
|
189
|
+
? [municipality.code]
|
|
190
|
+
: [smdLine.street, municipality.code];
|
|
175
191
|
const streetJoinCondition = isWholeMunicipalitySmdLine(smdLine)
|
|
176
192
|
? "LEFT JOIN street s ON a.street_code = s.code"
|
|
177
|
-
:
|
|
178
|
-
const
|
|
179
|
-
SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
193
|
+
: `JOIN street s ON a.street_code = s.code AND s.name = ? ${isSqlite() ? "COLLATE NOCASE" : ""}`;
|
|
194
|
+
const queryResult = yield knex.raw(`SELECT a.id, s.name AS street_name, o.name AS object_type_name, a.descriptive_number,
|
|
180
195
|
a.orientational_number, a.orientational_number_letter, c.name AS city_name,
|
|
181
196
|
d.name AS district_name, m.name AS municipality_part_name, p.name AS prague_district_name,
|
|
182
197
|
a.postal_code, a.wgs84_latitude, a.wgs84_longitude
|
|
@@ -187,11 +202,8 @@ export const findAddressPoints = (smdLine, municipality) => {
|
|
|
187
202
|
LEFT JOIN city_district d ON a.city_district_code = d.code
|
|
188
203
|
LEFT JOIN municipality_part m ON a.municipality_part_code = m.code
|
|
189
204
|
LEFT JOIN prague_district p ON a.prague_district_code = p.code
|
|
190
|
-
WHERE ${getMunicipalityWhere("a", municipality)}
|
|
191
|
-
const
|
|
192
|
-
? [municipality.code]
|
|
193
|
-
: [smdLine.street, municipality.code];
|
|
194
|
-
const filteredAddressPoints = statement.all(...params).map(rowToAddressPoint);
|
|
205
|
+
WHERE ${getMunicipalityWhere("a", municipality)}`, params);
|
|
206
|
+
const filteredAddressPoints = queryResult.map(rowToAddressPoint);
|
|
195
207
|
if (isWholeMunicipalitySmdLine(smdLine)) {
|
|
196
208
|
return filteredAddressPoints;
|
|
197
209
|
}
|
|
@@ -212,7 +224,7 @@ export const findAddressPoints = (smdLine, municipality) => {
|
|
|
212
224
|
result.push(...filteredAddressPoints.filter((addressPoint) => !toExclude.includes(addressPoint)));
|
|
213
225
|
}
|
|
214
226
|
return result;
|
|
215
|
-
};
|
|
227
|
+
});
|
|
216
228
|
const filterAddressPointsByRanges = (addressPoints, seriesSpec) => {
|
|
217
229
|
const result = [];
|
|
218
230
|
seriesSpec.ranges.forEach((range) => {
|
package/dist/db/db.d.ts
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Knex } from "knex";
|
|
2
2
|
interface DbConfig {
|
|
3
|
-
|
|
3
|
+
dbType: SupportedDbType;
|
|
4
|
+
pgConnectionString?: string;
|
|
5
|
+
initFilePath: string;
|
|
4
6
|
filePath?: string;
|
|
5
|
-
verbose
|
|
7
|
+
verbose: boolean;
|
|
6
8
|
}
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
+
export declare enum SupportedDbType {
|
|
10
|
+
sqlite = "sqlite",
|
|
11
|
+
postgres = "postgres"
|
|
12
|
+
}
|
|
13
|
+
export declare const getKnexDb: (config?: Partial<DbConfig>) => Knex;
|
|
14
|
+
export declare const isPostgres: () => boolean;
|
|
15
|
+
export declare const isSqlite: () => boolean;
|
|
16
|
+
export declare const initDb: (config?: Partial<DbConfig>) => Promise<Knex>;
|
|
17
|
+
export declare const clearDb: (config?: Partial<DbConfig>) => Promise<Knex>;
|
|
18
|
+
export declare const disconnectKnex: () => Promise<void>;
|
|
9
19
|
export declare const nonEmptyOrNull: (value: string) => string | null;
|
|
10
20
|
/**
|
|
11
21
|
* Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
|
|
12
22
|
* column should be unique (PK or UNIQUE).
|
|
13
23
|
*/
|
|
14
|
-
export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicatesByFirstColumn?: boolean) => number
|
|
24
|
+
export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicatesByFirstColumn?: boolean) => Promise<number>;
|
|
15
25
|
/**
|
|
16
26
|
* Insert a single row and return the autoincremented ID.
|
|
17
27
|
*/
|
|
18
|
-
export declare const insertAutoincrementRow: (row: string[], table: string, columnNames: string[]) => number | null
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const clearDuplicates: (rows: string[][], table: string, columnNames: string[]) => string[][]
|
|
21
|
-
export declare const disconnect: () => void;
|
|
28
|
+
export declare const insertAutoincrementRow: (row: string[], table: string, columnNames: string[]) => Promise<number | null>;
|
|
29
|
+
export declare const deleteMultipleRowsKnex: (keys: string[], table: string, keyColumnName: string) => Promise<void>;
|
|
30
|
+
export declare const clearDuplicates: (rows: string[][], table: string, columnNames: string[]) => Promise<string[][]>;
|
|
22
31
|
export declare const generatePlaceholders: (n: number) => string;
|
|
23
32
|
export declare const generate2DPlaceholders: (inner: number, outer: number) => string;
|
|
24
33
|
export declare const extractKeyValuesPairs: (array: string[][], keyIndex: number, valuesIndices: number[]) => string[][];
|