import { ControllerConfig } from "../main/config/definitions/parts/controllerConfig"; import BackErrorBag from "./BackErrorBag"; import Component from './component/Component'; import { ConsumeInputFunction, InputValidationCheckFunction } from '../main/input/inputClosureCreator'; import { CompHandleMiddlewareInvoker } from '../main/compHandleMiddleware/compHandleMiddlewareUtils'; import Socket from './Socket'; import Packet from './Packet'; import { NormalAccessCustomFunction } from '../main/config/definitions/parts/accessConfigs'; import { PreparedProcessChain } from '../main/processChain/prepareProcessChainConfig'; /** * The Controller is one of the zation components. * It followers the request-response principle. * The controller can be protected with access rules, also it * supports input validation by using models. Additionally, * it is easy to return a result or a collection of errors to the client. * A controller should be used for determining an action that * the client can make e.g., login, register, or sendMessage. * If you have some actions that not return any value and the * status of the processed request does not matter on the * client-side you should look at Receivers. * Also if you want to get data from the server it is recommended to * use a Databox instead of a Controller because it is much easier to * use for this case and provides the functionality to * keep the data up to date in real-time. */ export default class Controller extends Component { constructor(identifier: string, preparedData: ControllerPreparedData, apiLevel: number | undefined); /** * @description * This property is used for getting the configuration of this controller. */ static readonly config: ControllerConfig; /** * @description * Gets invoked when the controller gets an request and input is correct. * This method will only be invoked when the beforeHandle method has not thrown an error. * @param socket * @param input * @param packet * @return * The Return value of the function is send to the client with an success response. * JSONString class is supported and will send the result without JSON.stringify. * @throws * You can throw BackError or BackErrorBag, which are sent to the client with a not success response. * Notice that only the BackError or BackErrorBag sends back to the client. * All other errors or objects will be converted to an unknown BackError. */ protected handle(socket: Socket, input: any, packet: Packet): Promise | any; /** * @description * Gets invoked when the controller gets an request with invalid input. * @param socket * @param rawInput * Notice that you will get the raw input means only * the data the user has sent without processed by the models. * @param packet * @param backErrorBag * @throws * You can throw BackError or BackErrorBag * than the errors will be merged with the previous errors and send back to the client. * Notice that only the BackError or BackErrorBag sends back to the client. * All other errors or objects will be converted to an * unknown BackError and overrides all previous BackErrors. */ protected invalidInput(socket: Socket, rawInput: any, packet: Packet, backErrorBag: BackErrorBag): Promise | void; /** * Decorator for set the Controller config. * But notice that when you use the decorator * that you cannot set the config property by yourself. * @param controllerConfig * @example * @Controller.Config({}); */ static Config(controllerConfig: ControllerConfig): (target: typeof Controller) => void; } export declare type ControllerClass = (new (...args: any[]) => Controller) & { config: ControllerConfig; prototype: Controller; }; export interface ControllerPreparedData extends PreparedProcessChain { controllerConfig: ControllerConfig; checkAccess: NormalAccessCustomFunction; handleMiddlewareInvoke: CompHandleMiddlewareInvoker; handleReturnsComplexTypes: boolean; consumeInput: ConsumeInputFunction; checkInputValidation: InputValidationCheckFunction; }