UNPKG

@creamapi/cream

Version:

Concise REST API Maker - An extension library for express to create REST APIs faster

49 lines (48 loc) 1.9 kB
import { ExpressApplication } from '../ExpressApplication'; /** * This abstract class is used to declare a service for the app. <br> * This service is active all time during the lifetime of the owner app <br> * A service is mainly used for exchanging information between controllers <br> * for example daisy chaining updates within the controllers. <br> * Another useful example is just to initialize and share a database connection <br> * between multiple controllers or just to run some code at startup. */ export declare abstract class ExpressService { /** * the application owning the service */ private _app; /** * The id of the service. This id is used to retrieve the service from within the app */ private _id; /** * This method must be implemented to bootstrap the service. * If the service is successfully started then this method * must return true. If there is an error with the initialization * the method must return false */ abstract init(): Promise<boolean>; /** * This is the setter to set the owning application */ set app(v: ExpressApplication); /** * This method is use to get the owning application */ get app(): ExpressApplication; /** * This method is used to get the current identifier of the service */ get id(): string; /** * This decorator is used to declare the identifier of the service * @remarks It is mandatory * @param id The identifier that uniquely identifies the service. Having multiple services with the same ID will give conflicts * @returns the decorator that will create a new class based from the service and will also set the identifier */ static IdentifiedBy<T extends { new (...args: any[]): any; }>(id: string): (target: T) => T; } export type ExpressServices = ExpressService[];