@fin.cx/opendata 3.6.0 → 4.0.0

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.
Files changed (78) hide show
  1. package/.smartconfig.json +20 -20
  2. package/dist_ts/00_commitinfo_data.js +3 -3
  3. package/dist_ts/handelsregister/classes.handelsregisterclient.d.ts +64 -0
  4. package/dist_ts/handelsregister/classes.handelsregisterclient.js +397 -0
  5. package/dist_ts/handelsregister/classes.handelsregistererror.d.ts +56 -0
  6. package/dist_ts/handelsregister/classes.handelsregistererror.js +37 -0
  7. package/dist_ts/handelsregister/classes.portalsession.d.ts +46 -0
  8. package/dist_ts/handelsregister/classes.portalsession.js +160 -0
  9. package/dist_ts/handelsregister/classes.slidingwindowgate.d.ts +32 -0
  10. package/dist_ts/handelsregister/classes.slidingwindowgate.js +55 -0
  11. package/dist_ts/handelsregister/constants.d.ts +13 -0
  12. package/dist_ts/handelsregister/constants.js +19 -0
  13. package/dist_ts/handelsregister/data.codelists.d.ts +29 -0
  14. package/dist_ts/handelsregister/data.codelists.js +616 -0
  15. package/dist_ts/handelsregister/forms.d.ts +27 -0
  16. package/dist_ts/handelsregister/forms.js +77 -0
  17. package/dist_ts/handelsregister/html.d.ts +26 -0
  18. package/dist_ts/handelsregister/html.js +82 -0
  19. package/dist_ts/handelsregister/index.d.ts +9 -0
  20. package/dist_ts/handelsregister/index.js +10 -0
  21. package/dist_ts/handelsregister/interfaces.d.ts +240 -0
  22. package/dist_ts/handelsregister/interfaces.js +2 -0
  23. package/dist_ts/handelsregister/parse.searchresults.d.ts +35 -0
  24. package/dist_ts/handelsregister/parse.searchresults.js +175 -0
  25. package/dist_ts/handelsregister/parse.structuredcontent.d.ts +6 -0
  26. package/dist_ts/handelsregister/parse.structuredcontent.js +306 -0
  27. package/dist_ts/handelsregister/plugins.d.ts +4 -0
  28. package/dist_ts/handelsregister/plugins.js +8 -0
  29. package/dist_ts/handelsregister/references.d.ts +34 -0
  30. package/dist_ts/handelsregister/references.js +76 -0
  31. package/dist_ts/index.d.ts +0 -2
  32. package/dist_ts/index.js +1 -3
  33. package/dist_ts/plugins.d.ts +2 -20
  34. package/dist_ts/plugins.js +3 -22
  35. package/package.json +33 -37
  36. package/readme.md +159 -126
  37. package/ts/00_commitinfo_data.ts +2 -2
  38. package/ts/handelsregister/classes.handelsregisterclient.ts +474 -0
  39. package/ts/handelsregister/classes.handelsregistererror.ts +82 -0
  40. package/ts/handelsregister/classes.portalsession.ts +191 -0
  41. package/ts/handelsregister/classes.slidingwindowgate.ts +74 -0
  42. package/ts/handelsregister/constants.ts +30 -0
  43. package/ts/handelsregister/data.codelists.ts +640 -0
  44. package/ts/handelsregister/forms.ts +99 -0
  45. package/ts/handelsregister/html.ts +113 -0
  46. package/ts/handelsregister/index.ts +27 -0
  47. package/ts/handelsregister/interfaces.ts +272 -0
  48. package/ts/handelsregister/parse.searchresults.ts +241 -0
  49. package/ts/handelsregister/parse.structuredcontent.ts +338 -0
  50. package/ts/handelsregister/plugins.ts +15 -0
  51. package/ts/handelsregister/references.ts +115 -0
  52. package/ts/index.ts +0 -2
  53. package/ts/plugins.ts +0 -39
  54. package/dist_ts/classes.businessrecord.d.ts +0 -38
  55. package/dist_ts/classes.businessrecord.js +0 -90
  56. package/dist_ts/classes.handelsregister.d.ts +0 -134
  57. package/dist_ts/classes.handelsregister.js +0 -307
  58. package/dist_ts/classes.jsonldata.d.ts +0 -43
  59. package/dist_ts/classes.jsonldata.js +0 -68
  60. package/dist_ts/classes.main.opendata.d.ts +0 -25
  61. package/dist_ts/classes.main.opendata.js +0 -91
  62. package/dist_ts/laws/classes.lawrecord.d.ts +0 -24
  63. package/dist_ts/laws/classes.lawrecord.js +0 -181
  64. package/dist_ts/laws/classes.lawservice.d.ts +0 -52
  65. package/dist_ts/laws/classes.lawservice.js +0 -740
  66. package/dist_ts/laws/index.d.ts +0 -3
  67. package/dist_ts/laws/index.js +0 -4
  68. package/dist_ts/laws/interfaces.law.d.ts +0 -35
  69. package/dist_ts/laws/interfaces.law.js +0 -2
  70. package/readme.hints.md +0 -89
  71. package/ts/classes.businessrecord.ts +0 -67
  72. package/ts/classes.handelsregister.ts +0 -385
  73. package/ts/classes.jsonldata.ts +0 -114
  74. package/ts/classes.main.opendata.ts +0 -120
  75. package/ts/laws/classes.lawrecord.ts +0 -81
  76. package/ts/laws/classes.lawservice.ts +0 -1010
  77. package/ts/laws/index.ts +0 -3
  78. package/ts/laws/interfaces.law.ts +0 -48
