import { Context, WebSocketSession, HttpSession, Geo } from '@based/functions'; import type { ActiveObservable } from './query/index.js'; import uws from '@based/uws'; import { BasedFunctions, FunctionConfig } from './functions/index.js'; import { BasedAuth, AuthConfig } from './auth/index.js'; import { BasedErrorCode, BasedErrorData } from '@based/errors'; import { BasedServerFunctionClient } from './functionApi/index.js'; import { ActiveChannel } from './channel/index.js'; import util from 'node:util'; type EventMap = { error: BasedErrorData | BasedErrorCode; ratelimit: void; log: any; }; type Event = keyof EventMap; type Listener = (context: Context, data?: T, err?: Error | string) => void; type RateLimit = { ws: number; http: number; drain: number; }; type GetIp = (res: uws.HttpResponse, req: uws.HttpRequest) => string; type QueryEvents = { subscribe: (obs: ActiveObservable, ctx?: Context) => void; unsubscribe: (obs: ActiveObservable, ctx?: Context) => void; get: (obs: ActiveObservable, ctx?: Context) => void; }; type ChannelEvents = { subscribe: (obs: ActiveChannel, ctx?: Context) => void; unsubscribe: (obs: ActiveChannel, ctx?: Context) => void; }; export type ServerOptions = { clients?: { [key: string]: any; }; port?: number; key?: string; geo?: (ctx: Context) => Geo; disableRest?: boolean; disableWs?: boolean; silent?: boolean; cert?: string; functions?: FunctionConfig; rateLimit?: RateLimit; client?: (server: BasedServer) => BasedServerFunctionClient; auth?: AuthConfig; query?: QueryEvents; channel?: ChannelEvents; ws?: { maxBackpressureSize?: number; open?: (client: Context) => void; close?: (client: Context) => void; }; http?: { open?: (client: Context) => void; close?: (client: Context) => void; }; getIp?: GetIp; console?: Console; }; /** Based server ```js const server = new BasedServer({ port: 9910, functions: { configs: { hello: { type: 'function', fn: async () => 'hello' }, counter: { type: 'query', fn: () => () => {} } } } }) server.functions.add({ hello: { type: 'function', fn: async () => 'hello' } }) server.functions.addRoutes({ bla: { type: 'query' } }) await server.start() ``` */ export declare class BasedServer { console: Console; clients: { [key: string]: any; }; client: BasedServerFunctionClient; functions: BasedFunctions; auth: BasedAuth; port: number; uwsApp: uws.TemplatedApp; silent: boolean; queryEvents: QueryEvents; channelEvents: ChannelEvents; rateLimit: RateLimit; listenSocket: any; forceReloadLastSeqId: number; encodedForceReload: Uint8Array; sendInitialForceReload: boolean; forceReloadTimer: ReturnType; forceReload(type?: number, validTime?: number): void; geo: (ctx: Context) => Geo; getIp: GetIp; blockedIps: Set; allowedIps: Set; rateLimitCounter: Map; }>; requestsCounterInProgress: boolean; requestsCounterTimeout: NodeJS.Timeout; obsCleanTimeout: NodeJS.Timeout; obsCleanupCycle: number; activeObservables: { [name: string]: Map; }; activeObservablesById: Map; channelCleanTimeout: NodeJS.Timeout; channelCleanupCycle: number; restFallbackPath: string; activeChannels: { [name: string]: Map; }; activeChannelsById: Map; listeners: { [E in Event]?: Listener[]; }; workerRequest: (type: string, payload?: any) => void | Promise; private http; [util.inspect.custom](): string; constructor(opts: ServerOptions); emit(type: Event, client: Context, val: EventMap[Event], err?: Error | string): void; on(type: Event, fn: Listener): void; removeAllListeners(): void; once(type: Event, fn: Listener): void; off(type: Event, fn: Listener): void; start(port?: number, sharedSocket?: boolean): Promise; destroy(): Promise; } export {};