jsm-core
Version:
Core library for JSM project
87 lines (86 loc) • 5.75 kB
TypeScript
import { RequestHandler, Request, Response, NextFunction, Router } from "express";
export declare enum HttpMethods {
GET = "get",
POST = "post",
PUT = "put",
DELETE = "delete",
PATCH = "patch",
OPTIONS = "options",
HEAD = "head"
}
export declare const JsmRequestHandlerMiddleware: (errorHandler?: (err: Error | Jsm.Core.Utils.Api.Response.Error, req: Request, res: Response, next: NextFunction) => void) => Router;
type TRegisterRouteHandlerOptions = {
customId?: string;
addApiPrefix?: boolean;
} | string | boolean;
/**
* Register a request handler for a specific HTTP method and path.
* @param {HttpMethods} method - The HTTP method to register the handler for.
* @param {string} path - The path to register the handler for.
* @param {boolean} addApiPrefix - Whether to add the API prefix to the path. @default true
* @param {string} [customId] - Used to check if it's already registered to prevent duplications.
*
*/
export declare const registerRouteHandler: (method: HttpMethods, path: `/${string}`, requestHandler: RequestHandler | RequestHandler[], opt?: {
customId?: string;
addApiPrefix?: boolean;
}) => void;
export declare const router: {
/**
* Registers a GET request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
get(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers a POST request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
post(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers a PUT request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
put(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers a DELETE request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
delete(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers a PATCH request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
patch(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers an OPTIONS request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
options(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
/**
* Registers a HEAD request handler for the specified path.
* @param {`/${string}`} path - The path to register the handler for.
* @param {...(RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)} args - The request handlers or options for the route. Multiple handlers can be provided.
* @param {boolean} [addApiPrefix] - Whether to add the API prefix to the path. Defaults to true.
* @param {string} [customId] - A custom identifier for the route, used to prevent duplicate registrations.
*/
head(path: `/${string}`, ...args: (RequestHandler | RequestHandler[] | TRegisterRouteHandlerOptions)[]): void;
};
export {};