import { ComponentClass } from './component/Component'; /** * @description * Router class for creating a structure of * components and register them. * @example * const rootRouter = new Router('app'); * * const chatRouter = new Router('chat'); * rootRouter.use(chatRouter); * * // app/chat/sendMessage * chatRouter.use(SendMessageController); * * // app/chat/addMember * chatRouter.use(AddMemberController); * * // app/chat/messages * chatRouter.use(MessagesDatabox); * * rootRouter.register(); */ export default class Router { private readonly _route; private readonly _components; private readonly _innerRouters; constructor(route?: string); /** * Returns the route of the router. */ get route(): string; /** * @description * Attaches a router on this router. * Can be used to create deep structures. * @param router */ use(router: Router): Router; /** * @description * Attaches a Component (Controller, Receiver, Channel or Databox) to a Router. * You are able to register multiple components with the same * type and identifier but different API levels. * The identifier of the component will be created with the endpoint name of * the component and the router chain. * The endpoint name and apiLevel can be provided with the API decorator. * Otherwise, the endpoint name and apiLevel are parsed from the class name. * Therefore a particular class name convention needs to be followed, see the code examples. * However, you are able to override the resulting endpoint name or apiLevel with * the second parameter of this method. * Notice that you need to call register on the root Router * to register all components recursively. * @example * Example 1: * @API("sendMsg",1) * class SendMessageController extends Controller {} * Endpoint name = sendMsg, apiLevel = 1 * * Example 2: * class SendMessageController extends Controller {} * Endpoint name = sendMessage, apiLevel = undefined * * Example 3: * class RemoveItem extends Controller {} * Endpoint name = removeItem, apiLevel = undefined * * Example 4: * class BlockUserController_4 extends Controller {} * Endpoint name = blockUser, apiLevel = 4 * * Example 5: * class AddItem_4 extends Controller {} * Endpoint name = addItem, apiLevel = 4 * * Example 6: * class ProfileDatabox_13 extends Databox {} * Endpoint name = profile, apiLevel = 13 * * Example 7: * class ProfileChannel_5 extends Channel {} * Endpoint name = profile, apiLevel = 5 * * Example 8: * class MoveReceiver extends Receiver {} * Endpoint name = move, apiLevel = undefined * @param component * @param override * Optional parameter to override the resulting endpoint name and apiLevel. */ use(component: ComponentClass, override?: { endpointName?: string; apiLevel?: number | null; }): Router; /** * @description * Registers all components also from inner routers. * Notice to call the method only on the root router * and after attaching all components and routers. * Don't forget to import the file in the app config. */ register(): void; }