export = RestNio; /** * @exports RestNio * @class RestNio * @classdesc * Server driver for a REST and websocket interface. */ declare class RestNio { /** * Constructs a new RestNio server. * @param {import("./routes/Router").RouteBack} router - main router function. * @param {import("./util/Options").Options} options - options to use. */ constructor(router: import("./routes/Router").RouteBack, options: import("./util/Options").Options); version: string; params: import("./params/").Params; $p: import("./params/").Params; serve: serve.Serve; cors: cors.Cors; ratelimit: ratelimit.RateLimit; http: typeof HttpConnector; request: (method: string, url: (string | any[]), params?: (any[] | httpCallback), headers?: (any[] | httpCallback), callback: httpCallback, json?: boolean) => Promise; websocket: (url: string, onMessage?: wsCallback, onConnect?: wsCallback, onClose?: wsCallback, onError?: wsCallback, timeout?: number, clientTimeoutExtra?: number) => WebSocket; /** @type {import("./util/Options").Options} */ options: import("./util/Options").Options; /** @type {import("./util/RouteMap")} */ routes: import("./util/RouteMap"); router: Router; subscriptions: SubscriptionMap; /** @type {Map} */ inters: Map; /** @type {import("./authentication/Token")} */ token: import("./authentication/Token"); httpServer: Http.Server; wsServer: WebSocket.Server; /** * Gets the clientset belonging to a certain subscription set name. * @param {string} name - The name of the subscription set to get. * @returns {ClientSet} - the clientset belonging to a subscription. */ subs(name: string): ClientSet; /** * Opens a persistent outbound websocket to another RestNio server and * registers it under `name`. The returned {@link InterClient} can be used * to send envelopes (`peer.obj({path, params})`) and to define routes * that fire when the remote pushes envelopes back. Routes are kept in a * peer-private map — they don't collide with the main `rnio.routes`. * * Example: * ```js * rnio.interconnect('park', 'ws://park.local/', { * token: parkJwt, * onConnect: () => console.log('linked to park'), * routes: (router) => { * router.ws('/setPower', { kw: rnio.params.number }, ({kw}) => turbine.set(kw)); * } * }); * rnio.inter('park').obj({ path: '/turbine/heartbeat', params: { rpm: 12 } }); * ``` * * @param {string} name - logical name for `inter(name)` lookup. * @param {string} url - target websocket URL. * @param {import("./client/InterClient").InterconnectOptions} [options] * @returns {InterClient} */ interconnect(name: string, url: string, options?: import("./client/InterClient").InterconnectOptions): InterClient; /** * Looks up a previously-registered outbound peer by name. * @param {string} name * @returns {InterClient} */ inter(name: string): InterClient; /** * Starts the RestNio server and binds to the port. * @param {number} [port=this.options.port] - Optional port to bind to. * If not specified the port from the options will be taken. * The port in the options is defaulted to 7070 */ bind(port?: number): void; /** * Installs process-level safety nets so that an unhandled error in a * single client (e.g. a frame-decoding failure that escapes the per-socket * handler) cannot terminate the whole RestNio process. Only attaches when * no other listener is already registered, so application authors who * have intentionally wired their own crash-on-unhandled policy keep it. * Disable entirely by setting `options.crashOnUnhandled = true`. */ installSafetyNet(): void; _safetyNetInstalled: boolean; } declare namespace RestNio { export let params: import("./params/").Params; export { params as $p }; export { httpConnector as http }; export let request: (method: string, url: (string | any[]), params?: (any[] | httpCallback), headers?: (any[] | httpCallback), callback: httpCallback, json?: boolean) => Promise; export { wsConnector as websocket }; export { serve }; export { cors }; export { ratelimit }; export { codecs }; } import serve = require("./plugins/serve"); import cors = require("./plugins/cors"); import ratelimit = require("./plugins/ratelimit"); import HttpConnector = require("./connector/httpConnector"); import WsConnector = require("./connector/wsConnector"); import WebSocket = require("ws"); import Router = require("./routes/Router"); import SubscriptionMap = require("./util/SubscriptionMap"); import InterClient = require("./client/InterClient"); import Http = require("http"); import ClientSet = require("./util/ClientSet"); /** @type {import("./params/").Params} */ declare const params_1: import("./params/").Params; import httpConnector = require("./connector/httpConnector"); import wsConnector = require("./connector/wsConnector"); import codecs = require("./codec");