UNPKG

@creamapi/cream

Version:

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

45 lines (44 loc) 1.88 kB
import { ExpressApplication } from '../ExpressApplication'; import { Constructable } from '../Utils/Constructable'; export declare const SERVICE_ID_METADATA: unique symbol; /** * 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; /** * 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(): any; /** * 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 Constructable<ExpressService>>(id: string): (target: T) => T; } export type ExpressServices = ExpressService[];