Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
6258dcdff1 | |||
605b050177 | |||
c97c8e711a | |||
d5654a7bc7 | |||
c91439ab6b | |||
ad0c6a4112 | |||
dd110a198d | |||
c30fc40e06 | |||
a8a6bf02bc | |||
8f98b0fb12 |
46
changelog.md
Normal file
46
changelog.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-12-31 - 1.1.3 - fix(core)
|
||||
Added missing license file for project completeness.
|
||||
|
||||
- Introduced a LICENSE file to the project, ensuring clarity on software usage permissions.
|
||||
|
||||
## 2024-12-31 - 1.1.2 - fix(GermanBusinessData)
|
||||
Ensure unique ID generation for BusinessRecord
|
||||
|
||||
- Added generation of a new ID for each BusinessRecord in GermanBusinessData.
|
||||
- Ensures each business record has a unique identifier.
|
||||
|
||||
## 2024-12-31 - 1.1.1 - fix(dependencies)
|
||||
Update dependencies and devDependencies to newer versions.
|
||||
|
||||
- @git.zone/tsbuild from ^2.1.25 to ^2.2.0
|
||||
- @git.zone/tsbundle from ^2.0.5 to ^2.1.0
|
||||
- @git.zone/tsrun from ^1.2.46 to ^1.3.3
|
||||
- @git.zone/tstest from ^1.0.84 to ^1.0.90
|
||||
- @push.rocks/tapbundle from ^5.0.15 to ^5.5.4
|
||||
- @types/node from ^20.9.0 to ^22.10.2
|
||||
- @push.rocks/qenv from ^6.0.4 to ^6.1.0
|
||||
- @push.rocks/smartarchive from ^4.0.19 to ^4.0.39
|
||||
- @push.rocks/smartdata from ^5.0.33 to ^5.2.10
|
||||
- @push.rocks/smartfile from ^11.0.0 to ^11.0.23
|
||||
- @push.rocks/smartpath from ^5.0.11 to ^5.0.18
|
||||
- @push.rocks/smartpromise from ^4.0.3 to ^4.0.4
|
||||
- @push.rocks/smartrequest from ^2.0.21 to ^2.0.23
|
||||
- @push.rocks/smartstream from ^3.0.30 to ^3.2.5
|
||||
|
||||
## 2024-12-31 - 1.1.0 - feat(core)
|
||||
Enhanced data handling and retrieval features, improved usage documentation
|
||||
|
||||
- Updated package description and added project keywords in package.json.
|
||||
- Extended readme with detailed usage examples and class structures.
|
||||
- Added getBusinessRecordByName function for dynamic business record retrieval.
|
||||
|
||||
## 2024-07-02 - 1.0.3 - fix(core)
|
||||
No new changes detected. Preparing for patch release.
|
||||
|
||||
|
||||
## 2023-11-14 - 1.0.1 to 1.0.2 - General Updates
|
||||
Minor version updates and fixes.
|
||||
|
||||
- fix(core): update
|
19
license
Normal file
19
license
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2022 Task Venture Capital GmbH (hello@task.vc)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -5,10 +5,22 @@
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "fin.cx",
|
||||
"gitrepo": "opendata",
|
||||
"description": "open business data",
|
||||
"description": "A TypeScript-based library for accessing and managing open business data, specifically for German companies.",
|
||||
"npmPackagename": "@fin.cx/opendata",
|
||||
"license": "MIT",
|
||||
"projectDomain": "fin.cx"
|
||||
"projectDomain": "fin.cx",
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"open data",
|
||||
"business data",
|
||||
"German companies",
|
||||
"data management",
|
||||
"business registry",
|
||||
"npm package",
|
||||
"database",
|
||||
"MongoDB",
|
||||
"automation"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
|
44
package.json
44
package.json
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@fin.cx/opendata",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.3",
|
||||
"private": false,
|
||||
"description": "open business data",
|
||||
"description": "A TypeScript-based library for accessing and managing open business data, specifically for German companies.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
@ -14,23 +14,23 @@
|
||||
"buildDocs": "(tsdoc)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.25",
|
||||
"@git.zone/tsbundle": "^2.0.5",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.84",
|
||||
"@push.rocks/tapbundle": "^5.0.15",
|
||||
"@types/node": "^20.9.0"
|
||||
"@git.zone/tsbuild": "^2.2.0",
|
||||
"@git.zone/tsbundle": "^2.1.0",
|
||||
"@git.zone/tsrun": "^1.3.3",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.5.4",
|
||||
"@types/node": "^22.10.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/qenv": "^6.0.4",
|
||||
"@push.rocks/smartarchive": "^4.0.19",
|
||||
"@push.rocks/smartdata": "^5.0.33",
|
||||
"@push.rocks/qenv": "^6.1.0",
|
||||
"@push.rocks/smartarchive": "^4.0.39",
|
||||
"@push.rocks/smartdata": "^5.2.10",
|
||||
"@push.rocks/smartdelay": "^3.0.5",
|
||||
"@push.rocks/smartfile": "^11.0.0",
|
||||
"@push.rocks/smartpath": "^5.0.11",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartrequest": "^2.0.21",
|
||||
"@push.rocks/smartstream": "^3.0.30"
|
||||
"@push.rocks/smartfile": "^11.0.23",
|
||||
"@push.rocks/smartpath": "^5.0.18",
|
||||
"@push.rocks/smartpromise": "^4.0.4",
|
||||
"@push.rocks/smartrequest": "^2.0.23",
|
||||
"@push.rocks/smartstream": "^3.2.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -54,5 +54,17 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"keywords": [
|
||||
"TypeScript",
|
||||
"open data",
|
||||
"business data",
|
||||
"German companies",
|
||||
"data management",
|
||||
"business registry",
|
||||
"npm package",
|
||||
"database",
|
||||
"MongoDB",
|
||||
"automation"
|
||||
]
|
||||
}
|
||||
|
12905
pnpm-lock.yaml
generated
12905
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
0
readme.hints.md
Normal file
0
readme.hints.md
Normal file
268
readme.md
268
readme.md
@ -1,31 +1,253 @@
|
||||
```markdown
|
||||
# @fin.cx/opendata
|
||||
open business data
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@fin.cx/opendata)
|
||||
* [gitlab.com (source)](https://gitlab.com/fin.cx/opendata)
|
||||
* [github.com (source mirror)](https://github.com/fin.cx/opendata)
|
||||
* [docs (typedoc)](https://fin.cx.gitlab.io/opendata/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
To install the `@fin.cx/opendata` package, you can use npm or yarn as your package manager. Here's how you can do it:
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Using npm:
|
||||
|
||||
```bash
|
||||
npm install @fin.cx/opendata
|
||||
```
|
||||
|
||||
Using yarn:
|
||||
|
||||
```bash
|
||||
yarn add @fin.cx/opendata
|
||||
```
|
||||
|
||||
## Usage
|
||||
Use TypeScript for best in class intellisense
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
## Legal
|
||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
The `@fin.cx/opendata` package offers functionalities for handling open business data, with a primary focus on German business data. Let's explore its capabilities through detailed examples.
|
||||
|
||||
### Setting Up
|
||||
|
||||
#### Importing the Module
|
||||
|
||||
Begin by importing necessary components from the `@fin.cx/opendata` package. You'll also need to set up some environment variables for the MongoDB instance.
|
||||
|
||||
```typescript
|
||||
import { OpenData } from '@fin.cx/opendata';
|
||||
|
||||
const startOpenDataInstance = async () => {
|
||||
const openData = new OpenData();
|
||||
|
||||
await openData.start(); // Start the open data instance
|
||||
console.log('OpenData instance started.');
|
||||
|
||||
// your code here
|
||||
|
||||
await openData.stop();
|
||||
console.log('OpenData instance stopped.');
|
||||
};
|
||||
|
||||
startOpenDataInstance().catch(console.error);
|
||||
```
|
||||
|
||||
### BusinessRecord Usage
|
||||
|
||||
A `BusinessRecord` is the main entity you'll be working with. Here's how you manage business records.
|
||||
|
||||
#### Creating a New BusinessRecord
|
||||
|
||||
```typescript
|
||||
import { BusinessRecord } from '@fin.cx/opendata';
|
||||
|
||||
const createBusinessRecord = async (openData: OpenData) => {
|
||||
const businessRecord = new openData.CBusinessRecord();
|
||||
businessRecord.data.name = "Example Company";
|
||||
businessRecord.data.address = "Example Street 1";
|
||||
businessRecord.data.postalCode = "12345";
|
||||
businessRecord.data.city = "Example City";
|
||||
businessRecord.data.country = "Germany";
|
||||
businessRecord.data.phone = "+49 123 456789";
|
||||
businessRecord.data.email = "contact@example.com";
|
||||
businessRecord.data.website = "https://example.com";
|
||||
businessRecord.data.businessType = "GmbH";
|
||||
businessRecord.data.registrationNumber = "HRB 123456";
|
||||
businessRecord.data.registrationCourt = "Munich";
|
||||
businessRecord.data.legalForm = "GmbH";
|
||||
businessRecord.data.managingDirectors = ["John Doe", "Jane Smith"];
|
||||
businessRecord.data.foundingDate = new Date().toISOString();
|
||||
businessRecord.data.capital = "50,000 EUR";
|
||||
businessRecord.data.purpose = "Tech Solutions";
|
||||
businessRecord.data.lastUpdate = new Date().toISOString();
|
||||
|
||||
await businessRecord.save();
|
||||
console.log('BusinessRecord saved:', businessRecord);
|
||||
};
|
||||
```
|
||||
|
||||
#### Retrieving BusinessRecord
|
||||
|
||||
Retrieve a business record by querying the database.
|
||||
|
||||
```typescript
|
||||
import { BusinessRecord } from '@fin.cx/opendata';
|
||||
|
||||
const findBusinessRecord = async (openData: OpenData) => {
|
||||
const businessRecords = await openData.db.collection<BusinessRecord>('businessrecords').find().toArray();
|
||||
console.log('Retrieved Business Records:', businessRecords);
|
||||
};
|
||||
```
|
||||
|
||||
### Updating Business Data
|
||||
|
||||
The `GermanBusinessData` class handles the specifics of updating and maintaining the data.
|
||||
|
||||
#### Updating German Business Data
|
||||
|
||||
```typescript
|
||||
import { OpenData } from '@fin.cx/opendata';
|
||||
|
||||
const updateGermanBusinessData = async (openData: OpenData) => {
|
||||
await openData.germanBusinesses.update();
|
||||
console.log('German business data updated.');
|
||||
};
|
||||
|
||||
startOpenDataInstance()
|
||||
.then((openData) => {
|
||||
// Use the instance
|
||||
return updateGermanBusinessData(openData);
|
||||
})
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
This function downloads the latest data from the German business data source, processes it, and updates the local database.
|
||||
|
||||
### Detailed Class Structures and Methods
|
||||
|
||||
#### OpenData Class
|
||||
|
||||
The `OpenData` class is the main entry point.
|
||||
|
||||
```typescript
|
||||
import { OpenData } from '@fin.cx/opendata';
|
||||
|
||||
class OpenData {
|
||||
db: plugins.smartdata.SmartdataDb;
|
||||
germanBusinesses: GermanBusinessData;
|
||||
|
||||
private serviceQenv = new plugins.qenv.Qenv(paths.packageDir, paths.nogitDir);
|
||||
|
||||
public CBusinessRecord = plugins.smartdata.setDefaultManagerForDoc(this, BusinessRecord);
|
||||
|
||||
public async start() {
|
||||
// Initialize smart data DB
|
||||
this.db = new plugins.smartdata.SmartdataDb({
|
||||
mongoDbUrl: await this.serviceQenv.getEnvVarOnDemand('MONGODB_URL'),
|
||||
mongoDbName: await this.serviceQenv.getEnvVarOnDemand('MONGODB_NAME'),
|
||||
mongoDbUser: await this.serviceQenv.getEnvVarOnDemand('MONGODB_USER'),
|
||||
mongoDbPass: await this.serviceQenv.getEnvVarOnDemand('MONGODB_PASS'),
|
||||
});
|
||||
|
||||
await this.db.init();
|
||||
this.germanBusinesses = new GermanBusinessData(this);
|
||||
await this.germanBusinesses.start();
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
// Clean up resources if necessary
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### GermanBusinessData Class
|
||||
|
||||
The `GermanBusinessData` class handles the specifics of German business data.
|
||||
|
||||
```typescript
|
||||
import { OpenData } from '@fin.cx/opendata';
|
||||
import * as plugins from './plugins';
|
||||
import * as paths from './paths';
|
||||
|
||||
class GermanBusinessData {
|
||||
public openDataRef: OpenData;
|
||||
|
||||
constructor(openDataRef: OpenData) {
|
||||
this.openDataRef = openDataRef;
|
||||
}
|
||||
|
||||
public async start() {
|
||||
await this.update();
|
||||
}
|
||||
|
||||
public async stop() {
|
||||
// Stop any ongoing processing
|
||||
}
|
||||
|
||||
public async update() {
|
||||
const dataUrl = 'https://daten.offeneregister.de/de_companies_ocdata.jsonl.bz2';
|
||||
const dataExists = await plugins.smartfile.fs.isDirectory(paths.germanBusinessDataDir);
|
||||
|
||||
if (!dataExists) {
|
||||
await plugins.smartfile.fs.ensureDir(paths.germanBusinessDataDir);
|
||||
}
|
||||
|
||||
const smartarchive = await plugins.smartarchive.SmartArchive.fromArchiveUrl(dataUrl);
|
||||
const jsonlDataStream = await smartarchive.exportToStreamOfStreamFiles();
|
||||
|
||||
let totalRecordsCounter = 0;
|
||||
let nextRest: string = '';
|
||||
|
||||
jsonlDataStream.pipe(
|
||||
new plugins.smartstream.SmartDuplex({
|
||||
objectMode: true,
|
||||
writeFunction: async (chunkArg: plugins.smartfile.StreamFile, streamToolsArg) => {
|
||||
const readStream = await chunkArg.createReadStream();
|
||||
readStream.pipe(
|
||||
new plugins.smartstream.SmartDuplex({
|
||||
objectMode: true,
|
||||
writeFunction: async (chunkArg: Buffer, streamToolsArg) => {
|
||||
const currentString = nextRest + chunkArg.toString();
|
||||
|
||||
const lines = currentString.split('\n');
|
||||
nextRest = lines.pop();
|
||||
|
||||
for (const line of lines) {
|
||||
let entry: any;
|
||||
try {
|
||||
entry = JSON.parse(line);
|
||||
} catch (err) {
|
||||
console.error('Error parsing line:', err);
|
||||
continue;
|
||||
}
|
||||
|
||||
totalRecordsCounter++;
|
||||
if (totalRecordsCounter % 10000 === 0) {
|
||||
console.log(`${totalRecordsCounter} total records.`);
|
||||
}
|
||||
|
||||
const businessRecord = new this.openDataRef.CBusinessRecord();
|
||||
businessRecord.data.name = entry?.name;
|
||||
|
||||
await businessRecord.save();
|
||||
}
|
||||
},
|
||||
finalFunction: async (streamToolsArg) => {
|
||||
if (nextRest) {
|
||||
try {
|
||||
JSON.parse(nextRest);
|
||||
} catch (err) {
|
||||
console.error('Error parsing final chunk:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
This module is designed to make it easier to manage open business data, especially focusing on German business data. The examples above demonstrate the core functionalities, including starting and stopping the service, managing business records, and updating data.
|
||||
|
||||
As you work with `@fin.cx/opendata`, you’ll discover it offers a robust and flexible approach for working with open business data seamlessly. Happy coding!
|
||||
```
|
||||
undefined
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@fin.cx/opendata',
|
||||
version: '1.0.2',
|
||||
description: 'open business data'
|
||||
version: '1.1.3',
|
||||
description: 'A TypeScript-based library for accessing and managing open business data, specifically for German companies.'
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ import * as plugins from './plugins.js';
|
||||
|
||||
@plugins.smartdata.Manager()
|
||||
export class BusinessRecord extends plugins.smartdata.SmartDataDbDoc<BusinessRecord, BusinessRecord> {
|
||||
|
||||
@plugins.smartdata.unI()
|
||||
id: string;
|
||||
|
||||
@plugins.smartdata.svDb()
|
||||
data: {
|
||||
name?: string,
|
||||
|
@ -57,6 +57,7 @@ export class GermanBusinessData {
|
||||
totalRecordsCounter++;
|
||||
if (totalRecordsCounter % 10000 === 0) console.log(`${totalRecordsCounter} total records.`);
|
||||
const businessRecord = new this.openDataRef.CBusinessRecord();
|
||||
businessRecord.id = await this.openDataRef.CBusinessRecord.getNewId();
|
||||
businessRecord.data.name = entry.name;
|
||||
await businessRecord.save();
|
||||
// console.log(`stored ${businessRecord.data.name}`);
|
||||
@ -72,4 +73,13 @@ export class GermanBusinessData {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public async getBusinessRecordByName(nameArg: string) {
|
||||
const businessRecord = await this.openDataRef.CBusinessRecord.getInstance({
|
||||
data: {
|
||||
name: { $regex: `${nameArg}`, $options: "i" } as any,
|
||||
}
|
||||
});
|
||||
return businessRecord;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user