refactor: build system

This commit is contained in:
2023-03-22 11:45:30 +01:00
parent 4df19e8c20
commit 8cb9285462
427 changed files with 3978 additions and 9810 deletions

View File

@@ -19,14 +19,11 @@ import {join} from 'path';
import {executeConnector, isValidSCNamespace} from './common.js';
import {MinimalConnector} from './minimal-connector.js';
process.on('unhandledRejection', (error) => {
process.on('unhandledRejection', error => {
throw error;
});
const connectorVersion = JSON.parse(
readFileSync(join(__dirname, '..', 'package.json'))
.toString(),
).version;
const connectorVersion = JSON.parse(readFileSync(join(__dirname, '..', 'package.json')).toString()).version;
const commander = new Command();
@@ -41,25 +38,25 @@ commander
.command('run <backendURL> <origin> <licensePlate>')
.version(connectorVersion)
.action(async (backendURL: string, origin: string, licensePlate: string) => {
if (backendURL.length === 0) {
throw new Error('Param "backend" needs to have a length greater zero.');
}
const originRegex = /^[a-z\-\_0-9]+$/;
if (!originRegex.test(origin)) {
throw new Error(
'Origin name can only consist of lowercase letters from a-z, "-", "_" and integer numbers.',
);
}
if (backendURL.length === 0) {
throw new Error('Param "backend" needs to have a length greater zero.');
}
const originRegex = /^[a-z\-\_0-9]+$/;
if (!originRegex.test(origin)) {
throw new Error('Origin name can only consist of lowercase letters from a-z, "-", "_" and integer numbers.');
}
if (!isValidSCNamespace(licensePlate)) {
throw new Error('Not a valid license plate. Please register a namespace with a unique-id in "core"');
}
if (!isValidSCNamespace(licensePlate)) {
throw new Error('Not a valid license plate. Please register a namespace with a unique-id in "core"');
}
// TODO for connector-developers: set your connector here
const connector = new MinimalConnector(licensePlate, origin);
// TODO for connector-developers: set your connector here
const connector = new MinimalConnector(licensePlate, origin);
await executeConnector(backendURL, connector);
Logger.ok('Done');
},
);
await executeConnector(backendURL, connector);
Logger.ok('Done');
});
commander.parse(process.argv);

View File

@@ -14,11 +14,7 @@
*/
import {ConnectorClient} from '@openstapps/api/lib/connector-client.js';
import {HttpClient} from '@openstapps/api/lib/http-client.js';
import {
SCLicensePlate,
SCNamespaces,
SCThings,
} from '@openstapps/core';
import {SCLicensePlate, SCNamespaces, SCThings} from '@openstapps/core';
import {Connector} from './connector.js';
/**
@@ -27,8 +23,7 @@ import {Connector} from './connector.js';
* @param input Name of the potential SCNamespace
*/
export function isValidSCNamespace(input: string): input is SCLicensePlate {
return Object.keys(SCNamespaces)
.indexOf(input) > 0;
return Object.keys(SCNamespaces).indexOf(input) > 0;
}
/**
@@ -50,15 +45,9 @@ export function createUUID(itemIdentifier: unknown, licensePlate: SCLicensePlate
* @param backend URL of the StApps backend eployment
* @param connector Connector to be executed
*/
export async function executeConnector<T extends SCThings>(
backend: string,
connector: Connector<T>,
) {
export async function executeConnector<T extends SCThings>(backend: string, connector: Connector<T>) {
const items: T[] = await connector.getItems();
const client: ConnectorClient = new ConnectorClient(
new HttpClient(),
backend,
);
const client: ConnectorClient = new ConnectorClient(new HttpClient(), backend);
try {
await client.index<T>(items, connector.origin);
} catch (err) {