@theia/core 1.26.0 → 1.27.0-next.10
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/README.md +6 -7
- package/lib/browser/messaging/ws-connection-provider.d.ts +5 -4
- package/lib/browser/messaging/ws-connection-provider.d.ts.map +1 -1
- package/lib/browser/messaging/ws-connection-provider.js +30 -23
- package/lib/browser/messaging/ws-connection-provider.js.map +1 -1
- package/lib/browser/progress-status-bar-item.d.ts +1 -1
- package/lib/browser/progress-status-bar-item.d.ts.map +1 -1
- package/lib/browser/tree/tree-compression/compressed-tree-widget.js +2 -2
- package/lib/browser/tree/tree-compression/compressed-tree-widget.js.map +1 -1
- package/lib/browser/widgets/select-component.d.ts +4 -1
- package/lib/browser/widgets/select-component.d.ts.map +1 -1
- package/lib/browser/widgets/select-component.js +30 -16
- package/lib/browser/widgets/select-component.js.map +1 -1
- package/lib/common/cancellation.d.ts +1 -0
- package/lib/common/cancellation.d.ts.map +1 -1
- package/lib/common/cancellation.js +8 -0
- package/lib/common/cancellation.js.map +1 -1
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/message-rpc/channel.d.ts +106 -0
- package/lib/common/message-rpc/channel.d.ts.map +1 -0
- package/lib/common/message-rpc/channel.js +195 -0
- package/lib/common/message-rpc/channel.js.map +1 -0
- package/lib/common/message-rpc/channel.spec.d.ts +9 -0
- package/lib/common/message-rpc/channel.spec.d.ts.map +1 -0
- package/lib/common/message-rpc/channel.spec.js +80 -0
- package/lib/common/message-rpc/channel.spec.js.map +1 -0
- package/lib/common/message-rpc/index.d.ts +4 -0
- package/lib/common/message-rpc/index.d.ts.map +1 -0
- package/lib/{node/messaging/logger.js → common/message-rpc/index.js} +6 -19
- package/lib/common/message-rpc/index.js.map +1 -0
- package/lib/common/message-rpc/message-buffer.d.ts +50 -0
- package/lib/common/message-rpc/message-buffer.d.ts.map +1 -0
- package/lib/common/message-rpc/message-buffer.js +56 -0
- package/lib/common/message-rpc/message-buffer.js.map +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.d.ts +159 -0
- package/lib/common/message-rpc/rpc-message-encoder.d.ts.map +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.js +362 -0
- package/lib/common/message-rpc/rpc-message-encoder.js.map +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.spec.d.ts +2 -0
- package/lib/common/message-rpc/rpc-message-encoder.spec.d.ts.map +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.spec.js +37 -0
- package/lib/common/message-rpc/rpc-message-encoder.spec.js.map +1 -0
- package/lib/common/message-rpc/rpc-protocol.d.ts +61 -0
- package/lib/common/message-rpc/rpc-protocol.d.ts.map +1 -0
- package/lib/common/message-rpc/rpc-protocol.js +183 -0
- package/lib/common/message-rpc/rpc-protocol.js.map +1 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.d.ts +52 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.d.ts.map +1 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.js +169 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.js.map +1 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.spec.d.ts +2 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.spec.d.ts.map +1 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.spec.js +39 -0
- package/lib/common/message-rpc/uint8-array-message-buffer.spec.js.map +1 -0
- package/lib/common/messaging/abstract-connection-provider.d.ts +9 -8
- package/lib/common/messaging/abstract-connection-provider.d.ts.map +1 -1
- package/lib/common/messaging/abstract-connection-provider.js +20 -35
- package/lib/common/messaging/abstract-connection-provider.js.map +1 -1
- package/lib/common/messaging/connection-error-handler.d.ts +1 -2
- package/lib/common/messaging/connection-error-handler.d.ts.map +1 -1
- package/lib/common/messaging/connection-error-handler.js +1 -1
- package/lib/common/messaging/connection-error-handler.js.map +1 -1
- package/lib/common/messaging/handler.d.ts +2 -2
- package/lib/common/messaging/handler.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.d.ts +13 -7
- package/lib/common/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.js +18 -13
- package/lib/common/messaging/proxy-factory.js.map +1 -1
- package/lib/common/messaging/proxy-factory.spec.js +4 -15
- package/lib/common/messaging/proxy-factory.spec.js.map +1 -1
- package/lib/common/messaging/web-socket-channel.d.ts +54 -48
- package/lib/common/messaging/web-socket-channel.d.ts.map +1 -1
- package/lib/common/messaging/web-socket-channel.js +41 -105
- package/lib/common/messaging/web-socket-channel.js.map +1 -1
- package/lib/electron-browser/messaging/electron-ipc-connection-provider.d.ts +2 -2
- package/lib/electron-browser/messaging/electron-ipc-connection-provider.d.ts.map +1 -1
- package/lib/electron-browser/messaging/electron-ipc-connection-provider.js +18 -7
- package/lib/electron-browser/messaging/electron-ipc-connection-provider.js.map +1 -1
- package/lib/electron-browser/messaging/electron-ws-connection-provider.d.ts +2 -2
- package/lib/electron-browser/messaging/electron-ws-connection-provider.d.ts.map +1 -1
- package/lib/electron-browser/messaging/electron-ws-connection-provider.js +5 -7
- package/lib/electron-browser/messaging/electron-ws-connection-provider.js.map +1 -1
- package/lib/electron-main/messaging/electron-messaging-contribution.d.ts +37 -9
- package/lib/electron-main/messaging/electron-messaging-contribution.d.ts.map +1 -1
- package/lib/electron-main/messaging/electron-messaging-contribution.js +83 -68
- package/lib/electron-main/messaging/electron-messaging-contribution.js.map +1 -1
- package/lib/electron-main/messaging/electron-messaging-service.d.ts +2 -8
- package/lib/electron-main/messaging/electron-messaging-service.d.ts.map +1 -1
- package/lib/electron-main/messaging/electron-messaging-service.js.map +1 -1
- package/lib/electron-main/theia-electron-window.d.ts.map +1 -1
- package/lib/electron-main/theia-electron-window.js +11 -8
- package/lib/electron-main/theia-electron-window.js.map +1 -1
- package/lib/node/messaging/binary-message-pipe.d.ts +45 -0
- package/lib/node/messaging/binary-message-pipe.d.ts.map +1 -0
- package/lib/node/messaging/binary-message-pipe.js +152 -0
- package/lib/node/messaging/binary-message-pipe.js.map +1 -0
- package/lib/node/messaging/ipc-bootstrap.js +2 -11
- package/lib/node/messaging/ipc-bootstrap.js.map +1 -1
- package/lib/node/messaging/ipc-channel.d.ts +26 -0
- package/lib/node/messaging/ipc-channel.d.ts.map +1 -0
- package/lib/node/messaging/ipc-channel.js +86 -0
- package/lib/node/messaging/ipc-channel.js.map +1 -0
- package/lib/node/messaging/ipc-connection-provider.d.ts +3 -5
- package/lib/node/messaging/ipc-connection-provider.d.ts.map +1 -1
- package/lib/node/messaging/ipc-connection-provider.js +14 -31
- package/lib/node/messaging/ipc-connection-provider.js.map +1 -1
- package/lib/node/messaging/ipc-protocol.d.ts +2 -2
- package/lib/node/messaging/ipc-protocol.d.ts.map +1 -1
- package/lib/node/messaging/messaging-contribution.d.ts +6 -9
- package/lib/node/messaging/messaging-contribution.d.ts.map +1 -1
- package/lib/node/messaging/messaging-contribution.js +23 -68
- package/lib/node/messaging/messaging-contribution.js.map +1 -1
- package/lib/node/messaging/messaging-service.d.ts +4 -23
- package/lib/node/messaging/messaging-service.d.ts.map +1 -1
- package/lib/node/messaging/messaging-service.js +1 -15
- package/lib/node/messaging/messaging-service.js.map +1 -1
- package/lib/node/messaging/test/test-web-socket-channel.d.ts +4 -2
- package/lib/node/messaging/test/test-web-socket-channel.d.ts.map +1 -1
- package/lib/node/messaging/test/test-web-socket-channel.js +25 -12
- package/lib/node/messaging/test/test-web-socket-channel.js.map +1 -1
- package/package.json +5 -8
- package/src/browser/messaging/ws-connection-provider.ts +34 -25
- package/src/browser/progress-status-bar-item.ts +1 -1
- package/src/browser/style/menus.css +1 -0
- package/src/browser/tree/tree-compression/compressed-tree-widget.tsx +2 -2
- package/src/browser/widgets/select-component.tsx +37 -17
- package/src/common/cancellation.ts +8 -0
- package/src/common/index.ts +2 -0
- package/src/common/message-rpc/channel.spec.ts +88 -0
- package/src/common/message-rpc/channel.ts +260 -0
- package/src/{node/messaging/logger.ts → common/message-rpc/index.ts} +4 -23
- package/src/common/message-rpc/message-buffer.ts +99 -0
- package/src/common/message-rpc/rpc-message-encoder.spec.ts +42 -0
- package/src/common/message-rpc/rpc-message-encoder.ts +497 -0
- package/src/common/message-rpc/rpc-protocol.ts +217 -0
- package/src/common/message-rpc/uint8-array-message-buffer.spec.ts +41 -0
- package/src/common/message-rpc/uint8-array-message-buffer.ts +206 -0
- package/src/common/messaging/abstract-connection-provider.ts +28 -37
- package/src/common/messaging/connection-error-handler.ts +1 -2
- package/src/common/messaging/handler.ts +2 -2
- package/src/common/messaging/proxy-factory.spec.ts +4 -17
- package/src/common/messaging/proxy-factory.ts +27 -16
- package/src/common/messaging/web-socket-channel.ts +79 -135
- package/src/electron-browser/messaging/electron-ipc-connection-provider.ts +21 -7
- package/src/electron-browser/messaging/electron-ws-connection-provider.ts +5 -8
- package/src/electron-main/messaging/electron-messaging-contribution.ts +87 -65
- package/src/electron-main/messaging/electron-messaging-service.ts +2 -8
- package/src/electron-main/theia-electron-window.ts +12 -9
- package/src/node/messaging/binary-message-pipe.ts +168 -0
- package/src/node/messaging/ipc-bootstrap.ts +3 -11
- package/src/node/messaging/ipc-channel.ts +97 -0
- package/src/node/messaging/ipc-connection-provider.ts +18 -35
- package/src/node/messaging/ipc-protocol.ts +2 -2
- package/src/node/messaging/messaging-contribution.ts +29 -74
- package/src/node/messaging/messaging-service.ts +4 -31
- package/src/node/messaging/test/test-web-socket-channel.ts +26 -17
- package/lib/node/messaging/logger.d.ts +0 -8
- package/lib/node/messaging/logger.d.ts.map +0 -1
- package/lib/node/messaging/logger.js.map +0 -1
- package/shared/vscode-ws-jsonrpc/index.d.ts +0 -1
- package/shared/vscode-ws-jsonrpc/index.js +0 -1
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2022 Red Hat, Inc. and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.RpcMessageEncoder = exports.RpcMessageDecoder = exports.ObjectType = exports.ResponseError = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* A special error that can be returned in case a request
|
|
22
|
+
* has failed. Provides additional information i.e. an error code
|
|
23
|
+
* and additional error data.
|
|
24
|
+
*/
|
|
25
|
+
class ResponseError extends Error {
|
|
26
|
+
constructor(code, message, data) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.code = code;
|
|
29
|
+
this.data = data;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ResponseError = ResponseError;
|
|
33
|
+
/**
|
|
34
|
+
* The tag values for the default {@link ValueEncoder}s & {@link ValueDecoder}s
|
|
35
|
+
*/
|
|
36
|
+
var ObjectType;
|
|
37
|
+
(function (ObjectType) {
|
|
38
|
+
ObjectType[ObjectType["JSON"] = 0] = "JSON";
|
|
39
|
+
ObjectType[ObjectType["ByteArray"] = 1] = "ByteArray";
|
|
40
|
+
ObjectType[ObjectType["ObjectArray"] = 2] = "ObjectArray";
|
|
41
|
+
ObjectType[ObjectType["Undefined"] = 3] = "Undefined";
|
|
42
|
+
ObjectType[ObjectType["Object"] = 4] = "Object";
|
|
43
|
+
ObjectType[ObjectType["String"] = 5] = "String";
|
|
44
|
+
ObjectType[ObjectType["Boolean"] = 6] = "Boolean";
|
|
45
|
+
ObjectType[ObjectType["Number"] = 7] = "Number";
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
47
|
+
ObjectType[ObjectType["ResponseError"] = 8] = "ResponseError";
|
|
48
|
+
ObjectType[ObjectType["Error"] = 9] = "Error";
|
|
49
|
+
})(ObjectType = exports.ObjectType || (exports.ObjectType = {}));
|
|
50
|
+
/**
|
|
51
|
+
* A `RpcMessageDecoder` parses a a binary message received via {@link ReadBuffer} into a {@link RpcMessage}
|
|
52
|
+
*/
|
|
53
|
+
class RpcMessageDecoder {
|
|
54
|
+
constructor() {
|
|
55
|
+
this.decoders = new Map();
|
|
56
|
+
this.registerDecoder(ObjectType.JSON, {
|
|
57
|
+
read: buf => {
|
|
58
|
+
const json = buf.readString();
|
|
59
|
+
return JSON.parse(json);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
this.registerDecoder(ObjectType.Error, {
|
|
63
|
+
read: buf => {
|
|
64
|
+
const serializedError = JSON.parse(buf.readString());
|
|
65
|
+
const error = new Error(serializedError.message);
|
|
66
|
+
Object.assign(error, serializedError);
|
|
67
|
+
return error;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this.registerDecoder(ObjectType.ResponseError, {
|
|
71
|
+
read: buf => {
|
|
72
|
+
const error = JSON.parse(buf.readString());
|
|
73
|
+
return new ResponseError(error.code, error.message, error.data);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.registerDecoder(ObjectType.ByteArray, {
|
|
77
|
+
read: buf => buf.readBytes()
|
|
78
|
+
});
|
|
79
|
+
this.registerDecoder(ObjectType.ObjectArray, {
|
|
80
|
+
read: buf => this.readArray(buf)
|
|
81
|
+
});
|
|
82
|
+
this.registerDecoder(ObjectType.Undefined, {
|
|
83
|
+
read: () => undefined
|
|
84
|
+
});
|
|
85
|
+
this.registerDecoder(ObjectType.Object, {
|
|
86
|
+
read: (buf, recursiveRead) => {
|
|
87
|
+
const propertyCount = buf.readLength();
|
|
88
|
+
const result = Object.create({});
|
|
89
|
+
for (let i = 0; i < propertyCount; i++) {
|
|
90
|
+
const key = buf.readString();
|
|
91
|
+
const value = recursiveRead(buf);
|
|
92
|
+
result[key] = value;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.registerDecoder(ObjectType.String, {
|
|
98
|
+
read: (buf, recursiveRead) => buf.readString()
|
|
99
|
+
});
|
|
100
|
+
this.registerDecoder(ObjectType.Boolean, {
|
|
101
|
+
read: buf => buf.readUint8() === 1
|
|
102
|
+
});
|
|
103
|
+
this.registerDecoder(ObjectType.Number, {
|
|
104
|
+
read: buf => buf.readNumber()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Registers a new {@link ValueDecoder} for the given tag.
|
|
109
|
+
* After the successful registration the {@link tagIntType} is recomputed
|
|
110
|
+
* by retrieving the highest tag value and calculating the required Uint size to store it.
|
|
111
|
+
* @param tag the tag for which the decoder should be registered.
|
|
112
|
+
* @param decoder the decoder that should be registered.
|
|
113
|
+
*/
|
|
114
|
+
registerDecoder(tag, decoder) {
|
|
115
|
+
if (this.decoders.has(tag)) {
|
|
116
|
+
throw new Error(`Decoder already registered: ${tag}`);
|
|
117
|
+
}
|
|
118
|
+
this.decoders.set(tag, decoder);
|
|
119
|
+
}
|
|
120
|
+
parse(buf) {
|
|
121
|
+
try {
|
|
122
|
+
const msgType = buf.readUint8();
|
|
123
|
+
switch (msgType) {
|
|
124
|
+
case 1 /* Request */:
|
|
125
|
+
return this.parseRequest(buf);
|
|
126
|
+
case 2 /* Notification */:
|
|
127
|
+
return this.parseNotification(buf);
|
|
128
|
+
case 3 /* Reply */:
|
|
129
|
+
return this.parseReply(buf);
|
|
130
|
+
case 4 /* ReplyErr */:
|
|
131
|
+
return this.parseReplyErr(buf);
|
|
132
|
+
case 5 /* Cancel */:
|
|
133
|
+
return this.parseCancel(buf);
|
|
134
|
+
}
|
|
135
|
+
throw new Error(`Unknown message type: ${msgType}`);
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
// exception does not show problematic content: log it!
|
|
139
|
+
console.log('failed to parse message: ' + buf);
|
|
140
|
+
throw e;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
parseCancel(msg) {
|
|
144
|
+
const callId = msg.readUint32();
|
|
145
|
+
return {
|
|
146
|
+
type: 5 /* Cancel */,
|
|
147
|
+
id: callId
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
parseRequest(msg) {
|
|
151
|
+
const callId = msg.readUint32();
|
|
152
|
+
const method = msg.readString();
|
|
153
|
+
let args = this.readArray(msg);
|
|
154
|
+
// convert `null` to `undefined`, since we don't use `null` in internal plugin APIs
|
|
155
|
+
args = args.map(arg => arg === null ? undefined : arg); // eslint-disable-line no-null/no-null
|
|
156
|
+
return {
|
|
157
|
+
type: 1 /* Request */,
|
|
158
|
+
id: callId,
|
|
159
|
+
method: method,
|
|
160
|
+
args: args
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
parseNotification(msg) {
|
|
164
|
+
const callId = msg.readUint32();
|
|
165
|
+
const method = msg.readString();
|
|
166
|
+
let args = this.readArray(msg);
|
|
167
|
+
// convert `null` to `undefined`, since we don't use `null` in internal plugin APIs
|
|
168
|
+
args = args.map(arg => arg === null ? undefined : arg); // eslint-disable-line no-null/no-null
|
|
169
|
+
return {
|
|
170
|
+
type: 2 /* Notification */,
|
|
171
|
+
id: callId,
|
|
172
|
+
method: method,
|
|
173
|
+
args: args
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
parseReply(msg) {
|
|
177
|
+
const callId = msg.readUint32();
|
|
178
|
+
const value = this.readTypedValue(msg);
|
|
179
|
+
return {
|
|
180
|
+
type: 3 /* Reply */,
|
|
181
|
+
id: callId,
|
|
182
|
+
res: value
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
parseReplyErr(msg) {
|
|
186
|
+
const callId = msg.readUint32();
|
|
187
|
+
const err = this.readTypedValue(msg);
|
|
188
|
+
return {
|
|
189
|
+
type: 4 /* ReplyErr */,
|
|
190
|
+
id: callId,
|
|
191
|
+
err
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
readArray(buf) {
|
|
195
|
+
const length = buf.readLength();
|
|
196
|
+
const result = new Array(length);
|
|
197
|
+
for (let i = 0; i < length; i++) {
|
|
198
|
+
result[i] = this.readTypedValue(buf);
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
readTypedValue(buf) {
|
|
203
|
+
const type = buf.readUint8();
|
|
204
|
+
const decoder = this.decoders.get(type);
|
|
205
|
+
if (!decoder) {
|
|
206
|
+
throw new Error(`No decoder for tag ${type}`);
|
|
207
|
+
}
|
|
208
|
+
return decoder.read(buf, innerBuffer => this.readTypedValue(innerBuffer));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.RpcMessageDecoder = RpcMessageDecoder;
|
|
212
|
+
/**
|
|
213
|
+
* A `RpcMessageEncoder` writes {@link RpcMessage} objects to a {@link WriteBuffer}. Note that it is
|
|
214
|
+
* up to clients to commit the message. This allows for multiple messages being
|
|
215
|
+
* encoded before sending.
|
|
216
|
+
*/
|
|
217
|
+
class RpcMessageEncoder {
|
|
218
|
+
constructor() {
|
|
219
|
+
this.encoders = [];
|
|
220
|
+
this.registeredTags = new Set();
|
|
221
|
+
this.registerEncoders();
|
|
222
|
+
}
|
|
223
|
+
registerEncoders() {
|
|
224
|
+
// encoders will be consulted in reverse order of registration, so the JSON fallback needs to be last
|
|
225
|
+
this.registerEncoder(ObjectType.JSON, {
|
|
226
|
+
is: () => true,
|
|
227
|
+
write: (buf, value) => {
|
|
228
|
+
buf.writeString(JSON.stringify(value));
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
this.registerEncoder(ObjectType.Object, {
|
|
232
|
+
is: value => typeof value === 'object',
|
|
233
|
+
write: (buf, object, recursiveEncode) => {
|
|
234
|
+
const properties = Object.keys(object);
|
|
235
|
+
const relevant = [];
|
|
236
|
+
for (const property of properties) {
|
|
237
|
+
const value = object[property];
|
|
238
|
+
if (typeof value !== 'function') {
|
|
239
|
+
relevant.push([property, value]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
buf.writeLength(relevant.length);
|
|
243
|
+
for (const [property, value] of relevant) {
|
|
244
|
+
buf.writeString(property);
|
|
245
|
+
recursiveEncode === null || recursiveEncode === void 0 ? void 0 : recursiveEncode(buf, value);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
this.registerEncoder(ObjectType.Error, {
|
|
250
|
+
is: value => value instanceof Error,
|
|
251
|
+
write: (buf, error) => {
|
|
252
|
+
const { name, message } = error;
|
|
253
|
+
const stack = error.stacktrace || error.stack;
|
|
254
|
+
const serializedError = {
|
|
255
|
+
$isError: true,
|
|
256
|
+
name,
|
|
257
|
+
message,
|
|
258
|
+
stack
|
|
259
|
+
};
|
|
260
|
+
buf.writeString(JSON.stringify(serializedError));
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
this.registerEncoder(ObjectType.ResponseError, {
|
|
264
|
+
is: value => value instanceof ResponseError,
|
|
265
|
+
write: (buf, value) => buf.writeString(JSON.stringify(value))
|
|
266
|
+
});
|
|
267
|
+
this.registerEncoder(ObjectType.Undefined, {
|
|
268
|
+
// eslint-disable-next-line no-null/no-null
|
|
269
|
+
is: value => value == null,
|
|
270
|
+
write: () => { }
|
|
271
|
+
});
|
|
272
|
+
this.registerEncoder(ObjectType.ObjectArray, {
|
|
273
|
+
is: value => Array.isArray(value),
|
|
274
|
+
write: (buf, value) => {
|
|
275
|
+
this.writeArray(buf, value);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
this.registerEncoder(ObjectType.ByteArray, {
|
|
279
|
+
is: value => value instanceof Uint8Array,
|
|
280
|
+
write: (buf, value) => {
|
|
281
|
+
buf.writeBytes(value);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
this.registerEncoder(ObjectType.String, {
|
|
285
|
+
is: value => typeof value === 'string',
|
|
286
|
+
write: (buf, value) => {
|
|
287
|
+
buf.writeString(value);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
this.registerEncoder(ObjectType.Boolean, {
|
|
291
|
+
is: value => typeof value === 'boolean',
|
|
292
|
+
write: (buf, value) => {
|
|
293
|
+
buf.writeUint8(value === true ? 1 : 0);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
this.registerEncoder(ObjectType.Number, {
|
|
297
|
+
is: value => typeof value === 'number',
|
|
298
|
+
write: (buf, value) => {
|
|
299
|
+
buf.writeNumber(value);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Registers a new {@link ValueEncoder} for the given tag.
|
|
305
|
+
* After the successful registration the {@link tagIntType} is recomputed
|
|
306
|
+
* by retrieving the highest tag value and calculating the required Uint size to store it.
|
|
307
|
+
* @param tag the tag for which the encoder should be registered.
|
|
308
|
+
* @param decoder the encoder that should be registered.
|
|
309
|
+
*/
|
|
310
|
+
registerEncoder(tag, encoder) {
|
|
311
|
+
if (this.registeredTags.has(tag)) {
|
|
312
|
+
throw new Error(`Tag already registered: ${tag}`);
|
|
313
|
+
}
|
|
314
|
+
this.registeredTags.add(tag);
|
|
315
|
+
this.encoders.push([tag, encoder]);
|
|
316
|
+
}
|
|
317
|
+
cancel(buf, requestId) {
|
|
318
|
+
buf.writeUint8(5 /* Cancel */);
|
|
319
|
+
buf.writeUint32(requestId);
|
|
320
|
+
}
|
|
321
|
+
notification(buf, requestId, method, args) {
|
|
322
|
+
buf.writeUint8(2 /* Notification */);
|
|
323
|
+
buf.writeUint32(requestId);
|
|
324
|
+
buf.writeString(method);
|
|
325
|
+
this.writeArray(buf, args);
|
|
326
|
+
}
|
|
327
|
+
request(buf, requestId, method, args) {
|
|
328
|
+
buf.writeUint8(1 /* Request */);
|
|
329
|
+
buf.writeUint32(requestId);
|
|
330
|
+
buf.writeString(method);
|
|
331
|
+
this.writeArray(buf, args);
|
|
332
|
+
}
|
|
333
|
+
replyOK(buf, requestId, res) {
|
|
334
|
+
buf.writeUint8(3 /* Reply */);
|
|
335
|
+
buf.writeUint32(requestId);
|
|
336
|
+
this.writeTypedValue(buf, res);
|
|
337
|
+
}
|
|
338
|
+
replyErr(buf, requestId, err) {
|
|
339
|
+
buf.writeUint8(4 /* ReplyErr */);
|
|
340
|
+
buf.writeUint32(requestId);
|
|
341
|
+
this.writeTypedValue(buf, err);
|
|
342
|
+
}
|
|
343
|
+
writeTypedValue(buf, value) {
|
|
344
|
+
for (let i = this.encoders.length - 1; i >= 0; i--) {
|
|
345
|
+
if (this.encoders[i][1].is(value)) {
|
|
346
|
+
buf.writeUint8(this.encoders[i][0]);
|
|
347
|
+
this.encoders[i][1].write(buf, value, (innerBuffer, innerValue) => {
|
|
348
|
+
this.writeTypedValue(innerBuffer, innerValue);
|
|
349
|
+
});
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
writeArray(buf, value) {
|
|
355
|
+
buf.writeLength(value.length);
|
|
356
|
+
for (let i = 0; i < value.length; i++) {
|
|
357
|
+
this.writeTypedValue(buf, value[i]);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
exports.RpcMessageEncoder = RpcMessageEncoder;
|
|
362
|
+
//# sourceMappingURL=rpc-message-encoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-message-encoder.js","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-message-encoder.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EA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KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;IACL,CAAC;CACJ;AApKD,8CAoKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-message-encoder.spec.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-message-encoder.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2021 Red Hat, Inc. and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const chai_1 = require("chai");
|
|
19
|
+
const uint8_array_message_buffer_1 = require("./uint8-array-message-buffer");
|
|
20
|
+
const rpc_message_encoder_1 = require("./rpc-message-encoder");
|
|
21
|
+
describe('PPC Message Codex', () => {
|
|
22
|
+
describe('RPC Message Encoder & Decoder', () => {
|
|
23
|
+
it('should encode object into binary message and decode the message back into the original object', () => {
|
|
24
|
+
const buffer = new Uint8Array(1024);
|
|
25
|
+
const writer = new uint8_array_message_buffer_1.Uint8ArrayWriteBuffer(buffer);
|
|
26
|
+
const encoder = new rpc_message_encoder_1.RpcMessageEncoder();
|
|
27
|
+
const jsonMangled = JSON.parse(JSON.stringify(encoder));
|
|
28
|
+
encoder.writeTypedValue(writer, encoder);
|
|
29
|
+
const written = writer.getCurrentContents();
|
|
30
|
+
const reader = new uint8_array_message_buffer_1.Uint8ArrayReadBuffer(written);
|
|
31
|
+
const decoder = new rpc_message_encoder_1.RpcMessageDecoder();
|
|
32
|
+
const decoded = decoder.readTypedValue(reader);
|
|
33
|
+
(0, chai_1.expect)(decoded).deep.equal(jsonMangled);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=rpc-message-encoder.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-message-encoder.spec.js","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-message-encoder.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;;AAEhF,+BAA8B;AAC9B,6EAA2F;AAC3F,+DAA6E;AAE7E,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC3C,EAAE,CAAC,+FAA+F,EAAE,GAAG,EAAE;YACrG,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,MAAM,GAAG,IAAI,kDAAqB,CAAC,MAAM,CAAC,CAAC;YAEjD,MAAM,OAAO,GAAG,IAAI,uCAAiB,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YAExD,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAEzC,MAAM,OAAO,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;YAE5C,MAAM,MAAM,GAAG,IAAI,iDAAoB,CAAC,OAAO,CAAC,CAAC;YAEjD,MAAM,OAAO,GAAG,IAAI,uCAAiB,EAAE,CAAC;YACxC,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAE/C,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CancellationTokenSource } from '../cancellation';
|
|
2
|
+
import { DisposableCollection } from '../disposable';
|
|
3
|
+
import { Emitter, Event } from '../event';
|
|
4
|
+
import { Deferred } from '../promise-util';
|
|
5
|
+
import { Channel } from './channel';
|
|
6
|
+
import { RpcMessage, RpcMessageDecoder, RpcMessageEncoder } from './rpc-message-encoder';
|
|
7
|
+
/**
|
|
8
|
+
* Handles request messages received by the {@link RpcServer}.
|
|
9
|
+
*/
|
|
10
|
+
export declare type RequestHandler = (method: string, args: any[]) => Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Initialization options for a {@link RpcProtocol}.
|
|
13
|
+
*/
|
|
14
|
+
export interface RpcProtocolOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The message encoder that should be used. If `undefined` the default {@link RpcMessageEncoder} will be used.
|
|
17
|
+
*/
|
|
18
|
+
encoder?: RpcMessageEncoder;
|
|
19
|
+
/**
|
|
20
|
+
* The message decoder that should be used. If `undefined` the default {@link RpcMessageDecoder} will be used.
|
|
21
|
+
*/
|
|
22
|
+
decoder?: RpcMessageDecoder;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Establish a bi-directional RPC protocol on top of a given channel. Bi-directional means to send
|
|
26
|
+
* sends requests and notifications to the remote side as well as receiving requests and notifications from the remote side.
|
|
27
|
+
* Clients can get a promise for a remote request result that will be either resolved or
|
|
28
|
+
* rejected depending on the success of the request. Keeps track of outstanding requests and matches replies to the appropriate request
|
|
29
|
+
* Currently, there is no timeout handling for long running requests implemented.
|
|
30
|
+
*/
|
|
31
|
+
export declare class RpcProtocol {
|
|
32
|
+
readonly channel: Channel;
|
|
33
|
+
readonly requestHandler: RequestHandler;
|
|
34
|
+
static readonly CANCELLATION_TOKEN_KEY = "add.cancellation.token";
|
|
35
|
+
protected readonly pendingRequests: Map<number, Deferred<any>>;
|
|
36
|
+
protected nextMessageId: number;
|
|
37
|
+
protected readonly encoder: RpcMessageEncoder;
|
|
38
|
+
protected readonly decoder: RpcMessageDecoder;
|
|
39
|
+
protected readonly onNotificationEmitter: Emitter<{
|
|
40
|
+
method: string;
|
|
41
|
+
args: any[];
|
|
42
|
+
}>;
|
|
43
|
+
protected readonly cancellationTokenSources: Map<number, CancellationTokenSource>;
|
|
44
|
+
get onNotification(): Event<{
|
|
45
|
+
method: string;
|
|
46
|
+
args: any[];
|
|
47
|
+
}>;
|
|
48
|
+
protected toDispose: DisposableCollection;
|
|
49
|
+
constructor(channel: Channel, requestHandler: RequestHandler, options?: RpcProtocolOptions);
|
|
50
|
+
handleMessage(message: RpcMessage): void;
|
|
51
|
+
protected handleReply(id: number, value: any): void;
|
|
52
|
+
protected handleReplyErr(id: number, error: any): void;
|
|
53
|
+
sendRequest<T>(method: string, args: any[]): Promise<T>;
|
|
54
|
+
sendNotification(method: string, args: any[]): void;
|
|
55
|
+
sendCancel(requestId: number): void;
|
|
56
|
+
cancelError(): Error;
|
|
57
|
+
protected handleCancel(id: number): void;
|
|
58
|
+
protected handleRequest(id: number, method: string, args: any[]): Promise<void>;
|
|
59
|
+
protected handleNotify(id: number, method: string, args: any[]): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=rpc-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-protocol.d.ts","sourceRo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