text-to-map 1.1.5 → 1.1.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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
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, getKnexDb } from "../db/db";
11
+ function main() {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const knex = getKnexDb();
14
+ yield knex.schema.alterTable("school_founder", (table) => {
15
+ table.unique(["school_izo", "founder_id"]);
16
+ });
17
+ yield disconnectKnex();
18
+ });
19
+ }
20
+ main();
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[], preventDuplicates?: boolean, keyColumns?: string[]) => Promise<number>;
24
+ export declare const insertMultipleRows: (rows: string[][], table: string, columnNames: string[], preventDuplicates?: boolean) => 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
@@ -41,7 +41,7 @@ export const getKnexDb = (config = {}) => {
41
41
  },
42
42
  pool: {
43
43
  afterCreate: (db, done) => {
44
- db.pragma('journal_mode = WAL;');
44
+ db.pragma("journal_mode = WAL;");
45
45
  done(false, done);
46
46
  },
47
47
  },
@@ -115,23 +115,12 @@ export const nonEmptyOrNull = (value) => {
115
115
  * Efficiently insert multiple rows. If preventDuplicatesByFirstColumn is true, the first
116
116
  * column should be unique (PK or UNIQUE).
117
117
  */
118
- export const insertMultipleRows = (rows, table, columnNames, preventDuplicates = true, keyColumns = []) => __awaiter(void 0, void 0, void 0, function* () {
118
+ export const insertMultipleRows = (rows, table, columnNames, preventDuplicates = true) => __awaiter(void 0, void 0, void 0, function* () {
119
119
  if (rows.length === 0) {
120
120
  return 0;
121
121
  }
122
- // if (preventDuplicatesByFirstColumn) {
123
- // rows = await clearDuplicates(rows, table, columnNames);
124
- // if (rows.length === 0) {
125
- // return 0;
126
- // }
127
- // }
128
122
  const insertPlaceholders = generate2DPlaceholders(columnNames.length, rows.length);
129
- if (preventDuplicates && keyColumns.length === 0) {
130
- keyColumns = [columnNames[0]];
131
- }
132
- const onConfict = preventDuplicates
133
- ? `ON CONFLICT (${keyColumns.join(", ")}) DO NOTHING`
134
- : "";
123
+ const onConfict = preventDuplicates ? `ON CONFLICT DO NOTHING` : "";
135
124
  yield getKnexDb().raw(`INSERT INTO ${table} (${columnNames.join(",")}) VALUES ${insertPlaceholders} ${onConfict}`, rows.flat());
136
125
  return rows.length;
137
126
  });
@@ -152,14 +141,6 @@ export const deleteMultipleRowsKnex = (keys, table, keyColumnName) => __awaiter(
152
141
  }
153
142
  yield getKnexDb().from(table).whereIn(keyColumnName, keys).del();
154
143
  });
155
- export const clearDuplicates = (rows, table, columnNames) => __awaiter(void 0, void 0, void 0, function* () {
156
- const existing = yield getKnexDb()
157
- .select(columnNames[0])
158
- .from(table)
159
- .whereIn(columnNames[0], rows.map((row) => row[0]));
160
- const keys = existing.map((row) => row[columnNames[0]].toString());
161
- return rows.filter((row) => !keys.includes(row[0]));
162
- });
163
144
  const generateRepetitiveString = (value, glue, n) => {
164
145
  return new Array(n).fill(value).join(glue);
165
146
  };
@@ -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"], true, ["school_izo", "founder_id"]);
89
+ const insertedConnections = yield insertMultipleRows(schoolFounderConnectionData, "school_founder", ["school_izo", "founder_id"], true);
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();
@@ -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"], true, ["school_izo", "address_point_id"]);
41
+ insertedLocations += yield insertMultipleRows([location], "school_location", ["school_izo", "address_point_id"], true);
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.5",
56
+ "version": "1.1.7",
57
57
  "main": "dist/index.js",
58
58
  "types": "dist/index.d.ts",
59
59
  "files": [