import { ArkosGatewayConfig, ArkosGatewayErrorHandler, ArkosGatewayEventConfig, ArkosGatewayHandler, ArkosGatewayPipe, ArkosGatewayConnectionHandler, ArkosGatewayRegisterOptions, ArkosBroadcastOperator, ArkosEmitTarget } from "./types"; import { Validator } from "../../types/validation/validator"; import { BroadcastOperator, Namespace, Server } from "socket.io"; export declare class IArkosGateway { private config; private events; private pipes; private gateways; private hooks; private _nsp; constructor(config: ArkosGatewayConfig); get nsp(): Omit> & ArkosBroadcastOperator; /** * Register a Socket.io connection-level middleware — runs before a socket * is accepted into this gateway's namespace. Also accepts a child * `ArkosGateway` which will inherit this gateway's name as prefix along * with its auth, rateLimit, and pipes. * * @example * chatGateway.use((socket, next) => { * console.log("incoming connection", socket.id) * }) * * // nested gateway * chatGateway.use(notificationsGateway) */ use(...middlewareOrGateway: Array): this; /** * Register a pipe — middleware that runs before event handlers. * * When called with a function only, the pipe runs before every event * handler in this gateway and drills down to child gateways. * * When called with an event config object, the pipe runs only for that * specific event. * * @example * // runs before every event in this gateway * chatGateway.pipe((socket, data) => { * }) * * // runs only before "send_message" * chatGateway.pipe({ event: "send_message" }, (socket, data) => { * }) */ pipe(fn: ArkosGatewayPipe): this; pipe(eventConfig: { event: string; }, fn: ArkosGatewayPipe): this; /** * Register an event handler. * * @example * chatGateway.on( * { event: "send_message", validation: MessageSchema, ack: true }, * (socket, data, ack) => { * socket.to(data.room).emit("receive_message", data) * ack?.({ status: "ok" }) * } * ) */ on(eventConfig: ArkosGatewayEventConfig, handler: ArkosGatewayHandler): this; /** * Register a lifecycle hook. * * - `"connection"` — called after a socket successfully connects and passes authentication. * - `"disconnect"` — called when a socket disconnects. * - `"error"` — called when an error is thrown inside any event handler. * If not registered, Arkos emits a default `"error"` event to the socket. * * @example * chatGateway.hook("connection", (socket) => { * console.log("connected", socket.user.id) * }) * * chatGateway.hook("error", (err, socket) => { * socket.emit("error", { message: err.message }) * }) */ hook(type: "connection", handler: ArkosGatewayConnectionHandler): this; hook(type: "disconnect", handler: ArkosGatewayConnectionHandler): this; hook(type: "error", handler: ArkosGatewayErrorHandler): this; /** * Wire this gateway into a Socket.io `Server` instance. * Registers the namespace, auth middleware, rate limiting, pipes, * and all event handlers — then recurses into child gateways. * * @example * const io = new Server(server) * chatGateway.register(io) */ register(io: Server, options?: ArkosGatewayRegisterOptions): void; private _register; } /** * Creates an Arkos WebSocket Gateway backed by Socket.io. * * Handles authentication, validation, rate limiting, pipes, * error handling, and nested gateways — all declaratively. * Enhances every connected socket with `socket.user()`, `socket.peer()`, * `socket.retry()`, and automatic `_meta` injection on outgoing emits. * * @example * ```ts * const chatGateway = ArkosGateway({ * name: "chat", * authentication: true, * rateLimit: { windowMs: 60_000, max: 200 }, * }) * * chatGateway.on( * { event: "send_message", validation: MessageSchema, ack: true }, * (socket, data, ack) => { * socket.to(data.room).emit("receive_message", data) * ack?.({ status: "ok" }) * } * ) * ``` * @since 1.7.0-canary.18 * @see {@link https://www.arkosjs.com/docs/core-concepts/components/gateways} */ declare function ArkosGateway(config: ArkosGatewayConfig): IArkosGateway; export default ArkosGateway;