import type { AnyClass, EndFn, RealAny } from "../types/internal"; import HttpRequestContext from "./request/HttpRequestContext"; import WsOpenContext from "./request/WsOpenContext"; import WsMessageContext from "./request/WsMessageContext"; import WsCloseContext from "./request/WsCloseContext"; import type Server from "./Server"; import type RequestContext from "../types/internal/classes/RequestContext"; import type GlobalContext from "../types/internal/classes/GlobalContext"; import type Base from "./request/Base"; export type UsableMiddleware = any, ModifiedHttpContext extends AnyClass = any, ModifiedWsOpenContext extends AnyClass = any, ModifiedWsMessageContext extends AnyClass = any, ModifiedWsCloseContext extends AnyClass = any> = { NOTICE: 'DO NOT CALL MANUALLY, THIS IS FOR RJWEB INTERNALLY'; classContexts: { HttpRequest(config: Config, Original: AnyClass): ModifiedHttpContext; WsOpen(config: Config, Original: AnyClass): ModifiedWsOpenContext; WsMessage(config: Config, Original: AnyClass): ModifiedWsMessageContext; WsClose(config: Config, Original: AnyClass): ModifiedWsCloseContext; }; infos: { name: string; version: string; }; rjwebVersion: number; config: Config; callbacks: { load?(config: any, server: any, context: any): RealAny; httpRequest?(config: any, server: any, context: any, ctr: any, end: any): RealAny; wsOpen?(config: any, server: any, context: any, ctr: any, end: any): RealAny; wsMessage?(config: any, server: any, context: any, ctr: any, end: any): RealAny; wsClose?(config: any, server: any, context: any, ctr: any, end: any): RealAny; }; finishCallbacks: { httpRequest?(config: any, server: any, context: any, ctr: any, ms: number): RealAny; wsOpen?(config: any, server: any, context: any, ctr: any, ms: number): RealAny; wsMessage?(config: any, server: any, context: any, ctr: any, ms: number): RealAny; wsClose?(config: any, server: any, context: any, ctr: any, ms: number): RealAny; }; }; export declare const currentVersion = 9; declare class Dummy { } export default class Middleware = {}, InternalData extends Record = {}, ModifiedHttpContext extends AnyClass = typeof Dummy, ModifiedWsOpenContext extends AnyClass = typeof Dummy, ModifiedWsMessageContext extends AnyClass = typeof Dummy, ModifiedWsCloseContext extends AnyClass = typeof Dummy, Excluded extends (keyof Middleware)[] = []> { private name; private version; private data; /** * Build a new Middleware * @example * ``` * import { Middleware } from "rjweb-server" * * const middleware = new Middleware<{ greeting: string }>('Say Hi', '1.0.0') * .httpRequest((config, server, context, ctr, end) => { * if (ctr.url.path.includes('hello')) end(ctr.print(config.greeting)) * }) * .export() * ``` * @since 9.0.0 */ constructor(name: string, version: string); /** * Callback that runs when the middleware is loaded (server starting, can be multiple times!) * @since 9.0.0 */ load(callback: (config: Config, server: Server<{}, [], {}>, context: GlobalContext) => RealAny): Omit, Excluded[number] | 'load'>; /** * Callback that runs when any HTTP Request is made * @since 9.0.0 */ httpRequest(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: HttpRequestContext & InstanceType, end: EndFn) => RealAny): Omit, Excluded[number] | 'httpRequest'>; /** * Callback that runs when any HTTP Request finishes * @since 9.0.0 */ httpRequestFinish(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: Base, ms: number) => RealAny): Omit, Excluded[number] | 'httpRequestFinish'>; /** * Modify the HttpRequestContext Class to add new properties or methods for the user * @since 9.0.0 */ httpRequestContext(callback: (config: Config, Original: typeof HttpRequestContext) => NewClass): Omit, Excluded[number] | 'httpRequestContext'>; /** * Callback that runs when any WebSocket Connection is opened * @since 9.0.0 */ wsOpen(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: WsOpenContext & InstanceType, end: EndFn) => RealAny): Omit, Excluded[number] | 'wsOpen'>; /** * Callback that runs when any WebSocket Connection is opened and finishes running all events * @since 9.0.0 */ wsOpenFinish(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: Base, ms: number) => RealAny): Omit, Excluded[number] | 'wsOpenFinish'>; /** * Modify the WsOpenContext Class to add new properties or methods for the user * @since 9.0.0 */ wsOpenContext(callback: (config: Config, Original: typeof WsOpenContext) => NewClass): Omit, Excluded[number] | 'wsOpenContext'>; /** * Callback that runs when any WebSocket Message is recieved * @since 9.0.0 */ wsMessage(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: WsMessageContext & InstanceType, end: EndFn) => RealAny): Omit, Excluded[number] | 'wsMessage'>; /** * Callback that runs when any WebSocket Message is recieved and finishes running all events * @since 9.0.0 */ wsMessageFinish(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: Base, ms: number) => RealAny): Omit, Excluded[number] | 'wsMessageFinish'>; /** * Modify the WsMessageContext Class to add new properties or methods for the user * @since 9.0.0 */ wsMessageContext(callback: (config: Config, Original: typeof WsMessageContext) => NewClass): Omit, Excluded[number] | 'wsMessageContext'>; /** * Callback that runs when any WebSocket Connection is closed * @since 9.0.0 */ wsClose(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: WsCloseContext & InstanceType, end: EndFn) => RealAny): Omit, Excluded[number] | 'wsClose'>; /** * Callback that runs when any WebSocket Connection is closed and finishes running all events * @since 9.0.0 */ wsCloseFinish(callback: (config: Config, server: Server<{}, [], {}>, context: RequestContext, ctr: Base, ms: number) => RealAny): Omit, Excluded[number] | 'wsCloseFinish'>; /** * Modify the WsCloseContext Class to add new properties or methods for the user * @since 9.0.0 */ wsCloseContext(callback: (config: Config, Original: typeof WsCloseContext) => NewClass): Omit, Excluded[number] | 'wsCloseContext'>; /** * Export the Middleware for use in the Server * @since 9.0.0 */ export(): { use(config: Config): UsableMiddleware; }; } export {};