feat: migrate to esm

This commit is contained in:
2023-03-16 01:58:13 +01:00
parent fd740b3091
commit 4df19e8c20
512 changed files with 3016 additions and 2222 deletions

View File

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

View File

@@ -2,6 +2,7 @@
"name": "@openstapps/api",
"description": "Node.js library to interact with the StApps backend service",
"version": "2.1.0",
"type": "module",
"license": "GPL-3.0-only",
"repository": "git@gitlab.com:openstapps/api.git",
"author": "Karl-Philipp Wulfert <krlwlfrt@gmail.com>",
@@ -19,10 +20,9 @@
"openstapps-api": "app.js"
},
"scripts": {
"build": "npm run lint && npm run compile",
"build": "rimraf lib && tsc",
"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 --includeVersion --out docs --readme README.md --listInvalidSymbolLinks --entryPointStrategy expand src",
"lint": "eslint --ext .ts src/",
"postversion": "npm run changelog",
@@ -87,8 +87,8 @@
"prettier": "2.8.8",
"rimraf": "4.4.0",
"ts-node": "10.9.1",
"typedoc": "0.22.18",
"typescript": "4.4.4"
"typedoc": "0.23.26",
"typescript": "4.8.4"
},
"peerDependencies": {
"@openstapps/core": "~2.1.0"

View File

@@ -21,8 +21,8 @@ import {
SCThings,
SCThingType,
} from '@openstapps/core';
import {Client} from './client';
import {BulkWithMultipleTypesError} from './errors';
import {Client} from './client.js';
import {BulkWithMultipleTypesError} from './errors.js';
/**
* A bulk

View File

@@ -19,10 +19,10 @@ import {readFileSync} from 'fs';
import path from 'path';
import {URL} from 'url';
import waitOn from 'wait-on';
import {copy} from './copy';
import {copy} from './copy.js';
// eslint-disable-next-line unicorn/prevent-abbreviations
import {e2eRun} from './e2e';
import {HttpClient} from './http-client';
import {e2eRun} from './e2e.js';
import {HttpClient} from './http-client.js';
process.on('unhandledRejection', async error => {
await Logger.error('unhandledRejection', error);

View File

@@ -31,8 +31,8 @@ import {
SCSearchRoute,
SCThings,
} from '@openstapps/core';
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError, PluginNotAvailableError} from './errors';
import {HttpClientHeaders, HttpClientInterface} from './http-client-interface';
import {ApiError, CoreVersionIncompatibleError, OutOfRangeError, PluginNotAvailableError} from './errors.js';
import {HttpClientHeaders, HttpClientInterface} from './http-client-interface.js';
/**
* StApps-API client

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {asyncPool} from '@krlwlfrt/async-pool/lib/async-pool';
import {asyncPool} from '@krlwlfrt/async-pool/lib/async-pool.js';
import {
isThing,
SCAssociatedThingWithoutReferences,
@@ -28,9 +28,9 @@ import {
import moment from 'moment';
import clone = require('rfdc');
import {v5} from 'uuid';
import {Bulk} from './bulk';
import {Client} from './client';
import {EmptyBulkError, NamespaceNotDefinedError} from './errors';
import {Bulk} from './bulk.js';
import {Client} from './client.js';
import {EmptyBulkError, NamespaceNotDefinedError} from './errors.js';
/**
* StApps-API client
@@ -187,7 +187,7 @@ export class ConnectorClient extends Client {
*/
async bulk<T extends SCThings>(type: SCThingType, source: string, timeout?: number): Promise<Bulk<T>> {
// set default value for timeout to one hour
const bulkTimeout = typeof timeout !== 'number' ? ConnectorClient.BULK_TIMEOUT : timeout;
const bulkTimeout = typeof timeout === 'number' ? timeout : ConnectorClient.BULK_TIMEOUT;
const bulkData = await this.invokeRoute<SCBulkResponse>(this.bulkRoute, undefined, {
expiration: moment().add(bulkTimeout, 'seconds').format(),

View File

@@ -12,13 +12,13 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {asyncPool} from '@krlwlfrt/async-pool/lib/async-pool';
import {asyncPool} from '@krlwlfrt/async-pool/lib/async-pool.js';
import {SCSearchRequest, SCThingType} from '@openstapps/core';
import {Bar} from 'cli-progress';
import {Client} from './client';
import {ConnectorClient} from './connector-client';
import {OutOfRangeError} from './errors';
import {HttpClientInterface} from './http-client-interface';
import {Client} from './client.js';
import {ConnectorClient} from './connector-client.js';
import {OutOfRangeError} from './errors.js';
import {HttpClientInterface} from './http-client-interface.js';
/**
* Options to set up copying data from one backend to another

View File

@@ -20,8 +20,8 @@ import {deepStrictEqual} from 'assert';
import {readdir, readFile} from 'fs';
import path from 'path';
import {promisify} from 'util';
import {ConnectorClient} from './connector-client';
import {HttpClientInterface} from './http-client-interface';
import {ConnectorClient} from './connector-client.js';
import {HttpClientInterface} from './http-client-interface.js';
const localItemMap: Map<string, SCThings> = new Map();
const remoteItemMap: Map<string, SCThings> = new Map();

View File

@@ -13,8 +13,8 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {SCPluginRegisterRequest, SCPluginRegisterRoute} from '@openstapps/core';
import {ConnectorClient} from './connector-client';
import {Plugin} from './plugin';
import {ConnectorClient} from './connector-client.js';
import {Plugin} from './plugin.js';
/**
* The PluginClient for registering and unregistering HTTP Plugins

View File

@@ -12,8 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Converter} from '@openstapps/core-tools/lib/schema';
import {Converter} from '@openstapps/core-tools/lib/schema.js';
import {Logger} from '@openstapps/logger';
import bodyParser from 'body-parser';
import express from 'express';
@@ -126,7 +125,7 @@ export abstract class Plugin {
this.app.use(bodyParser.json());
this.port = Plugin.normalizePort(
/* istanbul ignore next */
typeof process.env.PORT !== 'undefined' ? process.env.PORT : port.toString(),
typeof process.env.PORT === 'undefined' ? port.toString() : process.env.PORT,
);
this.app.set('port', this.port);
@@ -175,18 +174,21 @@ export abstract class Plugin {
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
case 'EACCES': {
// tslint:disable-next-line:no-floating-promises
Logger.error(`${bind} requires elevated privileges`);
process.exit(1);
break;
case 'EADDRINUSE':
}
case 'EADDRINUSE': {
// tslint:disable-next-line:no-floating-promises
Logger.error(`${bind} is already in use`);
process.exit(1);
break;
default:
}
default: {
throw error;
}
}
}

View File

@@ -19,10 +19,10 @@ import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import {suite, test} from '@testdeck/mocha';
import moment from 'moment';
import {Bulk} from '../src/bulk';
import {Client} from '../src/client';
import {BulkWithMultipleTypesError} from '../src/errors';
import {HttpClient} from '../src/http-client';
import {Bulk} from '../src/bulk.js';
import {Client} from '../src/client.js';
import {BulkWithMultipleTypesError} from '../src/errors.js';
import {HttpClient} from '../src/http-client.js';
chai.should();
chai.use(chaiSpies);

View File

@@ -29,10 +29,10 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import {suite, test} from '@testdeck/mocha';
import {Client} from '../src/client';
import {ApiError, OutOfRangeError} from '../src/errors';
import {HttpClient} from '../src/http-client';
import {HttpClientResponse} from '../src/http-client-interface';
import {Client} from '../src/client.js';
import {ApiError, OutOfRangeError} from '../src/errors.js';
import {HttpClient} from '../src/http-client.js';
import {HttpClientResponse} from '../src/http-client-interface.js';
chai.should();
chai.use(chaiSpies);

View File

@@ -39,10 +39,10 @@ import moment from 'moment';
import {join, resolve} from 'path';
import traverse from 'traverse';
import {promisify} from 'util';
import {ConnectorClient} from '../src/connector-client';
import {EmptyBulkError, NamespaceNotDefinedError} from '../src/errors';
import {HttpClient} from '../src/http-client';
import {HttpClientRequest, HttpClientResponse} from '../src/http-client-interface';
import {ConnectorClient} from '../src/connector-client.js';
import {EmptyBulkError, NamespaceNotDefinedError} from '../src/errors.js';
import {HttpClient} from '../src/http-client.js';
import {HttpClientRequest, HttpClientResponse} from '../src/http-client-interface.js';
chai.should();
chai.use(chaiSpies);

View File

@@ -29,9 +29,9 @@ import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import {suite, test} from '@testdeck/mocha';
import moment from 'moment';
import {copy} from '../src/copy';
import {ApiError} from '../src/errors';
import {HttpClient, RequestOptions, Response} from '../src/http-client';
import {copy} from '../src/copy.js';
import {ApiError} from '../src/errors.js';
import {HttpClient, RequestOptions, Response} from '../src/http-client.js';
import {RecursivePartial} from './client.spec';
chai.should();

View File

@@ -34,9 +34,9 @@ import {existsSync, mkdirSync, rmdirSync, unlinkSync} from 'fs';
import {createFileSync} from 'fs-extra';
import {suite, test} from '@testdeck/mocha';
import {join} from 'path';
import {e2eRun, getItemsFromSamples} from '../src/e2e';
import {ApiError} from '../src/errors';
import {HttpClient, RequestOptions, Response} from '../src/http-client';
import {e2eRun, getItemsFromSamples} from '../src/e2e.js';
import {ApiError} from '../src/errors.js';
import {HttpClient, RequestOptions, Response} from '../src/http-client.js';
import {RecursivePartial} from './client.spec';
chai.should();

View File

@@ -17,7 +17,7 @@ import {expect} from 'chai';
import chaiAsPromised from 'chai-as-promised';
import chaiSpies from 'chai-spies';
import {suite, test} from '@testdeck/mocha';
import {ApiError} from '../src/errors';
import {ApiError} from '../src/errors.js';
chai.should();
chai.use(chaiSpies);

View File

@@ -15,7 +15,7 @@
import {expect} from 'chai';
import {suite, test} from '@testdeck/mocha';
import nock from 'nock';
import {HttpClient} from '../src/http-client';
import {HttpClient} from '../src/http-client.js';
// TODO: use after each to clean up the nock (then there is no need for numerated resource links)

View File

@@ -17,10 +17,10 @@ import chai from 'chai';
import {expect} from 'chai';
import chaiSpies from 'chai-spies';
import {suite, test, timeout} from '@testdeck/mocha';
import {HttpClient} from '../src/http-client';
import {HttpClientResponse} from '../src/http-client-interface';
import {PluginClient} from '../src/plugin-client';
import {TestPlugin} from './plugin-resources/test-plugin';
import {HttpClient} from '../src/http-client.js';
import {HttpClientResponse} from '../src/http-client-interface.js';
import {PluginClient} from '../src/plugin-client.js';
import {TestPlugin} from './plugin-resources/test-plugin.js';
chai.use(chaiSpies);

View File

@@ -14,7 +14,7 @@
*/
import * as express from 'express';
import {Plugin} from '../../src/plugin';
import {Plugin} from '../../src/plugin.js';
/**
* A test plugin we use for all the tests

View File

@@ -20,8 +20,8 @@ import chaiSpies from 'chai-spies';
import {readFileSync} from 'fs';
import {suite, test, timeout} from '@testdeck/mocha';
import {resolve} from 'path';
import {HttpClient} from '../src/http-client';
import {TestPlugin} from './plugin-resources/test-plugin';
import {HttpClient} from '../src/http-client.js';
import {TestPlugin} from './plugin-resources/test-plugin.js';
chai.use(chaiSpies);