adba
Version:
Any DataBase to API
46 lines (45 loc) • 2.28 kB
TypeScript
/**
* @file express-router.ts
* @description This file provides functionalities for creating an Express router with dynamic routes based on ORM models.
*/
import { Model } from "objection";
import express from 'express';
import type { IExpressRouterConf, IRoutesObject } from "./types";
import GenericController from "./controller";
/**
* Modifies predefined routes by either adding new ones or removing existing ones.
* @param defs - The definitions to be added or removed.
* @param remove - Whether to remove the definitions.
*/
export declare function modifyDefinedRoutes(defs: Record<string, string> | string[], remove?: boolean): void;
/**
* Adds alias mappings for table names.
* @param alias - The alias mappings.
*/
export declare function addTableAlias(alias: Record<string, string>): void;
/**
* Generates an object containing routes for each model and controller based on provided configuration.
* @param models - The models to generate routes for.
* @param controllers - The associated controllers for each model.
* @param config - The configuration for including or excluding routes.
* @returns The constructed routes object.
*/
export declare function routesObject(models: Record<string, typeof Model>, controllers?: Record<string, typeof GenericController>, config?: IExpressRouterConf): IRoutesObject;
/**
* Lists the routes currently defined in the Express router.
* @param router - The Express router.
* @returns An array of strings representing each route method and path.
*/
export declare function listRoutes(router: express.Router): string[];
/**
* Main function to configure an Express router with dynamic routes.
* @param routesObject - The routes object containing route definitions.
* @param config - Configuration options for the router.
* @returns The configured Express router.
*/
export default function expressRouter(routesObject: IRoutesObject, { router, beforeProcess, afterProcess, debugLog }?: {
router?: import("express-serve-static-core").Router | undefined;
beforeProcess?: ((tn: string, a: string, data: any, i: string) => any) | undefined;
afterProcess?: ((tn: string, a: string, data: any, i: string) => any) | undefined;
debugLog?: boolean | undefined;
}): import("express-serve-static-core").Router;