UNPKG

@chris.troutner/ipfs-message-port-server

Version:
223 lines 7.04 kB
export type EncodedError = import('@chris.troutner/ipfs-message-port-protocol/src/data').EncodedError; export type Result<X, T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/data').Result<X, T_1>; export type ProcedureNames<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').ProcedureNames<T_1>; export type Method<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Method<T_1>; export type Namespace<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Namespace<T_1>; export type ServiceQuery<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').ServiceQuery<T_1>; export type RPCQuery<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').RPCQuery<T_1>; export type Inn<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Inn<T_1>; export type Out<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Out<T_1>; export type QueryMessage<T_1> = { type: 'query'; namespace: Namespace<T_1>; method: Method<T_1>; id: string; input: Inn<T_1>; }; export type AbortMessage = { type: 'abort'; id: string; }; export type TransferOptions = { transfer?: Transferable[] | undefined; }; export type QueryResult<O> = O & TransferOptions; export type Message<T_1> = AbortMessage | QueryMessage<T_1>; export type NamespacedQuery<T_1, K> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').NamespacedQuery<T_1, K>; export type MultiService<T_1> = import('@chris.troutner/ipfs-message-port-protocol/src/rpc').MultiService<T_1>; /** * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/data').EncodedError} EncodedError */ /** * @template X, T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/data').Result<X, T>} Result */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').ProcedureNames<T>} ProcedureNames */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Method<T>} Method */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Namespace<T>} Namespace */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').ServiceQuery<T>} ServiceQuery */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').RPCQuery<T>} RPCQuery */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Inn<T>} Inn */ /** * @template T * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').Out<T>} Out */ /** * @template T * @typedef {Object} QueryMessage * @property {'query'} type * @property {Namespace<T>} namespace * @property {Method<T>} method * @property {string} id * @property {Inn<T>} input */ /** * @typedef {Object} AbortMessage * @property {'abort'} type * @property {string} id */ /** * @typedef {Object} TransferOptions * @property {Transferable[]} [transfer] */ /** * @template O * @typedef {O & TransferOptions} QueryResult */ /** * @template T * @typedef {AbortMessage|QueryMessage<T>} Message */ /** * @template T, K * @typedef {import('@chris.troutner/ipfs-message-port-protocol/src/rpc').NamespacedQuery<T, K>} NamespacedQuery */ /** * Represents a client query received on the server. * * @template T * @extends {ServiceQuery<T>} */ export const Query: { new <T>(namespace: Namespace<T>, method: Method<T>, input: Inn<T>): { result: Promise<any>; succeed: (value: any) => void; fail: (reason?: any) => void; namespace: Namespace<T>; method: Method<T>; input: Inn<T>; abortController: AbortController; signal: AbortSignal; /** * Aborts this query if it is still pending. */ abort(): void; }; }; export class Server<T> { /** * @param {MultiService<T>} services */ constructor(services: MultiService<T>); services: import("@chris.troutner/ipfs-message-port-protocol/src/rpc").MultiService<T>; /** @type {Record<string, Query<T>>} */ queries: Record<string, { result: Promise<any>; succeed: (value: any) => void; fail: (reason?: any) => void; namespace: Namespace<T>; method: Method<T>; input: Inn<T>; abortController: AbortController; signal: AbortSignal; /** * Aborts this query if it is still pending. */ abort(): void; }>; /** * @param {MessagePort} port */ connect(port: MessagePort): void; /** * @param {MessagePort} port */ disconnect(port: MessagePort): void; /** * Handles messages received from connected clients * * @param {MessageEvent} event * @returns {void} */ handleEvent(event: MessageEvent): void; /** * Abort query for the given id. * * @param {string} id */ abort(id: string): void; /** * Handles query received from the client. * * @param {string} id * @param {Query<T>} query * @param {MessagePort} port */ handleQuery(id: string, query: { result: Promise<any>; succeed: (value: any) => void; fail: (reason?: any) => void; namespace: Namespace<T>; method: Method<T>; input: Inn<T>; abortController: AbortController; signal: AbortSignal; /** * Aborts this query if it is still pending. */ abort(): void; }, port: MessagePort): Promise<void>; /** * @param {Query<T>} query * @returns {void} */ run(query: { result: Promise<any>; succeed: (value: any) => void; fail: (reason?: any) => void; namespace: Namespace<T>; method: Method<T>; input: Inn<T>; abortController: AbortController; signal: AbortSignal; /** * Aborts this query if it is still pending. */ abort(): void; }): void; /** * @param {RPCQuery<T>} data * @returns {Out<T>} */ execute(data: RPCQuery<T>): Out<T>; } export const UnsupportedMessageError: { new (event: MessageEvent): { event: MessageEvent<any>; readonly name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; export const AbortError: { new (message?: string | undefined): { readonly name: string; message: string; stack?: string | undefined; }; captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void; prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined; stackTraceLimit: number; }; //# sourceMappingURL=server.d.ts.map