import { RateLimitError } from "../errors/RatelimitError.js"; import { type RequestSchedulerOptions as InternalRequestSchedulerOptions, type RequestLane, RequestScheduler } from "../internals/RequestScheduler.js"; export type RuntimeProfile = "serverless" | "persistent"; export type RequestPriority = RequestLane; export type RequestSchedulerOptions = InternalRequestSchedulerOptions; /** * The options used to initialize the RequestClient */ export type RequestClientOptions = { /** * The header used to send the token in the request. * This should generally always be "Bot" unless you are working with OAuth. * * @default "Bot" */ tokenHeader?: "Bot" | "Bearer"; /** * The base URL of the API. * @default https://discord.com/api */ baseUrl?: string; /** * The version of the API to use. * @default 10 */ apiVersion?: number; /** * The user agent to use when making requests. * @default DiscordBot (https://github.com/buape/carbon, v0.0.0) */ userAgent?: string; /** * The timeout for requests. * @default 15000 */ timeout?: number; /** * Whether or not to queue requests if you are rate limited. * If this is true, requests will be queued and wait for the ratelimit to clear. * If this is false, requests will be made immediately and will throw a RateLimitError if you are rate limited. * * @default true */ queueRequests?: boolean; /** * Legacy global max queue size. In lane-based scheduler mode this is used as fallback * when lane-specific max queue sizes are not configured. * * @default 1000 */ maxQueueSize?: number; /** * Runtime profile used to derive scheduler defaults. * * @default "serverless" */ runtimeProfile?: RuntimeProfile; /** * Scheduler controls for weighted fairness and backpressure. */ scheduler?: RequestSchedulerOptions; /** * A custom fetch function to use for requests. * This allows you to inject your own fetch implementation for proxy support, * testing, mocking, or custom transport layers. */ fetch?: (input: string | URL | Request, init?: RequestInit) => Promise; }; export type QueuedRequest = { method: string; path: string; data?: RequestData; query?: Record; resolve: (value?: unknown) => void; reject: (reason?: unknown) => void; routeKey: string; }; type ScheduledRequest = QueuedRequest & { id: number; priority: RequestPriority; enqueuedAt: number; retryCount: number; }; export type RequestData = { body?: unknown; rawBody?: boolean; headers?: Record; }; /** * This is the main class that handles making requests to the Discord API. * It is used internally by Carbon, and you should not need to use it directly, but feel free to if you feel like living dangerously. */ export declare class RequestClient { /** * The options used to initialize the client */ readonly options: RequestClientOptions; protected token: string; protected customFetch: ((input: string | URL | Request, init?: RequestInit) => Promise) | undefined; protected nextRequestId: number; protected wakeupTimer: ReturnType | null; protected wakeupDueAt: number | null; protected activeWorkers: number; protected activeBucketKeys: Set; protected maxConcurrentWorkers: number; protected maxRateLimitRetries: number; protected scheduler: RequestScheduler; protected routeBuckets: Map; protected bucketStates: Map; protected globalRateLimitUntil: number; protected requestControllers: Set; constructor(token: string, options?: RequestClientOptions); get(path: string, query?: QueuedRequest["query"]): Promise; post(path: string, data?: RequestData, query?: QueuedRequest["query"]): Promise; patch(path: string, data?: RequestData, query?: QueuedRequest["query"]): Promise; put(path: string, data?: RequestData, query?: QueuedRequest["query"]): Promise; delete(path: string, data?: RequestData, query?: QueuedRequest["query"]): Promise; protected configureScheduler(): void; protected request(method: string, path: string, { data, query }: { data?: RequestData; query?: QueuedRequest["query"]; }): Promise; protected enqueueRequest(request: ScheduledRequest): Error | null; protected pumpQueue(): void; protected runQueuedRequest(request: ScheduledRequest): Promise; protected takeNextReadyRequest(): ScheduledRequest | null; protected scheduleWakeup(waitMs: number): void; protected clearWakeupTimer(): void; protected getRouteWaitTime(routeKey: string, now?: number): number; protected getPriority(method: string, path: string): RequestPriority; protected executeRequest(request: ScheduledRequest): Promise; protected waitForBucket(routeKey: string): Promise; protected scheduleRateLimit(routeKey: string, path: string, error: RateLimitError): void; protected updateBucketFromHeaders(routeKey: string, path: string, response: Response): void; protected getCurrentBucketKey(routeKey: string): string; protected getBucketKey(routeKey: string, path: string, bucketId?: string | null): string; protected getMajorParameter(path: string): string | null | undefined; protected getRouteKey(method: string, path: string): string; clearQueue(): void; get queueSize(): number; getSchedulerMetrics(): { globalRateLimitUntil: number; activeBuckets: number; laneCounts: { critical: number; standard: number; background: number; }; laneDropped: { critical: number; standard: number; background: number; }; oldestByLane: { critical: number; standard: number; background: number; }; queueSize: number; activeWorkers: number; maxConcurrentWorkers: number; }; abortAllRequests(): void; } export {}; //# sourceMappingURL=RequestClient.d.ts.map