text-to-map 1.1.17 → 1.1.18

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.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { readFileSync, writeFileSync } from "fs";
11
- import { getNewMunicipality, parseOrdinanceToAddressPoints, } from "../street-markdown/smd";
11
+ import { getNewMunicipalityByName, parseOrdinanceToAddressPoints, } from "../street-markdown/smd";
12
12
  function main() {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  // take first node argument as a file name
@@ -35,7 +35,7 @@ function main() {
35
35
  warningCount++;
36
36
  };
37
37
  console.time("downloadAndImportAllLatestAddressPoints");
38
- const { municipality } = yield getNewMunicipality("Česká Lípa");
38
+ const { municipality } = yield getNewMunicipalityByName("Česká Lípa");
39
39
  const addressPoints = yield parseOrdinanceToAddressPoints(lines, {
40
40
  // currentMunicipality: municipality,
41
41
  }, reportErrors, reportWarnings);
@@ -1,6 +1,10 @@
1
1
  import { DbMunicipalityResult, MunicipalityPartResult, SmdError } from "../street-markdown/types";
2
2
  import { Founder, MunicipalityType } from "./types";
3
3
  export declare const insertFounders: (founders: Founder[]) => Promise<number>;
4
+ export declare const getFounderById: (id: number) => Promise<{
5
+ founder: Founder;
6
+ errors: SmdError[];
7
+ }>;
4
8
  export declare const findFounder: (nameWithHashtag: string) => Promise<{
5
9
  founder: Founder;
6
10
  errors: SmdError[];
@@ -223,14 +223,27 @@ const extractFounderName = (line) => {
223
223
  return line.trim();
224
224
  }
225
225
  };
226
- export const findFounder = (nameWithHashtag) => __awaiter(void 0, void 0, void 0, function* () {
227
- const errors = [];
228
- const name = extractFounderName(nameWithHashtag);
229
- const result = yield getKnexDb()
226
+ const getBaseFounderQuery = () => {
227
+ return getKnexDb()
230
228
  .select("f.id", "f.name", "f.ico", "f.founder_type_code", "f.city_code", "f.city_district_code")
231
229
  .from("founder as f")
232
230
  .leftJoin("city as c", "c.code", "f.city_code")
233
- .leftJoin("city_district as d", "d.code", "f.city_district_code")
231
+ .leftJoin("city_district as d", "d.code", "f.city_district_code");
232
+ };
233
+ export const getFounderById = (id) => __awaiter(void 0, void 0, void 0, function* () {
234
+ const result = yield getBaseFounderQuery().where("f.id", id).first();
235
+ const founder = yield resultToFounder(result);
236
+ return {
237
+ founder: founder !== null && founder !== void 0 ? founder : null,
238
+ errors: founder
239
+ ? []
240
+ : [wholeLineError(`Zřizovatel s id ${id} neexistuje.`, "")],
241
+ };
242
+ });
243
+ export const findFounder = (nameWithHashtag) => __awaiter(void 0, void 0, void 0, function* () {
244
+ const errors = [];
245
+ const name = extractFounderName(nameWithHashtag);
246
+ const result = yield getBaseFounderQuery()
234
247
  .where("f.name", name)
235
248
  .orWhere("c.name", name)
236
249
  .orWhere("d.name", name)
@@ -2,7 +2,11 @@ import { Founder } from "../db/types";
2
2
  import { ErrorCallbackParams, Municipality, MunicipalityWithFounder, ProcessLineCallbackParams, School, SmdError, SmdState } from "./types";
3
3
  export declare const parseOrdinanceToAddressPoints: (lines: string[], initialState?: Partial<SmdState>, onError?: (params: ErrorCallbackParams) => void, onWarning?: (params: ErrorCallbackParams) => void, onProcessedLine?: (params: ProcessLineCallbackParams) => void) => Promise<Municipality[]>;
4
4
  export declare const convertMunicipality: (municipality: MunicipalityWithFounder) => Municipality;
5
- export declare const getNewMunicipality: (name: string) => Promise<{
5
+ export declare const getNewMunicipalityByName: (name: string) => Promise<{
6
+ municipality: MunicipalityWithFounder;
7
+ errors: SmdError[];
8
+ }>;
9
+ export declare const getNewMunicipalityByFounderId: (founderId: number) => Promise<{
6
10
  municipality: MunicipalityWithFounder;
7
11
  errors: SmdError[];
8
12
  }>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { checkStreetExists, findAddressPoints, getAddressPointById, } from "../db/address-points";
11
11
  import { disconnectKnex } from "../db/db";
12
- import { findFounder } from "../db/founders";
12
+ import { findFounder, getFounderById } from "../db/founders";
13
13
  import { findSchool } from "../db/schools";
14
14
  import { founderToMunicipality } from "../db/types";
15
15
  import { getMunicipalityPartResult, getRestOfMunicipalityPart, getSwitchMunicipality, getWholeMunicipality, isMunicipalitySwitch, isRestOfMunicipalityLine, isRestOfMunicipalityPartLine, isRestWithNoStreetNameLine, isWholeMunicipality, } from "./municipality";
@@ -115,7 +115,7 @@ const processMunicipalityLine = ({ line, lineNumber, state, onError, }) => __awa
115
115
  state.currentSchool = null;
116
116
  }
117
117
  yield completeCurrentMunicipality(state);
118
- const { municipality, errors } = yield getNewMunicipality(line);
118
+ const { municipality, errors } = yield getNewMunicipalityByName(line);
119
119
  if (errors.length > 0) {
120
120
  onError({ lineNumber, line, errors });
121
121
  }
@@ -262,16 +262,21 @@ const addRestOfMunicipalityPart = (state, municipalityPartCode, schoolIzo) => __
262
262
  });
263
263
  yield addRestToSchool(allPoints, schoolIzo, state);
264
264
  });
265
- export const getNewMunicipality = (name) => __awaiter(void 0, void 0, void 0, function* () {
265
+ export const getNewMunicipalityByName = (name) => __awaiter(void 0, void 0, void 0, function* () {
266
266
  const { founder, errors } = yield findFounder(name);
267
- return {
268
- municipality: {
269
- municipalityName: founder ? founder.name : "Neznámá obec",
270
- founder,
271
- schools: [],
272
- },
273
- errors,
274
- };
267
+ return getNewMunicipality(founder, errors);
268
+ });
269
+ export const getNewMunicipalityByFounderId = (founderId) => __awaiter(void 0, void 0, void 0, function* () {
270
+ const { founder, errors } = yield getFounderById(founderId);
271
+ return getNewMunicipality(founder, errors);
272
+ });
273
+ const getNewMunicipality = (founder, errors) => ({
274
+ municipality: {
275
+ municipalityName: founder ? founder.name : "Neznámá obec",
276
+ founder,
277
+ schools: [],
278
+ },
279
+ errors,
275
280
  });
276
281
  export const getNewSchool = (name, founder, lineNumber, onError) => __awaiter(void 0, void 0, void 0, function* () {
277
282
  let exportSchool = {
package/package.json CHANGED
@@ -57,7 +57,7 @@
57
57
  },
58
58
  "name": "text-to-map",
59
59
  "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.",
60
- "version": "1.1.17",
60
+ "version": "1.1.18",
61
61
  "main": "dist/index.js",
62
62
  "types": "dist/index.d.ts",
63
63
  "files": [