@orpc/client
Version:
<div align="center"> <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" /> </div>
60 lines (55 loc) • 2.77 kB
text/typescript
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BOYsZIRq.mjs';
import { f as StandardLinkClient } from '../../shared/client.Bwgm6dgk.mjs';
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.Ycwr4Tuo.mjs';
import '@orpc/shared';
/**
* The message port used by electron in main process
*/
interface MessagePortMainLike {
on: <T extends string>(event: T, callback: (event?: {
data: any;
}) => void) => void;
postMessage: (data: any) => void;
}
/**
* The message port used by browser extension
*/
interface BrowserPortLike {
onMessage: {
addListener: (callback: (data: any) => void) => void;
};
onDisconnect: {
addListener: (callback: () => void) => void;
};
postMessage: (data: any) => void;
}
type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
/**
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
*/
type SupportedMessagePortData = string | ArrayBufferLike | Uint8Array;
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
interface LinkMessagePortClientOptions {
port: SupportedMessagePort;
}
declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
private readonly peer;
constructor(options: LinkMessagePortClientOptions);
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
}
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
}
/**
* The RPC Link for common message port implementations.
*
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
* @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
*/
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
constructor(options: RPCLinkOptions<T>);
}
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };