import type { UsableMiddleware } from "../Middleware"; import type { UsableValidator } from "../Validator"; import type { RateLimitConfig } from "../../types/internal"; import RateLimit from "./RateLimit"; import type GlobalContext from "../../types/internal/classes/GlobalContext"; import type { oas31 } from "openapi3-ts"; import Path from "./Path"; export default class File = {}, Excluded extends (keyof File)[] = []> { private validators; protected _httpRatelimit: RateLimitConfig | null; protected _wsRatelimit: RateLimitConfig | null; protected promises: Promise[]; protected openApi: oas31.OperationObject; private _global; private prefix; private computePath; /** * Create a new File Loader * @since 9.0.0 */ constructor(prefix: string, global: GlobalContext, validators?: Validators, ratelimits?: [RateLimitConfig, RateLimitConfig], promises?: Promise[]); /** * Add OpenAPI Documentation to all HTTP Endpoints in this Path (and all children) * @since 9.0.0 */ document(item: oas31.OperationObject): Omit, Excluded[number] | 'document'>; /** * Add a Ratelimit to all HTTP Endpoints in this Path (and all children) * * When a User requests an Endpoint, that will count against their hit count, if * the hits exceeds the `` in `ms`, they wont be able to access * the route for `ms`. * @example * ``` * import { time } from "@rjweb/utils" * * server.path('/', (path) => path * .httpRateLimit((limit) => limit * .hits(5) * .window(time(20).s()) * .penalty(0) * ) // This will allow 5 requests every 20 seconds * .http('GET', '/hello', (ws) => ws * .onRequest(async(ctr) => { * ctr.print('Hello bro!') * }) * ) * ) * * server.rateLimit('httpRequest', (ctr) => { * ctr.print(`Please wait ${ctr.getRateLimit()?.resetIn}ms!!!!!`) * }) * ``` * @since 9.0.0 */ httpRatelimit(callback: (limit: RateLimit) => any): Omit, Excluded[number] | 'httpRatelimit'>; /** * Add a Ratelimit to all WebSocket Endpoints in this Path (and all children) * * When a User sends a message to a Socket, that will count against their hit count, if * the hits exceeds the `` in `ms`, they wont be able to access * the route for `ms`. * @example * ``` * import { time } from "@rjweb/utils" * * server.path('/', (path) => path * .httpRateLimit((limit) => limit * .hits(5) * .window(time(20).s()) * .penalty(0) * ) // This will allow 5 messages every 20 seconds * .ws('/echo', (ws) => ws * .onMessage(async(ctr) => { * ctr.print(await ctr.rawMessageBytes()) * }) * ) * ) * * server.rateLimit('wsMessage', (ctr) => { * ctr.print(`Please wait ${ctr.getRateLimit()?.resetIn}ms!!!!!`) * }) * ``` * @since 9.0.0 */ wsRatelimit(callback: (limit: RateLimit) => any): Omit, Excluded[number] | 'wsRatelimit'>; /** * Use a Validator on all Endpoints in this Path * * This will attach a Validator to all Endpoints in this Path * @since 9.0.0 */ validate<_Validator extends UsableValidator>(validator: _Validator): File; /** * Load Files from a Directory * @since 9.0.0 */ load(directory: string, options?: { /** * Function to filter which files get loaded * @default (path) => path.endsWith('js') * @since 9.0.0 */ filter?: (path: string) => boolean; /** * Whether to use file based routing * @default false * @since 9.0.0 */ fileBasedRouting?: boolean; }): this; /** * Export the File Loader to be used in route files * @since 9.0.0 */ export(): { Path: new (prefix: string) => Path; }; }