text-to-map 1.1.4 → 1.1.6

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/db/db.d.ts CHANGED
@@ -21,13 +21,12 @@ export declare const nonEmptyOrNull: (value: string) => string | null;
21
21
  * Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
22
22
  * column should be unique (PK or UNIQUE).
23
23
  */
24
- export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicatesByFirstColumn?: boolean) => Promise<number>;
24
+ export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicates?: boolean, keyColumns?: string[]) => Promise<number>;
25
25
  /**
26
26
  * Insert a single row and return the autoincremented ID.
27
27
  */
28
28
  export declare const insertAutoincrementRow: (row: any[], table: string, columnNames: string[]) => Promise<number | null>;
29
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[][]>;
31
30
  export declare const generatePlaceholders: (n: number) => string;
32
31
  export declare const generate2DPlaceholders: (inner: number, outer: number) => string;
33
32
  export declare const extractKeyValuesPairs: (array: string[][], keyIndex: number, valuesIndices: number[]) => string[][];
package/dist/db/db.js CHANGED
@@ -39,6 +39,12 @@ export const getKnexDb = (config = {}) => {
39
39
  connection: {
40
40
  filename: _knexDbConfig.filePath,
41
41
  },
42
+ pool: {
43
+ afterCreate: (db, done) => {
44
+ db.pragma("journal_mode = WAL;");
45
+ done(false, done);
46
+ },
47
+ },
42
48
  useNullAsDefault: true,
43
49
  debug: _knexDbConfig.verbose,
44
50
  });
