@theia/core 1.33.0-next.5 → 1.33.0-next.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/README.md +6 -6
- package/lib/common/message-rpc/channel.d.ts +9 -0
- package/lib/common/message-rpc/channel.d.ts.map +1 -1
- package/lib/common/message-rpc/channel.js +22 -19
- package/lib/common/message-rpc/channel.js.map +1 -1
- package/lib/common/message-rpc/index.d.ts +2 -2
- package/lib/common/message-rpc/index.d.ts.map +1 -1
- package/lib/common/message-rpc/index.js +5 -3
- package/lib/common/message-rpc/index.js.map +1 -1
- package/lib/common/message-rpc/msg-pack-extension-manager.d.ts +23 -0
- package/lib/common/message-rpc/msg-pack-extension-manager.d.ts.map +1 -0
- package/lib/common/message-rpc/msg-pack-extension-manager.js +58 -0
- package/lib/common/message-rpc/msg-pack-extension-manager.js.map +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.d.ts +1 -0
- package/lib/common/message-rpc/rpc-message-encoder.d.ts.map +1 -1
- package/lib/common/message-rpc/rpc-message-encoder.js +24 -16
- package/lib/common/message-rpc/rpc-message-encoder.js.map +1 -1
- package/lib/common/message-rpc/rpc-protocol.d.ts +11 -5
- package/lib/common/message-rpc/rpc-protocol.d.ts.map +1 -1
- package/lib/common/message-rpc/rpc-protocol.js +45 -28
- package/lib/common/message-rpc/rpc-protocol.js.map +1 -1
- package/lib/node/messaging/index.d.ts +1 -0
- package/lib/node/messaging/index.d.ts.map +1 -1
- package/lib/node/messaging/index.js +1 -0
- package/lib/node/messaging/index.js.map +1 -1
- package/package.json +4 -4
- package/src/common/message-rpc/channel.ts +20 -5
- package/src/common/message-rpc/index.ts +6 -2
- package/src/common/message-rpc/msg-pack-extension-manager.ts +70 -0
- package/src/common/message-rpc/rpc-message-encoder.ts +24 -22
- package/src/common/message-rpc/rpc-protocol.ts +57 -33
- package/src/node/messaging/index.ts +1 -0
package/README.md
CHANGED
|
@@ -86,12 +86,12 @@ export class SomeClass {
|
|
|
86
86
|
- `@phosphor/signaling` (from [`@phosphor/signaling@1`](https://www.npmjs.com/package/@phosphor/signaling))
|
|
87
87
|
- `@phosphor/virtualdom` (from [`@phosphor/virtualdom@1`](https://www.npmjs.com/package/@phosphor/virtualdom))
|
|
88
88
|
- `@phosphor/widgets` (from [`@phosphor/widgets@1`](https://www.npmjs.com/package/@phosphor/widgets))
|
|
89
|
-
- `@theia/application-package` (from [`@theia/application-package@1.33.0-next.
|
|
90
|
-
- `@theia/application-package/lib/api` (from [`@theia/application-package@1.33.0-next.
|
|
91
|
-
- `@theia/application-package/lib/environment` (from [`@theia/application-package@1.33.0-next.
|
|
92
|
-
- `@theia/request` (from [`@theia/request@1.33.0-next.
|
|
93
|
-
- `@theia/request/lib/proxy` (from [`@theia/request@1.33.0-next.
|
|
94
|
-
- `@theia/request/lib/node-request-service` (from [`@theia/request@1.33.0-next.
|
|
89
|
+
- `@theia/application-package` (from [`@theia/application-package@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/application-package/v/1.33.0-next.9))
|
|
90
|
+
- `@theia/application-package/lib/api` (from [`@theia/application-package@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/application-package/v/1.33.0-next.9))
|
|
91
|
+
- `@theia/application-package/lib/environment` (from [`@theia/application-package@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/application-package/v/1.33.0-next.9))
|
|
92
|
+
- `@theia/request` (from [`@theia/request@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/request/v/1.33.0-next.9))
|
|
93
|
+
- `@theia/request/lib/proxy` (from [`@theia/request@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/request/v/1.33.0-next.9))
|
|
94
|
+
- `@theia/request/lib/node-request-service` (from [`@theia/request@1.33.0-next.9+1dcddc630`](https://www.npmjs.com/package/@theia/request/v/1.33.0-next.9))
|
|
95
95
|
- `fs-extra` (from [`fs-extra@^4.0.2`](https://www.npmjs.com/package/fs-extra))
|
|
96
96
|
- `fuzzy` (from [`fuzzy@^0.1.3`](https://www.npmjs.com/package/fuzzy))
|
|
97
97
|
- `inversify` (from [`inversify@^5.1.1`](https://www.npmjs.com/package/inversify))
|
|
@@ -58,6 +58,15 @@ export declare abstract class AbstractChannel implements Channel {
|
|
|
58
58
|
close(): void;
|
|
59
59
|
abstract getWriteBuffer(): WriteBuffer;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A very basic {@link AbstractChannel} implementation which takes a function
|
|
63
|
+
* for retrieving the {@link WriteBuffer} as constructor argument.
|
|
64
|
+
*/
|
|
65
|
+
export declare class BasicChannel extends AbstractChannel {
|
|
66
|
+
protected writeBufferProvider: () => WriteBuffer;
|
|
67
|
+
constructor(writeBufferProvider: () => WriteBuffer);
|
|
68
|
+
getWriteBuffer(): WriteBuffer;
|
|
69
|
+
}
|
|
61
70
|
/**
|
|
62
71
|
* Helper class to implement the single channels on a {@link ChannelMultiplexer}. Simply forwards write requests to
|
|
63
72
|
* the given write buffer source i.e. the main channel of the {@link ChannelMultiplexer}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/channel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/channel.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,OAAO;IAEpB;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAElC;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAExB;;OAEG;IACH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kB,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW;IAOrD,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IASxC,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWlC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI/C,OAAO,IAAI,IAAI;CAGlB"}
|
|
@@ -14,18 +14,8 @@
|
|
|
14
14
|
//
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.ChannelMultiplexer = exports.MessageTypes = exports.ForwardingChannel = exports.AbstractChannel = void 0;
|
|
28
|
-
const inversify_1 = require("../../../shared/inversify");
|
|
18
|
+
exports.ChannelMultiplexer = exports.MessageTypes = exports.ForwardingChannel = exports.BasicChannel = exports.AbstractChannel = void 0;
|
|
29
19
|
const disposable_1 = require("../disposable");
|
|
30
20
|
const event_1 = require("../event");
|
|
31
21
|
;
|
|
@@ -33,7 +23,7 @@ const event_1 = require("../event");
|
|
|
33
23
|
* Reusable abstract {@link Channel} implementation that sets up
|
|
34
24
|
* the basic channel event listeners and offers a generic close method.
|
|
35
25
|
*/
|
|
36
|
-
|
|
26
|
+
class AbstractChannel {
|
|
37
27
|
constructor() {
|
|
38
28
|
this.onCloseEmitter = new event_1.Emitter();
|
|
39
29
|
this.onErrorEmitter = new event_1.Emitter();
|
|
@@ -56,12 +46,22 @@ let AbstractChannel = class AbstractChannel {
|
|
|
56
46
|
close() {
|
|
57
47
|
this.toDispose.dispose();
|
|
58
48
|
}
|
|
59
|
-
}
|
|
60
|
-
AbstractChannel = __decorate([
|
|
61
|
-
(0, inversify_1.injectable)(),
|
|
62
|
-
__metadata("design:paramtypes", [])
|
|
63
|
-
], AbstractChannel);
|
|
49
|
+
}
|
|
64
50
|
exports.AbstractChannel = AbstractChannel;
|
|
51
|
+
/**
|
|
52
|
+
* A very basic {@link AbstractChannel} implementation which takes a function
|
|
53
|
+
* for retrieving the {@link WriteBuffer} as constructor argument.
|
|
54
|
+
*/
|
|
55
|
+
class BasicChannel extends AbstractChannel {
|
|
56
|
+
constructor(writeBufferProvider) {
|
|
57
|
+
super();
|
|
58
|
+
this.writeBufferProvider = writeBufferProvider;
|
|
59
|
+
}
|
|
60
|
+
getWriteBuffer() {
|
|
61
|
+
return this.writeBufferProvider();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.BasicChannel = BasicChannel;
|
|
65
65
|
/**
|
|
66
66
|
* Helper class to implement the single channels on a {@link ChannelMultiplexer}. Simply forwards write requests to
|
|
67
67
|
* the given write buffer source i.e. the main channel of the {@link ChannelMultiplexer}.
|
|
@@ -145,7 +145,7 @@ class ChannelMultiplexer {
|
|
|
145
145
|
return this.handleClose(id);
|
|
146
146
|
}
|
|
147
147
|
case MessageTypes.Data: {
|
|
148
|
-
return this.handleData(id, buffer
|
|
148
|
+
return this.handleData(id, buffer);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -183,7 +183,7 @@ class ChannelMultiplexer {
|
|
|
183
183
|
handleData(id, data) {
|
|
184
184
|
const channel = this.openChannels.get(id);
|
|
185
185
|
if (channel) {
|
|
186
|
-
channel.onMessageEmitter.fire(() => data);
|
|
186
|
+
channel.onMessageEmitter.fire(() => data.sliceAtReadPosition());
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
createChannel(id) {
|
|
@@ -205,6 +205,9 @@ class ChannelMultiplexer {
|
|
|
205
205
|
this.openChannels.delete(id);
|
|
206
206
|
}
|
|
207
207
|
open(id) {
|
|
208
|
+
if (this.openChannels.has(id)) {
|
|
209
|
+
throw new Error(`Another channel with the id '${id}' is already open.`);
|
|
210
|
+
}
|
|
208
211
|
const result = new Promise((resolve, reject) => {
|
|
209
212
|
this.pendingOpen.set(id, resolve);
|
|
210
213
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../../../src/common/message-rpc/channel.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
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../../../src/common/message-rpc/channel.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,8CAAiE;AACjE,oCAA0C;AA0CzC,CAAC;AAUF;;;GAGG;AACH,MAAsB,eAAe;IAmBjC;QAjBA,mBAAc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AE,oBAAoB,CAAC,CAAC;SAC3E;QACD,MAAM,MAAM,GAAG,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACpD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;QAC/F,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,cAAc,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,OAAO;QACH,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ;AA7ID,gDA6IC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { Channel, AbstractChannel, ChannelCloseEvent, MessageProvider } from './channel';
|
|
1
|
+
export { AbstractChannel, Channel, ChannelCloseEvent, MessageProvider } from './channel';
|
|
3
2
|
export { ReadBuffer, WriteBuffer } from './message-buffer';
|
|
3
|
+
export { RequestHandler, RpcProtocol, RpcProtocolOptions } from './rpc-protocol';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcProtocol = exports.AbstractChannel = void 0;
|
|
4
4
|
// *****************************************************************************
|
|
5
5
|
// Copyright (C) 2022 STMicroelectronics and others.
|
|
6
6
|
//
|
|
@@ -16,8 +16,10 @@ exports.AbstractChannel = exports.RpcProtocol = void 0;
|
|
|
16
16
|
//
|
|
17
17
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
18
18
|
// *****************************************************************************
|
|
19
|
-
var rpc_protocol_1 = require("./rpc-protocol");
|
|
20
|
-
Object.defineProperty(exports, "RpcProtocol", { enumerable: true, get: function () { return rpc_protocol_1.RpcProtocol; } });
|
|
21
19
|
var channel_1 = require("./channel");
|
|
22
20
|
Object.defineProperty(exports, "AbstractChannel", { enumerable: true, get: function () { return channel_1.AbstractChannel; } });
|
|
21
|
+
var rpc_protocol_1 = require("./rpc-protocol");
|
|
22
|
+
Object.defineProperty(exports, "RpcProtocol", { enumerable: true, get: function () { return rpc_protocol_1.RpcProtocol; } });
|
|
23
|
+
const rpc_message_encoder_1 = require("./rpc-message-encoder");
|
|
24
|
+
(0, rpc_message_encoder_1.registerMsgPackExtensions)();
|
|
23
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/message-rpc/index.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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;AAChF,+CAAiF;AAAxD,2GAAA,WAAW,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/message-rpc/index.ts"],"names":[],"mappings":";;;AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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;AAChF,qCAAyF;AAAhF,0GAAA,eAAe,OAAA;AAExB,+CAAiF;AAAxD,2GAAA,WAAW,OAAA;AAEpC,+DAAkE;AAElE,IAAA,+CAAyB,GAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the global registration of custom MsgPackR extensions
|
|
3
|
+
* required for the default RPC communication. MsgPackR extensions
|
|
4
|
+
* are installed globally on both ends of the communication channel.
|
|
5
|
+
* (frontend-backend, pluginExt-pluginMain).
|
|
6
|
+
* Is implemented as singleton as it is also used in plugin child processes which have no access to inversify.
|
|
7
|
+
*/
|
|
8
|
+
export declare class MsgPackExtensionManager {
|
|
9
|
+
private static readonly INSTANCE;
|
|
10
|
+
static getInstance(): MsgPackExtensionManager;
|
|
11
|
+
private extensions;
|
|
12
|
+
private constructor();
|
|
13
|
+
registerExtensions(...extensions: MsgPackExtension[]): void;
|
|
14
|
+
getExtension(tag: number): MsgPackExtension | undefined;
|
|
15
|
+
}
|
|
16
|
+
export interface MsgPackExtension {
|
|
17
|
+
class: Function;
|
|
18
|
+
tag: number;
|
|
19
|
+
serialize(instance: unknown): unknown;
|
|
20
|
+
deserialize(serialized: any): unknown;
|
|
21
|
+
}
|
|
22
|
+
export declare type Constructor<T> = new (...params: unknown[]) => T;
|
|
23
|
+
//# sourceMappingURL=msg-pack-extension-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msg-pack-extension-manager.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/msg-pack-extension-manager.ts"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,qBAAa,uBAAuB;IAChC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAiC;WACnD,WAAW,IAAI,uBAAuB;IAIpD,OAAO,CAAC,UAAU,CAAuC;IAEzD,OAAO;IAGP,kBAAkB,CAAC,GAAG,UAAU,EAAE,gBAAgB,EAAE,GAAG,IAAI;IAmB3D,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;CAG1D;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,QAAQ,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC;IAEtC,WAAW,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CAAA;CACxC;AAED,oBAAY,WAAW,CAAC,CAAC,IAAI,KAAK,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2022 STMicroelectronics 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
|
+
exports.MsgPackExtensionManager = void 0;
|
|
19
|
+
const msgpackr_1 = require("msgpackr");
|
|
20
|
+
/**
|
|
21
|
+
* Handles the global registration of custom MsgPackR extensions
|
|
22
|
+
* required for the default RPC communication. MsgPackR extensions
|
|
23
|
+
* are installed globally on both ends of the communication channel.
|
|
24
|
+
* (frontend-backend, pluginExt-pluginMain).
|
|
25
|
+
* Is implemented as singleton as it is also used in plugin child processes which have no access to inversify.
|
|
26
|
+
*/
|
|
27
|
+
class MsgPackExtensionManager {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.extensions = new Map();
|
|
30
|
+
}
|
|
31
|
+
static getInstance() {
|
|
32
|
+
return this.INSTANCE;
|
|
33
|
+
}
|
|
34
|
+
registerExtensions(...extensions) {
|
|
35
|
+
extensions.forEach(extension => {
|
|
36
|
+
if (extension.tag < 1 || extension.tag > 100) {
|
|
37
|
+
// MsgPackR reserves the tag range 1-100 for custom extensions.
|
|
38
|
+
throw new Error(`MsgPack extension tag should be a number from 1-100 but was '${extension.tag}'`);
|
|
39
|
+
}
|
|
40
|
+
if (this.extensions.has(extension.tag)) {
|
|
41
|
+
throw new Error(`Another MsgPack extension with the tag '${extension.tag}' is already registered`);
|
|
42
|
+
}
|
|
43
|
+
this.extensions.set(extension.tag, extension);
|
|
44
|
+
(0, msgpackr_1.addExtension)({
|
|
45
|
+
Class: extension.class,
|
|
46
|
+
type: extension.tag,
|
|
47
|
+
write: extension.serialize,
|
|
48
|
+
read: extension.deserialize
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getExtension(tag) {
|
|
53
|
+
return this.extensions.get(tag);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.MsgPackExtensionManager = MsgPackExtensionManager;
|
|
57
|
+
MsgPackExtensionManager.INSTANCE = new MsgPackExtensionManager();
|
|
58
|
+
//# sourceMappingURL=msg-pack-extension-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msg-pack-extension-manager.js","sourceRoot":"","sources":["../../../src/common/message-rpc/msg-pack-extension-manager.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,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,uCAAwC;AAExC;;;;;;GAMG;AACH,MAAa,uBAAuB;IAQhC;QAFQ,eAAU,GAAG,IAAI,GAAG,EAA4B,CAAC;IAGzD,CAAC;IAPM,MAAM,CAAC,WAAW;QACrB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAOD,kBAAkB,CAAC,GAAG,UAA8B;QAChD,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YAC3B,IAAI,SAAS,CAAC,GAAG,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,GAAG,GAAG,EAAE;gBAC1C,+DAA+D;gBAC/D,MAAM,IAAI,KAAK,CAAC,gEAAgE,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC;aACrG;YACD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;gBACpC,MAAM,IAAI,KAAK,CAAC,2CAA2C,SAAS,CAAC,GAAG,yBAAyB,CAAC,CAAC;aACtG;YACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9C,IAAA,uBAAY,EAAC;gBACT,KAAK,EAAE,SAAS,CAAC,KAAK;gBACtB,IAAI,EAAE,SAAS,CAAC,GAAG;gBACnB,KAAK,EAAE,SAAS,CAAC,SAAS;gBAC1B,IAAI,EAAE,SAAS,CAAC,WAAW;aAC9B,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,YAAY,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;;AAhCL,0DAiCC;AAhC2B,gCAAQ,GAAG,IAAI,uBAAuB,EAAE,CAAC"}
|
|
@@ -100,4 +100,5 @@ export declare class MsgPackMessageDecoder implements RpcMessageDecoder {
|
|
|
100
100
|
decode<T = any>(buf: ReadBuffer): T;
|
|
101
101
|
parse(buffer: ReadBuffer): RpcMessage;
|
|
102
102
|
}
|
|
103
|
+
export declare function registerMsgPackExtensions(): void;
|
|
103
104
|
//# sourceMappingURL=rpc-message-encoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-message-encoder.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-message-encoder.ts"],"names":[],"mappings":"AAiBA,OAAO,
|
|
1
|
+
{"version":3,"file":"rpc-message-encoder.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-message-encoder.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG3D;;;;;;GAMG;AAEH,oBAAY,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,eAAe,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAE/G,0BAAkB,cAAc;IAC5B,OAAO,IAAI;IACX,YAAY,IAAI;IAChB,KAAK,IAAI;IACT,QAAQ,IAAI;IACZ,MAAM,IAAI;CACb;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC;IAC5B,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,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;IAI7D,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;CAUxD;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IAC/C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO;gBAAhB,OAAO,GAAE,OAAwB;IAEhE,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC;IAKnC,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU;CAGxC;AAED,wBAAgB,yBAAyB,IAAI,IAAI,CAmBhD"}
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.MsgPackMessageDecoder = exports.MsgPackMessageEncoder = exports.defaultMsgPack = exports.EncodingError = exports.ResponseError = void 0;
|
|
19
|
+
exports.registerMsgPackExtensions = exports.MsgPackMessageDecoder = exports.MsgPackMessageEncoder = exports.defaultMsgPack = exports.EncodingError = exports.ResponseError = void 0;
|
|
20
20
|
const msgpackr_1 = require("msgpackr");
|
|
21
|
+
const msg_pack_extension_manager_1 = require("./msg-pack-extension-manager");
|
|
21
22
|
/**
|
|
22
23
|
* A special error that can be returned in case a request
|
|
23
24
|
* has failed. Provides additional information i.e. an error code
|
|
@@ -43,21 +44,6 @@ class EncodingError extends Error {
|
|
|
43
44
|
}
|
|
44
45
|
exports.EncodingError = EncodingError;
|
|
45
46
|
exports.defaultMsgPack = new msgpackr_1.Packr({ moreTypes: true, encodeUndefinedAsNil: false, bundleStrings: false });
|
|
46
|
-
// Add custom msgpackR extension for ResponseErrors.
|
|
47
|
-
(0, msgpackr_1.addExtension)({
|
|
48
|
-
Class: ResponseError,
|
|
49
|
-
type: 1,
|
|
50
|
-
write: (instance) => {
|
|
51
|
-
const { code, data, message, name, stack } = instance;
|
|
52
|
-
return { code, data, message, name, stack };
|
|
53
|
-
},
|
|
54
|
-
read: data => {
|
|
55
|
-
const error = new ResponseError(data.code, data.message, data.data);
|
|
56
|
-
error.name = data.name;
|
|
57
|
-
error.stack = data.stack;
|
|
58
|
-
return error;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
47
|
class MsgPackMessageEncoder {
|
|
62
48
|
constructor(msgPack = exports.defaultMsgPack) {
|
|
63
49
|
this.msgPack = msgPack;
|
|
@@ -103,4 +89,26 @@ class MsgPackMessageDecoder {
|
|
|
103
89
|
}
|
|
104
90
|
}
|
|
105
91
|
exports.MsgPackMessageDecoder = MsgPackMessageDecoder;
|
|
92
|
+
function registerMsgPackExtensions() {
|
|
93
|
+
// Register custom msgPack extension for Errors.
|
|
94
|
+
msg_pack_extension_manager_1.MsgPackExtensionManager.getInstance().registerExtensions({
|
|
95
|
+
class: Error,
|
|
96
|
+
tag: 1,
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
+
serialize: (error) => {
|
|
99
|
+
var _a;
|
|
100
|
+
const { code, data, message, name } = error;
|
|
101
|
+
const stack = (_a = error.stacktrace) !== null && _a !== void 0 ? _a : error.stack;
|
|
102
|
+
const isResponseError = error instanceof ResponseError;
|
|
103
|
+
return { code, data, message, name, stack, isResponseError };
|
|
104
|
+
},
|
|
105
|
+
deserialize: data => {
|
|
106
|
+
const error = data.isResponseError ? new ResponseError(data.code, data.message, data.data) : new Error(data.message);
|
|
107
|
+
error.name = data.name;
|
|
108
|
+
error.stack = data.stack;
|
|
109
|
+
return error;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
exports.registerMsgPackExtensions = registerMsgPackExtensions;
|
|
106
114
|
//# sourceMappingURL=rpc-message-encoder.js.map
|
|
@@ -1 +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,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;AAChF,uDAAuD;;;AAEvD,
|
|
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,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,gFAAgF;AAChF,uDAAuD;;;AAEvD,uCAA4C;AAE5C,6EAAuE;AA0DvE;;;;GAIG;AACH,MAAa,aAAc,SAAQ,KAAK;IACpC,YAAqB,IAAY,EAAE,OAAe,EAAW,IAAS;QAClE,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,SAAI,GAAJ,IAAI,CAAQ;QAA4B,SAAI,GAAJ,IAAI,CAAK;IAEtE,CAAC;CACJ;AAJD,sCAIC;AAED;;;GAGG;AACH,MAAa,aAAc,SAAQ,KAAK;IACpC,YAAY,GAAW,EAAS,KAAa;QACzC,KAAK,CAAC,GAAG,CAAC,CAAC;QADiB,UAAK,GAAL,KAAK,CAAQ;IAE7C,CAAC;CACJ;AAJD,sCAIC;AA2BY,QAAA,cAAc,GAAG,IAAI,gBAAO,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;AAElH,MAAa,qBAAqB;IAE9B,YAA+B,UAAmB,sBAAc;QAAjC,YAAO,GAAP,OAAO,CAA0B;IAA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C,IAAI,CAAC;YACvB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACzB,OAAO,KAAK,CAAC;QACjB,CAAC;KACJ,CAAC,CAAC;AACP,CAAC;AAnBD,8DAmBC"}
|
|
@@ -5,7 +5,7 @@ import { Deferred } from '../promise-util';
|
|
|
5
5
|
import { Channel } from './channel';
|
|
6
6
|
import { RpcMessage, RpcMessageDecoder, RpcMessageEncoder } from './rpc-message-encoder';
|
|
7
7
|
/**
|
|
8
|
-
* Handles request messages received by the {@link
|
|
8
|
+
* Handles request messages received by the {@link RPCProtocol}.
|
|
9
9
|
*/
|
|
10
10
|
export declare type RequestHandler = (method: string, args: any[]) => Promise<any>;
|
|
11
11
|
/**
|
|
@@ -20,22 +20,28 @@ export interface RpcProtocolOptions {
|
|
|
20
20
|
* The message decoder that should be used. If `undefined` the default {@link RpcMessageDecoder} will be used.
|
|
21
21
|
*/
|
|
22
22
|
decoder?: RpcMessageDecoder;
|
|
23
|
+
/**
|
|
24
|
+
* The runtime mode determines whether the RPC protocol is bi-directional (default) or acts as a client or server only.
|
|
25
|
+
*/
|
|
26
|
+
mode?: 'default' | 'clientOnly' | 'serverOnly';
|
|
23
27
|
}
|
|
24
28
|
/**
|
|
25
|
-
* Establish a
|
|
26
|
-
*
|
|
29
|
+
* Establish a RPC protocol on top of a given channel. By default the rpc protocol is bi-directional, meaning it is possible to send
|
|
30
|
+
* requests and notifications to the remote side (i.e. acts as client) as well as receiving requests and notifications from the remote side (i.e. acts as a server).
|
|
27
31
|
* Clients can get a promise for a remote request result that will be either resolved or
|
|
28
32
|
* rejected depending on the success of the request. Keeps track of outstanding requests and matches replies to the appropriate request
|
|
29
33
|
* Currently, there is no timeout handling for long running requests implemented.
|
|
34
|
+
* The bi-directional mode can be reconfigured using the {@link RpcProtocolOptions} to construct an RPC protocol instance that acts only as client or server instead.
|
|
30
35
|
*/
|
|
31
36
|
export declare class RpcProtocol {
|
|
32
37
|
readonly channel: Channel;
|
|
33
|
-
readonly requestHandler: RequestHandler;
|
|
38
|
+
readonly requestHandler: RequestHandler | undefined;
|
|
34
39
|
static readonly CANCELLATION_TOKEN_KEY = "add.cancellation.token";
|
|
35
40
|
protected readonly pendingRequests: Map<number, Deferred<any>>;
|
|
36
41
|
protected nextMessageId: number;
|
|
37
42
|
protected readonly encoder: RpcMessageEncoder;
|
|
38
43
|
protected readonly decoder: RpcMessageDecoder;
|
|
44
|
+
protected readonly mode: 'default' | 'clientOnly' | 'serverOnly';
|
|
39
45
|
protected readonly onNotificationEmitter: Emitter<{
|
|
40
46
|
method: string;
|
|
41
47
|
args: any[];
|
|
@@ -46,7 +52,7 @@ export declare class RpcProtocol {
|
|
|
46
52
|
args: any[];
|
|
47
53
|
}>;
|
|
48
54
|
protected toDispose: DisposableCollection;
|
|
49
|
-
constructor(channel: Channel, requestHandler: RequestHandler, options?: RpcProtocolOptions);
|
|
55
|
+
constructor(channel: Channel, requestHandler: RequestHandler | undefined, options?: RpcProtocolOptions);
|
|
50
56
|
handleMessage(message: RpcMessage): void;
|
|
51
57
|
protected handleReply(id: number, value: any): void;
|
|
52
58
|
protected handleReplyErr(id: number, error: any): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAqB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,
|
|
1
|
+
{"version":3,"file":"rpc-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-protocol.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAqB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAc,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC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AM,CAAC;QAAC,IAAI,EAAE,GAAG,EAAE,CAAC;KAAE,CAAC,CAE5D;IAED,SAAS,CAAC,SAAS,uBAA8B;gBAErB,OAAO,EAAE,OAAO,EAAkB,cAAc,EAAE,cAAc,GAAG,SAAS,EAAE,OAAO,GAAE,kBAAuB;IAa1I,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI;IAiCxC,SAAS,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAUnD,SAAS,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IActD,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IA2BvD,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAanD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAMnC,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;cAOxB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;cA8BrE,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAMvF"}
|
|
@@ -22,17 +22,17 @@ const disposable_1 = require("../disposable");
|
|
|
22
22
|
const event_1 = require("../event");
|
|
23
23
|
const promise_util_1 = require("../promise-util");
|
|
24
24
|
const rpc_message_encoder_1 = require("./rpc-message-encoder");
|
|
25
|
-
const uint8_array_message_buffer_1 = require("./uint8-array-message-buffer");
|
|
26
25
|
/**
|
|
27
|
-
* Establish a
|
|
28
|
-
*
|
|
26
|
+
* Establish a RPC protocol on top of a given channel. By default the rpc protocol is bi-directional, meaning it is possible to send
|
|
27
|
+
* requests and notifications to the remote side (i.e. acts as client) as well as receiving requests and notifications from the remote side (i.e. acts as a server).
|
|
29
28
|
* Clients can get a promise for a remote request result that will be either resolved or
|
|
30
29
|
* rejected depending on the success of the request. Keeps track of outstanding requests and matches replies to the appropriate request
|
|
31
30
|
* Currently, there is no timeout handling for long running requests implemented.
|
|
31
|
+
* The bi-directional mode can be reconfigured using the {@link RpcProtocolOptions} to construct an RPC protocol instance that acts only as client or server instead.
|
|
32
32
|
*/
|
|
33
33
|
class RpcProtocol {
|
|
34
34
|
constructor(channel, requestHandler, options = {}) {
|
|
35
|
-
var _a, _b;
|
|
35
|
+
var _a, _b, _c;
|
|
36
36
|
this.channel = channel;
|
|
37
37
|
this.requestHandler = requestHandler;
|
|
38
38
|
this.pendingRequests = new Map();
|
|
@@ -43,35 +43,47 @@ class RpcProtocol {
|
|
|
43
43
|
this.encoder = (_a = options.encoder) !== null && _a !== void 0 ? _a : new rpc_message_encoder_1.MsgPackMessageEncoder();
|
|
44
44
|
this.decoder = (_b = options.decoder) !== null && _b !== void 0 ? _b : new rpc_message_encoder_1.MsgPackMessageDecoder();
|
|
45
45
|
this.toDispose.push(this.onNotificationEmitter);
|
|
46
|
-
this.toDispose.push(channel.onMessage(readBuffer => this.handleMessage(this.decoder.parse(readBuffer()))));
|
|
47
46
|
channel.onClose(() => this.toDispose.dispose());
|
|
47
|
+
this.toDispose.push(channel.onMessage(readBuffer => this.handleMessage(this.decoder.parse(readBuffer()))));
|
|
48
|
+
this.mode = (_c = options.mode) !== null && _c !== void 0 ? _c : 'default';
|
|
49
|
+
if (this.mode !== 'clientOnly' && requestHandler === undefined) {
|
|
50
|
+
console.error('RPCProtocol was initialized without a request handler but was not set to clientOnly mode.');
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
get onNotification() {
|
|
50
54
|
return this.onNotificationEmitter.event;
|
|
51
55
|
}
|
|
52
56
|
handleMessage(message) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (this.mode !== 'clientOnly') {
|
|
58
|
+
switch (message.type) {
|
|
59
|
+
case 5 /* Cancel */: {
|
|
60
|
+
this.handleCancel(message.id);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
case 1 /* Request */: {
|
|
64
|
+
this.handleRequest(message.id, message.method, message.args);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
case 2 /* Notification */: {
|
|
68
|
+
this.handleNotify(message.id, message.method, message.args);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
}
|
|
73
|
+
if (this.mode !== 'serverOnly') {
|
|
74
|
+
switch (message.type) {
|
|
75
|
+
case 3 /* Reply */: {
|
|
76
|
+
this.handleReply(message.id, message.res);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
case 4 /* ReplyErr */: {
|
|
80
|
+
this.handleReplyErr(message.id, message.err);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
73
83
|
}
|
|
74
84
|
}
|
|
85
|
+
// If the message was not handled until here, it is incompatible with the mode.
|
|
86
|
+
console.warn(`Received message incompatible with this RPCProtocol's mode '${this.mode}'. Type: ${message.type}. ID: ${message.id}.`);
|
|
75
87
|
}
|
|
76
88
|
handleReply(id, value) {
|
|
77
89
|
const replyHandler = this.pendingRequests.get(id);
|
|
@@ -99,11 +111,11 @@ class RpcProtocol {
|
|
|
99
111
|
}
|
|
100
112
|
}
|
|
101
113
|
sendRequest(method, args) {
|
|
102
|
-
const id = this.nextMessageId++;
|
|
103
|
-
const reply = new promise_util_1.Deferred();
|
|
104
114
|
// The last element of the request args might be a cancellation token. As these tokens are not serializable we have to remove it from the
|
|
105
115
|
// args array and the `CANCELLATION_TOKEN_KEY` string instead.
|
|
106
116
|
const cancellationToken = args.length && cancellation_1.CancellationToken.is(args[args.length - 1]) ? args.pop() : undefined;
|
|
117
|
+
const id = this.nextMessageId++;
|
|
118
|
+
const reply = new promise_util_1.Deferred();
|
|
107
119
|
if (cancellationToken) {
|
|
108
120
|
args.push(RpcProtocol.CANCELLATION_TOKEN_KEY);
|
|
109
121
|
}
|
|
@@ -120,6 +132,12 @@ class RpcProtocol {
|
|
|
120
132
|
return reply.promise;
|
|
121
133
|
}
|
|
122
134
|
sendNotification(method, args) {
|
|
135
|
+
// If the notification supports a CancellationToken, it needs to be treated like a request
|
|
136
|
+
// because cancellation does not work with the simplified "fire and forget" approach of simple notifications.
|
|
137
|
+
if (args.length && cancellation_1.CancellationToken.is(args[args.length - 1])) {
|
|
138
|
+
this.sendRequest(method, args);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
123
141
|
const output = this.channel.getWriteBuffer();
|
|
124
142
|
this.encoder.notification(output, this.nextMessageId++, method, args);
|
|
125
143
|
output.commit();
|
|
@@ -132,7 +150,6 @@ class RpcProtocol {
|
|
|
132
150
|
handleCancel(id) {
|
|
133
151
|
const cancellationTokenSource = this.cancellationTokenSources.get(id);
|
|
134
152
|
if (cancellationTokenSource) {
|
|
135
|
-
this.cancellationTokenSources.delete(id);
|
|
136
153
|
cancellationTokenSource.cancel();
|
|
137
154
|
}
|
|
138
155
|
}
|
|
@@ -155,7 +172,7 @@ class RpcProtocol {
|
|
|
155
172
|
catch (err) {
|
|
156
173
|
// In case of an error the output buffer might already contains parts of an message.
|
|
157
174
|
// => Dispose the current buffer and retrieve a new, clean one for writing the response error.
|
|
158
|
-
if (output
|
|
175
|
+
if (disposable_1.Disposable.is(output)) {
|
|
159
176
|
output.dispose();
|
|
160
177
|
}
|
|
161
178
|
const errorOutput = this.channel.getWriteBuffer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-protocol.js","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-protocol.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;AAChF,uDAAuD;;;AAEvD,kDAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"rpc-protocol.js","sourceRoot":"","sources":["../../../src/common/message-rpc/rpc-protocol.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;AAChF,uDAAuD;;;AAEvD,kDAA6E;AAC7E,8CAAiE;AACjE,oCAA0C;AAC1C,kDAA2C;AAE3C,+DAAuJ;AAyBvJ;;;;;;;GAOG;AACH,MAAa,WAAW;IAoBpB,YAA4B,OAAgB,EAAkB,cAA0C,EAAE,UAA8B,EAAE;;QAA9G,YAAO,GAAP,OAAO,CAAS;QAAkB,mBAAc,GAAd,cAAc,CAA4B;QAjBrF,oBAAe,GAA+B,IAAI,GAAG,EAAE,CAAC;QAEjE,kBAAa,GAAW,CAAC,CAAC;QAMjB,0BAAqB,GAA8C,IAAI,eAAO,EAAE,CAAC;QACjF,6BAAwB,GAAG,IAAI,GAAG,EAAmC,CAAC;QAM/E,cAAS,GAAG,IAAI,iCAAoB,EAAE,CAAC;QAG7C,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,IAAI,2CAAqB,EAAE,CAAC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/index.ts"],"names":[],"mappings":"AAgBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/messaging/index.ts"],"names":[],"mappings":"AAgBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,eAAe,CAAC"}
|
|
@@ -27,4 +27,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
__exportStar(require("./messaging-service"), exports);
|
|
29
29
|
__exportStar(require("./ipc-connection-provider"), exports);
|
|
30
|
+
__exportStar(require("./ipc-channel"), exports);
|
|
30
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/messaging/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,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,sDAAoC;AACpC,4DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/node/messaging/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,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,sDAAoC;AACpC,4DAA0C;AAC1C,gDAA8B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/core",
|
|
3
|
-
"version": "1.33.0-next.
|
|
3
|
+
"version": "1.33.0-next.9+1dcddc630",
|
|
4
4
|
"description": "Theia is a cloud & desktop IDE framework implemented in TypeScript.",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"@phosphor/signaling": "1",
|
|
17
17
|
"@phosphor/virtualdom": "1",
|
|
18
18
|
"@phosphor/widgets": "1",
|
|
19
|
-
"@theia/application-package": "1.33.0-next.
|
|
20
|
-
"@theia/request": "1.33.0-next.
|
|
19
|
+
"@theia/application-package": "1.33.0-next.9+1dcddc630",
|
|
20
|
+
"@theia/request": "1.33.0-next.9+1dcddc630",
|
|
21
21
|
"@types/body-parser": "^1.16.4",
|
|
22
22
|
"@types/cookie": "^0.3.3",
|
|
23
23
|
"@types/dompurify": "^2.2.2",
|
|
@@ -202,5 +202,5 @@
|
|
|
202
202
|
"nyc": {
|
|
203
203
|
"extends": "../../configs/nyc.json"
|
|
204
204
|
},
|
|
205
|
-
"gitHead": "
|
|
205
|
+
"gitHead": "1dcddc630ab0beb5d66ec885d207d3e6529fb692"
|
|
206
206
|
}
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import { injectable } from '../../../shared/inversify';
|
|
18
17
|
import { Disposable, DisposableCollection } from '../disposable';
|
|
19
18
|
import { Emitter, Event } from '../event';
|
|
20
19
|
import { ReadBuffer, WriteBuffer } from './message-buffer';
|
|
@@ -72,7 +71,6 @@ export type MessageProvider = () => ReadBuffer;
|
|
|
72
71
|
* Reusable abstract {@link Channel} implementation that sets up
|
|
73
72
|
* the basic channel event listeners and offers a generic close method.
|
|
74
73
|
*/
|
|
75
|
-
@injectable()
|
|
76
74
|
export abstract class AbstractChannel implements Channel {
|
|
77
75
|
|
|
78
76
|
onCloseEmitter: Emitter<ChannelCloseEvent> = new Emitter();
|
|
@@ -101,7 +99,21 @@ export abstract class AbstractChannel implements Channel {
|
|
|
101
99
|
}
|
|
102
100
|
|
|
103
101
|
abstract getWriteBuffer(): WriteBuffer;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A very basic {@link AbstractChannel} implementation which takes a function
|
|
106
|
+
* for retrieving the {@link WriteBuffer} as constructor argument.
|
|
107
|
+
*/
|
|
108
|
+
export class BasicChannel extends AbstractChannel {
|
|
109
|
+
|
|
110
|
+
constructor(protected writeBufferProvider: () => WriteBuffer) {
|
|
111
|
+
super();
|
|
112
|
+
}
|
|
104
113
|
|
|
114
|
+
getWriteBuffer(): WriteBuffer {
|
|
115
|
+
return this.writeBufferProvider();
|
|
116
|
+
}
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
/**
|
|
@@ -194,7 +206,7 @@ export class ChannelMultiplexer implements Disposable {
|
|
|
194
206
|
return this.handleClose(id);
|
|
195
207
|
}
|
|
196
208
|
case MessageTypes.Data: {
|
|
197
|
-
return this.handleData(id, buffer
|
|
209
|
+
return this.handleData(id, buffer);
|
|
198
210
|
}
|
|
199
211
|
}
|
|
200
212
|
}
|
|
@@ -206,7 +218,7 @@ export class ChannelMultiplexer implements Disposable {
|
|
|
206
218
|
const channel = this.createChannel(id);
|
|
207
219
|
this.pendingOpen.delete(id);
|
|
208
220
|
this.openChannels.set(id, channel);
|
|
209
|
-
resolve
|
|
221
|
+
resolve(channel);
|
|
210
222
|
this.onOpenChannelEmitter.fire({ id, channel });
|
|
211
223
|
}
|
|
212
224
|
}
|
|
@@ -236,7 +248,7 @@ export class ChannelMultiplexer implements Disposable {
|
|
|
236
248
|
protected handleData(id: string, data: ReadBuffer): void {
|
|
237
249
|
const channel = this.openChannels.get(id);
|
|
238
250
|
if (channel) {
|
|
239
|
-
channel.onMessageEmitter.fire(() => data);
|
|
251
|
+
channel.onMessageEmitter.fire(() => data.sliceAtReadPosition());
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
|
|
@@ -263,6 +275,9 @@ export class ChannelMultiplexer implements Disposable {
|
|
|
263
275
|
}
|
|
264
276
|
|
|
265
277
|
open(id: string): Promise<Channel> {
|
|
278
|
+
if (this.openChannels.has(id)) {
|
|
279
|
+
throw new Error(`Another channel with the id '${id}' is already open.`);
|
|
280
|
+
}
|
|
266
281
|
const result = new Promise<Channel>((resolve, reject) => {
|
|
267
282
|
this.pendingOpen.set(id, resolve);
|
|
268
283
|
});
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
//
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
|
-
export {
|
|
17
|
-
export { Channel, AbstractChannel, ChannelCloseEvent, MessageProvider } from './channel';
|
|
16
|
+
export { AbstractChannel, Channel, ChannelCloseEvent, MessageProvider } from './channel';
|
|
18
17
|
export { ReadBuffer, WriteBuffer } from './message-buffer';
|
|
18
|
+
export { RequestHandler, RpcProtocol, RpcProtocolOptions } from './rpc-protocol';
|
|
19
|
+
|
|
20
|
+
import { registerMsgPackExtensions } from './rpc-message-encoder';
|
|
21
|
+
|
|
22
|
+
registerMsgPackExtensions();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { addExtension } from 'msgpackr';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Handles the global registration of custom MsgPackR extensions
|
|
21
|
+
* required for the default RPC communication. MsgPackR extensions
|
|
22
|
+
* are installed globally on both ends of the communication channel.
|
|
23
|
+
* (frontend-backend, pluginExt-pluginMain).
|
|
24
|
+
* Is implemented as singleton as it is also used in plugin child processes which have no access to inversify.
|
|
25
|
+
*/
|
|
26
|
+
export class MsgPackExtensionManager {
|
|
27
|
+
private static readonly INSTANCE = new MsgPackExtensionManager();
|
|
28
|
+
public static getInstance(): MsgPackExtensionManager {
|
|
29
|
+
return this.INSTANCE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private extensions = new Map<number, MsgPackExtension>();
|
|
33
|
+
|
|
34
|
+
private constructor() {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
registerExtensions(...extensions: MsgPackExtension[]): void {
|
|
38
|
+
extensions.forEach(extension => {
|
|
39
|
+
if (extension.tag < 1 || extension.tag > 100) {
|
|
40
|
+
// MsgPackR reserves the tag range 1-100 for custom extensions.
|
|
41
|
+
throw new Error(`MsgPack extension tag should be a number from 1-100 but was '${extension.tag}'`);
|
|
42
|
+
}
|
|
43
|
+
if (this.extensions.has(extension.tag)) {
|
|
44
|
+
throw new Error(`Another MsgPack extension with the tag '${extension.tag}' is already registered`);
|
|
45
|
+
}
|
|
46
|
+
this.extensions.set(extension.tag, extension);
|
|
47
|
+
addExtension({
|
|
48
|
+
Class: extension.class,
|
|
49
|
+
type: extension.tag,
|
|
50
|
+
write: extension.serialize,
|
|
51
|
+
read: extension.deserialize
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getExtension(tag: number): MsgPackExtension | undefined {
|
|
57
|
+
return this.extensions.get(tag);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface MsgPackExtension {
|
|
62
|
+
class: Function,
|
|
63
|
+
tag: number,
|
|
64
|
+
serialize(instance: unknown): unknown,
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
deserialize(serialized: any): unknown
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type Constructor<T> = new (...params: unknown[]) => T;
|
|
70
|
+
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { Packr as MsgPack } from 'msgpackr';
|
|
19
19
|
import { ReadBuffer, WriteBuffer } from './message-buffer';
|
|
20
|
+
import { MsgPackExtensionManager } from './msg-pack-extension-manager';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* This code lets you encode rpc protocol messages (request/reply/notification/error/cancel)
|
|
@@ -121,27 +122,10 @@ export interface RpcMessageEncoder {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
export const defaultMsgPack = new MsgPack({ moreTypes: true, encodeUndefinedAsNil: false, bundleStrings: false });
|
|
124
|
-
// Add custom msgpackR extension for ResponseErrors.
|
|
125
|
-
addExtension({
|
|
126
|
-
Class: ResponseError,
|
|
127
|
-
type: 1,
|
|
128
|
-
write: (instance: ResponseError) => {
|
|
129
|
-
const { code, data, message, name, stack } = instance;
|
|
130
|
-
return { code, data, message, name, stack };
|
|
131
|
-
},
|
|
132
|
-
read: data => {
|
|
133
|
-
const error = new ResponseError(data.code, data.message, data.data);
|
|
134
|
-
error.name = data.name;
|
|
135
|
-
error.stack = data.stack;
|
|
136
|
-
return error;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
125
|
|
|
140
126
|
export class MsgPackMessageEncoder implements RpcMessageEncoder {
|
|
141
127
|
|
|
142
|
-
constructor(protected readonly msgPack: MsgPack = defaultMsgPack) {
|
|
143
|
-
|
|
144
|
-
}
|
|
128
|
+
constructor(protected readonly msgPack: MsgPack = defaultMsgPack) { }
|
|
145
129
|
|
|
146
130
|
cancel(buf: WriteBuffer, requestId: number): void {
|
|
147
131
|
this.encode<CancelMessage>(buf, { type: RpcMessageType.Cancel, id: requestId });
|
|
@@ -169,13 +153,11 @@ export class MsgPackMessageEncoder implements RpcMessageEncoder {
|
|
|
169
153
|
throw err;
|
|
170
154
|
}
|
|
171
155
|
}
|
|
172
|
-
|
|
173
156
|
}
|
|
174
157
|
|
|
175
158
|
export class MsgPackMessageDecoder implements RpcMessageDecoder {
|
|
176
|
-
constructor(protected readonly msgPack: MsgPack = defaultMsgPack) {
|
|
159
|
+
constructor(protected readonly msgPack: MsgPack = defaultMsgPack) { }
|
|
177
160
|
|
|
178
|
-
}
|
|
179
161
|
decode<T = any>(buf: ReadBuffer): T {
|
|
180
162
|
const bytes = buf.readBytes();
|
|
181
163
|
return this.msgPack.decode(bytes);
|
|
@@ -184,5 +166,25 @@ export class MsgPackMessageDecoder implements RpcMessageDecoder {
|
|
|
184
166
|
parse(buffer: ReadBuffer): RpcMessage {
|
|
185
167
|
return this.decode(buffer);
|
|
186
168
|
}
|
|
169
|
+
}
|
|
187
170
|
|
|
171
|
+
export function registerMsgPackExtensions(): void {
|
|
172
|
+
// Register custom msgPack extension for Errors.
|
|
173
|
+
MsgPackExtensionManager.getInstance().registerExtensions({
|
|
174
|
+
class: Error,
|
|
175
|
+
tag: 1,
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
serialize: (error: any) => {
|
|
178
|
+
const { code, data, message, name } = error;
|
|
179
|
+
const stack = error.stacktrace ?? error.stack;
|
|
180
|
+
const isResponseError = error instanceof ResponseError;
|
|
181
|
+
return { code, data, message, name, stack, isResponseError };
|
|
182
|
+
},
|
|
183
|
+
deserialize: data => {
|
|
184
|
+
const error = data.isResponseError ? new ResponseError(data.code, data.message, data.data) : new Error(data.message);
|
|
185
|
+
error.name = data.name;
|
|
186
|
+
error.stack = data.stack;
|
|
187
|
+
return error;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
188
190
|
}
|
|
@@ -16,15 +16,14 @@
|
|
|
16
16
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
17
17
|
|
|
18
18
|
import { CancellationToken, CancellationTokenSource } from '../cancellation';
|
|
19
|
-
import { DisposableCollection } from '../disposable';
|
|
19
|
+
import { Disposable, DisposableCollection } from '../disposable';
|
|
20
20
|
import { Emitter, Event } from '../event';
|
|
21
21
|
import { Deferred } from '../promise-util';
|
|
22
22
|
import { Channel } from './channel';
|
|
23
23
|
import { MsgPackMessageDecoder, MsgPackMessageEncoder, RpcMessage, RpcMessageDecoder, RpcMessageEncoder, RpcMessageType } from './rpc-message-encoder';
|
|
24
|
-
import { Uint8ArrayWriteBuffer } from './uint8-array-message-buffer';
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
|
-
* Handles request messages received by the {@link
|
|
26
|
+
* Handles request messages received by the {@link RPCProtocol}.
|
|
28
27
|
*/
|
|
29
28
|
export type RequestHandler = (method: string, args: any[]) => Promise<any>;
|
|
30
29
|
|
|
@@ -39,15 +38,20 @@ export interface RpcProtocolOptions {
|
|
|
39
38
|
/**
|
|
40
39
|
* The message decoder that should be used. If `undefined` the default {@link RpcMessageDecoder} will be used.
|
|
41
40
|
*/
|
|
42
|
-
decoder?: RpcMessageDecoder
|
|
41
|
+
decoder?: RpcMessageDecoder,
|
|
42
|
+
/**
|
|
43
|
+
* The runtime mode determines whether the RPC protocol is bi-directional (default) or acts as a client or server only.
|
|
44
|
+
*/
|
|
45
|
+
mode?: 'default' | 'clientOnly' | 'serverOnly'
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/**
|
|
46
|
-
* Establish a
|
|
47
|
-
*
|
|
49
|
+
* Establish a RPC protocol on top of a given channel. By default the rpc protocol is bi-directional, meaning it is possible to send
|
|
50
|
+
* requests and notifications to the remote side (i.e. acts as client) as well as receiving requests and notifications from the remote side (i.e. acts as a server).
|
|
48
51
|
* Clients can get a promise for a remote request result that will be either resolved or
|
|
49
52
|
* rejected depending on the success of the request. Keeps track of outstanding requests and matches replies to the appropriate request
|
|
50
53
|
* Currently, there is no timeout handling for long running requests implemented.
|
|
54
|
+
* The bi-directional mode can be reconfigured using the {@link RpcProtocolOptions} to construct an RPC protocol instance that acts only as client or server instead.
|
|
51
55
|
*/
|
|
52
56
|
export class RpcProtocol {
|
|
53
57
|
static readonly CANCELLATION_TOKEN_KEY = 'add.cancellation.token';
|
|
@@ -58,6 +62,7 @@ export class RpcProtocol {
|
|
|
58
62
|
|
|
59
63
|
protected readonly encoder: RpcMessageEncoder;
|
|
60
64
|
protected readonly decoder: RpcMessageDecoder;
|
|
65
|
+
protected readonly mode: 'default' | 'clientOnly' | 'serverOnly';
|
|
61
66
|
|
|
62
67
|
protected readonly onNotificationEmitter: Emitter<{ method: string; args: any[]; }> = new Emitter();
|
|
63
68
|
protected readonly cancellationTokenSources = new Map<number, CancellationTokenSource>();
|
|
@@ -68,37 +73,50 @@ export class RpcProtocol {
|
|
|
68
73
|
|
|
69
74
|
protected toDispose = new DisposableCollection();
|
|
70
75
|
|
|
71
|
-
constructor(public readonly channel: Channel, public readonly requestHandler: RequestHandler, options: RpcProtocolOptions = {}) {
|
|
76
|
+
constructor(public readonly channel: Channel, public readonly requestHandler: RequestHandler | undefined, options: RpcProtocolOptions = {}) {
|
|
72
77
|
this.encoder = options.encoder ?? new MsgPackMessageEncoder();
|
|
73
78
|
this.decoder = options.decoder ?? new MsgPackMessageDecoder();
|
|
74
79
|
this.toDispose.push(this.onNotificationEmitter);
|
|
75
|
-
this.toDispose.push(channel.onMessage(readBuffer => this.handleMessage(this.decoder.parse(readBuffer()))));
|
|
76
80
|
channel.onClose(() => this.toDispose.dispose());
|
|
81
|
+
this.toDispose.push(channel.onMessage(readBuffer => this.handleMessage(this.decoder.parse(readBuffer()))));
|
|
82
|
+
this.mode = options.mode ?? 'default';
|
|
83
|
+
|
|
84
|
+
if (this.mode !== 'clientOnly' && requestHandler === undefined) {
|
|
85
|
+
console.error('RPCProtocol was initialized without a request handler but was not set to clientOnly mode.');
|
|
86
|
+
}
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
handleMessage(message: RpcMessage): void {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
if (this.mode !== 'clientOnly') {
|
|
91
|
+
switch (message.type) {
|
|
92
|
+
case RpcMessageType.Cancel: {
|
|
93
|
+
this.handleCancel(message.id);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
case RpcMessageType.Request: {
|
|
97
|
+
this.handleRequest(message.id, message.method, message.args);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
case RpcMessageType.Notification: {
|
|
101
|
+
this.handleNotify(message.id, message.method, message.args);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
92
104
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
}
|
|
106
|
+
if (this.mode !== 'serverOnly') {
|
|
107
|
+
switch (message.type) {
|
|
108
|
+
case RpcMessageType.Reply: {
|
|
109
|
+
this.handleReply(message.id, message.res);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
case RpcMessageType.ReplyErr: {
|
|
113
|
+
this.handleReplyErr(message.id, message.err);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
100
116
|
}
|
|
101
117
|
}
|
|
118
|
+
// If the message was not handled until here, it is incompatible with the mode.
|
|
119
|
+
console.warn(`Received message incompatible with this RPCProtocol's mode '${this.mode}'. Type: ${message.type}. ID: ${message.id}.`);
|
|
102
120
|
}
|
|
103
121
|
|
|
104
122
|
protected handleReply(id: number, value: any): void {
|
|
@@ -126,13 +144,13 @@ export class RpcProtocol {
|
|
|
126
144
|
}
|
|
127
145
|
|
|
128
146
|
sendRequest<T>(method: string, args: any[]): Promise<T> {
|
|
129
|
-
const id = this.nextMessageId++;
|
|
130
|
-
const reply = new Deferred<T>();
|
|
131
|
-
|
|
132
147
|
// The last element of the request args might be a cancellation token. As these tokens are not serializable we have to remove it from the
|
|
133
148
|
// args array and the `CANCELLATION_TOKEN_KEY` string instead.
|
|
134
149
|
const cancellationToken: CancellationToken | undefined = args.length && CancellationToken.is(args[args.length - 1]) ? args.pop() : undefined;
|
|
135
150
|
|
|
151
|
+
const id = this.nextMessageId++;
|
|
152
|
+
const reply = new Deferred<T>();
|
|
153
|
+
|
|
136
154
|
if (cancellationToken) {
|
|
137
155
|
args.push(RpcProtocol.CANCELLATION_TOKEN_KEY);
|
|
138
156
|
}
|
|
@@ -153,6 +171,13 @@ export class RpcProtocol {
|
|
|
153
171
|
}
|
|
154
172
|
|
|
155
173
|
sendNotification(method: string, args: any[]): void {
|
|
174
|
+
// If the notification supports a CancellationToken, it needs to be treated like a request
|
|
175
|
+
// because cancellation does not work with the simplified "fire and forget" approach of simple notifications.
|
|
176
|
+
if (args.length && CancellationToken.is(args[args.length - 1])) {
|
|
177
|
+
this.sendRequest(method, args);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
156
181
|
const output = this.channel.getWriteBuffer();
|
|
157
182
|
this.encoder.notification(output, this.nextMessageId++, method, args);
|
|
158
183
|
output.commit();
|
|
@@ -167,7 +192,6 @@ export class RpcProtocol {
|
|
|
167
192
|
protected handleCancel(id: number): void {
|
|
168
193
|
const cancellationTokenSource = this.cancellationTokenSources.get(id);
|
|
169
194
|
if (cancellationTokenSource) {
|
|
170
|
-
this.cancellationTokenSources.delete(id);
|
|
171
195
|
cancellationTokenSource.cancel();
|
|
172
196
|
}
|
|
173
197
|
}
|
|
@@ -185,14 +209,14 @@ export class RpcProtocol {
|
|
|
185
209
|
}
|
|
186
210
|
|
|
187
211
|
try {
|
|
188
|
-
const result = await this.requestHandler(method, args);
|
|
212
|
+
const result = await this.requestHandler!(method, args);
|
|
189
213
|
this.cancellationTokenSources.delete(id);
|
|
190
214
|
this.encoder.replyOK(output, id, result);
|
|
191
215
|
output.commit();
|
|
192
216
|
} catch (err) {
|
|
193
217
|
// In case of an error the output buffer might already contains parts of an message.
|
|
194
218
|
// => Dispose the current buffer and retrieve a new, clean one for writing the response error.
|
|
195
|
-
if (output
|
|
219
|
+
if (Disposable.is(output)) {
|
|
196
220
|
output.dispose();
|
|
197
221
|
}
|
|
198
222
|
const errorOutput = this.channel.getWriteBuffer();
|