@@ -1,114 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import type { OpenData } from './classes.main.opendata.js';
3
-
4
- export type SeedEntryType = {
5
- all_attributes: {
6
- _registerArt: string;
7
- _registerNummer: string;
8
- additional_data: {
9
- AD: boolean;
10
- CD: boolean;
11
- DK: boolean;
12
- HD: boolean;
13
- SI: boolean;
14
- UT: boolean;
15
- VÖ: boolean;
16
- };
17
- federal_state: string;
18
- native_company_number: string;
19
- registered_office: string;
20
- registrar: string;
21
- };
22
- company_number: string;
23
- current_status: string;
24
- jurisdiction_code: string;
25
- name: string;
26
- officers: {
27
- name: string;
28
- other_attributes: {
29
- city: string;
30
- firstname: string;
31
- flag: string;
32
- lastname: string;
33
- };
34
- position: string;
35
- start_date: string; // ISO 8601 date string
36
- type: string;
37
- }[];
38
- registered_address: string;
39
- retrieved_at: string; // ISO 8601 date string
40
- };
41
-
42
- export class JsonlDataProcessor<T> {
43
- private germanBusinessDataDir: string;
44
- public forEachFunction: (entryArg: T) => Promise<void>;
45
-
46
- constructor(germanBusinessDataDirArg: string, forEachFunctionArg: typeof this.forEachFunction) {
47
- this.germanBusinessDataDir = germanBusinessDataDirArg;
48
- this.forEachFunction = forEachFunctionArg;
49
- }
50
-
51
- // TODO: define a mapper as argument instead of hard-coding it
52
- public async processDataFromUrl(
53
- dataUrlArg = 'https://daten.offeneregister.de/de_companies_ocdata.jsonl.bz2'
54
- ) {
55
- const done = plugins.smartpromise.defer();
56
- const dataExists = await plugins.smartfs.directory(this.germanBusinessDataDir).exists();
57
- if (!dataExists) {
58
- await plugins.smartfs.directory(this.germanBusinessDataDir).create();
59
- } else {
60
- }
61
-
62
- const jsonlDataStream = await plugins.smartarchive.SmartArchive.create()
63
- .url(dataUrlArg)
64
- .toStreamFiles();
65
- let totalRecordsCounter = 0;
66
- let nextRest: string = '';
67
- jsonlDataStream.pipe(
68
- new plugins.smartstream.SmartDuplex({
69
- objectMode: true,
70
- writeFunction: async (chunkArg: plugins.smartfile.StreamFile, streamToolsArg) => {
71
- const readStream = await chunkArg.createReadStream();
72
- readStream.pipe(
73
- new plugins.smartstream.SmartDuplex({
74
- objectMode: true,
75
- writeFunction: async (chunkArg: Buffer, streamToolsArg) => {
76
- const currentString = nextRest + chunkArg.toString();
77
- const lines = currentString.split('\n');
78
- nextRest = lines.pop() ?? '';
79
- console.log(`Got another ${lines.length} records.`);
80
- const concurrentProcessor = new plugins.smartarray.ConcurrentProcessor<string>(
81
- async (line) => {
82
- let entry: T | undefined;
83
- if (!line) return;
84
- try {
85
- entry = JSON.parse(line);
86
- } catch (err) {
87
- console.log(line);
88
- await plugins.smartdelay.delayFor(10000);
89
- }
90
- if (!entry) return;
91
- totalRecordsCounter++;
92
- if (totalRecordsCounter % 10000 === 0)
93
- console.log(`${totalRecordsCounter} total records.`);
94
- await this.forEachFunction(entry);
95
- },
96
- 1000
97
- );
98
- await concurrentProcessor.process(lines);
99
- },
100
- finalFunction: async (streamToolsArg) => {
101
- console.log(`finished processing ${totalRecordsCounter} records.`);
102
- if (nextRest) {
103
- JSON.parse(nextRest);
104
- };
105
- done.resolve();
106
- },
107
- })
108
- );
109
- },
110
- })
111
- );
112
- await done.promise;
113
- }
114
- }
@@ -1,120 +0,0 @@
1
- import { BusinessRecord } from './classes.businessrecord.js';
2
- import { HandelsRegister } from './classes.handelsregister.js';
3
- import { JsonlDataProcessor, type SeedEntryType } from './classes.jsonldata.js';
4
- import * as plugins from './plugins.js';
5
-
6
- export interface IOpenDataConfig {
7
- downloadDir: string;
8
- germanBusinessDataDir: string;
9
- nogitDir: string;
10
- }
11
-
12
- export class OpenData {
13
- public db!: plugins.smartdata.SmartdataDb;
14
- private localSmartDb?: plugins.smartdb.LocalSmartDb;
15
- private config: IOpenDataConfig;
16
- private started = false;
17
-
18
- public jsonLDataProcessor!: JsonlDataProcessor<SeedEntryType>;
19
- public handelsregister!: HandelsRegister;
20
-
21
- public CBusinessRecord = plugins.smartdata.setDefaultManagerForDoc(this, BusinessRecord);
22
-
23
- constructor(configArg: IOpenDataConfig) {
24
- if (!configArg) {
25
- throw new Error('@fin.cx/opendata: Configuration is required. You must provide downloadDir, germanBusinessDataDir, and nogitDir paths.');
26
- }
27
- if (!configArg.downloadDir || !configArg.germanBusinessDataDir || !configArg.nogitDir) {
28
- throw new Error('@fin.cx/opendata: All directory paths are required (downloadDir, germanBusinessDataDir, nogitDir).');
29
- }
30
- this.config = configArg;
31
- }
32
-
33
- public async start() {
34
- if (this.started) {
35
- return;
36
- }
37
-
38
- // Ensure configured directories exist
39
- await plugins.smartfs.directory(this.config.nogitDir).create();
40
- await plugins.smartfs.directory(this.config.downloadDir).create();
41
- await plugins.smartfs.directory(this.config.germanBusinessDataDir).create();
42
-
43
- this.localSmartDb = new plugins.smartdb.LocalSmartDb({
44
- folderPath: plugins.path.join(this.config.nogitDir, 'opendata-smartdb'),
45
- });
46
-
47
- const connectionInfo = await this.localSmartDb.start();
48
- this.db = new plugins.smartdata.SmartdataDb({
49
- mongoDbUrl: connectionInfo.connectionUri,
50
- mongoDbName: 'opendata',
51
- });
52
-
53
- try {
54
- await this.db.init();
55
- await this.db.mongoDb.collection('_opendata_bootstrap').insertOne({
56
- createdAt: new Date(),
57
- });
58
- await this.db.mongoDb.collection('_opendata_bootstrap').deleteMany({});
59
-
60
- this.jsonLDataProcessor = new JsonlDataProcessor(
61
- this.config.germanBusinessDataDir,
62
- async (entryArg) => {
63
- const businessRecord = new this.CBusinessRecord();
64
- businessRecord.id = await this.CBusinessRecord.getNewId();
65
- businessRecord.data.name = entryArg.name;
66
- businessRecord.data.germanParsedRegistration = {
67
- court: entryArg.all_attributes.registered_office,
68
- number: entryArg.all_attributes._registerNummer,
69
- type: entryArg.all_attributes._registerArt as 'HRA' | 'HRB',
70
- };
71
- await businessRecord.save();
72
- }
73
- );
74
-
75
- this.handelsregister = new HandelsRegister(this, this.config.downloadDir);
76
- await this.handelsregister.start();
77
- this.started = true;
78
- } catch (error) {
79
- if (this.handelsregister) {
80
- await this.handelsregister.stop().catch(() => {});
81
- }
82
- await this.db.close().catch(() => {});
83
- await this.localSmartDb.stop().catch(() => {});
84
- this.localSmartDb = undefined;
85
- throw error;
86
- }
87
- }
88
-
89
- public async buildInitialDb() {
90
- await this.jsonLDataProcessor.processDataFromUrl();
91
- }
92
-
93
- public async slowValidateDb() {
94
-
95
- }
96
-
97
- public async validateSearchByName() {
98
-
99
- }
100
-
101
- public async searchDbByBusinessNameAndPostalCode(businessNameArg: string, postalCodeArg: string) {
102
-
103
- }
104
-
105
-
106
-
107
- public async stop() {
108
- if (!this.started) {
109
- return;
110
- }
111
-
112
- if (this.handelsregister) {
113
- await this.handelsregister.stop();
114
- }
115
- await this.db.close();
116
- await this.localSmartDb?.stop();
117
- this.localSmartDb = undefined;
118
- this.started = false;
119
- }
120
- }
@@ -1,81 +0,0 @@
1
- import * as plugins from '../plugins.js';
2
- import type { TJurisdiction, TLawSource, TRawLawFormat } from './interfaces.law.js';
3
-
4
- @plugins.smartdata.Manager()
5
- export class LawRecord extends plugins.smartdata.SmartDataDbDoc<LawRecord, LawRecord> {
6
- public static getByLookupKey = async (lookupKeyArg: string) => {
7
- const lawRecords = await LawRecord.getInstances({
8
- lookupKey: lookupKeyArg,
9
- });
10
- return lawRecords[0];
11
- };
12
-
13
- @plugins.smartdata.unI()
14
- id!: string;
15
-
16
- @plugins.smartdata.unI()
17
- @plugins.smartdata.svDb()
18
- lookupKey!: string;
19
-
20
- @plugins.smartdata.index()
21
- @plugins.smartdata.svDb()
22
- jurisdiction!: TJurisdiction;
23
-
24
- @plugins.smartdata.index()
25
- @plugins.smartdata.svDb()
26
- source!: TLawSource;
27
-
28
- @plugins.smartdata.searchable()
29
- @plugins.smartdata.svDb()
30
- identifier!: string;
31
-
32
- @plugins.smartdata.searchable()
33
- @plugins.smartdata.svDb()
34
- title!: string;
35
-
36
- @plugins.smartdata.searchable()
37
- @plugins.smartdata.svDb()
38
- shortTitle: string = '';
39
-
40
- @plugins.smartdata.searchable()
41
- @plugins.smartdata.svDb()
42
- citation: string = '';
43
-
44
- @plugins.smartdata.index()
45
- @plugins.smartdata.svDb()
46
- type: string = '';
47
-
48
- @plugins.smartdata.index()
49
- @plugins.smartdata.svDb()
50
- language: string = '';
51
-
52
- @plugins.smartdata.svDb()
53
- sourceUrl!: string;
54
-
55
- @plugins.smartdata.svDb()
56
- rawFormat!: TRawLawFormat;
57
-
58
- @plugins.smartdata.svDb()
59
- rawBody!: string;
60
-
61
- @plugins.smartdata.searchable()
62
- @plugins.smartdata.svDb()
63
- text!: string;
64
-
65
- @plugins.smartdata.index()
66
- @plugins.smartdata.svDb()
67
- dateIssued: string = '';
68
-
69
- @plugins.smartdata.index()
70
- @plugins.smartdata.svDb()
71
- lastModified: string = '';
72
-
73
- @plugins.smartdata.svDb()
74
- sourceMeta: Record<string, string> = {};
75
-
76
- @plugins.smartdata.svDb()
77
- fetchedAt: Date = new Date();
78
-
79
- @plugins.smartdata.svDb()
80
- syncedAt: Date = new Date();
81
- }