UNPKG

@celosiajs/core

Version:

CelosiaJS Core. A framework for REST API based on Express.js

80 lines (79 loc) 3.81 kB
import { CelosiaInstance, CelosiaRequest, CelosiaResponse, CelosiaRouter } from './'; export type ExtensionHandler<T, Args extends any[], Return> = (extended: T, ...args: Args) => Return; export type CelosiaInstanceExtensionHandler<Args extends any[] = any[], Return = void> = ExtensionHandler<CelosiaInstance<boolean>, Args, Return>; export type CelosiaRouterExtensionHandler<Args extends any[] = any[], Return = void> = ExtensionHandler<CelosiaRouter<boolean>, Args, Return>; export type CelosiaRequestExtensionHandler<Args extends any[] = any[], Return = void> = ExtensionHandler<CelosiaRequest<any>, Args, Return>; export type CelosiaResponseExtensionHandler<Args extends any[] = any[], Return = void> = ExtensionHandler<CelosiaResponse<any>, Args, Return>; export type TransformExtensionHandlerToExtensionType<Handler extends ExtensionHandler<any, any, any>> = Handler extends ExtensionHandler<any, infer Args, infer Return> ? (...args: Args) => Return : never; export declare class ExtensionsRegistryClass { private celosiaInstanceExtensionsHandler; private celosiaRouterExtensionsHandler; private celosiaRequestExtensionsHandler; private celosiaResponseExtensionsHandler; /** * Register a new extension for CelosiaInstance. * * Throws `DuplicateExtensionError` when a key has been registered. */ registerCelosiaInstanceExtension(key: string | symbol, handler: CelosiaInstanceExtensionHandler): void; /** * Remove an extension for CelosiaInstance. * * Throws `InvalidExtensionError` when a key has not been registered. */ removeCelosiaInstanceExtension(key: string | symbol): void; /** * Get a registered extension for CelosiaInstance. */ getCelosiaInstanceExtension(key: string | symbol): CelosiaInstanceExtensionHandler | undefined; /** * Register a new extension for CelosiaRouter. * * Throws `DuplicateExtensionError` when a key has been registered. */ registerCelosiaRouterExtension(key: string | symbol, handler: CelosiaRouterExtensionHandler): void; /** * Remove an extension for CelosiaRouter. * * Throws `InvalidExtensionError` when a key has not been registered. */ removeCelosiaRouterExtension(key: string | symbol): void; /** * Get a registered extension for CelosiaRouter. */ getCelosiaRouterExtension(key: string | symbol): CelosiaRouterExtensionHandler | undefined; /** * Register a new extension for CelosiaRequest. * * Throws `DuplicateExtensionError` when a key has been registered. */ registerCelosiaRequestExtension(key: string | symbol, handler: CelosiaRequestExtensionHandler): void; /** * Remove an extension for CelosiaRequest. * * Throws `InvalidExtensionError` when a key has not been registered. */ removeCelosiaRequestExtension(key: string | symbol): void; /** * Get a registered extension for CelosiaRequest. */ getCelosiaRequestExtension(key: string | symbol): CelosiaRequestExtensionHandler | undefined; /** * Register a new extension for CelosiaResponse. * * Throws `DuplicateExtensionError` when a key has been registered. */ registerCelosiaResponseExtension(key: string | symbol, handler: CelosiaResponseExtensionHandler): void; /** * Remove an extension for CelosiaResponse. * * Throws `InvalidExtensionError` when a key has not been registered. */ removeCelosiaResponseExtension(key: string | symbol): void; /** * Get a registered extension for CelosiaResponse. */ getCelosiaResponseExtension(key: string | symbol): CelosiaResponseExtensionHandler | undefined; } declare const ExtensionsRegistry: ExtensionsRegistryClass; export default ExtensionsRegistry;