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

@@ -1,15 +0,0 @@
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@@ -2,35 +2,29 @@
(Summarize the bug encountered concisely)
## Steps to reproduce
(How one can reproduce the issue - this is very important)
## Example Project
(If possible, please create an example project here on GitLab.com that exhibits the problematic behaviour, and link to it here in the bug report)
(If you are using an older version of GitLab, this will also determine whether the bug has been fixed in a more recent version)
## What is the current bug behavior?
(What actually happens)
## What is the expected correct behavior?
(What you should see instead)
## Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output,
logs, and code as it's very hard to read otherwise.)
## Possible fixes
(If you can, link to the line of code that might be responsible for the problem)

View File

@@ -2,15 +2,12 @@
(Describe the feature that you're requesting concisely)
## Explanation
(Explain why the feature is necessary)
## Dependencies, issues to be resolved beforehand
(List issues or dependencies that need to be resolved before this feature can be implemented)
/label ~meeting

View File

@@ -1,21 +1,11 @@
# [0.2.0](https://gitlab.com/openstapps/minimal-connector/compare/v0.1.0...v0.2.0) (2019-02-07)
# [0.1.0](https://gitlab.com/openstapps/minimal-connector/compare/v0.0.2...v0.1.0) (2019-01-30)
## [0.0.2](https://gitlab.com/openstapps/minimal-connector/compare/v0.0.1...v0.0.2) (2018-12-03)
## [0.0.1](https://gitlab.com/openstapps/minimal-connector/compare/d332f6e...v0.0.1) (2018-12-03)
### Features
* add minimal connector ([d332f6e](https://gitlab.com/openstapps/minimal-connector/commit/d332f6e))
- add minimal connector ([d332f6e](https://gitlab.com/openstapps/minimal-connector/commit/d332f6e))

View File

@@ -2,23 +2,26 @@
## Prerequisites:
* `node` (version 10 LTS) and `npm` installed
- `node` (version 10 LTS) and `npm` installed
* a backend, which is running locally (on http://localhost:3000) for testing purposes, it is advisable to use `minimal-deployment` project
- a backend, which is running locally (on http://localhost:3000) for testing purposes, it is advisable to use `minimal-deployment` project
## How to get started
To install all needed `npm` packages:
```shell
npm install
```
To prepare the script to be executed, run:
```shell
npm run build
```
To execute the code in "CLI" script (basically to execute the connector):
```shell
node lib/cli.js run <backendURL> <origin> <licensePlate>
e.g.:
@@ -26,6 +29,7 @@ node lib/cli.js run http://localhost:3000 minimal-connector f-u
```
To run some sample tests, use:
```shell
npm test
```
@@ -33,11 +37,13 @@ npm test
The `npm` scripts are defined in `package.json` file.
After building the project once, the connector image can be build.
```shell
docker build .
```
Use the following command to run the container of this connector. Assuming there is a local backend running.
```shell
docker run --network host <image-id> <backendURL> <origin> <licensePlate>
e.g.:
@@ -53,8 +59,9 @@ docker run --network host registry.gitlab.com/openstapps/minimal-connector http:
## Next steps
You may want to:
* modify the convenience methods in the `minimal-connector/api` to your needs.
* add additional options to your cli.
- modify the convenience methods in the `minimal-connector/api` to your needs.
- add additional options to your cli.
Explore open source connectors from other schools to get some ideas.
@@ -66,16 +73,17 @@ Explore open source connectors from other schools to get some ideas.
## Code structure
Folder [src](src/) contains:
* Reference implementations for CLI and a connector, using the api-classes.
* [/cli.ts](src/cli.ts)
* minimal CLI to start your connector, that uses CLI-args, so that there are no hard coded values for configuration.
* will execute the specified connectors and push the data to the backend
* [/common.ts](src/api/Connector.ts)
* `createUUID`, that will generate a unique id for a given identifying object
* `executeConnector`, that will execute the connector, which will fetch the items and push them to the backend
* [/Connector.ts](src/api/Connector.ts) abstracts the process of executing your specific connector and creating unique ids for the imported items
* [/MinimalConnector.ts](src/MinimalConnector.ts) example connector with mock-up data
* shows how to instantiate things
* shows how to use the convenience functions
- Reference implementations for CLI and a connector, using the api-classes.
- [/cli.ts](src/cli.ts)
- minimal CLI to start your connector, that uses CLI-args, so that there are no hard coded values for configuration.
- will execute the specified connectors and push the data to the backend
- [/common.ts](src/api/Connector.ts)
- `createUUID`, that will generate a unique id for a given identifying object
- `executeConnector`, that will execute the connector, which will fetch the items and push them to the backend
- [/Connector.ts](src/api/Connector.ts) abstracts the process of executing your specific connector and creating unique ids for the imported items
- [/MinimalConnector.ts](src/MinimalConnector.ts) example connector with mock-up data
- shows how to instantiate things
- shows how to use the convenience functions
File [test/MinimalConnector.spec.ts](test/MinimalConnector.spec.ts) contains sample test suite using `mocha` and `chai`.

View File

@@ -1,2 +1,2 @@
#!/usr/bin/env node
import './lib/cli.js'
import './lib/cli.js';

View File

@@ -15,17 +15,12 @@
"main": "lib/cli.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "npm run compile",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md && git commit -m 'docs: update changelog'",
"check-configuration": "openstapps-configuration",
"compile": "rimraf lib && tsc",
"documentation": "typedoc --includeDeclarations --mode modules --out docs --readme README.md --listInvalidSymbolLinks src",
"lint": "tslint -p tsconfig.json -c tslint.json 'src/**/*.ts'",
"postversion": "npm run changelog",
"prepublishOnly": "npm ci && npm run build",
"preversion": "npm run prepublishOnly",
"push": "git push && git push origin \"v$npm_package_version\"",
"test": "nyc mocha --require ts-node/register --require source-map-support/register --recursive 'test/*.spec.ts'"
"build": "tsup --dts",
"format": "prettier .",
"format:fix": "prettier --write .",
"lint": "eslint --ext .ts src/",
"lint:fix": "eslint --fix --ext .ts src/",
"test": "nyc mocha 'test/**/*.spec.ts'"
},
"dependencies": {
"@openstapps/api": "workspace:*",
@@ -34,8 +29,11 @@
"commander": "10.0.0"
},
"devDependencies": {
"@openstapps/configuration": "workspace:*",
"@openstapps/core-tools": "workspace:*",
"@openstapps/eslint-config": "workspace:*",
"@openstapps/nyc-config": "workspace:*",
"@openstapps/prettier-config": "workspace:*",
"@openstapps/tsconfig": "workspace:*",
"@testdeck/mocha": "0.3.3",
"@types/chai": "4.3.4",
"@types/chai-as-promised": "7.1.5",
@@ -47,38 +45,26 @@
"mocha": "10.2.0",
"nock": "13.3.0",
"nyc": "15.1.0",
"rimraf": "4.4.0",
"ts-node": "10.9.1",
"typedoc": "0.23.26",
"tsup": "6.7.0",
"typescript": "4.8.4"
},
"nyc": {
"all": true,
"branches": 95,
"check-coverage": true,
"exclude": [
"src/test/**/*.spec.ts",
"tsup": {
"entry": [
"src/cli.ts"
],
"extension": [
".ts"
],
"functions": 95,
"include": [
"src"
],
"lines": 95,
"per-file": true,
"reporter": [
"html",
"text-summary"
],
"require": [
"ts-node/register"
],
"statements": 95
"sourcemap": true,
"clean": true,
"format": "esm",
"outDir": "lib"
},
"openstappsConfiguration": {
"forPackaging": false
"prettier": "@openstapps/prettier-config",
"eslintConfig": {
"extends": [
"@openstapps"
]
},
"nyc": {
"extends": "@openstapps/nyc-config"
}
}

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) {

View File

@@ -40,9 +40,9 @@ export class CommonSpec {
@test
testCreateUUID() {
const item = {
type: 'Not even a thing'
type: 'Not even a thing',
};
expect(createUUID(item,'f-u')).to.equal('3ac2b548-75d3-5326-920a-241e514fe445');
expect(createUUID(item, 'f-u')).to.equal('3ac2b548-75d3-5326-920a-241e514fe445');
// ID was generated once before!
}
@@ -57,18 +57,14 @@ export class CommonSpec {
uid: '744321ca-cc95-4967-b8df-42c98b792db6',
};
nock('http://localhost:3000')
.post('/bulk')
.reply(200, bulkOpen);
nock('http://localhost:3000').post('/bulk').reply(200, bulkOpen);
const nockBulkAdd = nock('http://localhost:3000')
.post('/bulk/744321ca-cc95-4967-b8df-42c98b792db6')
.reply(201, {})
.persist(); // otherwise consumed!
.post('/bulk/744321ca-cc95-4967-b8df-42c98b792db6')
.reply(201, {})
.persist(); // otherwise consumed!
nock('http://localhost:3000')
.post('/bulk/744321ca-cc95-4967-b8df-42c98b792db6/done')
.reply(204, {});
nock('http://localhost:3000').post('/bulk/744321ca-cc95-4967-b8df-42c98b792db6/done').reply(204, {});
// should succeed
expect(await CommonSpec.runExecuteConnector()).to.equal(true);
@@ -77,17 +73,16 @@ export class CommonSpec {
// should fail due to nockBulkAdd being consumed
expect(await CommonSpec.runExecuteConnector()).to.equal(false);
}
/**
* Executes the connector
*/
static async runExecuteConnector(): Promise<boolean> {
try{
await executeConnector('http://localhost:3000', CommonSpec.connector)
try {
await executeConnector('http://localhost:3000', CommonSpec.connector);
return true;
}catch(err){
} catch (err) {
return false;
}
}

View File

@@ -35,11 +35,12 @@ export class ConnectorSpec {
@test
async testAutomaticMissingUIDGeneration() {
const uuidRegExp = new RegExp('^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$');
const uuidRegExp = new RegExp(
'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$',
);
const messages = await ConnectorSpec.connector.getItems();
for(const message of messages){
for (const message of messages) {
expect(message.uid).to.match(uuidRegExp);
}
}
}

View File

@@ -66,12 +66,10 @@ export class MinimalConnectorSpec {
@test
getSampleThings() {
return MinimalConnectorSpec.connector
.getItems()
.then(<T extends SCThings>(items: T[]) => {
if (items.length > 0) {
MinimalConnectorSpec.validateThings(items);
}
});
return MinimalConnectorSpec.connector.getItems().then(<T extends SCThings>(items: T[]) => {
if (items.length > 0) {
MinimalConnectorSpec.validateThings(items);
}
});
}
}

View File

@@ -1,3 +1,3 @@
{
"extends": "./node_modules/@openstapps/configuration/tsconfig.json"
"extends": "@openstapps/tsconfig"
}