<commit_before>"use strict";
import * as Router from "koa-router";
import {controllers} from "../Controllers";

export class RouterBuilder {

    private _router: Router;
    private _controllerInstances: any[];
    private _built: boolean;

    constructor() {
        this._router = new Router();
        this._controllerInstances = [];
        this._built = false;
    }

    private buildRouter() {
        if (!this._built) {
            for (let e of controllers) {
                let obj = Reflect.construct(e, []);
                let routePrefix = Reflect.get(e, "routePrefix")
                let prefix: string = routePrefix ? routePrefix : "/";

                if (prefix[prefix.length - 1] !== "/") {
                    prefix += "/";
                }

                for (let router of obj.routers) {
                    let path: string = router.path;

                    if (!path.startsWith("/")) {
                        path = prefix + path;
                    }

                    switch (router.method) {
                        case "GET": this._router.get(path, obj[router.name].bind(obj)); break;
                        case "POST": this._router.post(path, obj[router.name].bind(obj)); break;
                        case "PUT": this._router.put(path, obj[router.name].bind(obj)); break;
                        case "DELETE": this._router.delete(path, obj[router.name].bind(obj)); break;<commit_msg>add type<commit_after>"use strict";
import * as Router from "koa-router";
import {controllers} from "../Controllers";

interface RouteInfo {
    path: string,
    method: string,
    name: string
}

export class RouterBuilder {

    private _router: Router;
    private _controllerInstances: any[];
    private _built: boolean;

    constructor() {
        this._router = new Router();
        this._controllerInstances = [];
        this._built = false;
    }

    private buildRouter() {
        if (!this._built) {
            for (let e of controllers) {
                let obj: { routers: RouteInfo[] } = Reflect.construct(e, []);
                let routePrefix = Reflect.get(e, "routePrefix")
                let prefix: string = routePrefix ? routePrefix : "/";

                if (prefix[prefix.length - 1] !== "/") {
                    prefix += "/";
                }

                for (let router of obj.routers) {
                    let path: string = router.path;

                    if (!path.startsWith("/")) {
                        path = prefix + path;
                    }

                    switch (router.method) {
                        case "GET": this._router.get(path, obj[router.name].bind(obj)); break;
                        case "POST": this._router.post(path, obj[router.name].bind(obj)); break;
                        case "PUT": this._router.put(path, obj[router.name].bind(obj)); break;
                        case "DELETE": this._router.delete(path, obj[router.name].bind(obj)); break;
{'fraction_non_alphanumeric': 0.13160552002692696, 'fraction_numerical': 0.0006731740154830024, 'mean_word_length': 1.6324180690876882, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5966751', 'n_tokens_mistral': 808, 'n_tokens_neox': 762, 'n_words': 192}