@opensumi/ide-connection 2.27.3-rc-1713838390.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.
Files changed (49) hide show
  1. package/lib/common/capturer.d.ts +21 -1
  2. package/lib/common/capturer.d.ts.map +1 -1
  3. package/lib/common/capturer.js +130 -4
  4. package/lib/common/capturer.js.map +1 -1
  5. package/lib/common/index.d.ts +0 -1
  6. package/lib/common/index.d.ts.map +1 -1
  7. package/lib/common/index.js +0 -1
  8. package/lib/common/index.js.map +1 -1
  9. package/lib/common/rpc/connection.d.ts +8 -2
  10. package/lib/common/rpc/connection.d.ts.map +1 -1
  11. package/lib/common/rpc/connection.js +17 -6
  12. package/lib/common/rpc/connection.js.map +1 -1
  13. package/lib/common/rpc/multiplexer.d.ts +9 -6
  14. package/lib/common/rpc/multiplexer.d.ts.map +1 -1
  15. package/lib/common/rpc/multiplexer.js +23 -23
  16. package/lib/common/rpc/multiplexer.js.map +1 -1
  17. package/lib/common/rpc-service/center.d.ts +1 -1
  18. package/lib/common/rpc-service/center.d.ts.map +1 -1
  19. package/lib/common/rpc-service/center.js.map +1 -1
  20. package/lib/common/rpc-service/proxy/base.d.ts +2 -11
  21. package/lib/common/rpc-service/proxy/base.d.ts.map +1 -1
  22. package/lib/common/rpc-service/proxy/base.js +3 -82
  23. package/lib/common/rpc-service/proxy/base.js.map +1 -1
  24. package/lib/common/rpc-service/proxy/json.d.ts +3 -1
  25. package/lib/common/rpc-service/proxy/json.d.ts.map +1 -1
  26. package/lib/common/rpc-service/proxy/json.js +12 -10
  27. package/lib/common/rpc-service/proxy/json.js.map +1 -1
  28. package/lib/common/rpc-service/proxy/sumi.d.ts.map +1 -1
  29. package/lib/common/rpc-service/proxy/sumi.js +3 -31
  30. package/lib/common/rpc-service/proxy/sumi.js.map +1 -1
  31. package/lib/common/rpc-service/registry.d.ts +1 -1
  32. package/lib/common/rpc-service/registry.d.ts.map +1 -1
  33. package/lib/common/rpc-service/registry.js +16 -15
  34. package/lib/common/rpc-service/registry.js.map +1 -1
  35. package/lib/common/ws-channel.d.ts +0 -1
  36. package/lib/common/ws-channel.d.ts.map +1 -1
  37. package/lib/common/ws-channel.js +0 -4
  38. package/lib/common/ws-channel.js.map +1 -1
  39. package/package.json +5 -5
  40. package/src/common/capturer.ts +169 -3
  41. package/src/common/index.ts +0 -1
  42. package/src/common/rpc/connection.ts +34 -7
  43. package/src/common/rpc/multiplexer.ts +31 -26
  44. package/src/common/rpc-service/center.ts +2 -1
  45. package/src/common/rpc-service/proxy/base.ts +5 -101
  46. package/src/common/rpc-service/proxy/json.ts +14 -12
  47. package/src/common/rpc-service/proxy/sumi.ts +3 -30
  48. package/src/common/rpc-service/registry.ts +20 -15
  49. package/src/common/ws-channel.ts +0 -4
@@ -10,7 +10,6 @@ export class ProxySumi extends ProxyBase<SumiConnection> {
10
10
  for (const method of methods) {
11
11
  if (method.startsWith('on')) {
12
12
  this.connection.onNotification(method, async (...args: any[]) => {
13
- this.captureOnNotification(method, args);
14
13
  try {
15
14
  await this.registry.invoke(method, ...args);
16
15
  } catch (e) {
@@ -18,19 +17,7 @@ export class ProxySumi extends ProxyBase<SumiConnection> {
18
17
  }
19
18
  });
20
19
  } else {
21
- this.connection.onRequest(method, async (...args: any[]) => {
22
- const requestId = this.nextRequestId();
23
- this.captureOnRequest(requestId, method, args);
24
-
25
- try {
26
- const result = await this.registry.invoke(method, ...args);
27
- this.captureOnRequestResult(requestId, method, result);
28
- return result;
29
- } catch (e) {
30
- this.captureOnRequestFail(requestId, method, e);
31
- throw e;
32
- }
33
- });
20
+ this.connection.onRequest(method, async (...args: any[]) => await this.registry.invoke(method, ...args));
34
21
  }
35
22
  }
36
23
  }
@@ -40,29 +27,15 @@ export class ProxySumi extends ProxyBase<SumiConnection> {
40
27
 
41
28
  // 调用方法为 on 开头时,作为单项通知
42
29
  if (prop.startsWith('on')) {
43
- this.captureSendNotification(prop, args);
44
30
  this.connection.sendNotification(prop, ...args);
45
31
  } else {
46
- // generate a unique requestId to associate request and requestResult
47
- const requestId = this.nextRequestId();
48
- this.captureSendRequest(requestId, prop, args);
49
- try {
50
- const result = await this.connection.sendRequest(prop, ...args);
51
- this.captureSendRequestResult(requestId, prop, result);
52
- return result;
53
- } catch (error) {
54
- this.captureSendRequestFail(requestId, prop, error);
55
- throw error;
56
- }
32
+ return await this.connection.sendRequest(prop, ...args);
57
33
  }
58
34
  }
59
35
 
60
36
  listen(connection: SumiConnection): void {
61
37
  super.listen(connection);
62
- connection.onRequestNotFound((method) => {
63
- const requestId = this.nextRequestId();
64
- this.captureOnRequest(requestId, method, []);
65
- this.captureOnRequestFail(requestId, method, METHOD_NOT_REGISTERED);
38
+ connection.onRequestNotFound(() => {
66
39
  throw METHOD_NOT_REGISTERED;
67
40
  });
68
41
  }
@@ -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
- let props: any[] = [];
8
-
9
- if (/^\s*class/.test(service.constructor.toString())) {
10
- let obj = service;
11
- do {
12
- props = props.concat(Object.getOwnPropertyNames(obj));
13
- } while ((obj = Object.getPrototypeOf(obj)));
14
- props = props.sort().filter((e, i, arr) => e !== arr[i + 1] && typeof service[e] === 'function');
15
- } else {
16
- for (const prop in service) {
17
- if (service[prop] && typeof service[prop] === 'function') {
18
- props.push(prop);
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
- return props;
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[]>();
@@ -5,7 +5,6 @@ import { DisposableCollection } from '@opensumi/ide-core-common';
5
5
 
6
6
  import { IConnectionShape } from './connection/types';
7
7
  import { oneOf7 } from './fury-extends/one-of';
8
- import { createWebSocketConnection } from './message';
9
8
  import { ISumiConnectionOptions, SumiConnection } from './rpc/connection';
10
9
  import { ILogger } from './types';
11
10
 
@@ -213,9 +212,6 @@ export class WSChannel {
213
212
  onceClose(cb: (code: number, reason: string) => void) {
214
213
  return this.emitter.once('close', cb);
215
214
  }
216
- createMessageConnection() {
217
- return createWebSocketConnection(this);
218
- }
219
215
 
220
216
  createConnection() {
221
217
  return {