/// /// import { BaseImplementation } from "../types/implementation"; import { Content, ServerStatus } from "../types/global"; import { FullServerOptions, ServerOptions } from "../types/structures/ServerOptions"; import ContentTypes from "./router/ContentTypes"; import { DataContext, EndFn, ErrorCallbacks, FinishCallbacks, RatelimitCallbacks, RealAny } from "../types/internal"; import FileLoader from "./router/File"; import { UsableMiddleware } from "./Middleware"; import Validator from "./Validator"; import Path from "./router/Path"; import { oas31 } from "openapi3-ts"; import Channel from "./Channel"; import HttpRequestContext from "./request/HttpRequestContext"; export declare const defaultOptions: FullServerOptions; export default class Server = {}> { private context; private options; private middlewares; private implementation; private _status; private global; private promises; private interval; private openAPISchemas; /** * Construct a new Server Instance * @example * ``` * import { Server } from "rjweb-server" * import { Runtime } from "@rjweb/runtime-bun" * * const server = new Server(Runtime, { * port: 3000 * }) * ``` * @since 3.0.0 */ constructor(implementation: BaseImplementation, options: Options, middlewares?: Middlewares, context?: Context); /** * Grab a Channel from either a string identifier or a Channel object * @example * ``` * const channel = ctr.$channel('channel') * * await channel.send('text', 'Ok') * * // or * * const ref = new Channel() * const channel = ctr.$channel(ref) * * await channel.send('text', 'Ok') * ``` * @since 9.8.1 */ $channel(channel: Channel | string): Channel; /** * Fetch (simulate) a request to the Server * @since 9.3.0 */ fetch(path: string | URL, request?: RequestInit): ReturnType; /** * Add a Content Type Mapping to override (or expand) content types * @since 5.3.0 */ contentTypes(callback: (builder: ContentTypes) => ContentTypes): this; Validator: new >(...args: ConstructorParameters>) => Validator; get FileLoader(): new (prefix: string) => FileLoader; /** * Listen to Error Callbacks * @since 9.0.0 */ error>(key: Key, callback: ErrorCallbacks[Key]): this; /** * Listen to Ratelimit Callbacks * @since 9.0.0 */ rateLimit>(key: Key, callback: RatelimitCallbacks[Key]): this; /** * Listen to Handler Finish Callbacks * @since 9.5.5 */ finish>(key: Key, callback: FinishCallbacks[Key]): this; /** * Listen to Not Found Callbacks * @since 9.0.0 */ notFound(callback: (ctr: DataContext<'HttpRequest', 'GET', HttpRequestContext, Middlewares>) => RealAny): this; /** * Create a new Path * @since 6.0.0 */ path(prefix: string, callback: (path: Path) => any): this; /** * Listen to all HTTP Requests (does not override routed ones) * @since 9.0.0 */ http(callback: (ctr: DataContext<'HttpRequest', 'GET', HttpRequestContext, Middlewares>, end: EndFn) => RealAny): this; /** * Generate an OpenAPI Specification for the Server * @since 9.0.0 */ openAPI(name: string, version: string, server: oas31.ServerObject, contact?: oas31.ContactObject): oas31.OpenAPIObject; /** * Add an OpenAPI Schema to the Server * @since 9.0.0 */ schema(name: string, schema: oas31.SchemaObject | oas31.ReferenceObject): this; /** * Get the Server's Port that its listening on * @since 9.0.0 */ port(): (Options extends { port: number; } ? Options['port'] extends 0 ? number : Options['port'] : number) | null; /** * Get the Server's Status * @since 9.0.0 */ status(): ServerStatus; /** * Start the Server Instance * @example * ``` * import { Server } from "rjweb-server" * * const server = new Server({}) * * server.start().then((port) => { * console.log(`Server Started on Port ${port}`) * }) * ``` * @since 3.0.0 */ start(): Promise; /** * Stop the Server Instance * @example * ``` * import { Server } from "rjweb-server" * * const server = new Server(...) * * server.start().then((port) => { * console.log(`Server Started on Port ${port}`) * * setTimeout(() => { * server.stop() * console.log('Server Stopped after 5 seconds') * }, 5000) * }) * ``` * @since 3.0.0 */ stop(): this; }