1 | import { Disposable } from '../disposable';
|
2 | import { Emitter, Event } from '../event';
|
3 | import { Channel } from '../message-rpc/channel';
|
4 | import { RequestHandler, RpcProtocol } from '../message-rpc/rpc-protocol';
|
5 | import { ConnectionHandler } from './handler';
|
6 | export declare type JsonRpcServer<Client> = Disposable & {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 | setClient(client: Client | undefined): void;
|
13 | getClient?(): Client | undefined;
|
14 | };
|
15 | export interface JsonRpcConnectionEventEmitter {
|
16 | readonly onDidOpenConnection: Event<void>;
|
17 | readonly onDidCloseConnection: Event<void>;
|
18 | }
|
19 | export declare type JsonRpcProxy<T> = T & JsonRpcConnectionEventEmitter;
|
20 | export declare class JsonRpcConnectionHandler<T extends object> implements ConnectionHandler {
|
21 | readonly path: string;
|
22 | readonly targetFactory: (proxy: JsonRpcProxy<T>) => any;
|
23 | readonly factoryConstructor: new () => JsonRpcProxyFactory<T>;
|
24 | constructor(path: string, targetFactory: (proxy: JsonRpcProxy<T>) => any, factoryConstructor?: new () => JsonRpcProxyFactory<T>);
|
25 | onConnection(connection: Channel): void;
|
26 | }
|
27 | /**
|
28 | * Factory for creating a new {@link RpcConnection} for a given chanel and {@link RequestHandler}.
|
29 | */
|
30 | export declare type RpcConnectionFactory = (channel: Channel, requestHandler: RequestHandler) => RpcProtocol;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export declare class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
|
74 | target?: any;
|
75 | protected rpcConnectionFactory: RpcConnectionFactory;
|
76 | protected readonly onDidOpenConnectionEmitter: Emitter<void>;
|
77 | protected readonly onDidCloseConnectionEmitter: Emitter<void>;
|
78 | protected connectionPromiseResolve: (connection: RpcProtocol) => void;
|
79 | protected connectionPromise: Promise<RpcProtocol>;
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | constructor(target?: any, rpcConnectionFactory?: RpcConnectionFactory);
|
87 | protected waitForConnection(): void;
|
88 | /**
|
89 | * Connect a MessageConnection to the factory.
|
90 | *
|
91 | * This connection will be used to send/receive JSON-RPC requests and
|
92 | * response.
|
93 | */
|
94 | listen(channel: Channel): void;
|
95 | /**
|
96 | * Process an incoming JSON-RPC method call.
|
97 | *
|
98 | * onRequest is called when the JSON-RPC connection received a method call
|
99 | * request. It calls the corresponding method on [[target]].
|
100 | *
|
101 | * The return value is a Promise object that is resolved with the return
|
102 | * value of the method call, if it is successful. The promise is rejected
|
103 | * if the called method does not exist or if it throws.
|
104 | *
|
105 | * @returns A promise of the method call completion.
|
106 | */
|
107 | protected onRequest(method: string, ...args: any[]): Promise<any>;
|
108 | /**
|
109 | * Process an incoming JSON-RPC notification.
|
110 | *
|
111 | * Same as [[onRequest]], but called on incoming notifications rather than
|
112 | * methods calls.
|
113 | */
|
114 | protected onNotification(method: string, ...args: any[]): void;
|
115 | /**
|
116 | * Create a Proxy exposing the interface of an object of type T. This Proxy
|
117 | * can be used to do JSON-RPC method calls on the remote target object as
|
118 | * if it was local.
|
119 | *
|
120 | * If `T` implements `JsonRpcServer` then a client is used as a target object for a remote target object.
|
121 | */
|
122 | createProxy(): JsonRpcProxy<T>;
|
123 | /**
|
124 | * Get a callable object that executes a JSON-RPC method call.
|
125 | *
|
126 | * Getting a property on the Proxy object returns a callable that, when
|
127 | * called, executes a JSON-RPC call. The name of the property defines the
|
128 | * method to be called. The callable takes a variable number of arguments,
|
129 | * which are passed in the JSON-RPC method call.
|
130 | *
|
131 | * For example, if you have a Proxy object:
|
132 | *
|
133 | * let fooProxyFactory = JsonRpcProxyFactory<Foo>('/foo')
|
134 | * let fooProxy = fooProxyFactory.createProxy()
|
135 | *
|
136 | * accessing `fooProxy.bar` will return a callable that, when called,
|
137 | * executes a JSON-RPC method call to method `bar`. Therefore, doing
|
138 | * `fooProxy.bar()` will call the `bar` method on the remote Foo object.
|
139 | *
|
140 | * @param target - unused.
|
141 | * @param p - The property accessed on the Proxy object.
|
142 | * @param receiver - unused.
|
143 | * @returns A callable that executes the JSON-RPC call.
|
144 | */
|
145 | get(target: T, p: PropertyKey, receiver: any): any;
|
146 | /**
|
147 | * Return whether the given property represents a notification.
|
148 | *
|
149 | * A property leads to a notification rather than a method call if its name
|
150 | * begins with `notify` or `on`.
|
151 | *
|
152 | * @param p - The property being called on the proxy.
|
153 | * @return Whether `p` represents a notification.
|
154 | */
|
155 | protected isNotification(p: PropertyKey): boolean;
|
156 | protected serializeError(e: any): any;
|
157 | protected deserializeError(capturedError: Error, e: any): any;
|
158 | }
|
159 | //# sourceMappingURL=proxy-factory.d.ts.map |
\ | No newline at end of file |