UNPKG

1.58 kBTypeScriptView Raw
1import { MessageConnection } from 'sourcegraph/module/jsonrpc2/connection';
2import { UpdateExtensionSettingsArgs } from './context';
3/** One side of a page/client connection. */
4export declare type Source = 'Page' | 'Client';
5/** A connection to the client. */
6export interface ClientConnection {
7 /** Listens for the latest client settings. */
8 onSettings: (callback: (settings: string) => void) => void;
9 /** Requests the client to update a setting. */
10 editSetting: (edit: UpdateExtensionSettingsArgs) => Promise<void>;
11 /** Asks the client for its settings. */
12 getSettings: () => Promise<string>;
13 /** The underlying JSON RPC connection. */
14 rawConnection: MessageConnection;
15}
16/** A connection to the page. */
17export interface PageConnection {
18 /** Listens for requests to edit settings. */
19 onEditSetting: (callback: (edit: UpdateExtensionSettingsArgs) => Promise<void>) => void;
20 /** Listens for requests for the latest settings. */
21 onGetSettings: (callback: () => Promise<string>) => void;
22 /** Notifies the page that the settings have been updated. */
23 sendSettings: (settings: string) => void;
24 /** The underlying JSON RPC connection. */
25 rawConnection: MessageConnection;
26}
27/**
28 * Connects the client (such as a browser extension) to a Sourcegraph extension registry page.
29 */
30export declare function connectAsClient(): Promise<PageConnection>;
31/**
32 * Connects the Sourcegraph extension registry page to a client (such as a browser extension).
33 */
34export declare function connectAsPage(): Promise<ClientConnection>;