/** @import {MsgRequestObj, Result, Metadata, MsgId} from './lib/types.js'*/ /** @typedef {import('./lib/types.js').MsgRequest} MsgRequest */ /** @typedef {import('./lib/types.js').MsgResponse} MsgResponse */ /** @typedef {import('./lib/types.js').MsgOn} MsgOn */ /** @typedef {import('./lib/types.js').MsgOff} MsgOff */ /** @typedef {import('./lib/types.js').MsgEmit} MsgEmit */ /** @typedef {import('./lib/types.js').Message} Message */ /** @typedef {import('./lib/types.js').NonEmptyArray} NonEmptyStringArray */ /** @typedef {import('./lib/types.js').MessagePortLike} MessagePortLike */ /** @typedef {import('worker_threads').MessagePort} MessagePortNode */ /** * @public * Create an RPC server that will receive messages via `receiver`, call the * matching method on `handler`, and send the reply via `send`. * * @param {{[method: string]: any}} handler Any method called on the client * object will be called on this object. Methods can return a value, a Promise, * or a ReadableStream. Your transport stream must be able to encode/decode any * values that your handler returns * @param {MessagePort | MessagePortLike | MessagePortNode | import('stream').Duplex} channel A Duplex Stream with objectMode=true or a MessagePort-like object that must implement an `.on('message')` event handler and a `.postMessage()` method. * @param {object} [options] Options object * @param {false | Omit} [options.logger = false] options.logger Set to `false` to disable logging, or pass a pino logger instance to enable logging * @param {(request: MsgRequestObj, next: (request: Omit) => Result) => void} [options.onRequestHook] Optional hook to observe and modify a request and its metadata, and to await the response. * @returns {{ close: () => void }} An object with a single method `close()` that will stop the server listening to and sending any more messages */ export function createServer(handler: { [method: string]: any; }, channel: MessagePort | MessagePortLike | MessagePortNode | import("stream").Duplex, { logger, onRequestHook }?: { logger?: false | Omit | undefined; onRequestHook?: ((request: MsgRequestObj, next: (request: Omit) => Result) => void) | undefined; }): { close: () => void; }; export type MsgRequest = import("./lib/types.js").MsgRequest; export type MsgResponse = import("./lib/types.js").MsgResponse; export type MsgOn = import("./lib/types.js").MsgOn; export type MsgOff = import("./lib/types.js").MsgOff; export type MsgEmit = import("./lib/types.js").MsgEmit; export type Message = import("./lib/types.js").Message; export type NonEmptyStringArray = import("./lib/types.js").NonEmptyArray; export type MessagePortLike = import("./lib/types.js").MessagePortLike; export type MessagePortNode = import("worker_threads").MessagePort; import type { MsgRequestObj } from './lib/types.js'; import type { Result } from './lib/types.js';