refactor: split api into api, api-cli & api-plugin

This commit is contained in:
2023-06-02 16:41:25 +02:00
parent 495a63977c
commit b21833de40
205 changed files with 1981 additions and 1492 deletions

View File

@@ -67,7 +67,6 @@ export class Client {
/**
* Create a new search request with altered pagination parameters to move to the next result window
*
* @param searchRequest Last search request
* @param searchResponse Search response for supplied search request
* @throws OutOfRangeError Throws an error if the next window is beyond the total number of results
@@ -90,7 +89,6 @@ export class Client {
/**
* Instantiate a new StApps-API client to communicate with a StApps-backend.
*
* @param httpClient HTTP client to use
* @param url URL of the backend
* @param version App version to use when requesting data *(only necessary if URL is ambiguous)*
@@ -112,7 +110,6 @@ export class Client {
/**
* Get a thing by its UID
*
* @param uid UID of the thing to fetch
*/
async getThing(uid: string): Promise<SCThings> {
@@ -136,7 +133,6 @@ export class Client {
/**
* Make a handshake with the backend and check StAppsCore version
*
* @param coreVersion StAppsCore version to check
*/
async handshake(coreVersion: string): Promise<SCIndexResponse> {
@@ -155,22 +151,21 @@ export class Client {
/**
* Invoke a plugin route
*
* @param name name of the plugin
* @param parameters Parameters for the URL fragment
* @param body Body for the request
*/
async invokePlugin<T>(name: string, parameters?: {[k: string]: string}, body?: SCRequests): Promise<T> {
if (typeof this.supportedFeatures === 'undefined') {
if (this.supportedFeatures === undefined) {
const request: SCIndexRequest = {};
const response = await this.invokeRoute<SCIndexResponse>(this.indexRoute, undefined, request);
if (typeof response?.app?.features !== 'undefined') {
if (response?.app?.features !== undefined) {
/* istanbul ignore next */
this.supportedFeatures = response?.app?.features;
}
}
const pluginInfo: SCFeatureConfigurationPlugin | undefined = this.supportedFeatures?.plugins?.[name];
if (typeof pluginInfo === 'undefined') {
if (pluginInfo === undefined) {
throw new PluginNotAvailableError(name);
}
@@ -182,7 +177,6 @@ export class Client {
/**
* Invoke a route
*
* @param route Route to invoke
* @param parameters Parameters for the URL fragment
* @param body Body for the request
@@ -212,7 +206,6 @@ export class Client {
* Send a multi search request to the backend
*
* All results will be returned for requests where no size is set.
*
* @param multiSearchRequest Multi search request
*/
async multiSearch(multiSearchRequest: SCMultiSearchRequest): Promise<SCMultiSearchResponse> {
@@ -223,7 +216,7 @@ export class Client {
for (const key of Object.keys(multiSearchRequest)) {
const searchRequest = multiSearchRequest[key];
if (typeof searchRequest.size === 'undefined') {
if (searchRequest.size === undefined) {
preFlightRequest[key] = {
...searchRequest,
};
@@ -265,13 +258,12 @@ export class Client {
* Send a search request to the backend
*
* All results will be returned if no size is set in the request.
*
* @param searchRequest Search request
*/
async search(searchRequest: SCSearchRequest): Promise<SCSearchResponse> {
let size: number | undefined = searchRequest.size;
if (typeof size === 'undefined') {
if (size === undefined) {
const preFlightResponse = await this.invokeRoute<SCSearchResponse>(this.searchRoute, undefined, {
...searchRequest,
size: 0,
@@ -288,7 +280,6 @@ export class Client {
/**
* Get the next search results
*
* @param searchRequest Last search request
* @param searchResponse Search response for supplied search request
*/