@opensumi/ide-connection 2.27.3-rc-1713855854.0 → 2.27.3-rc-1714116491.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/rpc/multiplexer.d.ts +9 -6
- package/lib/common/rpc/multiplexer.d.ts.map +1 -1
- package/lib/common/rpc/multiplexer.js +23 -23
- package/lib/common/rpc/multiplexer.js.map +1 -1
- package/lib/common/rpc-service/registry.d.ts +1 -1
- package/lib/common/rpc-service/registry.d.ts.map +1 -1
- package/lib/common/rpc-service/registry.js +16 -15
- package/lib/common/rpc-service/registry.js.map +1 -1
- package/package.json +5 -5
- package/src/common/rpc/multiplexer.ts +31 -26
- package/src/common/rpc-service/registry.ts +20 -15
|
@@ -13,21 +13,24 @@ export interface IRPCProtocol {
|
|
|
13
13
|
set<T>(identifier: ProxyIdentifier<T>, instance: T): T;
|
|
14
14
|
get<T>(identifier: ProxyIdentifier<T>): T;
|
|
15
15
|
}
|
|
16
|
-
export declare function getRPCName(serviceId: string, methodName: string): string;
|
|
17
|
-
export declare function extractServiceAndMethod(rpcId: string): [string, string];
|
|
18
16
|
/**
|
|
19
17
|
* A connection multiplexer that allows to register multiple local RPC services and to create proxies for them.
|
|
20
18
|
*/
|
|
21
19
|
export declare class SumiConnectionMultiplexer extends SumiConnection implements IRPCProtocol {
|
|
22
20
|
protected socket: BaseConnection<Uint8Array>;
|
|
23
21
|
protected options: ISumiConnectionOptions;
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
protected static SEP: string;
|
|
23
|
+
protected static SEP_LENGTH: number;
|
|
24
|
+
protected static getRPCName(serviceId: string, methodName: string): string;
|
|
25
|
+
protected static extractServiceAndMethod(rpcId: string): [string, string];
|
|
26
|
+
protected static normalizeServiceId(serviceId: string): string;
|
|
27
|
+
protected readonly _locals: Map<string, any>;
|
|
28
|
+
protected readonly _proxies: Map<string, any>;
|
|
26
29
|
constructor(socket: BaseConnection<Uint8Array>, options?: ISumiConnectionOptions);
|
|
27
30
|
set<T>(identifier: ProxyIdentifier<T>, instance: any): any;
|
|
28
31
|
get<T>(identifier: ProxyIdentifier<T>): any;
|
|
29
32
|
getProxy<T>(proxyId: ProxyIdentifier<T>): any;
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
protected _createProxy(rpcId: string): any;
|
|
34
|
+
protected _doInvokeHandler(rpcName: string, args: any[]): Promise<any>;
|
|
32
35
|
}
|
|
33
36
|
//# sourceMappingURL=multiplexer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiplexer.d.ts","sourceRoot":"","sources":["../../../src/common/rpc/multiplexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEtE,qBAAa,eAAe,CAAC,CAAC,GAAG,GAAG;IAClC,OAAc,KAAK,SAAK;IAExB,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,OAAO,EAAE,MAAM,CAAC;gBACpB,SAAS,EAAE,MAAM;IAK7B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM;CAG7B;AAED,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5C,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACvD,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC3C;
|
|
1
|
+
{"version":3,"file":"multiplexer.d.ts","sourceRoot":"","sources":["../../../src/common/rpc/multiplexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EA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AAC;IAC7C,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAExB,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAAY,OAAO,GAAE,sBAA2B;IAYjG,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG;IAKpD,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC;IAIrC,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;IAU9C,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM;cAmBpB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAc7E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SumiConnectionMultiplexer = exports.
|
|
3
|
+
exports.SumiConnectionMultiplexer = exports.IRPCProtocol = exports.ProxyIdentifier = void 0;
|
|
4
4
|
const connection_1 = require("./connection");
|
|
5
5
|
class ProxyIdentifier {
|
|
6
6
|
constructor(serviceId) {
|
|
@@ -14,47 +14,44 @@ class ProxyIdentifier {
|
|
|
14
14
|
exports.ProxyIdentifier = ProxyIdentifier;
|
|
15
15
|
ProxyIdentifier.count = 0;
|
|
16
16
|
exports.IRPCProtocol = Symbol('IRPCProtocol');
|
|
17
|
-
const SEP = '||';
|
|
18
|
-
const SEP_LENGTH = SEP.length;
|
|
19
|
-
function getRPCName(serviceId, methodName) {
|
|
20
|
-
return `${serviceId}${SEP}${methodName}`;
|
|
21
|
-
}
|
|
22
|
-
exports.getRPCName = getRPCName;
|
|
23
|
-
function extractServiceAndMethod(rpcId) {
|
|
24
|
-
const idx = rpcId.indexOf(SEP);
|
|
25
|
-
return [rpcId.substring(0, idx), rpcId.substring(idx + SEP_LENGTH)];
|
|
26
|
-
}
|
|
27
|
-
exports.extractServiceAndMethod = extractServiceAndMethod;
|
|
28
17
|
/**
|
|
29
18
|
* A connection multiplexer that allows to register multiple local RPC services and to create proxies for them.
|
|
30
19
|
*/
|
|
31
20
|
class SumiConnectionMultiplexer extends connection_1.SumiConnection {
|
|
21
|
+
static getRPCName(serviceId, methodName) {
|
|
22
|
+
return `${serviceId}${SumiConnectionMultiplexer.SEP}${methodName}`;
|
|
23
|
+
}
|
|
24
|
+
static extractServiceAndMethod(rpcId) {
|
|
25
|
+
const idx = rpcId.indexOf(SumiConnectionMultiplexer.SEP);
|
|
26
|
+
return [rpcId.substring(0, idx), rpcId.substring(idx + SumiConnectionMultiplexer.SEP_LENGTH)];
|
|
27
|
+
}
|
|
28
|
+
static normalizeServiceId(serviceId) {
|
|
29
|
+
return serviceId.replace(/\//g, '_');
|
|
30
|
+
}
|
|
32
31
|
constructor(socket, options = {}) {
|
|
33
32
|
super(socket, options);
|
|
34
33
|
this.socket = socket;
|
|
35
34
|
this.options = options;
|
|
36
35
|
this._locals = new Map();
|
|
37
36
|
this._proxies = new Map();
|
|
38
|
-
this.onRequestNotFound((rpcName, args) =>
|
|
39
|
-
const [rpcId, methodName] = extractServiceAndMethod(rpcName);
|
|
40
|
-
return this._doInvokeHandler(rpcId, methodName, args);
|
|
41
|
-
});
|
|
37
|
+
this.onRequestNotFound((rpcName, args) => this._doInvokeHandler(rpcName, args));
|
|
42
38
|
// call `listen` implicitly
|
|
43
39
|
// compatible behavior with the RPCProtocol
|
|
44
40
|
this.listen();
|
|
45
41
|
}
|
|
46
42
|
set(identifier, instance) {
|
|
47
|
-
this._locals.set(identifier.serviceId, instance);
|
|
43
|
+
this._locals.set(SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId), instance);
|
|
48
44
|
return instance;
|
|
49
45
|
}
|
|
50
46
|
get(identifier) {
|
|
51
|
-
return this._locals.get(identifier.serviceId);
|
|
47
|
+
return this._locals.get(SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId));
|
|
52
48
|
}
|
|
53
49
|
getProxy(proxyId) {
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
const serviceId = SumiConnectionMultiplexer.normalizeServiceId(proxyId.serviceId);
|
|
51
|
+
if (!this._proxies.has(serviceId)) {
|
|
52
|
+
this._proxies.set(serviceId, this._createProxy(serviceId));
|
|
56
53
|
}
|
|
57
|
-
return this._proxies.get(
|
|
54
|
+
return this._proxies.get(serviceId);
|
|
58
55
|
}
|
|
59
56
|
_createProxy(rpcId) {
|
|
60
57
|
const handler = {
|
|
@@ -64,7 +61,7 @@ class SumiConnectionMultiplexer extends connection_1.SumiConnection {
|
|
|
64
61
|
}
|
|
65
62
|
// charCodeAt(0) === 36 means starts with $
|
|
66
63
|
if (!target[name] && name.charCodeAt(0) === 36) {
|
|
67
|
-
const rpcName = getRPCName(rpcId, name);
|
|
64
|
+
const rpcName = SumiConnectionMultiplexer.getRPCName(rpcId, name);
|
|
68
65
|
target[name] = (...args) => this.sendRequest(rpcName, ...args);
|
|
69
66
|
}
|
|
70
67
|
return target[name];
|
|
@@ -72,7 +69,8 @@ class SumiConnectionMultiplexer extends connection_1.SumiConnection {
|
|
|
72
69
|
};
|
|
73
70
|
return new Proxy(Object.create(null), handler);
|
|
74
71
|
}
|
|
75
|
-
async _doInvokeHandler(
|
|
72
|
+
async _doInvokeHandler(rpcName, args) {
|
|
73
|
+
const [rpcId, methodName] = SumiConnectionMultiplexer.extractServiceAndMethod(rpcName);
|
|
76
74
|
const actor = this._locals.get(rpcId);
|
|
77
75
|
if (!actor) {
|
|
78
76
|
throw new Error('Unknown actor ' + rpcId);
|
|
@@ -85,4 +83,6 @@ class SumiConnectionMultiplexer extends connection_1.SumiConnection {
|
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
exports.SumiConnectionMultiplexer = SumiConnectionMultiplexer;
|
|
86
|
+
SumiConnectionMultiplexer.SEP = '/';
|
|
87
|
+
SumiConnectionMultiplexer.SEP_LENGTH = SumiConnectionMultiplexer.SEP.length;
|
|
88
88
|
//# sourceMappingURL=multiplexer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multiplexer.js","sourceRoot":"","sources":["../../../src/common/rpc/multiplexer.ts"],"names":[],"mappings":";;;AAEA,6CAAsE;AAEtE,MAAa,eAAe;IAK1B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,SAAiB;QAC1B,OAAO,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;;AAZH,0CAaC;AAZe,qBAAK,GAAG,CAAC,CAAC;AAcb,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAOnD,
|
|
1
|
+
{"version":3,"file":"multiplexer.js","sourceRoot":"","sources":["../../../src/common/rpc/multiplexer.ts"],"names":[],"mappings":";;;AAEA,6CAAsE;AAEtE,MAAa,eAAe;IAK1B,YAAY,SAAiB;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,EAAE,eAAe,CAAC,KAAK,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,SAAiB;QAC1B,OAAO,IAAI,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;;AAZH,0CAaC;AAZe,qBAAK,GAAG,CAAC,CAAC;AAcb,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAOnD;;GAEG;AACH,MAAa,yBAA0B,SAAQ,2BAAc;IAIjD,MAAM,CAAC,UAAU,CAAC,SAAiB,EAAE,UAAkB;QAC/D,OAAO,GAAG,SAAS,GAAG,yBAAyB,CAAC,GAAG,GAAG,UAAU,EAA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K,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC;SAC3C;QACD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,UAAU,GAAG,YAAY,GAAG,KAAK,CAAC,CAAC;SACxE;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;;AAnFH,8DAoFC;AAnFkB,6BAAG,GAAG,GAAG,CAAC;AACV,oCAAU,GAAG,yBAAyB,CAAC,GAAG,CAAC,MAAM,CAAC"}
|
|
@@ -3,7 +3,7 @@ import { MessageIO, TSumiProtocol } from '../rpc';
|
|
|
3
3
|
import { RPCServiceMethod } from '../types';
|
|
4
4
|
export declare function getServiceMethods(service: any): string[];
|
|
5
5
|
/**
|
|
6
|
-
* Store all executable services
|
|
6
|
+
* Store all executable services, and provide a way to invoke them.
|
|
7
7
|
*/
|
|
8
8
|
export declare class ServiceRegistry {
|
|
9
9
|
protected emitter: Emitter<string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAuB,MAAM,QAAQ,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAuB,MAAM,QAAQ,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAI5C,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,EAAE,CAqBxD;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,SAAS,CAAC,OAAO,oBAA2B;IAE5C,OAAO,CAAC,gBAAgB,CAA4C;IAEpE,gBAAgB,sDAAsB;IAEtC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB;IAKjD,eAAe,CACb,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;KACzC;IAkBH,GAAG,CAAC,IAAI,EAAE,WAAW;IAIrB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG;IAM9C,OAAO;CAGR;AAED,qBAAa,gBAAgB;IAC3B,SAAS,CAAC,OAAO,oBAA2B;IAE5C,OAAO,CAAC,WAAW,CAA+C;IAElE,gBAAgB,sDAAsB;IAEtC,WAAW,CACT,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;KACzC;IAsBH,OAAO,CAAC,EAAE,EAAE,SAAS;CActB"}
|
|
@@ -2,27 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProtocolRegistry = exports.ServiceRegistry = exports.getServiceMethods = void 0;
|
|
4
4
|
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
5
|
+
const skipMethods = new Set(['constructor']);
|
|
5
6
|
function getServiceMethods(service) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (service[prop] && typeof service[prop] === 'function') {
|
|
17
|
-
props.push(prop);
|
|
7
|
+
const props = new Set();
|
|
8
|
+
let obj = service;
|
|
9
|
+
do {
|
|
10
|
+
const propertyNames = Object.getOwnPropertyNames(obj);
|
|
11
|
+
for (const prop of propertyNames) {
|
|
12
|
+
if (skipMethods.has(prop)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (typeof service[prop] === 'function') {
|
|
16
|
+
props.add(prop);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
19
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
20
|
+
const array = Array.from(props);
|
|
21
|
+
array.sort();
|
|
22
|
+
return array;
|
|
22
23
|
}
|
|
23
24
|
exports.getServiceMethods = getServiceMethods;
|
|
24
25
|
/**
|
|
25
|
-
* Store all executable services
|
|
26
|
+
* Store all executable services, and provide a way to invoke them.
|
|
26
27
|
*/
|
|
27
28
|
class ServiceRegistry {
|
|
28
29
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":";;;AAAA,+DAAoD;AAKpD,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/common/rpc-service/registry.ts"],"names":[],"mappings":";;;AAAA,+DAAoD;AAKpD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAE7C,SAAgB,iBAAiB,CAAC,OAAY;IAC5C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,GAAG;QACD,MAAM,aAAa,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAEtD,KAAK,MAAM,IA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AAC;YACH,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC3B;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,CAAC,EAAa;QACnB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE;YAChD,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;SACjC;QAED,IAAI,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,EAAE;YAChC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBAC9C,IAAI,QAAQ,EAAE;oBACZ,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;iBACjC;aACF;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA/CD,4CA+CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-connection",
|
|
3
|
-
"version": "2.27.3-rc-
|
|
3
|
+
"version": "2.27.3-rc-1714116491.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@furyjs/fury": "0.5.9-beta",
|
|
21
21
|
"@opensumi/events": "^1.0.0",
|
|
22
|
-
"@opensumi/ide-core-common": "2.27.3-rc-
|
|
22
|
+
"@opensumi/ide-core-common": "2.27.3-rc-1714116491.0",
|
|
23
23
|
"@opensumi/vscode-jsonrpc": "^8.0.0-next.2",
|
|
24
24
|
"path-to-regexp": "^6.2.1",
|
|
25
25
|
"reconnecting-websocket": "^4.4.0",
|
|
26
26
|
"ws": "^8.16.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@opensumi/ide-components": "2.27.3-rc-
|
|
30
|
-
"@opensumi/ide-dev-tool": "2.27.3-rc-
|
|
29
|
+
"@opensumi/ide-components": "2.27.3-rc-1714116491.0",
|
|
30
|
+
"@opensumi/ide-dev-tool": "2.27.3-rc-1714116491.0",
|
|
31
31
|
"@opensumi/mock-socket": "^9.3.1"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "b3e24dca0866b038e5b93fb14119f30e947f4710"
|
|
34
34
|
}
|
|
@@ -24,34 +24,35 @@ export interface IRPCProtocol {
|
|
|
24
24
|
get<T>(identifier: ProxyIdentifier<T>): T;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const SEP = '||';
|
|
28
|
-
const SEP_LENGTH = SEP.length;
|
|
29
|
-
|
|
30
|
-
export function getRPCName(serviceId: string, methodName: string) {
|
|
31
|
-
return `${serviceId}${SEP}${methodName}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function extractServiceAndMethod(rpcId: string): [string, string] {
|
|
35
|
-
const idx = rpcId.indexOf(SEP);
|
|
36
|
-
return [rpcId.substring(0, idx), rpcId.substring(idx + SEP_LENGTH)];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
27
|
/**
|
|
40
28
|
* A connection multiplexer that allows to register multiple local RPC services and to create proxies for them.
|
|
41
29
|
*/
|
|
42
30
|
export class SumiConnectionMultiplexer extends SumiConnection implements IRPCProtocol {
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
protected static SEP = '/';
|
|
32
|
+
protected static SEP_LENGTH = SumiConnectionMultiplexer.SEP.length;
|
|
33
|
+
|
|
34
|
+
protected static getRPCName(serviceId: string, methodName: string) {
|
|
35
|
+
return `${serviceId}${SumiConnectionMultiplexer.SEP}${methodName}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected static extractServiceAndMethod(rpcId: string): [string, string] {
|
|
39
|
+
const idx = rpcId.indexOf(SumiConnectionMultiplexer.SEP);
|
|
40
|
+
return [rpcId.substring(0, idx), rpcId.substring(idx + SumiConnectionMultiplexer.SEP_LENGTH)];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected static normalizeServiceId(serviceId: string) {
|
|
44
|
+
return serviceId.replace(/\//g, '_');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected readonly _locals: Map<string, any>;
|
|
48
|
+
protected readonly _proxies: Map<string, any>;
|
|
45
49
|
|
|
46
50
|
constructor(protected socket: BaseConnection<Uint8Array>, protected options: ISumiConnectionOptions = {}) {
|
|
47
51
|
super(socket, options);
|
|
48
52
|
this._locals = new Map();
|
|
49
53
|
this._proxies = new Map();
|
|
50
54
|
|
|
51
|
-
this.onRequestNotFound((rpcName: string, args: any[]) =>
|
|
52
|
-
const [rpcId, methodName] = extractServiceAndMethod(rpcName);
|
|
53
|
-
return this._doInvokeHandler(rpcId, methodName, args);
|
|
54
|
-
});
|
|
55
|
+
this.onRequestNotFound((rpcName: string, args: any[]) => this._doInvokeHandler(rpcName, args));
|
|
55
56
|
|
|
56
57
|
// call `listen` implicitly
|
|
57
58
|
// compatible behavior with the RPCProtocol
|
|
@@ -59,23 +60,25 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
public set<T>(identifier: ProxyIdentifier<T>, instance: any) {
|
|
62
|
-
this._locals.set(identifier.serviceId, instance);
|
|
63
|
+
this._locals.set(SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId), instance);
|
|
63
64
|
return instance;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
public get<T>(identifier: ProxyIdentifier<T>) {
|
|
67
|
-
return this._locals.get(identifier.serviceId);
|
|
68
|
+
return this._locals.get(SumiConnectionMultiplexer.normalizeServiceId(identifier.serviceId));
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
public getProxy<T>(proxyId: ProxyIdentifier<T>) {
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const serviceId = SumiConnectionMultiplexer.normalizeServiceId(proxyId.serviceId);
|
|
73
|
+
|
|
74
|
+
if (!this._proxies.has(serviceId)) {
|
|
75
|
+
this._proxies.set(serviceId, this._createProxy(serviceId));
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
return this._proxies.get(
|
|
78
|
+
return this._proxies.get(serviceId);
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
protected _createProxy(rpcId: string) {
|
|
79
82
|
const handler = {
|
|
80
83
|
get: (target: any, name: string) => {
|
|
81
84
|
if (typeof name === 'symbol') {
|
|
@@ -83,7 +86,7 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
83
86
|
}
|
|
84
87
|
// charCodeAt(0) === 36 means starts with $
|
|
85
88
|
if (!target[name] && name.charCodeAt(0) === 36) {
|
|
86
|
-
const rpcName = getRPCName(rpcId, name);
|
|
89
|
+
const rpcName = SumiConnectionMultiplexer.getRPCName(rpcId, name);
|
|
87
90
|
target[name] = (...args: any[]) => this.sendRequest(rpcName, ...args);
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -94,7 +97,9 @@ export class SumiConnectionMultiplexer extends SumiConnection implements IRPCPro
|
|
|
94
97
|
return new Proxy(Object.create(null), handler);
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
protected async _doInvokeHandler(rpcName: string, args: any[]): Promise<any> {
|
|
101
|
+
const [rpcId, methodName] = SumiConnectionMultiplexer.extractServiceAndMethod(rpcName);
|
|
102
|
+
|
|
98
103
|
const actor = this._locals.get(rpcId);
|
|
99
104
|
if (!actor) {
|
|
100
105
|
throw new Error('Unknown actor ' + rpcId);
|
|
@@ -3,28 +3,33 @@ import { Emitter } from '@opensumi/ide-core-common';
|
|
|
3
3
|
import { MessageIO, TSumiProtocol, TSumiProtocolMethod } from '../rpc';
|
|
4
4
|
import { RPCServiceMethod } from '../types';
|
|
5
5
|
|
|
6
|
+
const skipMethods = new Set(['constructor']);
|
|
7
|
+
|
|
6
8
|
export function getServiceMethods(service: any): string[] {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const props = new Set<string>();
|
|
10
|
+
|
|
11
|
+
let obj = service;
|
|
12
|
+
do {
|
|
13
|
+
const propertyNames = Object.getOwnPropertyNames(obj);
|
|
14
|
+
|
|
15
|
+
for (const prop of propertyNames) {
|
|
16
|
+
if (skipMethods.has(prop)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof service[prop] === 'function') {
|
|
21
|
+
props.add(prop);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
|
-
}
|
|
24
|
+
} while ((obj = Object.getPrototypeOf(obj)));
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
const array = Array.from(props);
|
|
27
|
+
array.sort();
|
|
28
|
+
return array;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
/**
|
|
27
|
-
* Store all executable services
|
|
32
|
+
* Store all executable services, and provide a way to invoke them.
|
|
28
33
|
*/
|
|
29
34
|
export class ServiceRegistry {
|
|
30
35
|
protected emitter = new Emitter<string[]>();
|