@fin.cx/opendata 1.2.0 → 1.4.4

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.
@@ -1,12 +1,17 @@
1
+ import type { BusinessRecord } from './classes.businessrecord.js';
1
2
  import type { OpenData } from './classes.main.opendata.js';
2
3
  import * as plugins from './plugins.js';
4
+ import * as paths from './paths.js';
3
5
 
4
6
  /**
5
7
  * the HandlesRegister exposed as a class
6
8
  */
7
9
  export class HandelsRegister {
8
10
  private openDataRef: OpenData;
11
+ private asyncExecutionStack = new plugins.lik.AsyncExecutionStack();
12
+ private uniqueDowloadFolder = plugins.path.join(paths.downloadDir, plugins.smartunique.uniSimple());
9
13
 
14
+ // Puppeteer wrapper instance
10
15
  public smartbrowserInstance = new plugins.smartbrowser.SmartBrowser();
11
16
 
12
17
  constructor(openDataRef: OpenData) {
@@ -14,96 +19,72 @@ export class HandelsRegister {
14
19
  }
15
20
 
16
21
  public async start() {
22
+ // Start the browser
23
+ await plugins.smartfile.fs.ensureDir(this.uniqueDowloadFolder);
17
24
  await this.smartbrowserInstance.start();
18
25
  }
19
26
 
20
27
  public async stop() {
28
+ // Stop the browser
29
+ await plugins.smartfile.fs.remove(this.uniqueDowloadFolder);
21
30
  await this.smartbrowserInstance.stop();
22
31
  }
23
32
 
24
33
  /**
25
- * Search for a company by name
34
+ * Creates a new page and configures it to allow file downloads
35
+ * to a predefined path.
26
36
  */
27
- public async getDataForCompany(companyNameArg: string) {
37
+ public getNewPage = async () => {
28
38
  const page = await this.smartbrowserInstance.headlessBrowser.newPage();
29
- await page.setViewport({ width: 1920, height: 1080 });
30
- await page.goto('https://www.handelsregister.de/');
31
- await page.evaluate(() => {
32
- const elements = Array.from(document.querySelectorAll('.ui-menuitem-text > span'));
33
- const targetElement = elements.find((el) => el.textContent?.trim() === 'Normal search');
34
- if (targetElement) {
35
- (targetElement as HTMLElement).click();
36
- }
37
- });
38
39
 
39
- try {
40
- // Wait for the textarea to appear
41
- await page.waitForSelector('#form\\:schlagwoerter', { timeout: 5000 });
40
+ // 1) Create a DevTools session for this page
41
+ const cdpSession = await page.target().createCDPSession();
42
42
 
43
- // Enter text into the textarea using page.evaluate
44
- const inputText = companyNameArg;
45
- await page.evaluate((text) => {
46
- const textarea = document.querySelector<HTMLTextAreaElement>('#form\\:schlagwoerter');
47
- if (textarea) {
48
- textarea.value = text; // Set the value
49
- // Trigger the change event manually if required
50
- const event = new Event('change', { bubbles: true });
51
- textarea.dispatchEvent(event);
52
- }
53
- }, inputText);
43
+ // 2) Allow file downloads and set the download path
44
+ await cdpSession.send('Page.setDownloadBehavior', {
45
+ behavior: 'allow',
46
+ downloadPath: this.uniqueDowloadFolder, // <-- Change this to your desired absolute path
47
+ });
54
48
 
55
- console.log('Text entered successfully!');
56
- } catch (error) {
57
- console.error('Failed to find or enter text into the textarea:', error);
58
- }
49
+ // Optionally set viewport and go to page
50
+ await page.setViewport({ width: 1920, height: 1080 });
51
+ await page.goto('https://www.handelsregister.de/');
52
+ return page;
53
+ };
59
54
 
55
+ private navigateToPage = async (
56
+ pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page,
57
+ pageNameArg: string
58
+ ) => {
60
59
  try {
61
- // Wait for the radio button's label to appear
62
- await page.waitForSelector('label[for="form:schlagwortOptionen:0"]', { timeout: 5000 });
63
-
64
- // Click the label to select the radio button
65
- await page.evaluate(() => {
66
- const label = document.querySelector<HTMLLabelElement>(
67
- 'label[for="form:schlagwortOptionen:0"]'
68
- );
69
- if (label) {
70
- label.click();
60
+ await pageArg.evaluate((pageNameArg2) => {
61
+ const elements = Array.from(document.querySelectorAll('.ui-menuitem-text > span'));
62
+ const targetElement = elements.find((el) => el.textContent?.trim() === pageNameArg2);
63
+ if (targetElement) {
64
+ (targetElement as HTMLElement).click();
71
65
  }
72
- });
73
-
74
- console.log('Radio button clicked successfully!');
66
+ }, pageNameArg);
67
+ console.log(`Navigated to the ${pageNameArg} page successfully.`);
75
68
  } catch (error) {
76
- console.error('Failed to find or click the radio button:', error);
69
+ console.error(`Failed to navigate to the ${pageNameArg} page:`, error);
77
70
  }
71
+ };
78
72
 
79
- try {
80
- // Wait for the button with the text "Find" to appear
81
- await page.waitForSelector('span.ui-button-text.ui-c', { timeout: 5000 });
82
-
83
- // Locate and click the button using its text
84
- await page.evaluate(() => {
85
- const buttons = Array.from(document.querySelectorAll('span.ui-button-text.ui-c'));
86
- const targetButton = buttons.find((button) => button.textContent?.trim() === 'Find');
87
- if (targetButton) {
88
- const parentButton = targetButton.closest('button') || targetButton;
89
- (parentButton as HTMLElement).click();
90
- }
73
+ private waitForResults = async (pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page) => {
74
+ await pageArg
75
+ .waitForSelector('#ergebnissForm\\:selectedSuchErgebnisFormTable_data', {
76
+ timeout: 30000,
77
+ })
78
+ .catch(async (err) => {
79
+ await pageArg.screenshot({ path: paths.downloadDir + '/error.png' });
80
+ throw err;
91
81
  });
92
82
 
93
- console.log('Find button clicked successfully!');
94
- } catch (error) {
95
- console.error('Failed to find or click the "Find" button:', error);
96
- }
97
-
98
- await page.waitForSelector('#ergebnissForm\\:selectedSuchErgebnisFormTable_data', {
99
- timeout: 10000,
100
- });
101
-
102
- const businessRecords = await page.evaluate(() => {
83
+ const businessRecords: BusinessRecord['data'][] = await pageArg.evaluate(() => {
103
84
  const rows = document.querySelectorAll(
104
85
  '#ergebnissForm\\:selectedSuchErgebnisFormTable_data > tr'
105
86
  );
106
- const records = [];
87
+ const records: BusinessRecord['data'][] = [];
107
88
 
108
89
  rows.forEach((row) => {
109
90
  const nameElement = row.querySelector('td.ui-panelgrid-cell span.marginLeft20');
@@ -116,23 +97,262 @@ export class HandelsRegister {
116
97
  const name = nameElement?.textContent?.trim();
117
98
  const city = cityElement?.textContent?.trim();
118
99
  const status = statusElement?.textContent?.trim();
119
- const registrationCourt = registrationCourtElement?.textContent?.trim();
100
+ const registrationId = registrationCourtElement?.textContent?.trim();
120
101
 
121
102
  // Push parsed data into records array
122
103
  records.push({
123
104
  name,
124
105
  city,
125
- registrationCourt,
106
+ registrationId,
126
107
  businessType: status,
127
108
  });
128
109
  });
129
110
 
130
111
  return records;
131
112
  });
113
+ return businessRecords;
114
+ };
115
+
116
+ private clickFindButton = async (pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page, resultsLimitArg: number = 100) => {
117
+ try {
118
+ // Wait for the button with the text "Find" to appear
119
+ await pageArg.waitForSelector('span.ui-button-text.ui-c', { timeout: 5000 });
132
120
 
133
- await page.close();
121
+ // adjust to 100 results per page
122
+ await pageArg.select('#form\\:ergebnisseProSeite_input', `${resultsLimitArg}`);
134
123
 
135
- // Finally, we return an object, which triggers a JSON file download
136
- return businessRecords;
124
+ // Locate and click the button using its text
125
+ await pageArg.evaluate(() => {
126
+ const buttons = Array.from(document.querySelectorAll('span.ui-button-text.ui-c'));
127
+ const targetButton = buttons.find((button) => button.textContent?.trim() === 'Find');
128
+ if (targetButton) {
129
+ const parentButton = targetButton.closest('button') || targetButton;
130
+ (parentButton as HTMLElement).click();
131
+ }
132
+ });
133
+
134
+ console.log('Find button clicked successfully!');
135
+ } catch (error) {
136
+ console.error('Failed to find or click the "Find" button:', error);
137
+ }
138
+ };
139
+
140
+ private async downloadFile(
141
+ pageArg: plugins.smartbrowser.smartpuppeteer.puppeteer.Page,
142
+ typeArg: 'SI' | 'AD'
143
+ ) {
144
+ // Trigger the file download by clicking on the relevant link
145
+ await pageArg.evaluate((typeArg2) => {
146
+ // Locate the table body
147
+ const tableBody = document.querySelector(
148
+ '#ergebnissForm\\:selectedSuchErgebnisFormTable_data'
149
+ );
150
+ if (!tableBody) {
151
+ throw new Error('Table body not found');
152
+ }
153
+
154
+ // Locate the first row
155
+ const firstRow = tableBody.querySelector('tr:nth-child(1)');
156
+ if (!firstRow) {
157
+ throw new Error('First row not found');
158
+ }
159
+
160
+ // Locate the last cell in the first row
161
+ const lastCell = firstRow.querySelector('td:last-child');
162
+ if (!lastCell) {
163
+ throw new Error('Last cell not found in the first row');
164
+ }
165
+
166
+ // Locate the download links
167
+ const adLink = lastCell.querySelector('a:first-of-type');
168
+ const siLink = lastCell.querySelector('a:last-of-type');
169
+ if (!siLink) {
170
+ throw new Error('SI link not found in the last cell');
171
+ }
172
+
173
+ // Simulate a click on the last <a> element
174
+ switch (typeArg2) {
175
+ case 'AD':
176
+ (adLink as HTMLElement).click();
177
+ break;
178
+ case 'SI':
179
+ (siLink as HTMLElement).click();
180
+ break;
181
+ default:
182
+ throw new Error('Invalid file type');
183
+ }
184
+ }, typeArg);
185
+
186
+
187
+ await plugins.smartfile.fs.waitForFileToBeReady(this.uniqueDowloadFolder);
188
+
189
+ const files = await plugins.smartfile.fs.fileTreeToObject(this.uniqueDowloadFolder, '**/*');
190
+ const file = files[0];
191
+
192
+ // lets clear the folder for the next download
193
+ await plugins.smartfile.fs.ensureEmptyDir(this.uniqueDowloadFolder);
194
+ switch (typeArg) {
195
+ case 'AD':
196
+ await file.rename(`ad.pdf`);
197
+ break;
198
+ case 'SI':
199
+ await file.rename(`si.xml`);
200
+ break;
201
+ break;
202
+ }
203
+ return file;
204
+ }
205
+
206
+ /**
207
+ * Helper method to parse the German registration string
208
+ */
209
+ private async parseGermanRegistration(
210
+ input: string
211
+ ): Promise<BusinessRecord['data']['germanParsedRegistration']> {
212
+ // e.g. District court Berlin (Charlottenburg) HRB 123456
213
+ const regex =
214
+ /District court (\p{L}[\p{L}\s-]*?(?:\s*\([\p{L}\s-]+\))?)\s+(HRA|HRB|GnR|VR|PR|GsR)\s+(\d+)/u;
215
+ const match = input.match(regex);
216
+
217
+ if (match) {
218
+ return {
219
+ court: match[1],
220
+ type: match[2] as 'HRA' | 'HRB', // Adjust if needed
221
+ number: match[3],
222
+ };
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Search for a company by name and return basic info
228
+ */
229
+ public async searchCompany(companyNameArg: string, resultsLimitArg: number = 100) {
230
+ return this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
231
+ const page = await this.getNewPage();
232
+ await this.navigateToPage(page, 'Normal search');
233
+
234
+ try {
235
+ // Wait for the textarea to appear
236
+ await page.waitForSelector('#form\\:schlagwoerter', { timeout: 5000 });
237
+
238
+ // Enter text into the textarea
239
+ const inputText = companyNameArg;
240
+ await page.evaluate((text) => {
241
+ const textarea = document.querySelector<HTMLTextAreaElement>('#form\\:schlagwoerter');
242
+ if (textarea) {
243
+ textarea.value = text; // Set the value
244
+ // Trigger the change event manually if required
245
+ const event = new Event('change', { bubbles: true });
246
+ textarea.dispatchEvent(event);
247
+ }
248
+ }, inputText);
249
+
250
+ console.log('Text entered successfully!');
251
+ } catch (error) {
252
+ console.error('Failed to find or enter text into the textarea:', error);
253
+ }
254
+
255
+ try {
256
+ // Wait for the radio button's label to appear
257
+ await page.waitForSelector('label[for="form:schlagwortOptionen:0"]', { timeout: 5000 });
258
+
259
+ // Click the label to select the radio button
260
+ await page.evaluate(() => {
261
+ const label = document.querySelector<HTMLLabelElement>(
262
+ 'label[for="form:schlagwortOptionen:0"]'
263
+ );
264
+ if (label) {
265
+ label.click();
266
+ }
267
+ });
268
+
269
+ console.log('Radio button clicked successfully!');
270
+ } catch (error) {
271
+ console.error('Failed to find or click the radio button:', error);
272
+ }
273
+
274
+ await this.clickFindButton(page, resultsLimitArg);
275
+
276
+ const businessRecords = await this.waitForResults(page);
277
+
278
+ // Parse out the registration info
279
+ for (const record of businessRecords) {
280
+ if (record.registrationId) {
281
+ record.germanParsedRegistration = await this.parseGermanRegistration(
282
+ record.registrationId
283
+ );
284
+ }
285
+ }
286
+
287
+ await page.close();
288
+ return businessRecords;
289
+ }, 60000);
290
+ }
291
+
292
+ /**
293
+ * Search for a specific company (known register type/number/court),
294
+ * then click on an element that triggers a file download.
295
+ */
296
+ public async getSpecificCompany(companyArg: BusinessRecord['data']['germanParsedRegistration']) {
297
+ return this.asyncExecutionStack.getExclusiveExecutionSlot(async () => {
298
+ const page = await this.getNewPage();
299
+ await this.navigateToPage(page, 'Normal search');
300
+ await page.waitForSelector('#form\\:schlagwoerter', { timeout: 5000 });
301
+
302
+ // 1) Type of Register (e.g. HRB, HRA, etc.)
303
+ await page.waitForSelector('#form\\:registerArt_label');
304
+ await page.click('#form\\:registerArt_label');
305
+ await page.waitForSelector('#form\\:registerArt_items');
306
+ await page.evaluate((type) => {
307
+ const options = Array.from(document.querySelectorAll('#form\\:registerArt_items li'));
308
+ const targetOption = options.find((option) => option.textContent?.trim() === type);
309
+ (targetOption as HTMLElement)?.click();
310
+ }, companyArg.type);
311
+
312
+ // 2) Register number
313
+ await page.waitForSelector('#form\\:registerNummer');
314
+ await page.type('#form\\:registerNummer', companyArg.number);
315
+
316
+ // 3) Register court
317
+ await page.waitForSelector('#form\\:registergericht_label');
318
+ await page.click('#form\\:registergericht_label');
319
+ await page.waitForSelector('#form\\:registergericht_items');
320
+ await page.evaluate((court) => {
321
+ const options = Array.from(document.querySelectorAll('#form\\:registergericht_items li'));
322
+ const targetOption = options.find((option) => option.textContent?.trim() === court);
323
+ (targetOption as HTMLElement)?.click();
324
+ }, companyArg.court);
325
+
326
+ // Click 'Find'
327
+ await this.clickFindButton(page);
328
+
329
+ // Optionally grab the results, just for logging
330
+ const businessRecords = await this.waitForResults(page);
331
+ console.log(businessRecords);
332
+
333
+ const files: plugins.smartfile.SmartFile[] = [];
334
+
335
+ // download files
336
+ files.push(await this.downloadFile(page, 'SI'));
337
+ files.push(await this.downloadFile(page, 'AD'));
338
+
339
+ // At this point, the file should have been downloaded automatically
340
+ // to the path specified by `Page.setDownloadBehavior`
341
+ await page.close();
342
+
343
+ return {
344
+ businessRecords,
345
+ files,
346
+ };
347
+ }, 60000);
348
+ }
349
+
350
+ /**
351
+ * get specific company by full name
352
+ */
353
+ public async getSpecificCompanyByName(companyNameArg: string) {
354
+ const businessRecords = await this.searchCompany(companyNameArg, 1);
355
+ const result = this.getSpecificCompany(businessRecords[0].germanParsedRegistration);
356
+ return result;
137
357
  }
138
358
  }
@@ -2,16 +2,55 @@ import * as plugins from './plugins.js';
2
2
  import * as paths from './paths.js';
3
3
  import type { OpenData } from './classes.main.opendata.js';
4
4
 
5
- export class JsonlDataProcessor {
6
- public openDataRef: OpenData;
7
- constructor(openDataRefArg: OpenData) {
8
- this.openDataRef = openDataRefArg;
5
+ export type SeedEntryType = {
6
+ all_attributes: {
7
+ _registerArt: string;
8
+ _registerNummer: string;
9
+ additional_data: {
10
+ AD: boolean;
11
+ CD: boolean;
12
+ DK: boolean;
13
+ HD: boolean;
14
+ SI: boolean;
15
+ UT: boolean;
16
+ VÖ: boolean;
17
+ };
18
+ federal_state: string;
19
+ native_company_number: string;
20
+ registered_office: string;
21
+ registrar: string;
22
+ };
23
+ company_number: string;
24
+ current_status: string;
25
+ jurisdiction_code: string;
26
+ name: string;
27
+ officers: {
28
+ name: string;
29
+ other_attributes: {
30
+ city: string;
31
+ firstname: string;
32
+ flag: string;
33
+ lastname: string;
34
+ };
35
+ position: string;
36
+ start_date: string; // ISO 8601 date string
37
+ type: string;
38
+ }[];
39
+ registered_address: string;
40
+ retrieved_at: string; // ISO 8601 date string
41
+ };
42
+
43
+ export class JsonlDataProcessor<T> {
44
+ public forEachFunction: (entryArg: T) => Promise<void>;
45
+ constructor(forEachFunctionArg: typeof this.forEachFunction) {
46
+ this.forEachFunction = forEachFunctionArg;
9
47
  }
10
48
 
11
49
  // TODO: define a mapper as argument instead of hard-coding it
12
- public async processDataFromUrl(dataUrlArg = 'https://daten.offeneregister.de/de_companies_ocdata.jsonl.bz2') {
50
+ public async processDataFromUrl(
51
+ dataUrlArg = 'https://daten.offeneregister.de/de_companies_ocdata.jsonl.bz2'
52
+ ) {
13
53
  const done = plugins.smartpromise.defer();
14
- const promiseArray: Promise<any>[] = [];
15
54
  const dataExists = await plugins.smartfile.fs.isDirectory(paths.germanBusinessDataDir);
16
55
  if (!dataExists) {
17
56
  await plugins.smartfile.fs.ensureDir(paths.germanBusinessDataDir);
@@ -19,10 +58,6 @@ export class JsonlDataProcessor {
19
58
  }
20
59
 
21
60
  const smartarchive = await plugins.smartarchive.SmartArchive.fromArchiveUrl(dataUrlArg);
22
- promiseArray
23
- .push
24
- // smartarchive.exportToFs(paths.germanBusinessDataDir, 'de_companies_ocdata.jsonl')
25
- ();
26
61
  const jsonlDataStream = await smartarchive.exportToStreamOfStreamFiles();
27
62
  let totalRecordsCounter = 0;
28
63
  let nextRest: string = '';
@@ -39,42 +74,37 @@ export class JsonlDataProcessor {
39
74
  const lines = currentString.split('\n');
40
75
  nextRest = lines.pop();
41
76
  console.log(`Got another ${lines.length} records.`);
42
- for (const line of lines) {
43
- let entry: any;
44
- if (!line) continue;
45
- try {
46
- entry = JSON.parse(line);
47
- } catch (err) {
48
- console.log(line);
49
- await plugins.smartdelay.delayFor(10000);
50
- }
51
- if (!entry) continue;
52
- totalRecordsCounter++;
53
- if (totalRecordsCounter % 10000 === 0) console.log(`${totalRecordsCounter} total records.`);
54
- const businessRecord = new this.openDataRef.CBusinessRecord();
55
- businessRecord.id = await this.openDataRef.CBusinessRecord.getNewId();
56
- businessRecord.data.name = entry.name;
57
- await businessRecord.save();
58
- }
77
+ const concurrentProcessor = new plugins.smartarray.ConcurrentProcessor<string>(
78
+ async (line) => {
79
+ let entry: T;
80
+ if (!line) return;
81
+ try {
82
+ entry = JSON.parse(line);
83
+ } catch (err) {
84
+ console.log(line);
85
+ await plugins.smartdelay.delayFor(10000);
86
+ }
87
+ if (!entry) return;
88
+ totalRecordsCounter++;
89
+ if (totalRecordsCounter % 10000 === 0)
90
+ console.log(`${totalRecordsCounter} total records.`);
91
+ await this.forEachFunction(entry);
92
+ },
93
+ 1000
94
+ );
95
+ await concurrentProcessor.process(lines);
59
96
  },
60
97
  finalFunction: async (streamToolsArg) => {
61
98
  console.log(`finished processing ${totalRecordsCounter} records.`);
62
99
  if (!nextRest) return;
63
100
  JSON.parse(nextRest);
64
- }
101
+ done.resolve();
102
+ },
65
103
  })
66
104
  );
67
105
  },
68
106
  })
69
107
  );
70
- }
71
-
72
- public async getBusinessRecordByName(nameArg: string) {
73
- const businessRecord = await this.openDataRef.CBusinessRecord.getInstance({
74
- data: {
75
- name: { $regex: `${nameArg}`, $options: "i" } as any,
76
- }
77
- });
78
- return businessRecord;
108
+ await done.promise;
79
109
  }
80
110
  }
@@ -1,32 +1,61 @@
1
1
  import { BusinessRecord } from './classes.businessrecord.js';
2
- import { HandelsRegister } from './classes.handelsregister.js';
3
- import { JsonlDataProcessor } from './classes.jsonldata.js';
2
+ import { HandelsRegister } from './classes.handelsregister.js';
3
+ import { JsonlDataProcessor, type SeedEntryType } from './classes.jsonldata.js';
4
4
  import * as paths from './paths.js';
5
5
  import * as plugins from './plugins.js';
6
6
 
7
7
  export class OpenData {
8
8
  public db: plugins.smartdata.SmartdataDb;
9
9
  private serviceQenv = new plugins.qenv.Qenv(paths.packageDir, paths.nogitDir);
10
-
11
- public jsonLDataProcessor: JsonlDataProcessor;
10
+
11
+ public jsonLDataProcessor: JsonlDataProcessor<SeedEntryType>;
12
12
  public handelsregister: HandelsRegister;
13
-
13
+
14
14
  public CBusinessRecord = plugins.smartdata.setDefaultManagerForDoc(this, BusinessRecord);
15
15
 
16
16
  public async start() {
17
17
  this.db = new plugins.smartdata.SmartdataDb({
18
- mongoDbUrl: await this.serviceQenv.getEnvVarOnDemand('MONGODB_URL'),
19
- mongoDbName: await this.serviceQenv.getEnvVarOnDemand('MONGODB_NAME'),
20
- mongoDbUser: await this.serviceQenv.getEnvVarOnDemand('MONGODB_USER'),
21
- mongoDbPass: await this.serviceQenv.getEnvVarOnDemand('MONGODB_PASS'),
18
+ mongoDbUrl: await this.serviceQenv.getEnvVarOnDemand('MONGODB_URL'),
19
+ mongoDbName: await this.serviceQenv.getEnvVarOnDemand('MONGODB_NAME'),
20
+ mongoDbUser: await this.serviceQenv.getEnvVarOnDemand('MONGODB_USER'),
21
+ mongoDbPass: await this.serviceQenv.getEnvVarOnDemand('MONGODB_PASS'),
22
22
  });
23
23
  await this.db.init();
24
- this.jsonLDataProcessor = new JsonlDataProcessor(this);
24
+ this.jsonLDataProcessor = new JsonlDataProcessor(async (entryArg) => {
25
+ const businessRecord = new this.CBusinessRecord();
26
+ businessRecord.id = await this.CBusinessRecord.getNewId();
27
+ businessRecord.data.name = entryArg.name;
28
+ businessRecord.data.germanParsedRegistration = {
29
+ court: entryArg.all_attributes.registered_office,
30
+ number: entryArg.all_attributes._registerNummer,
31
+ type: entryArg.all_attributes._registerArt as 'HRA' | 'HRB',
32
+ };
33
+ await businessRecord.save();
34
+ });
25
35
  this.handelsregister = new HandelsRegister(this);
26
36
  await this.handelsregister.start();
27
37
  }
38
+
39
+ public async buildInitialDb() {
40
+ await this.jsonLDataProcessor.processDataFromUrl();
41
+ }
42
+
43
+ public async slowValidateDb() {
44
+
45
+ }
46
+
47
+ public async validateSearchByName() {
48
+
49
+ }
50
+
51
+ public async searchDbByBusinessNameAndPostalCode(businessNameArg: string, postalCodeArg: string) {
52
+
53
+ }
54
+
55
+
56
+
28
57
  public async stop() {
29
58
  await this.db.close();
30
59
  await this.handelsregister.stop();
31
60
  }
32
- }
61
+ }
package/ts/paths.ts CHANGED
@@ -8,4 +8,8 @@ export const packageDir = plugins.path.join(
8
8
  export const nogitDir = plugins.path.join(packageDir, './.nogit/');
9
9
  plugins.smartfile.fs.ensureDirSync(nogitDir);
10
10
 
11
+ export const downloadDir = plugins.path.join(nogitDir, 'downloads');
12
+ plugins.smartfile.fs.ensureDirSync(downloadDir);
13
+
14
+
11
15
  export const germanBusinessDataDir = plugins.path.join(nogitDir, 'germanbusinessdata');
package/ts/plugins.ts CHANGED
@@ -6,8 +6,10 @@ export {
6
6
  }
7
7
 
8
8
  // @push.rocks scope
9
+ import * as lik from '@push.rocks/lik';
9
10
  import * as qenv from '@push.rocks/qenv';
10
11
  import * as smartarchive from '@push.rocks/smartarchive';
12
+ import * as smartarray from '@push.rocks/smartarray';
11
13
  import * as smartbrowser from '@push.rocks/smartbrowser';
12
14
  import * as smartdata from '@push.rocks/smartdata';
13
15
  import * as smartdelay from '@push.rocks/smartdelay';
@@ -16,10 +18,14 @@ import * as smartpath from '@push.rocks/smartpath';
16
18
  import * as smartpromise from '@push.rocks/smartpromise';
17
19
  import * as smartrequest from '@push.rocks/smartrequest';
18
20
  import * as smartstream from '@push.rocks/smartstream';
21
+ import * as smartunique from '@push.rocks/smartunique';
22
+ import * as smartxml from '@push.rocks/smartxml';
19
23
 
20
24
  export {
25
+ lik,
21
26
  qenv,
22
27
  smartarchive,
28
+ smartarray,
23
29
  smartbrowser,
24
30
  smartdata,
25
31
  smartdelay,
@@ -28,4 +34,13 @@ export {
28
34
  smartpromise,
29
35
  smartrequest,
30
36
  smartstream,
31
- }
37
+ smartunique,
38
+ smartxml,
39
+ }
40
+
41
+ // @tsclass scope
42
+ import * as tsclass from '@tsclass/tsclass';
43
+
44
+ export {
45
+ tsclass,
46
+ }