@adminide-stack/extension-api 11.0.1-alpha.7 → 11.0.1-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/connections/jsonrpc2/connection.js +507 -525
- package/lib/connections/jsonrpc2/connection.js.map +1 -0
- package/lib/connections/jsonrpc2/events.js +100 -100
- package/lib/connections/jsonrpc2/events.js.map +1 -0
- package/lib/connections/jsonrpc2/linkedMap.js +248 -246
- package/lib/connections/jsonrpc2/linkedMap.js.map +1 -0
- package/lib/connections/jsonrpc2/messages.js +36 -40
- package/lib/connections/jsonrpc2/messages.js.map +1 -0
- package/lib/connections/jsonrpc2/test-helper.js +35 -21
- package/lib/connections/jsonrpc2/test-helper.js.map +1 -0
- package/lib/connections/jsonrpc2/trace.js +70 -82
- package/lib/connections/jsonrpc2/trace.js.map +1 -0
- package/lib/connections/jsonrpc2/transport.js +56 -56
- package/lib/connections/jsonrpc2/transport.js.map +1 -0
- package/lib/connections/jsonrpc2/transports/webWorker.js +80 -88
- package/lib/connections/jsonrpc2/transports/webWorker.js.map +1 -0
- package/lib/connections/proxy/proxy.js +46 -47
- package/lib/connections/proxy/proxy.js.map +1 -0
- package/lib/connections/remote-rpc/browser-remote-rpc.js +55 -54
- package/lib/connections/remote-rpc/browser-remote-rpc.js.map +1 -0
- package/lib/connections/remote-rpc/rxjs-websockets.js +68 -68
- package/lib/connections/remote-rpc/rxjs-websockets.js.map +1 -0
- package/lib/constants/action-types.js +27 -27
- package/lib/constants/action-types.js.map +1 -0
- package/lib/constants/types.js +7 -7
- package/lib/constants/types.js.map +1 -0
- package/lib/core/expr/evaluator.js +103 -104
- package/lib/core/expr/evaluator.js.map +1 -0
- package/lib/core/expr/lexer.js +366 -361
- package/lib/core/expr/lexer.js.map +1 -0
- package/lib/core/expr/parser.js +228 -217
- package/lib/core/expr/parser.js.map +1 -0
- package/lib/core/types/ext-host-types.js +53 -54
- package/lib/core/types/ext-host-types.js.map +1 -0
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -0
- package/lib/interfaces/contributions/contribution.js +40 -40
- package/lib/interfaces/contributions/contribution.js.map +1 -0
- package/lib/interfaces/graphql.js +1 -1
- package/lib/interfaces/graphql.js.map +1 -0
- package/lib/interfaces/model.js +3 -3
- package/lib/interfaces/model.js.map +1 -0
- package/lib/interfaces/text-document.js +76 -77
- package/lib/interfaces/text-document.js.map +1 -0
- package/lib/interfaces/webview/webview.js +3 -3
- package/lib/interfaces/webview/webview.js.map +1 -0
- package/lib/middlewares/extensionController.js +9 -5
- package/lib/middlewares/extensionController.js.map +1 -0
- package/lib/protocol/client.protocol.js +2 -2
- package/lib/protocol/client.protocol.js.map +1 -0
- package/lib/protocol/common.protocol.js +50 -48
- package/lib/protocol/common.protocol.js.map +1 -0
- package/lib/protocol/editor-missing-types.js +4 -4
- package/lib/protocol/editor-missing-types.js.map +1 -0
- package/lib/protocol/proxy-identifier.js +39 -39
- package/lib/protocol/proxy-identifier.js.map +1 -0
- package/lib/protocol/rpc-logger.js +39 -43
- package/lib/protocol/rpc-logger.js.map +1 -0
- package/lib/protocol/rpc-protocol.js +736 -724
- package/lib/protocol/rpc-protocol.js.map +1 -0
- package/lib/protocol/server.protocol.js +22 -22
- package/lib/protocol/server.protocol.js.map +1 -0
- package/lib/protocol/shared/editor.js +17 -17
- package/lib/protocol/shared/editor.js.map +1 -0
- package/lib/protocol/temporary-types.js +16 -16
- package/lib/protocol/temporary-types.js.map +1 -0
- package/lib/protocol/utils/lazy-promise.js +60 -61
- package/lib/protocol/utils/lazy-promise.js.map +1 -0
- package/lib/react/components/view-component/ViewComponent.js +31 -26
- package/lib/react/components/view-component/ViewComponent.js.map +1 -0
- package/lib/react/index.js +1 -1
- package/lib/react/index.js.map +1 -0
- package/lib/react/useExtensionController.js +12 -10
- package/lib/react/useExtensionController.js.map +1 -0
- package/lib/utils/abortable-rx.js +73 -70
- package/lib/utils/abortable-rx.js.map +1 -0
- package/lib/utils/errors.js +10 -10
- package/lib/utils/errors.js.map +1 -0
- package/lib/utils/extensions.js +11 -11
- package/lib/utils/extensions.js.map +1 -0
- package/lib/utils/helper.test.js +7 -4
- package/lib/utils/helper.test.js.map +1 -0
- package/lib/utils/paths-util.js +79 -82
- package/lib/utils/paths-util.js.map +1 -0
- package/lib/utils/rxjs/combineLatestOrDefault.js +72 -70
- package/lib/utils/rxjs/combineLatestOrDefault.js.map +1 -0
- package/lib/utils/util.js +24 -25
- package/lib/utils/util.js.map +1 -0
- package/package.json +4 -4
@@ -1,750 +1,762 @@
|
|
1
1
|
import {RunOnceScheduler}from'@vscode-alt/monaco-editor/esm/vs/base/common/async.js';import {CancellationTokenSource,CancellationToken}from'@vscode-alt/monaco-editor/esm/vs/base/common/cancellation.js';import*as errors from'@vscode-alt/monaco-editor/esm/vs/base/common/errors.js';import {Emitter}from'@vscode-alt/monaco-editor/esm/vs/base/common/event.js';import {Disposable}from'@vscode-alt/monaco-editor/esm/vs/base/common/lifecycle.js';import {transformIncomingURIs}from'@vscode-alt/monaco-editor/esm/vs/base/common/uriIpc.js';import {LazyPromise}from'./utils/lazy-promise.js';import {ProxyIdentifier,getStringIdentifierForProxy}from'./proxy-identifier.js';import {VSBuffer}from'@vscode-alt/monaco-editor/esm/vs/base/common/buffer.js';/* tslint:disable */
|
2
2
|
function safeStringify(obj, replacer) {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
}
|
3
|
+
try {
|
4
|
+
return JSON.stringify(obj, replacer);
|
5
|
+
} catch (err) {
|
6
|
+
return 'null';
|
7
|
+
}
|
9
8
|
}
|
10
9
|
function createURIReplacer(transformer) {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
if (!transformer) {
|
11
|
+
return null;
|
12
|
+
}
|
13
|
+
return (key, value) => {
|
14
|
+
if (value && value.$mid === 1) {
|
15
|
+
return transformer.transformOutgoing(value);
|
16
|
+
}
|
17
|
+
return value;
|
18
|
+
};
|
20
19
|
}
|
21
20
|
var RequestInitiator;
|
22
21
|
(function (RequestInitiator) {
|
23
|
-
|
24
|
-
|
22
|
+
RequestInitiator[RequestInitiator["LocalSide"] = 0] = "LocalSide";
|
23
|
+
RequestInitiator[RequestInitiator["OtherSide"] = 1] = "OtherSide";
|
25
24
|
})(RequestInitiator || (RequestInitiator = {}));
|
26
25
|
var ResponsiveState;
|
27
26
|
(function (ResponsiveState) {
|
28
|
-
|
29
|
-
|
27
|
+
ResponsiveState[ResponsiveState["Responsive"] = 0] = "Responsive";
|
28
|
+
ResponsiveState[ResponsiveState["Unresponsive"] = 1] = "Unresponsive";
|
30
29
|
})(ResponsiveState || (ResponsiveState = {}));
|
31
|
-
const noop = () => {
|
30
|
+
const noop = () => {};
|
32
31
|
class RPCProtocol extends Disposable {
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
32
|
+
static UNRESPONSIVE_TIME = 3 * 1000; // 3s
|
33
|
+
_onDidChangeResponsiveState = this._register(new Emitter());
|
34
|
+
onDidChangeResponsiveState = this._onDidChangeResponsiveState.event;
|
35
|
+
_protocol;
|
36
|
+
_logger;
|
37
|
+
_uriTransformer;
|
38
|
+
_uriReplacer;
|
39
|
+
_isDisposed;
|
40
|
+
_locals;
|
41
|
+
_proxies;
|
42
|
+
_lastMessageId;
|
43
|
+
_cancelInvokedHandlers;
|
44
|
+
_pendingRPCReplies;
|
45
|
+
_responsiveState;
|
46
|
+
_unacknowledgedCount;
|
47
|
+
_unresponsiveTime;
|
48
|
+
_asyncCheckUresponsive;
|
49
|
+
localHostId;
|
50
|
+
constructor(protocol, _localHostId = null, logger = null, transformer = null) {
|
51
|
+
super();
|
52
|
+
this.localHostId = _localHostId;
|
53
|
+
this._protocol = protocol;
|
54
|
+
this._logger = logger;
|
55
|
+
this._uriTransformer = transformer;
|
56
|
+
this._uriReplacer = createURIReplacer(this._uriTransformer);
|
57
|
+
this._isDisposed = false;
|
58
|
+
this._locals = [];
|
59
|
+
this._proxies = [];
|
60
|
+
for (let i = 0, len = ProxyIdentifier.count; i < len; i++) {
|
61
|
+
this._locals[i] = null;
|
62
|
+
this._proxies[i] = null;
|
63
|
+
}
|
64
|
+
this._lastMessageId = 0;
|
65
|
+
this._cancelInvokedHandlers = Object.create(null);
|
66
|
+
this._pendingRPCReplies = {};
|
67
|
+
this._responsiveState = 0 /* ResponsiveState.Responsive */;
|
68
|
+
this._unacknowledgedCount = 0;
|
69
|
+
this._unresponsiveTime = 0;
|
70
|
+
this._asyncCheckUresponsive = this._register(new RunOnceScheduler(() => this._checkUnresponsive(), 1000));
|
71
|
+
this._protocol.onMessage(msg => this._receiveOneMessage(msg));
|
72
|
+
}
|
73
|
+
dispose() {
|
74
|
+
this._isDisposed = true;
|
75
|
+
// Release all outstanding promises with a canceled error
|
76
|
+
Object.keys(this._pendingRPCReplies).forEach(msgId => {
|
77
|
+
const pending = this._pendingRPCReplies[msgId];
|
78
|
+
pending.resolveErr(errors.canceled());
|
79
|
+
});
|
80
|
+
}
|
81
|
+
_onWillSendRequest(req) {
|
82
|
+
if (this._unacknowledgedCount === 0) {
|
83
|
+
// Since this is the first request we are sending in a while,
|
84
|
+
// mark this moment as the start for the countdown to unresponsive time
|
85
|
+
this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
|
86
|
+
}
|
87
|
+
this._unacknowledgedCount++;
|
88
|
+
if (!this._asyncCheckUresponsive.isScheduled()) {
|
89
|
+
this._asyncCheckUresponsive.schedule();
|
90
|
+
}
|
91
|
+
}
|
92
|
+
_onDidReceiveAcknowledge(req) {
|
93
|
+
// The next possible unresponsive time is now + delta.
|
94
|
+
this._unresponsiveTime = Date.now() + RPCProtocol.UNRESPONSIVE_TIME;
|
95
|
+
this._unacknowledgedCount--;
|
96
|
+
if (this._unacknowledgedCount === 0) {
|
97
|
+
// No more need to check for unresponsive
|
98
|
+
this._asyncCheckUresponsive.cancel();
|
99
|
+
}
|
100
|
+
// The ext host is responsive!
|
101
|
+
this._setResponsiveState(0 /* ResponsiveState.Responsive */);
|
102
|
+
}
|
103
|
+
_checkUnresponsive() {
|
104
|
+
if (this._unacknowledgedCount === 0) {
|
105
|
+
// Not waiting for anything => cannot say if it is responsive or not
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
if (Date.now() > this._unresponsiveTime) {
|
109
|
+
// Unresponsive!!
|
110
|
+
this._setResponsiveState(1 /* ResponsiveState.Unresponsive */);
|
111
|
+
} else {
|
112
|
+
// Not (yet) unresponsive, be sure to check again soon
|
113
|
+
this._asyncCheckUresponsive.schedule();
|
114
|
+
}
|
115
|
+
}
|
116
|
+
_setResponsiveState(newResponsiveState) {
|
117
|
+
if (this._responsiveState === newResponsiveState) {
|
118
|
+
// no change
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
this._responsiveState = newResponsiveState;
|
122
|
+
this._onDidChangeResponsiveState.fire(this._responsiveState);
|
123
|
+
}
|
124
|
+
get responsiveState() {
|
125
|
+
return this._responsiveState;
|
126
|
+
}
|
127
|
+
transformIncomingURIs(obj) {
|
128
|
+
if (!this._uriTransformer) {
|
129
|
+
return obj;
|
130
|
+
}
|
131
|
+
return transformIncomingURIs(obj, this._uriTransformer);
|
132
|
+
}
|
133
|
+
getProxy(identifier) {
|
134
|
+
const rpcId = identifier.nid;
|
135
|
+
if (!this._proxies[rpcId]) {
|
136
|
+
this._proxies[rpcId] = this._createProxy(rpcId, identifier.hostId);
|
137
|
+
}
|
138
|
+
return this._proxies[rpcId];
|
139
|
+
}
|
140
|
+
_createProxy(rpcId, destId) {
|
141
|
+
let handler = {
|
142
|
+
get: (target, name) => {
|
143
|
+
// @sri due to some issue we need to do this way
|
144
|
+
// if (!target[name] && name.charCodeAt(0) === CharCode.DollarSign) {
|
145
|
+
if (!target[name] && name[0] === '$') {
|
146
|
+
target[name] = (...myArgs) => {
|
147
|
+
return this._remoteCall(destId, rpcId, name, myArgs);
|
148
|
+
};
|
149
|
+
}
|
150
|
+
return target[name];
|
151
|
+
}
|
152
|
+
};
|
153
|
+
return new Proxy(Object.create(null), handler);
|
154
|
+
}
|
155
|
+
set(identifier, value) {
|
156
|
+
this._locals[identifier.nid] = value;
|
157
|
+
return value;
|
158
|
+
}
|
159
|
+
assertRegistered(identifiers) {
|
160
|
+
for (let i = 0, len = identifiers.length; i < len; i++) {
|
161
|
+
const identifier = identifiers[i];
|
162
|
+
if (!this._locals[identifier.nid]) {
|
163
|
+
// @sri to log missing identifier
|
164
|
+
console.log('identifer missing', identifier);
|
165
|
+
throw new Error(`Missing actor ${identifier.sid} (isMain: ${identifier.isMain})`);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
}
|
169
|
+
_receiveOneMessage(rawmsg) {
|
170
|
+
if (this._isDisposed) {
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
let senderHost = null;
|
174
|
+
let destHostId = null;
|
175
|
+
let leadNum = 0;
|
176
|
+
if (this.localHostId !== null) {
|
177
|
+
destHostId = rawmsg.readUInt8(0);
|
178
|
+
if (destHostId !== this.localHostId) {
|
179
|
+
return this._protocol.forward(rawmsg, destHostId);
|
180
|
+
}
|
181
|
+
leadNum = 2;
|
182
|
+
senderHost = rawmsg.readUInt8(1);
|
183
|
+
}
|
184
|
+
const msgLength = rawmsg.byteLength - leadNum;
|
185
|
+
const buff = MessageBuffer.read(rawmsg, leadNum);
|
186
|
+
const messageType = buff.readUInt8();
|
187
|
+
const req = buff.readUInt32();
|
188
|
+
switch (messageType) {
|
189
|
+
case 1 /* MessageType.RequestJSONArgs */:
|
190
|
+
case 2 /* MessageType.RequestJSONArgsWithCancellation */:
|
191
|
+
{
|
192
|
+
let {
|
193
|
+
rpcId,
|
194
|
+
method,
|
195
|
+
args
|
196
|
+
} = MessageIO.deserializeRequestJSONArgs(buff);
|
197
|
+
if (this._uriTransformer) {
|
198
|
+
args = transformIncomingURIs(args, this._uriTransformer);
|
199
|
+
}
|
200
|
+
// @sri add senderHost for identification
|
201
|
+
this._receiveRequest(senderHost, msgLength, req, rpcId, method, args, messageType === 2 /* MessageType.RequestJSONArgsWithCancellation */);
|
202
|
+
break;
|
203
|
+
}
|
204
|
+
case 3 /* MessageType.RequestMixedArgs */:
|
205
|
+
case 4 /* MessageType.RequestMixedArgsWithCancellation */:
|
206
|
+
{
|
207
|
+
let {
|
208
|
+
rpcId,
|
209
|
+
method,
|
210
|
+
args
|
211
|
+
} = MessageIO.deserializeRequestMixedArgs(buff);
|
212
|
+
if (this._uriTransformer) {
|
213
|
+
args = transformIncomingURIs(args, this._uriTransformer);
|
214
|
+
}
|
215
|
+
// @sri add senderHost as identifier
|
216
|
+
this._receiveRequest(senderHost, msgLength, req, rpcId, method, args, messageType === 4 /* MessageType.RequestMixedArgsWithCancellation */);
|
217
|
+
break;
|
218
|
+
}
|
219
|
+
case 5 /* MessageType.Acknowledged */:
|
220
|
+
{
|
221
|
+
if (this._logger) {
|
222
|
+
this._logger.logIncoming(msgLength, req, 0 /* RequestInitiator.LocalSide */, `ack`);
|
223
|
+
}
|
224
|
+
this._onDidReceiveAcknowledge(req);
|
225
|
+
break;
|
226
|
+
}
|
227
|
+
case 6 /* MessageType.Cancel */:
|
228
|
+
{
|
229
|
+
this._receiveCancel(msgLength, req);
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
case 7 /* MessageType.ReplyOKEmpty */:
|
233
|
+
{
|
234
|
+
this._receiveReply(msgLength, req, undefined);
|
235
|
+
break;
|
236
|
+
}
|
237
|
+
case 9 /* MessageType.ReplyOKJSON */:
|
238
|
+
{
|
239
|
+
let value = MessageIO.deserializeReplyOKJSON(buff);
|
240
|
+
if (this._uriTransformer) {
|
241
|
+
value = transformIncomingURIs(value, this._uriTransformer);
|
242
|
+
}
|
243
|
+
this._receiveReply(msgLength, req, value);
|
244
|
+
break;
|
245
|
+
}
|
246
|
+
case 10 /* MessageType.ReplyOKJSONWithBuffers */:
|
247
|
+
{
|
248
|
+
let value = MessageIO.deserializeReplyOKBuffer(buff);
|
249
|
+
this._receiveReply(msgLength, req, value);
|
250
|
+
break;
|
251
|
+
}
|
252
|
+
case 8 /* MessageType.ReplyOKVSBuffer */:
|
253
|
+
{
|
254
|
+
let value = MessageIO.deserializeReplyOKVSBuffer(buff);
|
255
|
+
this._receiveReply(msgLength, req, value);
|
256
|
+
break;
|
257
|
+
}
|
258
|
+
case 11 /* MessageType.ReplyErrError */:
|
259
|
+
{
|
260
|
+
let err = MessageIO.deserializeReplyErrError(buff);
|
261
|
+
if (this._uriTransformer) {
|
262
|
+
err = transformIncomingURIs(err, this._uriTransformer);
|
263
|
+
}
|
264
|
+
this._receiveReplyErr(msgLength, req, err);
|
265
|
+
break;
|
266
|
+
}
|
267
|
+
case 12 /* MessageType.ReplyErrEmpty */:
|
268
|
+
{
|
269
|
+
this._receiveReplyErr(msgLength, req, undefined);
|
270
|
+
break;
|
271
|
+
}
|
272
|
+
default:
|
273
|
+
console.error(`received unexpected message`);
|
274
|
+
console.error(rawmsg);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
//@sri added destId for identification
|
278
|
+
_receiveRequest(destId, msgLength, req, rpcId, method, args, usesCancellationToken) {
|
279
|
+
if (this._logger) {
|
280
|
+
this._logger.logIncoming(msgLength, req, 1 /* RequestInitiator.OtherSide */, `receiveRequest ${getStringIdentifierForProxy(rpcId)}.${method}(`, args);
|
281
|
+
}
|
282
|
+
const callId = String(req);
|
283
|
+
let promise;
|
284
|
+
let cancel;
|
285
|
+
if (usesCancellationToken) {
|
286
|
+
const cancellationTokenSource = new CancellationTokenSource();
|
287
|
+
args.push(cancellationTokenSource.token);
|
288
|
+
promise = this._invokeHandler(rpcId, method, args);
|
289
|
+
cancel = () => cancellationTokenSource.cancel();
|
290
|
+
} else {
|
291
|
+
// cannot be cancelled
|
292
|
+
promise = this._invokeHandler(rpcId, method, args);
|
293
|
+
cancel = noop;
|
294
|
+
}
|
295
|
+
this._cancelInvokedHandlers[callId] = cancel;
|
296
|
+
// Acknowledge the request
|
297
|
+
const msg = MessageIO.serializeAcknowledged(req);
|
298
|
+
if (this._logger) {
|
299
|
+
this._logger.logOutgoing(msg.byteLength, req, 1 /* RequestInitiator.OtherSide */, `ack`);
|
300
|
+
}
|
301
|
+
this._protocol.send(msg, destId);
|
302
|
+
promise.then(r => {
|
303
|
+
delete this._cancelInvokedHandlers[callId];
|
304
|
+
const msg = MessageIO.serializeReplyOK(req, r, this._uriReplacer);
|
305
|
+
if (this._logger) {
|
306
|
+
this._logger.logOutgoing(msg.byteLength, req, 1 /* RequestInitiator.OtherSide */, `reply:`, r);
|
307
|
+
}
|
308
|
+
this._protocol.send(msg, destId);
|
309
|
+
}, err => {
|
310
|
+
delete this._cancelInvokedHandlers[callId];
|
311
|
+
const msg = MessageIO.serializeReplyErr(req, err);
|
312
|
+
if (this._logger) {
|
313
|
+
this._logger.logOutgoing(msg.byteLength, req, 1 /* RequestInitiator.OtherSide */, `replyErr:`, err);
|
314
|
+
}
|
315
|
+
this._protocol.send(msg, destId);
|
316
|
+
});
|
317
|
+
}
|
318
|
+
_receiveCancel(msgLength, req) {
|
319
|
+
if (this._logger) {
|
320
|
+
this._logger.logIncoming(msgLength, req, 1 /* RequestInitiator.OtherSide */, `receiveCancel`);
|
321
|
+
}
|
322
|
+
const callId = String(req);
|
323
|
+
if (this._cancelInvokedHandlers[callId]) {
|
324
|
+
this._cancelInvokedHandlers[callId]();
|
325
|
+
}
|
326
|
+
}
|
327
|
+
_receiveReply(msgLength, req, value) {
|
328
|
+
if (this._logger) {
|
329
|
+
this._logger.logIncoming(msgLength, req, 0 /* RequestInitiator.LocalSide */, `receiveReply:`, value);
|
330
|
+
}
|
331
|
+
const callId = String(req);
|
332
|
+
if (!this._pendingRPCReplies.hasOwnProperty(callId)) {
|
333
|
+
return;
|
334
|
+
}
|
335
|
+
const pendingReply = this._pendingRPCReplies[callId];
|
336
|
+
delete this._pendingRPCReplies[callId];
|
337
|
+
pendingReply.resolveOk(value);
|
338
|
+
}
|
339
|
+
_receiveReplyErr(msgLength, req, value) {
|
340
|
+
if (this._logger) {
|
341
|
+
this._logger.logIncoming(msgLength, req, 0 /* RequestInitiator.LocalSide */, `receiveReplyErr:`, value);
|
342
|
+
}
|
343
|
+
const callId = String(req);
|
344
|
+
if (!this._pendingRPCReplies.hasOwnProperty(callId)) {
|
345
|
+
return;
|
346
|
+
}
|
347
|
+
const pendingReply = this._pendingRPCReplies[callId];
|
348
|
+
delete this._pendingRPCReplies[callId];
|
349
|
+
let err = null;
|
350
|
+
if (value && value.$isError) {
|
351
|
+
err = new Error();
|
352
|
+
err.name = value.name;
|
353
|
+
err.message = value.message;
|
354
|
+
err.stack = value.stack;
|
355
|
+
}
|
356
|
+
pendingReply.resolveErr(err);
|
357
|
+
}
|
358
|
+
_invokeHandler(rpcId, methodName, args) {
|
359
|
+
try {
|
360
|
+
return Promise.resolve(this._doInvokeHandler(rpcId, methodName, args));
|
361
|
+
} catch (err) {
|
362
|
+
return Promise.reject(err);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
_doInvokeHandler(rpcId, methodName, args) {
|
366
|
+
const actor = this._locals[rpcId];
|
367
|
+
if (!actor) {
|
368
|
+
// @sri add logging
|
369
|
+
console.log('Unknown actor: ', {
|
370
|
+
actor: this._locals[0],
|
371
|
+
exists: this._locals.hasOwnProperty(rpcId),
|
372
|
+
actors: Object.keys(this._locals),
|
373
|
+
rpcId
|
374
|
+
});
|
375
|
+
throw new Error('Unknown actor ' + getStringIdentifierForProxy(rpcId));
|
376
|
+
}
|
377
|
+
let method = actor[methodName];
|
378
|
+
if (typeof method !== 'function') {
|
379
|
+
throw new Error('Unknown method ' + methodName + ' on actor ' + getStringIdentifierForProxy(rpcId));
|
380
|
+
}
|
381
|
+
return method.apply(actor, args);
|
382
|
+
}
|
383
|
+
_remoteCall(destId, rpcId, methodName, args) {
|
384
|
+
if (this._isDisposed) {
|
385
|
+
return Promise.reject(errors.canceled());
|
386
|
+
}
|
387
|
+
let cancellationToken = null;
|
388
|
+
if (args.length > 0 && CancellationToken.isCancellationToken(args[args.length - 1])) {
|
389
|
+
cancellationToken = args.pop();
|
390
|
+
}
|
391
|
+
if (cancellationToken && cancellationToken.isCancellationRequested) {
|
392
|
+
// No need to do anything...
|
393
|
+
return Promise.reject(errors.canceled());
|
394
|
+
}
|
395
|
+
const req = ++this._lastMessageId;
|
396
|
+
const callId = String(req);
|
397
|
+
const result = new LazyPromise();
|
398
|
+
if (cancellationToken) {
|
399
|
+
cancellationToken.onCancellationRequested(() => {
|
400
|
+
const msg = MessageIO.serializeCancel(req);
|
325
401
|
if (this._logger) {
|
326
|
-
|
327
|
-
}
|
328
|
-
const callId = String(req);
|
329
|
-
if (!this._pendingRPCReplies.hasOwnProperty(callId)) {
|
330
|
-
return;
|
331
|
-
}
|
332
|
-
const pendingReply = this._pendingRPCReplies[callId];
|
333
|
-
delete this._pendingRPCReplies[callId];
|
334
|
-
let err = null;
|
335
|
-
if (value && value.$isError) {
|
336
|
-
err = new Error();
|
337
|
-
err.name = value.name;
|
338
|
-
err.message = value.message;
|
339
|
-
err.stack = value.stack;
|
340
|
-
}
|
341
|
-
pendingReply.resolveErr(err);
|
342
|
-
}
|
343
|
-
_invokeHandler(rpcId, methodName, args) {
|
344
|
-
try {
|
345
|
-
return Promise.resolve(this._doInvokeHandler(rpcId, methodName, args));
|
346
|
-
}
|
347
|
-
catch (err) {
|
348
|
-
return Promise.reject(err);
|
349
|
-
}
|
350
|
-
}
|
351
|
-
_doInvokeHandler(rpcId, methodName, args) {
|
352
|
-
const actor = this._locals[rpcId];
|
353
|
-
if (!actor) {
|
354
|
-
// @sri add logging
|
355
|
-
console.log('Unknown actor: ', { actor: this._locals[0], exists: this._locals.hasOwnProperty(rpcId), actors: Object.keys(this._locals), rpcId });
|
356
|
-
throw new Error('Unknown actor ' + getStringIdentifierForProxy(rpcId));
|
357
|
-
}
|
358
|
-
let method = actor[methodName];
|
359
|
-
if (typeof method !== 'function') {
|
360
|
-
throw new Error('Unknown method ' + methodName + ' on actor ' + getStringIdentifierForProxy(rpcId));
|
402
|
+
this._logger.logOutgoing(msg.byteLength, req, 0 /* RequestInitiator.LocalSide */, `cancel`);
|
361
403
|
}
|
362
|
-
|
404
|
+
this._protocol.send(MessageIO.serializeCancel(req), destId);
|
405
|
+
});
|
363
406
|
}
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
if (args.length > 0 && CancellationToken.isCancellationToken(args[args.length - 1])) {
|
370
|
-
cancellationToken = args.pop();
|
371
|
-
}
|
372
|
-
if (cancellationToken && cancellationToken.isCancellationRequested) {
|
373
|
-
// No need to do anything...
|
374
|
-
return Promise.reject(errors.canceled());
|
375
|
-
}
|
376
|
-
const req = ++this._lastMessageId;
|
377
|
-
const callId = String(req);
|
378
|
-
const result = new LazyPromise();
|
379
|
-
if (cancellationToken) {
|
380
|
-
cancellationToken.onCancellationRequested(() => {
|
381
|
-
const msg = MessageIO.serializeCancel(req);
|
382
|
-
if (this._logger) {
|
383
|
-
this._logger.logOutgoing(msg.byteLength, req, 0 /* RequestInitiator.LocalSide */, `cancel`);
|
384
|
-
}
|
385
|
-
this._protocol.send(MessageIO.serializeCancel(req), destId);
|
386
|
-
});
|
387
|
-
}
|
388
|
-
this._pendingRPCReplies[callId] = result;
|
389
|
-
this._onWillSendRequest(req);
|
390
|
-
const msg = MessageIO.serializeRequest(req, rpcId, methodName, args, !!cancellationToken, this._uriReplacer);
|
391
|
-
if (this._logger) {
|
392
|
-
this._logger.logOutgoing(msg.byteLength, req, 0 /* RequestInitiator.LocalSide */, `request: ${getStringIdentifierForProxy(rpcId)}.${methodName}(`, args);
|
393
|
-
}
|
394
|
-
this._protocol.send(msg, destId);
|
395
|
-
return result;
|
407
|
+
this._pendingRPCReplies[callId] = result;
|
408
|
+
this._onWillSendRequest(req);
|
409
|
+
const msg = MessageIO.serializeRequest(req, rpcId, methodName, args, !!cancellationToken, this._uriReplacer);
|
410
|
+
if (this._logger) {
|
411
|
+
this._logger.logOutgoing(msg.byteLength, req, 0 /* RequestInitiator.LocalSide */, `request: ${getStringIdentifierForProxy(rpcId)}.${methodName}(`, args);
|
396
412
|
}
|
413
|
+
this._protocol.send(msg, destId);
|
414
|
+
return result;
|
415
|
+
}
|
397
416
|
}
|
398
417
|
class MessageBuffer {
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
}
|
560
|
-
}
|
561
|
-
return arr;
|
562
|
-
}
|
418
|
+
static alloc(type, req, messageSize) {
|
419
|
+
let result = new MessageBuffer(VSBuffer.alloc(messageSize + 1 /* type */ + 4 /* req */), 0);
|
420
|
+
result.writeUInt8(type);
|
421
|
+
result.writeUInt32(req);
|
422
|
+
return result;
|
423
|
+
}
|
424
|
+
static read(buff, offset) {
|
425
|
+
return new MessageBuffer(buff, offset);
|
426
|
+
}
|
427
|
+
_buff;
|
428
|
+
_offset;
|
429
|
+
get buffer() {
|
430
|
+
return this._buff;
|
431
|
+
}
|
432
|
+
constructor(buff, offset) {
|
433
|
+
this._buff = buff;
|
434
|
+
this._offset = offset;
|
435
|
+
}
|
436
|
+
static sizeUInt8() {
|
437
|
+
return 1;
|
438
|
+
}
|
439
|
+
writeUInt8(n) {
|
440
|
+
this._buff.writeUInt8(n, this._offset);
|
441
|
+
this._offset += 1;
|
442
|
+
}
|
443
|
+
readUInt8() {
|
444
|
+
const n = this._buff.readUInt8(this._offset);
|
445
|
+
this._offset += 1;
|
446
|
+
return n;
|
447
|
+
}
|
448
|
+
writeUInt32(n) {
|
449
|
+
this._buff.writeUInt32BE(n, this._offset);
|
450
|
+
this._offset += 4;
|
451
|
+
}
|
452
|
+
readUInt32() {
|
453
|
+
const n = this._buff.readUInt32BE(this._offset);
|
454
|
+
this._offset += 4;
|
455
|
+
return n;
|
456
|
+
}
|
457
|
+
static sizeShortString(str) {
|
458
|
+
return 1 /* string length */ + str.byteLength /* actual string */;
|
459
|
+
}
|
460
|
+
writeShortString(str) {
|
461
|
+
this._buff.writeUInt8(str.byteLength, this._offset);
|
462
|
+
this._offset += 1;
|
463
|
+
this._buff.set(str, this._offset);
|
464
|
+
this._offset += str.byteLength;
|
465
|
+
}
|
466
|
+
readShortString() {
|
467
|
+
const strByteLength = this._buff.readUInt8(this._offset);
|
468
|
+
this._offset += 1;
|
469
|
+
const strBuff = this._buff.slice(this._offset, this._offset + strByteLength);
|
470
|
+
const str = strBuff.toString();
|
471
|
+
this._offset += strByteLength;
|
472
|
+
return str;
|
473
|
+
}
|
474
|
+
static sizeLongString(str) {
|
475
|
+
return 4 /* string length */ + str.byteLength /* actual string */;
|
476
|
+
}
|
477
|
+
writeLongString(str) {
|
478
|
+
this._buff.writeUInt32BE(str.byteLength, this._offset);
|
479
|
+
this._offset += 4;
|
480
|
+
this._buff.set(str, this._offset);
|
481
|
+
this._offset += str.byteLength;
|
482
|
+
}
|
483
|
+
readLongString() {
|
484
|
+
const strByteLength = this._buff.readUInt32BE(this._offset);
|
485
|
+
this._offset += 4;
|
486
|
+
const strBuff = this._buff.slice(this._offset, this._offset + strByteLength);
|
487
|
+
const str = strBuff.toString();
|
488
|
+
this._offset += strByteLength;
|
489
|
+
return str;
|
490
|
+
}
|
491
|
+
static sizeBuffer(buff) {
|
492
|
+
return 4 /* buffer length */ + buff.byteLength /* actual buffer */;
|
493
|
+
}
|
494
|
+
writeBuffer(buff) {
|
495
|
+
this._buff.writeUInt32BE(buff.byteLength, this._offset);
|
496
|
+
this._offset += 4;
|
497
|
+
this._buff.set(buff, this._offset);
|
498
|
+
this._offset += buff.byteLength;
|
499
|
+
}
|
500
|
+
readBuffer() {
|
501
|
+
const buffLength = this._buff.readUInt32BE(this._offset);
|
502
|
+
this._offset += 4;
|
503
|
+
const buff = this._buff.slice(this._offset, this._offset + buffLength);
|
504
|
+
this._offset += buffLength;
|
505
|
+
return buff.buffer;
|
506
|
+
}
|
507
|
+
static sizeVSBuffer(buff) {
|
508
|
+
return 4 /* buffer length */ + buff.byteLength /* actual buffer */;
|
509
|
+
}
|
510
|
+
writeVSBuffer(buff) {
|
511
|
+
this._buff.writeUInt32BE(buff.byteLength, this._offset);
|
512
|
+
this._offset += 4;
|
513
|
+
this._buff.set(buff, this._offset);
|
514
|
+
this._offset += buff.byteLength;
|
515
|
+
}
|
516
|
+
readVSBuffer() {
|
517
|
+
const buffLength = this._buff.readUInt32BE(this._offset);
|
518
|
+
this._offset += 4;
|
519
|
+
const buff = this._buff.slice(this._offset, this._offset + buffLength);
|
520
|
+
this._offset += buffLength;
|
521
|
+
return buff;
|
522
|
+
}
|
523
|
+
static sizeMixedArray(arr, arrType) {
|
524
|
+
let size = 0;
|
525
|
+
size += 1; // arr length
|
526
|
+
for (let i = 0, len = arr.length; i < len; i++) {
|
527
|
+
const el = arr[i];
|
528
|
+
const elType = arrType[i];
|
529
|
+
size += 1; // arg type
|
530
|
+
if (elType === 1 /* ArgType.String */) {
|
531
|
+
size += this.sizeLongString(el);
|
532
|
+
} else if (elType === 2 /* ArgType.Buffer */) {
|
533
|
+
size += this.sizeBuffer(el);
|
534
|
+
} else {
|
535
|
+
size += this.sizeVSBuffer(el);
|
536
|
+
}
|
537
|
+
}
|
538
|
+
return size;
|
539
|
+
}
|
540
|
+
writeMixedArray(arr, arrType) {
|
541
|
+
this._buff.writeUInt8(arr.length, this._offset);
|
542
|
+
this._offset += 1;
|
543
|
+
for (let i = 0, len = arr.length; i < len; i++) {
|
544
|
+
const el = arr[i];
|
545
|
+
const elType = arrType[i];
|
546
|
+
if (elType === 1 /* ArgType.String */) {
|
547
|
+
this.writeUInt8(1 /* ArgType.String */);
|
548
|
+
this.writeLongString(el);
|
549
|
+
} else if (elType === 2 /* ArgType.Buffer */) {
|
550
|
+
this.writeUInt8(2 /* ArgType.Buffer */);
|
551
|
+
this.writeVSBuffer(el);
|
552
|
+
} else {
|
553
|
+
this.writeUInt8(3 /* ArgType.VSBuffer */);
|
554
|
+
this.writeVSBuffer(el);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
}
|
558
|
+
readMixedArray() {
|
559
|
+
const arrLen = this._buff.readUInt8(this._offset);
|
560
|
+
this._offset += 1;
|
561
|
+
let arr = new Array(arrLen);
|
562
|
+
for (let i = 0; i < arrLen; i++) {
|
563
|
+
const argType = this.readUInt8();
|
564
|
+
switch (argType) {
|
565
|
+
case 1 /* ArgType.String */:
|
566
|
+
arr[i] = this.readLongString();
|
567
|
+
break;
|
568
|
+
case 2 /* ArgType.Buffer */:
|
569
|
+
arr[i] = this.readBuffer();
|
570
|
+
break;
|
571
|
+
case 3 /* ArgType.VSBuffer */:
|
572
|
+
arr[i] = this.readVSBuffer();
|
573
|
+
break;
|
574
|
+
}
|
575
|
+
}
|
576
|
+
return arr;
|
577
|
+
}
|
563
578
|
}
|
564
579
|
class MessageIO {
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
static _serializeReplyErrEmpty(req) {
|
727
|
-
return MessageBuffer.alloc(12 /* MessageType.ReplyErrEmpty */, req, 0).buffer;
|
728
|
-
}
|
580
|
+
static _arrayContainsBuffer(arr) {
|
581
|
+
for (let i = 0, len = arr.length; i < len; i++) {
|
582
|
+
if (Buffer.isBuffer(arr[i])) {
|
583
|
+
return true;
|
584
|
+
}
|
585
|
+
if (arr[i] instanceof VSBuffer) {
|
586
|
+
return true;
|
587
|
+
}
|
588
|
+
}
|
589
|
+
return false;
|
590
|
+
}
|
591
|
+
static serializeRequest(req, rpcId, method, args, usesCancellationToken, replacer) {
|
592
|
+
if (this._arrayContainsBuffer(args)) {
|
593
|
+
let massagedArgs = [];
|
594
|
+
let massagedArgsType = [];
|
595
|
+
for (let i = 0, len = args.length; i < len; i++) {
|
596
|
+
const arg = args[i];
|
597
|
+
if (Buffer.isBuffer(arg)) {
|
598
|
+
massagedArgs[i] = VSBuffer.wrap(arg);
|
599
|
+
massagedArgsType[i] = 2 /* ArgType.Buffer */;
|
600
|
+
} else if (arg instanceof VSBuffer) {
|
601
|
+
massagedArgs[i] = arg;
|
602
|
+
massagedArgsType[i] = 3 /* ArgType.VSBuffer */;
|
603
|
+
} else {
|
604
|
+
massagedArgs[i] = VSBuffer.fromString(safeStringify(arg, replacer));
|
605
|
+
massagedArgsType[i] = 1 /* ArgType.String */;
|
606
|
+
}
|
607
|
+
}
|
608
|
+
return this._requestMixedArgs(req, rpcId, method, massagedArgs, massagedArgsType, usesCancellationToken);
|
609
|
+
}
|
610
|
+
return this._requestJSONArgs(req, rpcId, method, safeStringify(args, replacer), usesCancellationToken);
|
611
|
+
}
|
612
|
+
static _requestJSONArgs(req, rpcId, method, args, usesCancellationToken) {
|
613
|
+
const methodBuff = VSBuffer.fromString(method);
|
614
|
+
const argsBuff = VSBuffer.fromString(args);
|
615
|
+
let len = 0;
|
616
|
+
len += MessageBuffer.sizeUInt8();
|
617
|
+
len += MessageBuffer.sizeShortString(methodBuff);
|
618
|
+
len += MessageBuffer.sizeLongString(argsBuff);
|
619
|
+
let result = MessageBuffer.alloc(usesCancellationToken ? 2 /* MessageType.RequestJSONArgsWithCancellation */ : 1 /* MessageType.RequestJSONArgs */, req, len);
|
620
|
+
result.writeUInt8(rpcId);
|
621
|
+
result.writeShortString(methodBuff);
|
622
|
+
result.writeLongString(argsBuff);
|
623
|
+
return result.buffer;
|
624
|
+
}
|
625
|
+
static deserializeRequestJSONArgs(buff) {
|
626
|
+
const rpcId = buff.readUInt8();
|
627
|
+
const method = buff.readShortString();
|
628
|
+
const args = buff.readLongString();
|
629
|
+
return {
|
630
|
+
rpcId: rpcId,
|
631
|
+
method: method,
|
632
|
+
args: JSON.parse(args)
|
633
|
+
};
|
634
|
+
}
|
635
|
+
static _requestMixedArgs(req, rpcId, method, args, argsType, usesCancellationToken) {
|
636
|
+
const methodBuff = VSBuffer.fromString(method);
|
637
|
+
let len = 0;
|
638
|
+
len += MessageBuffer.sizeUInt8();
|
639
|
+
len += MessageBuffer.sizeShortString(methodBuff);
|
640
|
+
len += MessageBuffer.sizeMixedArray(args, argsType);
|
641
|
+
let result = MessageBuffer.alloc(usesCancellationToken ? 4 /* MessageType.RequestMixedArgsWithCancellation */ : 3 /* MessageType.RequestMixedArgs */, req, len);
|
642
|
+
result.writeUInt8(rpcId);
|
643
|
+
result.writeShortString(methodBuff);
|
644
|
+
result.writeMixedArray(args, argsType);
|
645
|
+
return result.buffer;
|
646
|
+
}
|
647
|
+
static deserializeRequestMixedArgs(buff) {
|
648
|
+
const rpcId = buff.readUInt8();
|
649
|
+
const method = buff.readShortString();
|
650
|
+
const rawargs = buff.readMixedArray();
|
651
|
+
const args = new Array(rawargs.length);
|
652
|
+
for (let i = 0, len = rawargs.length; i < len; i++) {
|
653
|
+
const rawarg = rawargs[i];
|
654
|
+
if (typeof rawarg === 'string') {
|
655
|
+
args[i] = JSON.parse(rawarg);
|
656
|
+
} else {
|
657
|
+
args[i] = rawarg;
|
658
|
+
}
|
659
|
+
}
|
660
|
+
return {
|
661
|
+
rpcId: rpcId,
|
662
|
+
method: method,
|
663
|
+
args: args
|
664
|
+
};
|
665
|
+
}
|
666
|
+
static serializeAcknowledged(req) {
|
667
|
+
return MessageBuffer.alloc(5 /* MessageType.Acknowledged */, req, 0).buffer;
|
668
|
+
}
|
669
|
+
static serializeCancel(req) {
|
670
|
+
return MessageBuffer.alloc(6 /* MessageType.Cancel */, req, 0).buffer;
|
671
|
+
}
|
672
|
+
static serializeReplyOK(req, res, replacer) {
|
673
|
+
if (typeof res === 'undefined') {
|
674
|
+
return this._serializeReplyOKEmpty(req);
|
675
|
+
}
|
676
|
+
if (Buffer.isBuffer(res)) {
|
677
|
+
return this._serializeReplyOKBuffer(req, res);
|
678
|
+
}
|
679
|
+
if (res instanceof VSBuffer) {
|
680
|
+
return this._serializeReplyOKVSBuffer(req, res);
|
681
|
+
}
|
682
|
+
return this._serializeReplyOKJSON(req, safeStringify(res, replacer));
|
683
|
+
}
|
684
|
+
static _serializeReplyOKEmpty(req) {
|
685
|
+
return MessageBuffer.alloc(7 /* MessageType.ReplyOKEmpty */, req, 0).buffer;
|
686
|
+
}
|
687
|
+
static _serializeReplyOKBuffer(req, res) {
|
688
|
+
const buff = VSBuffer.wrap(res);
|
689
|
+
let len = 0;
|
690
|
+
len += MessageBuffer.sizeBuffer(buff);
|
691
|
+
let result = MessageBuffer.alloc(10 /* MessageType.ReplyOKJSONWithBuffers */, req, len);
|
692
|
+
result.writeBuffer(buff);
|
693
|
+
return result.buffer;
|
694
|
+
}
|
695
|
+
static _serializeReplyOKVSBuffer(req, res) {
|
696
|
+
let len = 0;
|
697
|
+
len += MessageBuffer.sizeVSBuffer(res);
|
698
|
+
let result = MessageBuffer.alloc(8 /* MessageType.ReplyOKVSBuffer */, req, len);
|
699
|
+
result.writeVSBuffer(res);
|
700
|
+
return result.buffer;
|
701
|
+
}
|
702
|
+
static deserializeReplyOKBuffer(buff) {
|
703
|
+
return buff.readBuffer();
|
704
|
+
}
|
705
|
+
static deserializeReplyOKVSBuffer(buff) {
|
706
|
+
return buff.readVSBuffer();
|
707
|
+
}
|
708
|
+
static _serializeReplyOKJSON(req, res) {
|
709
|
+
const resBuff = VSBuffer.fromString(res);
|
710
|
+
let len = 0;
|
711
|
+
len += MessageBuffer.sizeLongString(resBuff);
|
712
|
+
let result = MessageBuffer.alloc(9 /* MessageType.ReplyOKJSON */, req, len);
|
713
|
+
result.writeLongString(resBuff);
|
714
|
+
return result.buffer;
|
715
|
+
}
|
716
|
+
static deserializeReplyOKJSON(buff) {
|
717
|
+
const res = buff.readLongString();
|
718
|
+
return JSON.parse(res);
|
719
|
+
}
|
720
|
+
static serializeReplyErr(req, err) {
|
721
|
+
if (err instanceof Error) {
|
722
|
+
return this._serializeReplyErrEror(req, err);
|
723
|
+
}
|
724
|
+
return this._serializeReplyErrEmpty(req);
|
725
|
+
}
|
726
|
+
static _serializeReplyErrEror(req, _err) {
|
727
|
+
const errBuff = VSBuffer.fromString(safeStringify(errors.transformErrorForSerialization(_err), null));
|
728
|
+
let len = 0;
|
729
|
+
len += MessageBuffer.sizeLongString(errBuff);
|
730
|
+
let result = MessageBuffer.alloc(11 /* MessageType.ReplyErrError */, req, len);
|
731
|
+
result.writeLongString(errBuff);
|
732
|
+
return result.buffer;
|
733
|
+
}
|
734
|
+
static deserializeReplyErrError(buff) {
|
735
|
+
const err = buff.readLongString();
|
736
|
+
return JSON.parse(err);
|
737
|
+
}
|
738
|
+
static _serializeReplyErrEmpty(req) {
|
739
|
+
return MessageBuffer.alloc(12 /* MessageType.ReplyErrEmpty */, req, 0).buffer;
|
740
|
+
}
|
729
741
|
}
|
730
742
|
var MessageType;
|
731
743
|
(function (MessageType) {
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
+
MessageType[MessageType["RequestJSONArgs"] = 1] = "RequestJSONArgs";
|
745
|
+
MessageType[MessageType["RequestJSONArgsWithCancellation"] = 2] = "RequestJSONArgsWithCancellation";
|
746
|
+
MessageType[MessageType["RequestMixedArgs"] = 3] = "RequestMixedArgs";
|
747
|
+
MessageType[MessageType["RequestMixedArgsWithCancellation"] = 4] = "RequestMixedArgsWithCancellation";
|
748
|
+
MessageType[MessageType["Acknowledged"] = 5] = "Acknowledged";
|
749
|
+
MessageType[MessageType["Cancel"] = 6] = "Cancel";
|
750
|
+
MessageType[MessageType["ReplyOKEmpty"] = 7] = "ReplyOKEmpty";
|
751
|
+
MessageType[MessageType["ReplyOKVSBuffer"] = 8] = "ReplyOKVSBuffer";
|
752
|
+
MessageType[MessageType["ReplyOKJSON"] = 9] = "ReplyOKJSON";
|
753
|
+
MessageType[MessageType["ReplyOKJSONWithBuffers"] = 10] = "ReplyOKJSONWithBuffers";
|
754
|
+
MessageType[MessageType["ReplyErrError"] = 11] = "ReplyErrError";
|
755
|
+
MessageType[MessageType["ReplyErrEmpty"] = 12] = "ReplyErrEmpty";
|
744
756
|
})(MessageType || (MessageType = {}));
|
745
757
|
var ArgType;
|
746
758
|
(function (ArgType) {
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
})(ArgType || (ArgType = {}));export{ArgType,MessageBuffer,MessageIO,MessageType,RPCProtocol,RequestInitiator,ResponsiveState,safeStringify}
|
759
|
+
ArgType[ArgType["String"] = 1] = "String";
|
760
|
+
ArgType[ArgType["Buffer"] = 2] = "Buffer";
|
761
|
+
ArgType[ArgType["VSBuffer"] = 3] = "VSBuffer";
|
762
|
+
})(ArgType || (ArgType = {}));export{ArgType,MessageBuffer,MessageIO,MessageType,RPCProtocol,RequestInitiator,ResponsiveState,safeStringify};//# sourceMappingURL=rpc-protocol.js.map
|