UNPKG

@swizzyweb/swizzy-web-service

Version:

Web service framework for swizzy dyn serve

90 lines (89 loc) 2.45 kB
import { ILogger } from "@swizzyweb/swizzy-common"; import { Application, Router } from "@swizzyweb/express"; import { IInternalWebServiceProps } from "./interface.js"; export interface IRunResult { } export interface IRunProps { } export interface IWebService { /** * Friendly name of webservice. */ readonly name: string; /** * instanceId of WebService. */ readonly instanceId: string; /** * Installs the WebService to the app. * @param props for install */ install(props: IRunProps): Promise<IRunResult>; /** * Uninstalls the WebService from the app. * @param props for uninstall */ uninstall(props: IRunProps): Promise<any>; /** * Whether the app is installed or not. */ isInstalled(): boolean; toJson(): any; toString(): string; } /** * Base web service class to be implemented. */ export declare abstract class WebService<APP_STATE> implements IWebService { readonly name: string; readonly instanceId: string; readonly port: number; readonly packageName: string; path: string; protected logger: ILogger<any>; protected state: APP_STATE; private _isInstalled; private app; private routerClasses; private installedRouters; private middleware; /** * Constructor for WebService base class. * Note: For subclasses of this, it is recommended to use {@link IWebServiceProps} * to simplify user implementation usage. * @param props internal props */ constructor(props: IInternalWebServiceProps<APP_STATE>); install(props: IRunProps): Promise<IRunResult>; private validateNotInstalled; isInstalled(): boolean; private installRouters; private installRouter; protected getState(): APP_STATE; private useRouter; private saveInstance; uninstall(props: IRunProps): Promise<any>; private uninstallRouters; private uninstallRouter; toJson(): { name: string; instanceId: string; isInstalled: boolean; logger: any; port: number; packageName: string; state: any; installedRouters: any; path: string; middleware: any; }; toString(): string; } export interface IInstallMiddlewareProps { app: Application; logger: ILogger<any>; } export interface IInstallMiddlewareToRouterProps { router: Router; logger: ILogger<any>; }