UNPKG

@metis-w/api-client

Version:

Modern TypeScript HTTP API client with dynamic routes, parameterized endpoints, interceptors, and advanced features

80 lines 5.34 kB
import { CacheManager } from "../managers"; import { MethodResolverOptions } from "../../utils"; import { APIResponse } from "../../types"; /** * Manages the creation and building of dynamic routes for the DynamicClient. * Handles route creation, action handlers, and parameterized routes. */ export declare class RouteBuilder { /** * Creates a dynamic route for the specified controller. * If the route is already cached, it returns the cached version. * Otherwise, it creates a new route and caches it. * * @param controller - The controller name to create the route for * @param cacheManager - The cache manager instance to use for caching routes * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @returns A dynamic route function that can handle actions and parameterized routes */ static createRoute(controller: string, cacheManager: CacheManager, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions): unknown; /** * Creates a dynamic action route for the specified controller. * If the action route is already cached, it returns the cached version. * Otherwise, it creates a new action route and caches it. * * @param controller - The controller name to create the action route for * @param cacheManager - The cache manager instance to use for caching routes * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @returns A dynamic action route object */ static createActionRoute(controller: string, cacheManager: CacheManager, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions): Record<string, unknown>; /** * Creates an action handler for the specified controller and action. * If the action handler is already cached, it returns the cached version. * Otherwise, it creates a new action handler and caches it. * * @param controller - The controller name to create the action handler for * @param action - The action name to create the handler for * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @returns A dynamic action handler function */ static createActionHandler(controller: string, action: string, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions): unknown; /** * Creates a parameterized route for the specified controller and ID. * If the parameterized route is already cached, it returns the cached version. * Otherwise, it creates a new parameterized route and caches it. * * @param controller - The controller name to create the parameterized route for * @param id - The ID to use in the parameterized route * @param cacheManager - The cache manager instance to use for caching routes * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @returns A dynamic parameterized route object */ static createParameterizedRoute(controller: string, id: string | number, cacheManager: CacheManager, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions): unknown; /** * Creates a handler for a specific endpoint. * This is used for both main actions and sub-actions. * * @param endpoint - The endpoint to create the handler for * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @param actionName - The action name for method resolution * @returns A function that can be called with payload and query parameters */ static createEndpointHandler(endpoint: string, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions, actionName?: string): (payload?: Record<string, unknown>, queryParams?: Record<string, string>) => Promise<APIResponse<unknown>>; /** * Creates a handler for sub-actions. * * @param baseEndpoint - The base endpoint for the sub-action * @param subAction - The sub-action name * @param requestMethod - The method to call for making HTTP requests * @param methodOptions - Options for HTTP method resolution * @returns A function that can be called with payload and query parameters */ static createSubActionHandler(baseEndpoint: string, subAction: string, requestMethod: (endpoint: string, payload?: Record<string, unknown>, config?: any) => Promise<APIResponse<unknown>>, methodOptions?: MethodResolverOptions): (payload?: Record<string, unknown>, queryParams?: Record<string, string>) => Promise<APIResponse<unknown>>; } //# sourceMappingURL=route-builder.d.ts.map