@@ -109,19 +115,16 @@ export const nonEmptyOrNull = (value) => {
109
115
  * Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
110
116
  * column should be unique (PK or UNIQUE).
111
117
  */
112
- export const insertMultipleRows = (rows, table, columnNames, preventDuplicatesByFirstColumn = true) => __awaiter(void 0, void 0, void 0, function* () {
118
+ export const insertMultipleRows = (rows, table, columnNames, preventDuplicates = true, keyColumns = []) => __awaiter(void 0, void 0, void 0, function* () {
113
119
  if (rows.length === 0) {
114
120
  return 0;
115
121
  }
116
- // if (preventDuplicatesByFirstColumn) {
117
- // rows = await clearDuplicates(rows, table, columnNames);
118
- // if (rows.length === 0) {
119
- // return 0;
120
- // }
121
- // }
122
122
  const insertPlaceholders = generate2DPlaceholders(columnNames.length, rows.length);
123
- const onConfict = preventDuplicatesByFirstColumn
124
- ? `ON CONFLICT (${columnNames[0]}) DO NOTHING`
123
+ if (preventDuplicates && keyColumns.length === 0) {
124
+ keyColumns = [columnNames[0]];
125
+ }
126
+ const onConfict = preventDuplicates
127
+ ? `ON CONFLICT (${keyColumns.join(", ")}) DO NOTHING`
125
128
  : "";
126
129
  yield getKnexDb().raw(`INSERT INTO ${table} (${columnNames.join(",")}) VALUES ${insertPlaceholders} ${onConfict}`, rows.flat());
127
130
  return rows.length;
@@ -143,14 +146,6 @@ export const deleteMultipleRowsKnex = (keys, table, keyColumnName) => __awaiter(
143
146
  }
144
147
  yield getKnexDb().from(table).whereIn(keyColumnName, keys).del();
145
148
  });
146
- export const clearDuplicates = (rows, table, columnNames) => __awaiter(void 0, void 0, void 0, function* () {
147
- const existing = yield getKnexDb()
148
- .select(columnNames[0])
149
- .from(table)
150
- .whereIn(columnNames[0], rows.map((row) => row[0]));
151
- const keys = existing.map((row) => row[columnNames[0]].toString());
152
- return rows.filter((row) => !keys.includes(row[0]));
153
- });
154
149
  const generateRepetitiveString = (value, glue, n) => {
155
150
  return new Array(n).fill(value).join(glue);
156
151
  };
@@ -15,7 +15,7 @@ import { MunicipalityType, } from "./types";
15
15
  const cityTypeCode = 261;
16
16
  const cityDistrictTypeCode = 263;
17
17
  export const insertFounders = (founders) => __awaiter(void 0, void 0, void 0, function* () {
18
- var _a;
18
+ var _a, _b, _c;
19
19
  let insertedFounders = 0;
20
20
  const schoolFounderConnectionData = [];
21
21
  for (const founder of founders) {
@@ -63,8 +63,9 @@ export const insertFounders = (founders) => __awaiter(void 0, void 0, void 0, fu
63
63
  name: sanitizeMunicipalityName(founder.name),
64
64
  ico: founder.ico,
65
65
  });
66
+ let founderId = (_c = (_b = existing[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null;
66
67
  if (existing.length === 0) {
67
- const founderId = yield insertAutoincrementRow([
68
+ founderId = yield insertAutoincrementRow([
68
69
  sanitizeMunicipalityName(founder.name),
69
70
  sanitizeMunicipalityName(extractedMunicipalityName),
70
71
  founder.ico,
@@ -80,12 +81,12 @@ export const insertFounders = (founders) => __awaiter(void 0, void 0, void 0, fu
80
81
  "city_district_code",
81
82
  ]);
82
83
  insertedFounders++;
83
- founder.schools.forEach((school) => {
84
- schoolFounderConnectionData.push([school.izo, founderId]);
85
- });
86
84
  }
85
+ founder.schools.forEach((school) => {
86
+ schoolFounderConnectionData.push([school.izo, founderId]);
87
+ });
87
88
  }
88
- const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"]);
89
+ const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"], true, ["school_izo", "founder_id"]);
89
90
  return insertedFounders + insertedConnections;
90
91
  });
91
92
  const getCityOfSchool = (izo) => __awaiter(void 0, void 0, void 0, function* () {
@@ -174,14 +175,14 @@ const fixFounderProblems = (founder, municipalityCode, differingSchools, extract
174
175
  }
175
176
  });
176
177
  const getCityCodeByDistrictCode = (districtCode) => __awaiter(void 0, void 0, void 0, function* () {
177
- var _b;
178
+ var _d;
178
179
  const result = yield getKnexDb()
179
180
  .first("city.code")
180
181
  .from("city_district")
181
182
  .join("city", "city_district.city_code", "city.code")
182
183
  .where("city_district.code", districtCode)
183
184
  .limit(1);
184
- return (_b = result === null || result === void 0 ? void 0 : result.code) !== null && _b !== void 0 ? _b : null;
185
+ return (_d = result === null || result === void 0 ? void 0 : result.code) !== null && _d !== void 0 ? _d : null;
185
186
  });
186
187
  const findMunicipalitiesAndPositionsByNameAndType = (name, type) => __awaiter(void 0, void 0, void 0, function* () {
187
188
  const knex = getKnexDb();
@@ -126,6 +126,7 @@ export function up(knex) {
126
126
  .references("id")
127
127
  .inTable("founder")
128
128
  .notNullable();
129
+ table_13.unique(["school_izo", "founder_id"]);
129
130
  });
130
131
  yield knex.schema.createTable("address_point", function (table) {
131
132
  table.increments("id");
@@ -38,7 +38,7 @@ export const insertSchools = (schools) => __awaiter(void 0, void 0, void 0, func
38
38
  // plus filter out duplicate locations (same address id + izo)
39
39
  for (const location of locations) {
40
40
  try {
41
- insertedLocations += yield insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], false);
41
+ insertedLocations += yield insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], true, ["school_izo", "address_point_id"]);
42
42
  }
43
43
  catch (error) {
44
44
  console.log(`Cannot add location with RUIAN code ${location[1]} (school IZO = ${location[0]}): code does not exist.`);
@@ -1,3 +1,3 @@
1
1
  import { OpenDataSyncOptionsPartial } from "../utils/helpers";
2
- export declare const downloadAndImportSchools: (options: OpenDataSyncOptionsPartial, saveFoundersToCsv?: boolean, saveSchoolsWithoutRuianToCsv?: boolean) => Promise<void>;
2
+ export declare const downloadAndImportSchools: (options?: OpenDataSyncOptionsPartial, saveFoundersToCsv?: boolean, saveSchoolsWithoutRuianToCsv?: boolean) => Promise<void>;
3
3
  export declare const deleteSchoolsXmlFile: (options?: OpenDataSyncOptionsPartial) => void;
@@ -299,7 +299,7 @@ const importDataToDb = (options, saveFoundersToCsv = false, saveSchoolsWithoutRu
299
299
  const getXmlFilePath = (options) => {
300
300
  return join(options.tmpDir, options.schoolsXmlFileName);
301
301
  };
302
- export const downloadAndImportSchools = (options, saveFoundersToCsv = false, saveSchoolsWithoutRuianToCsv = false) => __awaiter(void 0, void 0, void 0, function* () {
302
+ export const downloadAndImportSchools = (options = {}, saveFoundersToCsv = false, saveSchoolsWithoutRuianToCsv = false) => __awaiter(void 0, void 0, void 0, function* () {
303
303
  yield runSyncPart(SyncPart.Schools, [SyncPart.AddressPoints], () => __awaiter(void 0, void 0, void 0, function* () {
304
304
  const runOptions = prepareOptions(options);
305
305
  yield downloadXml(runOptions);
@@ -1,2 +1,2 @@
1
1
  import { OpenDataSyncOptionsPartial } from "../utils/helpers";
2
- export declare const downloadAndImportStreets: (options: OpenDataSyncOptionsPartial) => Promise<void>;
2
+ export declare const downloadAndImportStreets: (options?: OpenDataSyncOptionsPartial) => Promise<void>;
@@ -47,7 +47,7 @@ const importDataToDb = (data) => __awaiter(void 0, void 0, void 0, function* ()
47
47
  }
48
48
  yield insertStreetsFromDbf(data);
49
49
  });
50
- export const downloadAndImportStreets = (options) => __awaiter(void 0, void 0, void 0, function* () {
50
+ export const downloadAndImportStreets = (options = {}) => __awaiter(void 0, void 0, void 0, function* () {
51
51
  yield runSyncPart(SyncPart.Streets, [SyncPart.AddressPoints], () => __awaiter(void 0, void 0, void 0, function* () {
52
52
  console.log("Starting to download and import streets. This takes up to 1 hour.");
53
53
  const completeOptions = prepareOptions(options);
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "name": "text-to-map",
55
55
  "description": "Text To Map usiluje o lepší, strojově zpracovatelné využití částí vyhlášek s výčtem ulic a dalších lokací. Jde o rozšiřitelnou sadu konceptů a nástrojů, které zajistí hladký převod výčtu ulic a jejich rozsahů v lidsky srozumitelném jazyce do strojově zpracovatelného, uchopitelného formátu.",
56
- "version": "1.1.4",
56
+ "version": "1.1.6",
57
57
  "main": "dist/index.js",
58
58
  "types": "dist/index.d.ts",
59
59
  "files": [