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

@@ -20,7 +20,6 @@ import {Transport} from './transport.js';
/**
* Check if something has property STAPPS_LOG_LEVEL
*
* @param something Something to check
*/
// tslint:disable-next-line:completed-docs
@@ -30,7 +29,6 @@ function hasStAppsLogLevel(something: object): something is {STAPPS_LOG_LEVEL: n
/**
* Check if something has property STAPPS_EXIT_LEVEL
*
* @param something Something to check
*/
// tslint:disable-next-line:completed-docs
@@ -92,13 +90,12 @@ export class Logger {
/**
* Apply transformations to an output
* Will strip newlines in production environment
*
* @param logLevel Log level of the output
* @param output Output to apply transformations to
*/
private static applyTransformers(logLevel: LogLevel, output: string): string {
if (isProductiveEnvironment()) {
output = output.replace(/[\n\r]/g, ' ');
output = output.replaceAll(/[\n\r]/g, ' ');
}
if (!Array.isArray(Logger.transformations) || Logger.transformations.length === 0) {
@@ -115,7 +112,6 @@ export class Logger {
/**
* Check if intended exit level is allowed in environment exit level
*
* @param exitLevel Log level to check
*/
private static checkExitLevel(exitLevel: LogLevel): boolean {
@@ -129,7 +125,6 @@ export class Logger {
/**
* Check if intended log level is allowed in environment log level
*
* @param logLevel Log level to check
*/
private static checkLogLevel(logLevel: LogLevel): boolean {
@@ -168,7 +163,7 @@ export class Logger {
const environmentLevel = level === 'LOG' ? process.env.STAPPS_LOG_LEVEL : process.env.STAPPS_EXIT_LEVEL;
if (isNodeEnvironment() && typeof environmentLevel !== 'undefined') {
if (isNodeEnvironment() && environmentLevel !== undefined) {
// Node.js environment exists
return Number.parseInt(environmentLevel, 10);
}
@@ -186,7 +181,6 @@ export class Logger {
/**
* Get number of specific log level
*
* @param logLevel Log level to check
*/
private static logLevelNumber(logLevel: LogLevel): number {
@@ -195,7 +189,6 @@ export class Logger {
/**
* Log an error
*
* @param arguments_ Arguments to log
*/
public static async error(...arguments_: unknown[]): Promise<string | void> {
@@ -207,7 +200,7 @@ export class Logger {
console.error(Logger.applyTransformers('ERROR', Logger.stringifyArguments(...arguments_)));
if (isProductiveNodeEnvironment()) {
if (typeof Logger.transport !== 'undefined') {
if (Logger.transport !== undefined) {
return Logger.transport.send('Error', Logger.stringifyArguments(...arguments_));
}
@@ -224,7 +217,6 @@ export class Logger {
/**
* Log an information
*
* @param arguments_ Arguments to log
*/
public static info(...arguments_: unknown[]): void {
@@ -243,7 +235,7 @@ export class Logger {
* Check if the logger is initialized correctly
*/
public static initialized(): void {
if (isProductiveNodeEnvironment() && typeof Logger.transport === 'undefined') {
if (isProductiveNodeEnvironment() && Logger.transport === undefined) {
if (process.env.ALLOW_NO_TRANSPORT !== 'true') {
throw new Error(`Productive environment doesn't set a transport for error notifications.`);
}
@@ -254,7 +246,6 @@ export class Logger {
/**
* Log something
*
* @param arguments_ Arguments to log
*/
public static log(...arguments_: unknown[]): void {
@@ -271,7 +262,6 @@ export class Logger {
/**
* Log something successful
*
* @param arguments_ Arguments to log
*/
public static ok(...arguments_: unknown[]): void {
@@ -288,7 +278,6 @@ export class Logger {
/**
* Set transformations for log output
*
* @param transformations List of transformations
*/
public static setTransformations(transformations: Transformation[]) {
@@ -300,7 +289,6 @@ export class Logger {
/**
* Set a transport
*
* @param transport Transport to set
*/
public static setTransport(transport?: Transport) {
@@ -309,7 +297,6 @@ export class Logger {
/**
* Stringify a list of arguments
*
* @param arguments_ Arguments to stringify
*/
public static stringifyArguments(...arguments_: unknown[]): string {
@@ -320,7 +307,7 @@ export class Logger {
result.push(argument.toString());
} else if (argument instanceof Error) {
result.push(argument.message);
if (typeof argument.stack !== 'undefined') {
if (argument.stack !== undefined) {
result.push(argument.stack);
}
} else {
@@ -333,7 +320,6 @@ export class Logger {
/**
* Log a warning
*
* @param arguments_ Arguments to log
*/
public static warn(...arguments_: unknown[]): void {