@x-oasis/async-call-rpc 0.1.38
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 +48 -0
- package/dist/async-call-rpc.cjs.development.js +1275 -0
- package/dist/async-call-rpc.cjs.development.js.map +1 -0
- package/dist/async-call-rpc.cjs.production.min.js +2 -0
- package/dist/async-call-rpc.cjs.production.min.js.map +1 -0
- package/dist/async-call-rpc.esm.js +1559 -0
- package/dist/async-call-rpc.esm.js.map +1 -0
- package/dist/buffer/BufferFactory.d.ts +12 -0
- package/dist/buffer/DataBuffer.d.ts +2 -0
- package/dist/buffer/MessagePackBuffer.d.ts +10 -0
- package/dist/buffer/ReadBaseBuffer.d.ts +5 -0
- package/dist/buffer/ReadBuffer.d.ts +14 -0
- package/dist/buffer/SerializationFormat.d.ts +16 -0
- package/dist/buffer/WriteBaseBuffer.d.ts +5 -0
- package/dist/buffer/WriteBuffer.d.ts +5 -0
- package/dist/buffer/examples.d.ts +10 -0
- package/dist/buffer/index.d.ts +8 -0
- package/dist/common.d.ts +4 -0
- package/dist/endpoint/ProxyRPCClient.d.ts +12 -0
- package/dist/endpoint/RPCClientHost.d.ts +12 -0
- package/dist/endpoint/RPCService.d.ts +20 -0
- package/dist/endpoint/RPCServiceHost.d.ts +10 -0
- package/dist/error.d.ts +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -0
- package/dist/middlewares/buffer.d.ts +18 -0
- package/dist/middlewares/handleDisconnectedRequest.d.ts +7 -0
- package/dist/middlewares/handlePortRequest.d.ts +3 -0
- package/dist/middlewares/handleRequest.d.ts +3 -0
- package/dist/middlewares/handleRequestUtils.d.ts +10 -0
- package/dist/middlewares/handleResponse.d.ts +3 -0
- package/dist/middlewares/index.d.ts +7 -0
- package/dist/middlewares/logger.d.ts +4 -0
- package/dist/middlewares/normalize.d.ts +14 -0
- package/dist/middlewares/prepareRequestData.d.ts +28 -0
- package/dist/middlewares/sendRequest.d.ts +6 -0
- package/dist/middlewares/updateSeqInfo.d.ts +6 -0
- package/dist/middlewares/utils.d.ts +3 -0
- package/dist/protocol/AbstractChannelProtocol.d.ts +55 -0
- package/dist/protocol/MessageChannel.d.ts +18 -0
- package/dist/protocol/WebSocketChannel.d.ts +23 -0
- package/dist/protocol/WorkerChannel.d.ts +11 -0
- package/dist/types/buffer.d.ts +4 -0
- package/dist/types/channel.d.ts +27 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/middleware.d.ts +44 -0
- package/dist/types/proxyChannel.d.ts +3 -0
- package/dist/types/proxyService.d.ts +11 -0
- package/dist/types/rpc.d.ts +25 -0
- package/dist/types/rpcProtocol.d.ts +22 -0
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/jsonrpc.d.ts +36 -0
- package/package.json +36 -0
- package/src/buffer/ARCHITECTURE.md +298 -0
- package/src/buffer/BufferFactory.ts +124 -0
- package/src/buffer/CHANGELOG.md +207 -0
- package/src/buffer/DataBuffer.ts +1 -0
- package/src/buffer/MessagePackBuffer.ts +79 -0
- package/src/buffer/OPTIMIZATION.md +258 -0
- package/src/buffer/README.md +147 -0
- package/src/buffer/ReadBaseBuffer.ts +20 -0
- package/src/buffer/ReadBuffer.ts +58 -0
- package/src/buffer/SerializationFormat.ts +81 -0
- package/src/buffer/WriteBaseBuffer.ts +20 -0
- package/src/buffer/WriteBuffer.ts +15 -0
- package/src/buffer/examples.ts +242 -0
- package/src/buffer/index.ts +15 -0
- package/src/common.ts +20 -0
- package/src/endpoint/ProxyRPCClient.ts +64 -0
- package/src/endpoint/RPCClientHost.ts +45 -0
- package/src/endpoint/RPCService.ts +54 -0
- package/src/endpoint/RPCServiceHost.ts +18 -0
- package/src/error.ts +98 -0
- package/src/index.ts +16 -0
- package/src/middlewares/buffer.ts +33 -0
- package/src/middlewares/handleDisconnectedRequest.ts +30 -0
- package/src/middlewares/handlePortRequest.ts +141 -0
- package/src/middlewares/handleRequest.ts +128 -0
- package/src/middlewares/handleRequestUtils.ts +43 -0
- package/src/middlewares/handleResponse.ts +36 -0
- package/src/middlewares/index.ts +11 -0
- package/src/middlewares/logger.ts +22 -0
- package/src/middlewares/normalize.ts +167 -0
- package/src/middlewares/prepareRequestData.ts +137 -0
- package/src/middlewares/sendRequest.ts +15 -0
- package/src/middlewares/updateSeqInfo.ts +34 -0
- package/src/middlewares/utils.ts +67 -0
- package/src/protocol/AbstractChannelProtocol.ts +343 -0
- package/src/protocol/MessageChannel.ts +80 -0
- package/src/protocol/WebSocketChannel.ts +179 -0
- package/src/protocol/WorkerChannel.ts +36 -0
- package/src/types/buffer.ts +5 -0
- package/src/types/channel.ts +50 -0
- package/src/types/index.ts +9 -0
- package/src/types/messageChannel.ts +133 -0
- package/src/types/middleware.ts +54 -0
- package/src/types/proxyChannel.ts +3 -0
- package/src/types/proxyService.ts +18 -0
- package/src/types/rpc.ts +61 -0
- package/src/types/rpcProtocol.ts +24 -0
- package/src/utils/constants.ts +17 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/jsonrpc.ts +242 -0
|
@@ -0,0 +1,1559 @@
|
|
|
1
|
+
var ProxyRPCClient = /*#__PURE__*/function () {
|
|
2
|
+
function ProxyRPCClient(requestPath, options) {
|
|
3
|
+
var _ref = options || {},
|
|
4
|
+
channel = _ref.channel;
|
|
5
|
+
this.requestPath = requestPath;
|
|
6
|
+
if (channel) {
|
|
7
|
+
this.setChannel(channel);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var _proto = ProxyRPCClient.prototype;
|
|
11
|
+
_proto.setChannel = function setChannel(channel) {
|
|
12
|
+
this.channel = channel;
|
|
13
|
+
};
|
|
14
|
+
_proto.handleMessage = function handleMessage() {
|
|
15
|
+
var _this$channel;
|
|
16
|
+
(_this$channel = this.channel).onMessage.apply(_this$channel, arguments);
|
|
17
|
+
};
|
|
18
|
+
_proto.createProxy = function createProxy() {
|
|
19
|
+
var _this = this;
|
|
20
|
+
var getTrap = function getTrap(_, methodName) {
|
|
21
|
+
return function () {
|
|
22
|
+
if (!_this.channel) {
|
|
23
|
+
throw new Error("[ProxyRPCClient error] `this.channel` is null, when invoke function " + methodName);
|
|
24
|
+
}
|
|
25
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
+
args[_key] = arguments[_key];
|
|
27
|
+
}
|
|
28
|
+
return _this.channel.makeRequest({
|
|
29
|
+
requestPath: _this.requestPath,
|
|
30
|
+
methodName: methodName,
|
|
31
|
+
args: args
|
|
32
|
+
}).promise;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
return new Proxy({}, {
|
|
36
|
+
get: getTrap
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return ProxyRPCClient;
|
|
40
|
+
}();
|
|
41
|
+
|
|
42
|
+
var RPCClientHost = /*#__PURE__*/function () {
|
|
43
|
+
function RPCClientHost() {
|
|
44
|
+
this.hostMap = new Map();
|
|
45
|
+
}
|
|
46
|
+
var _proto = RPCClientHost.prototype;
|
|
47
|
+
_proto.registerClient = function registerClient(requestPath, options) {
|
|
48
|
+
var client = new ProxyRPCClient(requestPath, options);
|
|
49
|
+
this.hostMap.set(requestPath, client);
|
|
50
|
+
return client;
|
|
51
|
+
};
|
|
52
|
+
return RPCClientHost;
|
|
53
|
+
}();
|
|
54
|
+
var RPCClientHost$1 = /*#__PURE__*/new RPCClientHost();
|
|
55
|
+
|
|
56
|
+
var RPCService = /*#__PURE__*/function () {
|
|
57
|
+
function RPCService(servicePath, options) {
|
|
58
|
+
this.handlersMap = new Map();
|
|
59
|
+
var _ref = options || {},
|
|
60
|
+
channel = _ref.channel,
|
|
61
|
+
handlers = _ref.handlers,
|
|
62
|
+
serviceHost = _ref.serviceHost;
|
|
63
|
+
this.servicePath = servicePath;
|
|
64
|
+
this.serviceHost = serviceHost;
|
|
65
|
+
if (channel) {
|
|
66
|
+
this.setChannel(channel);
|
|
67
|
+
}
|
|
68
|
+
this.registerHandlers(handlers);
|
|
69
|
+
}
|
|
70
|
+
var _proto = RPCService.prototype;
|
|
71
|
+
_proto.setChannel = function setChannel(channel) {
|
|
72
|
+
this.channel = channel;
|
|
73
|
+
this.channel.setService(this);
|
|
74
|
+
this.channel.on(this.handleMessage.bind(this));
|
|
75
|
+
};
|
|
76
|
+
_proto.registerHandlers = function registerHandlers(handlers) {
|
|
77
|
+
if (!handlers) return;
|
|
78
|
+
for (var _i = 0, _Object$entries = Object.entries(handlers); _i < _Object$entries.length; _i++) {
|
|
79
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
80
|
+
methodName = _Object$entries$_i[0],
|
|
81
|
+
handler = _Object$entries$_i[1];
|
|
82
|
+
this.registerHandler(methodName, handler);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
_proto.handleMessage = function handleMessage() {
|
|
86
|
+
var _this$channel;
|
|
87
|
+
(_this$channel = this.channel).onMessage.apply(_this$channel, arguments);
|
|
88
|
+
};
|
|
89
|
+
_proto.registerHandler = function registerHandler(methodName, handler) {
|
|
90
|
+
this.handlersMap.set(methodName, handler);
|
|
91
|
+
};
|
|
92
|
+
_proto.getHandler = function getHandler(methodName) {
|
|
93
|
+
return this.handlersMap.get(methodName);
|
|
94
|
+
};
|
|
95
|
+
return RPCService;
|
|
96
|
+
}();
|
|
97
|
+
|
|
98
|
+
var RPCServiceHost = /*#__PURE__*/function () {
|
|
99
|
+
function RPCServiceHost() {
|
|
100
|
+
this.hostMap = new Map();
|
|
101
|
+
}
|
|
102
|
+
var _proto = RPCServiceHost.prototype;
|
|
103
|
+
_proto.registerService = function registerService(servicePath, serviceHandlers) {
|
|
104
|
+
var service = new RPCService(servicePath, {
|
|
105
|
+
handlers: serviceHandlers
|
|
106
|
+
});
|
|
107
|
+
this.hostMap.set(servicePath, service);
|
|
108
|
+
return service;
|
|
109
|
+
};
|
|
110
|
+
return RPCServiceHost;
|
|
111
|
+
}();
|
|
112
|
+
var RPCServiceHost$1 = /*#__PURE__*/new RPCServiceHost();
|
|
113
|
+
|
|
114
|
+
function _defineProperties(target, props) {
|
|
115
|
+
for (var i = 0; i < props.length; i++) {
|
|
116
|
+
var descriptor = props[i];
|
|
117
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
118
|
+
descriptor.configurable = true;
|
|
119
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
120
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
124
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
125
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
126
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
127
|
+
writable: false
|
|
128
|
+
});
|
|
129
|
+
return Constructor;
|
|
130
|
+
}
|
|
131
|
+
function _extends() {
|
|
132
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
133
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
134
|
+
var source = arguments[i];
|
|
135
|
+
for (var key in source) {
|
|
136
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
137
|
+
target[key] = source[key];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return target;
|
|
142
|
+
};
|
|
143
|
+
return _extends.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
function _inheritsLoose(subClass, superClass) {
|
|
146
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
147
|
+
subClass.prototype.constructor = subClass;
|
|
148
|
+
_setPrototypeOf(subClass, superClass);
|
|
149
|
+
}
|
|
150
|
+
function _setPrototypeOf(o, p) {
|
|
151
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
152
|
+
o.__proto__ = p;
|
|
153
|
+
return o;
|
|
154
|
+
};
|
|
155
|
+
return _setPrototypeOf(o, p);
|
|
156
|
+
}
|
|
157
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
158
|
+
if (source == null) return {};
|
|
159
|
+
var target = {};
|
|
160
|
+
var sourceKeys = Object.keys(source);
|
|
161
|
+
var key, i;
|
|
162
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
163
|
+
key = sourceKeys[i];
|
|
164
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
165
|
+
target[key] = source[key];
|
|
166
|
+
}
|
|
167
|
+
return target;
|
|
168
|
+
}
|
|
169
|
+
function _assertThisInitialized(self) {
|
|
170
|
+
if (self === void 0) {
|
|
171
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
172
|
+
}
|
|
173
|
+
return self;
|
|
174
|
+
}
|
|
175
|
+
function _toPrimitive(input, hint) {
|
|
176
|
+
if (typeof input !== "object" || input === null) return input;
|
|
177
|
+
var prim = input[Symbol.toPrimitive];
|
|
178
|
+
if (prim !== undefined) {
|
|
179
|
+
var res = prim.call(input, hint || "default");
|
|
180
|
+
if (typeof res !== "object") return res;
|
|
181
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
182
|
+
}
|
|
183
|
+
return (hint === "string" ? String : Number)(input);
|
|
184
|
+
}
|
|
185
|
+
function _toPropertyKey(arg) {
|
|
186
|
+
var key = _toPrimitive(arg, "string");
|
|
187
|
+
return typeof key === "symbol" ? key : String(key);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function _defineProperties$1(target, props) {
|
|
191
|
+
for (var i = 0; i < props.length; i++) {
|
|
192
|
+
var descriptor = props[i];
|
|
193
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
194
|
+
descriptor.configurable = true;
|
|
195
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
196
|
+
Object.defineProperty(target, _toPropertyKey$1(descriptor.key), descriptor);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function _createClass$1(Constructor, protoProps, staticProps) {
|
|
200
|
+
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
|
|
201
|
+
if (staticProps) _defineProperties$1(Constructor, staticProps);
|
|
202
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
203
|
+
writable: false
|
|
204
|
+
});
|
|
205
|
+
return Constructor;
|
|
206
|
+
}
|
|
207
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
208
|
+
if (!o) return;
|
|
209
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
210
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
211
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
212
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
213
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
214
|
+
}
|
|
215
|
+
function _arrayLikeToArray(arr, len) {
|
|
216
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
217
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
218
|
+
return arr2;
|
|
219
|
+
}
|
|
220
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
221
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
222
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
223
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
224
|
+
if (it) o = it;
|
|
225
|
+
var i = 0;
|
|
226
|
+
return function () {
|
|
227
|
+
if (i >= o.length) return {
|
|
228
|
+
done: true
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
done: false,
|
|
232
|
+
value: o[i++]
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
237
|
+
}
|
|
238
|
+
function _toPrimitive$1(input, hint) {
|
|
239
|
+
if (typeof input !== "object" || input === null) return input;
|
|
240
|
+
var prim = input[Symbol.toPrimitive];
|
|
241
|
+
if (prim !== undefined) {
|
|
242
|
+
var res = prim.call(input, hint || "default");
|
|
243
|
+
if (typeof res !== "object") return res;
|
|
244
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
245
|
+
}
|
|
246
|
+
return (hint === "string" ? String : Number)(input);
|
|
247
|
+
}
|
|
248
|
+
function _toPropertyKey$1(arg) {
|
|
249
|
+
var key = _toPrimitive$1(arg, "string");
|
|
250
|
+
return typeof key === "symbol" ? key : String(key);
|
|
251
|
+
}
|
|
252
|
+
function isObject(thing) {
|
|
253
|
+
return typeof thing === 'object' && thing !== null;
|
|
254
|
+
}
|
|
255
|
+
function isFunction(thing) {
|
|
256
|
+
return typeof thing === 'function';
|
|
257
|
+
}
|
|
258
|
+
function isArray(thing) {
|
|
259
|
+
return Array.isArray(thing);
|
|
260
|
+
}
|
|
261
|
+
function isIterable(thing) {
|
|
262
|
+
return thing && typeof thing === 'object' && typeof thing[Symbol.iterator] === 'function';
|
|
263
|
+
}
|
|
264
|
+
function dispose(disposables) {
|
|
265
|
+
if (isArray(disposables)) {
|
|
266
|
+
disposables.forEach(function (disposable) {
|
|
267
|
+
try {
|
|
268
|
+
disposable == null ? void 0 : disposable.dispose();
|
|
269
|
+
} catch (err) {}
|
|
270
|
+
});
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
if (isIterable(disposables) && !isArray(disposables)) {
|
|
274
|
+
for (var _iterator = _createForOfIteratorHelperLoose(disposables), _step; !(_step = _iterator()).done;) {
|
|
275
|
+
var disposable = _step.value;
|
|
276
|
+
try {
|
|
277
|
+
disposable == null ? void 0 : disposable.dispose();
|
|
278
|
+
} catch (err) {}
|
|
279
|
+
}
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
if (disposables && !isArray(disposables) && !isIterable(disposables) && isDisposable(disposables)) {
|
|
283
|
+
try {
|
|
284
|
+
disposables.dispose();
|
|
285
|
+
} catch (err) {}
|
|
286
|
+
return disposables;
|
|
287
|
+
}
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
var DisposableStore = /*#__PURE__*/function () {
|
|
291
|
+
function DisposableStore() {
|
|
292
|
+
this._toDispose = new Set();
|
|
293
|
+
this._isDisposed = false;
|
|
294
|
+
}
|
|
295
|
+
var _proto = DisposableStore.prototype;
|
|
296
|
+
_proto.dispose = function dispose() {
|
|
297
|
+
if (this._isDisposed) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this._isDisposed = true;
|
|
301
|
+
this.clear();
|
|
302
|
+
};
|
|
303
|
+
_proto.clear = function clear() {
|
|
304
|
+
if (this._toDispose.size === 0) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
dispose(this._toDispose);
|
|
308
|
+
this._toDispose.clear();
|
|
309
|
+
};
|
|
310
|
+
_proto.add = function add(thing) {
|
|
311
|
+
if (!thing) return thing;
|
|
312
|
+
if (thing === this) {
|
|
313
|
+
throw new Error('Cannot register a disposable on itself!');
|
|
314
|
+
}
|
|
315
|
+
if (this._isDisposed) ;else {
|
|
316
|
+
this._toDispose.add(thing);
|
|
317
|
+
}
|
|
318
|
+
return thing;
|
|
319
|
+
};
|
|
320
|
+
_proto["delete"] = function _delete(thing) {
|
|
321
|
+
if (!thing) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (thing === this) {
|
|
325
|
+
throw new Error('Cannot dispose a disposable on itself!');
|
|
326
|
+
}
|
|
327
|
+
this._toDispose["delete"](thing);
|
|
328
|
+
thing.dispose();
|
|
329
|
+
};
|
|
330
|
+
_createClass$1(DisposableStore, [{
|
|
331
|
+
key: "isDisposed",
|
|
332
|
+
get: function get() {
|
|
333
|
+
return this._isDisposed;
|
|
334
|
+
}
|
|
335
|
+
}]);
|
|
336
|
+
return DisposableStore;
|
|
337
|
+
}();
|
|
338
|
+
function isDisposable(thing) {
|
|
339
|
+
return isObject(thing) && isFunction(thing.dispose);
|
|
340
|
+
}
|
|
341
|
+
function toDisposable(fn) {
|
|
342
|
+
return {
|
|
343
|
+
dispose: function dispose() {
|
|
344
|
+
return fn();
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
var Disposable = /*#__PURE__*/function () {
|
|
349
|
+
function Disposable() {
|
|
350
|
+
this._store = new DisposableStore();
|
|
351
|
+
}
|
|
352
|
+
var _proto = Disposable.prototype;
|
|
353
|
+
_proto.dispose = function dispose() {
|
|
354
|
+
this._store.dispose();
|
|
355
|
+
};
|
|
356
|
+
_proto.registerDisposable = function registerDisposable(disposable) {
|
|
357
|
+
if (disposable === this) {
|
|
358
|
+
throw new Error('Can not register itself');
|
|
359
|
+
}
|
|
360
|
+
this._store.add(disposable);
|
|
361
|
+
};
|
|
362
|
+
return Disposable;
|
|
363
|
+
}();
|
|
364
|
+
Disposable.None = /*#__PURE__*/Object.freeze({
|
|
365
|
+
dispose: function dispose() {}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
function _unsupportedIterableToArray$1(o, minLen) {
|
|
369
|
+
if (!o) return;
|
|
370
|
+
if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
|
|
371
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
372
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
373
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
374
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
|
|
375
|
+
}
|
|
376
|
+
function _arrayLikeToArray$1(arr, len) {
|
|
377
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
378
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
379
|
+
return arr2;
|
|
380
|
+
}
|
|
381
|
+
function _createForOfIteratorHelperLoose$1(o, allowArrayLike) {
|
|
382
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
383
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
384
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
385
|
+
if (it) o = it;
|
|
386
|
+
var i = 0;
|
|
387
|
+
return function () {
|
|
388
|
+
if (i >= o.length) return {
|
|
389
|
+
done: true
|
|
390
|
+
};
|
|
391
|
+
return {
|
|
392
|
+
done: false,
|
|
393
|
+
value: o[i++]
|
|
394
|
+
};
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
398
|
+
}
|
|
399
|
+
var Event = /*#__PURE__*/function () {
|
|
400
|
+
function Event(props) {
|
|
401
|
+
this._listeners = [];
|
|
402
|
+
var name = props.name,
|
|
403
|
+
onWillAddFirstListener = props.onWillAddFirstListener,
|
|
404
|
+
onDidAddFirstListener = props.onDidAddFirstListener,
|
|
405
|
+
onDidAddListener = props.onDidAddListener,
|
|
406
|
+
onWillRemoveListener = props.onWillRemoveListener,
|
|
407
|
+
onDidRemoveLastListener = props.onDidRemoveLastListener,
|
|
408
|
+
coldTrigger = props.coldTrigger;
|
|
409
|
+
this.name = name;
|
|
410
|
+
this._coldTrigger = coldTrigger;
|
|
411
|
+
this._onWillAddFirstListener = onWillAddFirstListener;
|
|
412
|
+
this._onDidAddFirstListener = onDidAddFirstListener;
|
|
413
|
+
this._onDidAddListener = onDidAddListener;
|
|
414
|
+
this._onWillRemoveListener = onWillRemoveListener;
|
|
415
|
+
this._onDidRemoveLastListener = onDidRemoveLastListener;
|
|
416
|
+
this.subscribe = this.subscribe.bind(this);
|
|
417
|
+
}
|
|
418
|
+
var _proto = Event.prototype;
|
|
419
|
+
_proto.subscribe = function subscribe(listener) {
|
|
420
|
+
var _this = this;
|
|
421
|
+
if (!this._listeners.length) {
|
|
422
|
+
var _this$_onWillAddFirst;
|
|
423
|
+
(_this$_onWillAddFirst = this._onWillAddFirstListener) == null ? void 0 : _this$_onWillAddFirst.call(this);
|
|
424
|
+
}
|
|
425
|
+
var index = this._listeners.indexOf(listener);
|
|
426
|
+
if (index !== -1) {
|
|
427
|
+
console.error('add a duplicate listener');
|
|
428
|
+
} else {
|
|
429
|
+
var _this$_onDidAddFirstL, _this$_onDidAddListen;
|
|
430
|
+
this._listeners.push(listener);
|
|
431
|
+
if (this._listeners.length === 1) (_this$_onDidAddFirstL = this._onDidAddFirstListener) == null ? void 0 : _this$_onDidAddFirstL.call(this);
|
|
432
|
+
(_this$_onDidAddListen = this._onDidAddListener) == null ? void 0 : _this$_onDidAddListen.call(this);
|
|
433
|
+
if (this._coldTrigger && this._cacheCurrentValue) listener.apply(void 0, this._cacheCurrentValue);
|
|
434
|
+
}
|
|
435
|
+
return toDisposable(function () {
|
|
436
|
+
_this.removeListener(listener);
|
|
437
|
+
});
|
|
438
|
+
};
|
|
439
|
+
_proto.removeListener = function removeListener(listener) {
|
|
440
|
+
var _this$_onWillRemoveLi;
|
|
441
|
+
var index = this._listeners.indexOf(listener);
|
|
442
|
+
if (index === -1) return;
|
|
443
|
+
(_this$_onWillRemoveLi = this._onWillRemoveListener) == null ? void 0 : _this$_onWillRemoveLi.call(this);
|
|
444
|
+
this._listeners.splice(index, 1);
|
|
445
|
+
if (!this._listeners.length) {
|
|
446
|
+
var _this$_onDidRemoveLas;
|
|
447
|
+
(_this$_onDidRemoveLas = this._onDidRemoveLastListener) == null ? void 0 : _this$_onDidRemoveLas.call(this);
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
_proto.dispose = function dispose() {
|
|
451
|
+
var _this$_onDidRemoveLas2;
|
|
452
|
+
this._listeners = [];
|
|
453
|
+
(_this$_onDidRemoveLas2 = this._onDidRemoveLastListener) == null ? void 0 : _this$_onDidRemoveLas2.call(this);
|
|
454
|
+
};
|
|
455
|
+
_proto.fire = function fire() {
|
|
456
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
457
|
+
args[_key] = arguments[_key];
|
|
458
|
+
}
|
|
459
|
+
if (this._coldTrigger) {
|
|
460
|
+
this._cacheCurrentValue = args;
|
|
461
|
+
}
|
|
462
|
+
for (var _iterator = _createForOfIteratorHelperLoose$1(this._listeners), _step; !(_step = _iterator()).done;) {
|
|
463
|
+
var listener = _step.value;
|
|
464
|
+
listener.apply(void 0, args);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
return Event;
|
|
468
|
+
}();
|
|
469
|
+
|
|
470
|
+
var seenKeys = {};
|
|
471
|
+
var MULTIPLIER = /*#__PURE__*/Math.pow(2, 24);
|
|
472
|
+
var generateRandomKey = function generateRandomKey() {
|
|
473
|
+
var key;
|
|
474
|
+
while (key === undefined || seenKeys[key]) {
|
|
475
|
+
key = Math.floor(Math.random() * MULTIPLIER).toString(32);
|
|
476
|
+
}
|
|
477
|
+
seenKeys[key] = true;
|
|
478
|
+
return key;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
var RequestType;
|
|
482
|
+
(function (RequestType) {
|
|
483
|
+
RequestType["PromiseRequest"] = "pr";
|
|
484
|
+
RequestType["PromiseAbort"] = "pa";
|
|
485
|
+
RequestType["SignalRequest"] = "sr";
|
|
486
|
+
RequestType["SignalAbort"] = "sa";
|
|
487
|
+
})(RequestType || (RequestType = {}));
|
|
488
|
+
var ResponseType;
|
|
489
|
+
(function (ResponseType) {
|
|
490
|
+
ResponseType["ReturnSuccess"] = "rs";
|
|
491
|
+
ResponseType["ReturnFail"] = "rf";
|
|
492
|
+
ResponseType["PortSuccess"] = "ps";
|
|
493
|
+
ResponseType["PortFail"] = "pf";
|
|
494
|
+
})(ResponseType || (ResponseType = {}));
|
|
495
|
+
|
|
496
|
+
var SendMiddlewareLifecycle;
|
|
497
|
+
(function (SendMiddlewareLifecycle) {
|
|
498
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["Initial"] = 0] = "Initial";
|
|
499
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["Prepare"] = 10] = "Prepare";
|
|
500
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["Transform"] = 20] = "Transform";
|
|
501
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["DataOperation"] = 30] = "DataOperation";
|
|
502
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["Send"] = 40] = "Send";
|
|
503
|
+
SendMiddlewareLifecycle[SendMiddlewareLifecycle["Aborted"] = 100] = "Aborted";
|
|
504
|
+
})(SendMiddlewareLifecycle || (SendMiddlewareLifecycle = {}));
|
|
505
|
+
|
|
506
|
+
var serialize = function serialize(channel) {
|
|
507
|
+
var fn = function fn(value) {
|
|
508
|
+
return _extends({}, value, {
|
|
509
|
+
data: channel.writeBuffer.encode(value.data)
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
fn.lifecycle = SendMiddlewareLifecycle.DataOperation;
|
|
513
|
+
return fn;
|
|
514
|
+
};
|
|
515
|
+
var deserialize = function deserialize(channel) {
|
|
516
|
+
return function (value) {
|
|
517
|
+
var data = value.data;
|
|
518
|
+
var decoded = data;
|
|
519
|
+
try {
|
|
520
|
+
decoded = channel.readBuffer.decode(data);
|
|
521
|
+
} catch (err) {
|
|
522
|
+
console.error('[decode error]', data, err);
|
|
523
|
+
}
|
|
524
|
+
return _extends({}, value, {
|
|
525
|
+
data: decoded
|
|
526
|
+
});
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
var normalizeMessageChannelRawMessage = function normalizeMessageChannelRawMessage() {
|
|
531
|
+
return function (event) {
|
|
532
|
+
return {
|
|
533
|
+
event: event,
|
|
534
|
+
data: event.data,
|
|
535
|
+
ports: event.ports || []
|
|
536
|
+
};
|
|
537
|
+
};
|
|
538
|
+
};
|
|
539
|
+
function isBufferAvailable() {
|
|
540
|
+
return typeof Buffer !== 'undefined' && Buffer.isBuffer !== undefined;
|
|
541
|
+
}
|
|
542
|
+
function isBuffer(value) {
|
|
543
|
+
if (!isBufferAvailable()) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
return Buffer.isBuffer(value);
|
|
547
|
+
}
|
|
548
|
+
function arrayBufferToString(buffer) {
|
|
549
|
+
if (isBufferAvailable()) {
|
|
550
|
+
return Buffer.from(buffer).toString('utf8');
|
|
551
|
+
} else {
|
|
552
|
+
try {
|
|
553
|
+
return new TextDecoder('utf-8').decode(buffer);
|
|
554
|
+
} catch (e) {
|
|
555
|
+
var uint8Array = new Uint8Array(buffer);
|
|
556
|
+
return String.fromCharCode.apply(null, Array.from(uint8Array));
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function bufferToString(buffer) {
|
|
561
|
+
if (isBufferAvailable() && Buffer.isBuffer(buffer)) {
|
|
562
|
+
return buffer.toString('utf8');
|
|
563
|
+
}
|
|
564
|
+
return String(buffer);
|
|
565
|
+
}
|
|
566
|
+
var normalizeWebSocketRawMessage = function normalizeWebSocketRawMessage() {
|
|
567
|
+
return function (eventOrData) {
|
|
568
|
+
if (eventOrData === undefined || eventOrData === null) {
|
|
569
|
+
console.warn('[normalizeWebSocketRawMessage] Received undefined or null data');
|
|
570
|
+
return {
|
|
571
|
+
event: null,
|
|
572
|
+
data: '',
|
|
573
|
+
ports: []
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
var normalizedData = '';
|
|
577
|
+
var event = null;
|
|
578
|
+
var ports = [];
|
|
579
|
+
if (eventOrData && typeof eventOrData === 'object' && 'data' in eventOrData) {
|
|
580
|
+
event = eventOrData;
|
|
581
|
+
var data = event.data;
|
|
582
|
+
ports = event.ports ? [].concat(event.ports) : [];
|
|
583
|
+
if (data === undefined || data === null) {
|
|
584
|
+
normalizedData = '';
|
|
585
|
+
} else if (typeof data === 'string') {
|
|
586
|
+
normalizedData = data;
|
|
587
|
+
} else if (isBuffer(data)) {
|
|
588
|
+
normalizedData = bufferToString(data);
|
|
589
|
+
} else if (data instanceof ArrayBuffer) {
|
|
590
|
+
normalizedData = arrayBufferToString(data);
|
|
591
|
+
} else if (data instanceof Blob) {
|
|
592
|
+
normalizedData = '';
|
|
593
|
+
} else {
|
|
594
|
+
normalizedData = String(data);
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
var actualData = eventOrData;
|
|
598
|
+
if ((arguments.length <= 1 ? 0 : arguments.length - 1) > 0 && (typeof eventOrData === 'string' || isBuffer(eventOrData))) {
|
|
599
|
+
actualData = eventOrData;
|
|
600
|
+
}
|
|
601
|
+
if (isBuffer(actualData)) {
|
|
602
|
+
normalizedData = bufferToString(actualData);
|
|
603
|
+
} else if (typeof actualData === 'string') {
|
|
604
|
+
normalizedData = actualData;
|
|
605
|
+
} else if (actualData instanceof ArrayBuffer) {
|
|
606
|
+
normalizedData = arrayBufferToString(actualData);
|
|
607
|
+
} else {
|
|
608
|
+
normalizedData = String(actualData);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
if (normalizedData === undefined || normalizedData === null) {
|
|
612
|
+
normalizedData = '';
|
|
613
|
+
}
|
|
614
|
+
return {
|
|
615
|
+
event: event,
|
|
616
|
+
data: normalizedData,
|
|
617
|
+
ports: ports
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
var handleResponse = function handleResponse(protocol) {
|
|
623
|
+
return function (message) {
|
|
624
|
+
if (!message) return message;
|
|
625
|
+
var data = message.data;
|
|
626
|
+
var header = data[0];
|
|
627
|
+
var body = data[1];
|
|
628
|
+
var type = header[0];
|
|
629
|
+
if (Object.values(RequestType).includes(type)) {
|
|
630
|
+
return message;
|
|
631
|
+
}
|
|
632
|
+
var seqId = header[1];
|
|
633
|
+
var findDefer = protocol.ongoingRequests.get("" + seqId);
|
|
634
|
+
if (findDefer) {
|
|
635
|
+
protocol.ongoingRequests["delete"]("" + seqId);
|
|
636
|
+
if (type === ResponseType.PortSuccess) {
|
|
637
|
+
findDefer.resolve(message.ports[0]);
|
|
638
|
+
} else if (type === ResponseType.ReturnFail) {
|
|
639
|
+
findDefer.reject(body[0]);
|
|
640
|
+
} else findDefer.resolve(body[0]);
|
|
641
|
+
} else {
|
|
642
|
+
var findListener = protocol.requestEvents.get("" + seqId);
|
|
643
|
+
if (findListener) {
|
|
644
|
+
findListener.apply(void 0, body);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return null;
|
|
648
|
+
};
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
var prepareNormalData = function prepareNormalData(channel) {
|
|
652
|
+
var fn = function fn(props) {
|
|
653
|
+
var requestPath = '';
|
|
654
|
+
var methodName = '';
|
|
655
|
+
var params = [];
|
|
656
|
+
var seqId = channel.seqId;
|
|
657
|
+
var isOptionsRequest = false;
|
|
658
|
+
if (typeof props === 'string') {
|
|
659
|
+
requestPath = props;
|
|
660
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
661
|
+
args[_key3 - 1] = arguments[_key3];
|
|
662
|
+
}
|
|
663
|
+
methodName = args[0];
|
|
664
|
+
params = args.slice(1);
|
|
665
|
+
} else {
|
|
666
|
+
requestPath = props.requestPath;
|
|
667
|
+
methodName = props.methodName;
|
|
668
|
+
isOptionsRequest = props.isOptionsRequest;
|
|
669
|
+
params = [].concat(props.args);
|
|
670
|
+
}
|
|
671
|
+
var header = [RequestType.PromiseRequest, seqId, requestPath, methodName];
|
|
672
|
+
var body = params;
|
|
673
|
+
return {
|
|
674
|
+
seqId: seqId,
|
|
675
|
+
isOptionsRequest: isOptionsRequest,
|
|
676
|
+
data: [header, body]
|
|
677
|
+
};
|
|
678
|
+
};
|
|
679
|
+
fn.lifecycle = SendMiddlewareLifecycle.Prepare;
|
|
680
|
+
return fn;
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
function createDeferred() {
|
|
684
|
+
var resolve = null;
|
|
685
|
+
var reject = null;
|
|
686
|
+
var promise = new Promise(function (_resolve, _reject) {
|
|
687
|
+
resolve = _resolve;
|
|
688
|
+
reject = _reject;
|
|
689
|
+
});
|
|
690
|
+
return {
|
|
691
|
+
promise: promise,
|
|
692
|
+
resolve: resolve,
|
|
693
|
+
reject: reject
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function isUpperAsciiLetter(code) {
|
|
698
|
+
return code >= 65 && code <= 90;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
var isEventMethod = function isEventMethod(name) {
|
|
702
|
+
if (typeof name !== 'string') return false;
|
|
703
|
+
return name[0] === 'o' && name[1] === 'n' && isUpperAsciiLetter(name.charCodeAt(2));
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
var updateSeqInfo = function updateSeqInfo(channelProtocol) {
|
|
707
|
+
var fn = function fn(value) {
|
|
708
|
+
var data = value.data,
|
|
709
|
+
seqId = value.seqId;
|
|
710
|
+
var header = data[0];
|
|
711
|
+
var body = data[1];
|
|
712
|
+
var methodName = header[3];
|
|
713
|
+
if (methodName && isEventMethod(methodName)) {
|
|
714
|
+
channelProtocol.requestEvents.set("" + seqId, body[0]);
|
|
715
|
+
data[1] = [];
|
|
716
|
+
} else {
|
|
717
|
+
var returnValue = createDeferred();
|
|
718
|
+
channelProtocol.ongoingRequests.set("" + seqId, returnValue);
|
|
719
|
+
value.returnValue = returnValue;
|
|
720
|
+
}
|
|
721
|
+
return value;
|
|
722
|
+
};
|
|
723
|
+
fn.lifecycle = SendMiddlewareLifecycle.Transform;
|
|
724
|
+
return fn;
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
var sendRequest = function sendRequest(channelProtocol) {
|
|
728
|
+
var fn = function fn(value) {
|
|
729
|
+
var data = value.data,
|
|
730
|
+
transfer = value.transfer;
|
|
731
|
+
if (transfer) channelProtocol.send(data, transfer);else channelProtocol.send(data);
|
|
732
|
+
return value;
|
|
733
|
+
};
|
|
734
|
+
fn.lifecycle = SendMiddlewareLifecycle.Send;
|
|
735
|
+
return fn;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
var resumeMiddlewares = function resumeMiddlewares(middlewares, entry) {
|
|
739
|
+
var start = false;
|
|
740
|
+
return middlewares.reduce(function (a, b) {
|
|
741
|
+
var _a$middlewareContext;
|
|
742
|
+
if (!b.lifecycle) return a;
|
|
743
|
+
if (a.lifecycle >= b.lifecycle && b.displayName === a.methodName) {
|
|
744
|
+
start = true;
|
|
745
|
+
}
|
|
746
|
+
if (!start) return a;
|
|
747
|
+
var targetLifecycle = a == null ? void 0 : (_a$middlewareContext = a.middlewareContext) == null ? void 0 : _a$middlewareContext.minLifecycle;
|
|
748
|
+
var currentLifecycle = b == null ? void 0 : b.lifecycle;
|
|
749
|
+
if (targetLifecycle && currentLifecycle && currentLifecycle < targetLifecycle) {
|
|
750
|
+
return a;
|
|
751
|
+
}
|
|
752
|
+
return b(a);
|
|
753
|
+
}, entry);
|
|
754
|
+
};
|
|
755
|
+
var runMiddlewares = function runMiddlewares(middlewares, args, _context) {
|
|
756
|
+
var context = _extends({
|
|
757
|
+
isResumed: false,
|
|
758
|
+
startLifecycle: SendMiddlewareLifecycle.Initial,
|
|
759
|
+
minLifecycle: SendMiddlewareLifecycle.Initial
|
|
760
|
+
}, _context || {});
|
|
761
|
+
return middlewares.reduce(function (a, b, index) {
|
|
762
|
+
var _a$middlewareContext2;
|
|
763
|
+
if (!index) return b.apply(void 0, a);
|
|
764
|
+
if (index === 1) {
|
|
765
|
+
a.middlewareContext = context;
|
|
766
|
+
}
|
|
767
|
+
var targetLifecycle = a == null ? void 0 : (_a$middlewareContext2 = a.middlewareContext) == null ? void 0 : _a$middlewareContext2.minLifecycle;
|
|
768
|
+
var currentLifecycle = b == null ? void 0 : b.lifecycle;
|
|
769
|
+
if (targetLifecycle && currentLifecycle && currentLifecycle < targetLifecycle) {
|
|
770
|
+
return a;
|
|
771
|
+
}
|
|
772
|
+
return b(a);
|
|
773
|
+
}, args);
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
var ReadBaseBuffer = function ReadBaseBuffer() {};
|
|
777
|
+
|
|
778
|
+
var DataType;
|
|
779
|
+
(function (DataType) {
|
|
780
|
+
DataType[DataType["Undefined"] = 0] = "Undefined";
|
|
781
|
+
DataType[DataType["String"] = 1] = "String";
|
|
782
|
+
DataType[DataType["Buffer"] = 2] = "Buffer";
|
|
783
|
+
DataType[DataType["VSBuffer"] = 3] = "VSBuffer";
|
|
784
|
+
DataType[DataType["Array"] = 4] = "Array";
|
|
785
|
+
DataType[DataType["Object"] = 5] = "Object";
|
|
786
|
+
DataType[DataType["Int"] = 6] = "Int";
|
|
787
|
+
})(DataType || (DataType = {}));
|
|
788
|
+
var ReadBuffer = /*#__PURE__*/function (_ReadBaseBuffer) {
|
|
789
|
+
_inheritsLoose(ReadBuffer, _ReadBaseBuffer);
|
|
790
|
+
function ReadBuffer() {
|
|
791
|
+
return _ReadBaseBuffer.apply(this, arguments) || this;
|
|
792
|
+
}
|
|
793
|
+
var _proto = ReadBuffer.prototype;
|
|
794
|
+
_proto.decode = function decode(data) {
|
|
795
|
+
if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
|
|
796
|
+
var decoder = new TextDecoder();
|
|
797
|
+
var text = decoder.decode(data);
|
|
798
|
+
return JSON.parse(text);
|
|
799
|
+
}
|
|
800
|
+
return JSON.parse(data);
|
|
801
|
+
};
|
|
802
|
+
_proto.getFormat = function getFormat() {
|
|
803
|
+
return 'json';
|
|
804
|
+
};
|
|
805
|
+
return ReadBuffer;
|
|
806
|
+
}(ReadBaseBuffer);
|
|
807
|
+
|
|
808
|
+
var WriteBaseBuffer = function WriteBaseBuffer() {};
|
|
809
|
+
|
|
810
|
+
var WriteBuffer = /*#__PURE__*/function (_WriteBaseBuffer) {
|
|
811
|
+
_inheritsLoose(WriteBuffer, _WriteBaseBuffer);
|
|
812
|
+
function WriteBuffer() {
|
|
813
|
+
return _WriteBaseBuffer.apply(this, arguments) || this;
|
|
814
|
+
}
|
|
815
|
+
var _proto = WriteBuffer.prototype;
|
|
816
|
+
_proto.encode = function encode(data) {
|
|
817
|
+
return JSON.stringify(data);
|
|
818
|
+
};
|
|
819
|
+
_proto.getFormat = function getFormat() {
|
|
820
|
+
return 'json';
|
|
821
|
+
};
|
|
822
|
+
return WriteBuffer;
|
|
823
|
+
}(WriteBaseBuffer);
|
|
824
|
+
|
|
825
|
+
var _FORMAT_INFO;
|
|
826
|
+
var SerializationFormat;
|
|
827
|
+
(function (SerializationFormat) {
|
|
828
|
+
SerializationFormat["JSON"] = "json";
|
|
829
|
+
SerializationFormat["MESSAGEPACK"] = "msgpack";
|
|
830
|
+
SerializationFormat["CBOR"] = "cbor";
|
|
831
|
+
SerializationFormat["PROTOBUF"] = "protobuf";
|
|
832
|
+
SerializationFormat["CUSTOM"] = "custom";
|
|
833
|
+
})(SerializationFormat || (SerializationFormat = {}));
|
|
834
|
+
var FORMAT_INFO = (_FORMAT_INFO = {}, _FORMAT_INFO[SerializationFormat.JSON] = {
|
|
835
|
+
format: SerializationFormat.JSON,
|
|
836
|
+
name: 'JSON',
|
|
837
|
+
description: 'JavaScript Object Notation - Human-readable text format',
|
|
838
|
+
mimeType: 'application/json',
|
|
839
|
+
isBinary: false,
|
|
840
|
+
isText: true
|
|
841
|
+
}, _FORMAT_INFO[SerializationFormat.MESSAGEPACK] = {
|
|
842
|
+
format: SerializationFormat.MESSAGEPACK,
|
|
843
|
+
name: 'MessagePack',
|
|
844
|
+
description: 'Binary serialization format - High performance, compact size',
|
|
845
|
+
mimeType: 'application/x-msgpack',
|
|
846
|
+
isBinary: true,
|
|
847
|
+
isText: false
|
|
848
|
+
}, _FORMAT_INFO[SerializationFormat.CBOR] = {
|
|
849
|
+
format: SerializationFormat.CBOR,
|
|
850
|
+
name: 'CBOR',
|
|
851
|
+
description: 'Concise Binary Object Representation (RFC 7049)',
|
|
852
|
+
mimeType: 'application/cbor',
|
|
853
|
+
isBinary: true,
|
|
854
|
+
isText: false
|
|
855
|
+
}, _FORMAT_INFO[SerializationFormat.PROTOBUF] = {
|
|
856
|
+
format: SerializationFormat.PROTOBUF,
|
|
857
|
+
name: 'Protocol Buffers',
|
|
858
|
+
description: 'Google Protocol Buffers - Schema-based binary format',
|
|
859
|
+
mimeType: 'application/x-protobuf',
|
|
860
|
+
isBinary: true,
|
|
861
|
+
isText: false
|
|
862
|
+
}, _FORMAT_INFO[SerializationFormat.CUSTOM] = {
|
|
863
|
+
format: SerializationFormat.CUSTOM,
|
|
864
|
+
name: 'Custom',
|
|
865
|
+
description: 'User-defined custom serialization format',
|
|
866
|
+
mimeType: 'application/octet-stream',
|
|
867
|
+
isBinary: true,
|
|
868
|
+
isText: false
|
|
869
|
+
}, _FORMAT_INFO);
|
|
870
|
+
|
|
871
|
+
var BufferFactory = /*#__PURE__*/function () {
|
|
872
|
+
function BufferFactory() {}
|
|
873
|
+
BufferFactory.registerReadBuffer = function registerReadBuffer(format, factory) {
|
|
874
|
+
this.readBufferRegistry.set(format, factory);
|
|
875
|
+
};
|
|
876
|
+
BufferFactory.registerWriteBuffer = function registerWriteBuffer(format, factory) {
|
|
877
|
+
this.writeBufferRegistry.set(format, factory);
|
|
878
|
+
};
|
|
879
|
+
BufferFactory.createReadBuffer = function createReadBuffer(format) {
|
|
880
|
+
if (format === void 0) {
|
|
881
|
+
format = SerializationFormat.JSON;
|
|
882
|
+
}
|
|
883
|
+
var factory = this.readBufferRegistry.get(format);
|
|
884
|
+
if (factory) {
|
|
885
|
+
return factory();
|
|
886
|
+
}
|
|
887
|
+
switch (format) {
|
|
888
|
+
case SerializationFormat.JSON:
|
|
889
|
+
return new ReadBuffer();
|
|
890
|
+
case SerializationFormat.MESSAGEPACK:
|
|
891
|
+
try {
|
|
892
|
+
throw new Error('MessagePack not available. Install @msgpack/msgpack and register it.');
|
|
893
|
+
} catch (e) {
|
|
894
|
+
throw new Error("Unsupported read buffer format: " + format + ". Register a custom implementation.");
|
|
895
|
+
}
|
|
896
|
+
default:
|
|
897
|
+
throw new Error("Unsupported read buffer format: " + format);
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
BufferFactory.createWriteBuffer = function createWriteBuffer(format) {
|
|
901
|
+
if (format === void 0) {
|
|
902
|
+
format = SerializationFormat.JSON;
|
|
903
|
+
}
|
|
904
|
+
var factory = this.writeBufferRegistry.get(format);
|
|
905
|
+
if (factory) {
|
|
906
|
+
return factory();
|
|
907
|
+
}
|
|
908
|
+
switch (format) {
|
|
909
|
+
case SerializationFormat.JSON:
|
|
910
|
+
return new WriteBuffer();
|
|
911
|
+
case SerializationFormat.MESSAGEPACK:
|
|
912
|
+
try {
|
|
913
|
+
throw new Error('MessagePack not available. Install @msgpack/msgpack and register it.');
|
|
914
|
+
} catch (e) {
|
|
915
|
+
throw new Error("Unsupported write buffer format: " + format + ". Register a custom implementation.");
|
|
916
|
+
}
|
|
917
|
+
default:
|
|
918
|
+
throw new Error("Unsupported write buffer format: " + format);
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
BufferFactory.getRegisteredFormats = function getRegisteredFormats() {
|
|
922
|
+
var formats = new Set();
|
|
923
|
+
this.readBufferRegistry.forEach(function (_, format) {
|
|
924
|
+
return formats.add(format);
|
|
925
|
+
});
|
|
926
|
+
this.writeBufferRegistry.forEach(function (_, format) {
|
|
927
|
+
return formats.add(format);
|
|
928
|
+
});
|
|
929
|
+
return Array.from(formats);
|
|
930
|
+
};
|
|
931
|
+
return BufferFactory;
|
|
932
|
+
}();
|
|
933
|
+
BufferFactory.readBufferRegistry = /*#__PURE__*/new Map();
|
|
934
|
+
BufferFactory.writeBufferRegistry = /*#__PURE__*/new Map();
|
|
935
|
+
BufferFactory.registerReadBuffer(SerializationFormat.JSON, function () {
|
|
936
|
+
return new ReadBuffer();
|
|
937
|
+
});
|
|
938
|
+
BufferFactory.registerWriteBuffer(SerializationFormat.JSON, function () {
|
|
939
|
+
return new WriteBuffer();
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
var index = /*#__PURE__*/Function.call.bind(Object.prototype.toString);
|
|
943
|
+
|
|
944
|
+
var index$1 = function index$1(obj) {
|
|
945
|
+
if (index(obj) === '[object Promise]') return true;
|
|
946
|
+
if (index(obj) === '[object Object]') {
|
|
947
|
+
return typeof obj.then === 'function';
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
var ERROR = 'Error';
|
|
953
|
+
var isArray$1 = Array.isArray;
|
|
954
|
+
var isObject$1 = function isObject(val) {
|
|
955
|
+
return val !== null && typeof val === 'object' && !isArray$1(val);
|
|
956
|
+
};
|
|
957
|
+
var isFunction$1 = function isFunction(val) {
|
|
958
|
+
return typeof val === 'function';
|
|
959
|
+
};
|
|
960
|
+
var UNDEFINED = void 0;
|
|
961
|
+
|
|
962
|
+
var jsonrpc = '2.0';
|
|
963
|
+
var makeRequest = function makeRequest(id, method, params, remoteStack) {
|
|
964
|
+
var x = {
|
|
965
|
+
jsonrpc: jsonrpc,
|
|
966
|
+
id: id,
|
|
967
|
+
method: method,
|
|
968
|
+
params: params,
|
|
969
|
+
remoteStack: remoteStack
|
|
970
|
+
};
|
|
971
|
+
deleteUndefined(x, 'id');
|
|
972
|
+
deleteFalsy(x, 'remoteStack');
|
|
973
|
+
return x;
|
|
974
|
+
};
|
|
975
|
+
var makeSuccessResponse = function makeSuccessResponse(id, result) {
|
|
976
|
+
var x = {
|
|
977
|
+
jsonrpc: jsonrpc,
|
|
978
|
+
id: id,
|
|
979
|
+
result: result
|
|
980
|
+
};
|
|
981
|
+
deleteUndefined(x, 'id');
|
|
982
|
+
return x;
|
|
983
|
+
};
|
|
984
|
+
var makeErrorResponse = function makeErrorResponse(id, code, message, data) {
|
|
985
|
+
if (id === UNDEFINED) id = null;
|
|
986
|
+
code = Math.floor(code);
|
|
987
|
+
if (Number.isNaN(code)) code = -1;
|
|
988
|
+
var x = {
|
|
989
|
+
jsonrpc: jsonrpc,
|
|
990
|
+
id: id,
|
|
991
|
+
error: {
|
|
992
|
+
code: code,
|
|
993
|
+
message: message,
|
|
994
|
+
data: data
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
deleteUndefined(x.error, 'data');
|
|
998
|
+
return x;
|
|
999
|
+
};
|
|
1000
|
+
var ErrorResponseParseError = function ErrorResponseParseError(e, mapper) {
|
|
1001
|
+
var obj = ErrorResponseMapped({}, e, mapper);
|
|
1002
|
+
var o = obj.error;
|
|
1003
|
+
o.code = -32700;
|
|
1004
|
+
o.message = 'Parse error';
|
|
1005
|
+
return obj;
|
|
1006
|
+
};
|
|
1007
|
+
var ErrorResponseInvalidRequest = function ErrorResponseInvalidRequest(id) {
|
|
1008
|
+
return makeErrorResponse(id, -32600, 'Invalid Request');
|
|
1009
|
+
};
|
|
1010
|
+
var ErrorResponseMethodNotFound = function ErrorResponseMethodNotFound(id) {
|
|
1011
|
+
return makeErrorResponse(id, -32601, 'Method not found');
|
|
1012
|
+
};
|
|
1013
|
+
var ErrorResponseInvalidParams = function ErrorResponseInvalidParams(id) {
|
|
1014
|
+
return makeErrorResponse(id, -32602, 'Invalid params');
|
|
1015
|
+
};
|
|
1016
|
+
var ErrorResponseInternalError = function ErrorResponseInternalError(id) {
|
|
1017
|
+
return makeErrorResponse(id, -32603, 'Internal error');
|
|
1018
|
+
};
|
|
1019
|
+
var ErrorResponseMapped = function ErrorResponseMapped(request, e, mapper) {
|
|
1020
|
+
var id = request.id;
|
|
1021
|
+
var _mapper = mapper(e, request),
|
|
1022
|
+
code = _mapper.code,
|
|
1023
|
+
message = _mapper.message,
|
|
1024
|
+
data = _mapper.data;
|
|
1025
|
+
return makeErrorResponse(id, code, message, data);
|
|
1026
|
+
};
|
|
1027
|
+
var defaultErrorMapper = function defaultErrorMapper(stack, code) {
|
|
1028
|
+
if (stack === void 0) {
|
|
1029
|
+
stack = '';
|
|
1030
|
+
}
|
|
1031
|
+
if (code === void 0) {
|
|
1032
|
+
code = -1;
|
|
1033
|
+
}
|
|
1034
|
+
return function (e) {
|
|
1035
|
+
var message = toString('', function () {
|
|
1036
|
+
return e.message;
|
|
1037
|
+
});
|
|
1038
|
+
var type = toString(ERROR, function (ctor) {
|
|
1039
|
+
if (ctor === void 0) {
|
|
1040
|
+
ctor = e.constructor;
|
|
1041
|
+
}
|
|
1042
|
+
return isFunction$1(ctor) && ctor.name;
|
|
1043
|
+
});
|
|
1044
|
+
var E = globalThis.DOMException;
|
|
1045
|
+
if (E && e instanceof E) {
|
|
1046
|
+
type = "DOMException:" + e.name;
|
|
1047
|
+
}
|
|
1048
|
+
var eType = typeof e;
|
|
1049
|
+
if (eType === 'string' || eType === 'number' || eType === 'boolean' || eType === 'bigint') {
|
|
1050
|
+
type = ERROR;
|
|
1051
|
+
message = String(e);
|
|
1052
|
+
}
|
|
1053
|
+
var data = stack ? {
|
|
1054
|
+
stack: stack,
|
|
1055
|
+
type: type
|
|
1056
|
+
} : {
|
|
1057
|
+
type: type
|
|
1058
|
+
};
|
|
1059
|
+
return {
|
|
1060
|
+
code: code,
|
|
1061
|
+
message: message,
|
|
1062
|
+
data: data
|
|
1063
|
+
};
|
|
1064
|
+
};
|
|
1065
|
+
};
|
|
1066
|
+
var isJSONRPCObject = function isJSONRPCObject(data) {
|
|
1067
|
+
if (!isObject$1(data)) return false;
|
|
1068
|
+
if (!('jsonrpc' in data)) return false;
|
|
1069
|
+
var obj = data;
|
|
1070
|
+
if (obj.jsonrpc !== jsonrpc) return false;
|
|
1071
|
+
if ('params' in obj) {
|
|
1072
|
+
var params = obj.params;
|
|
1073
|
+
if (!isArray$1(params) && !isObject$1(params)) return false;
|
|
1074
|
+
}
|
|
1075
|
+
return true;
|
|
1076
|
+
};
|
|
1077
|
+
var toString = function toString(_default, val) {
|
|
1078
|
+
try {
|
|
1079
|
+
var v = val();
|
|
1080
|
+
if (v === UNDEFINED) return _default;
|
|
1081
|
+
return String(v);
|
|
1082
|
+
} catch (_unused) {
|
|
1083
|
+
return _default;
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
var deleteUndefined = function deleteUndefined(x, key) {
|
|
1087
|
+
if (x[key] === UNDEFINED) delete x[key];
|
|
1088
|
+
};
|
|
1089
|
+
var deleteFalsy = function deleteFalsy(x, key) {
|
|
1090
|
+
if (!x[key]) delete x[key];
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
var JSONRPCErrorCode;
|
|
1094
|
+
(function (JSONRPCErrorCode) {
|
|
1095
|
+
JSONRPCErrorCode[JSONRPCErrorCode["ParseError"] = -32700] = "ParseError";
|
|
1096
|
+
JSONRPCErrorCode[JSONRPCErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
1097
|
+
JSONRPCErrorCode[JSONRPCErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
1098
|
+
JSONRPCErrorCode[JSONRPCErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
1099
|
+
JSONRPCErrorCode[JSONRPCErrorCode["InternalError"] = -32603] = "InternalError";
|
|
1100
|
+
JSONRPCErrorCode[JSONRPCErrorCode["ServerErrorStart"] = -32000] = "ServerErrorStart";
|
|
1101
|
+
JSONRPCErrorCode[JSONRPCErrorCode["ServerErrorEnd"] = -32099] = "ServerErrorEnd";
|
|
1102
|
+
})(JSONRPCErrorCode || (JSONRPCErrorCode = {}));
|
|
1103
|
+
|
|
1104
|
+
var createErrorResponseBody = function createErrorResponseBody(error, request) {
|
|
1105
|
+
var mapper = defaultErrorMapper(error instanceof Error ? error.stack : '', JSONRPCErrorCode.InternalError);
|
|
1106
|
+
if (request) {
|
|
1107
|
+
var errorResponse = ErrorResponseMapped(request, error, mapper);
|
|
1108
|
+
return errorResponse.error;
|
|
1109
|
+
}
|
|
1110
|
+
var _mapper = mapper(error, {}),
|
|
1111
|
+
code = _mapper.code,
|
|
1112
|
+
message = _mapper.message,
|
|
1113
|
+
data = _mapper.data;
|
|
1114
|
+
return {
|
|
1115
|
+
code: code,
|
|
1116
|
+
message: message,
|
|
1117
|
+
data: data
|
|
1118
|
+
};
|
|
1119
|
+
};
|
|
1120
|
+
var handleRequest = function handleRequest(protocol) {
|
|
1121
|
+
return function (message) {
|
|
1122
|
+
var service = protocol.service;
|
|
1123
|
+
var data = message.data;
|
|
1124
|
+
var header = data[0];
|
|
1125
|
+
var body = data[1];
|
|
1126
|
+
var type = header[0];
|
|
1127
|
+
if (Object.values(ResponseType).includes(type)) {
|
|
1128
|
+
return message;
|
|
1129
|
+
}
|
|
1130
|
+
var seqId = header[1];
|
|
1131
|
+
var requestPath = header[2];
|
|
1132
|
+
var methodName = header[3];
|
|
1133
|
+
var args = body[0];
|
|
1134
|
+
var jsonrpcRequest = makeRequest(seqId, methodName, args);
|
|
1135
|
+
var handler = service.getHandler(methodName);
|
|
1136
|
+
if (!handler) {
|
|
1137
|
+
var errorResponse = ErrorResponseMethodNotFound(seqId);
|
|
1138
|
+
var responseHeader = [ResponseType.ReturnFail, seqId];
|
|
1139
|
+
var responseBody = [errorResponse.error];
|
|
1140
|
+
protocol.sendReply(protocol.writeBuffer.encode([responseHeader, responseBody]));
|
|
1141
|
+
return message;
|
|
1142
|
+
}
|
|
1143
|
+
var _result = handler(args);
|
|
1144
|
+
var result = Promise.resolve(_result);
|
|
1145
|
+
if (index$1(result)) {
|
|
1146
|
+
result.then(function (response) {
|
|
1147
|
+
var responseHeader = [ResponseType.ReturnSuccess, seqId];
|
|
1148
|
+
var responseBody = [];
|
|
1149
|
+
var sendData = null;
|
|
1150
|
+
try {
|
|
1151
|
+
responseBody = [response];
|
|
1152
|
+
sendData = protocol.writeBuffer.encode([responseHeader, responseBody]);
|
|
1153
|
+
} catch (err) {
|
|
1154
|
+
var errorBody = createErrorResponseBody(err, jsonrpcRequest);
|
|
1155
|
+
responseBody = [errorBody];
|
|
1156
|
+
sendData = protocol.writeBuffer.encode([responseHeader, responseBody]);
|
|
1157
|
+
console.error("[handleRequest sendReply encode error ] " + requestPath + " " + methodName, err);
|
|
1158
|
+
}
|
|
1159
|
+
protocol.sendReply(sendData);
|
|
1160
|
+
}, function (err) {
|
|
1161
|
+
var errorBody = createErrorResponseBody(err, jsonrpcRequest);
|
|
1162
|
+
var responseHeader = [ResponseType.ReturnFail, seqId];
|
|
1163
|
+
var responseBody = [errorBody];
|
|
1164
|
+
protocol.sendReply(protocol.writeBuffer.encode([responseHeader, responseBody]));
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
return message;
|
|
1168
|
+
};
|
|
1169
|
+
};
|
|
1170
|
+
|
|
1171
|
+
var AbstractChannelProtocol = /*#__PURE__*/function (_Disposable) {
|
|
1172
|
+
_inheritsLoose(AbstractChannelProtocol, _Disposable);
|
|
1173
|
+
function AbstractChannelProtocol(props) {
|
|
1174
|
+
var _this;
|
|
1175
|
+
_this = _Disposable.call(this) || this;
|
|
1176
|
+
_this._seqId = -1;
|
|
1177
|
+
_this._onMessageMiddleware = [normalizeMessageChannelRawMessage, deserialize, handleRequest, handleResponse];
|
|
1178
|
+
_this._senderMiddleware = [prepareNormalData, updateSeqInfo, serialize, sendRequest];
|
|
1179
|
+
_this._readBuffer = null;
|
|
1180
|
+
_this._writeBuffer = null;
|
|
1181
|
+
_this._isConnected = true;
|
|
1182
|
+
_this.ongoingRequests = new Map();
|
|
1183
|
+
_this.pendingSendEntries = new Set();
|
|
1184
|
+
_this.requestEvents = new Map();
|
|
1185
|
+
_this.onDidConnectedEvent = new Event({
|
|
1186
|
+
name: 'on-did-connected'
|
|
1187
|
+
});
|
|
1188
|
+
_this.onDidConnected = _this.onDidConnectedEvent.subscribe;
|
|
1189
|
+
_this.onDidDisconnectedEvent = new Event({
|
|
1190
|
+
name: 'on-did-disconnect'
|
|
1191
|
+
});
|
|
1192
|
+
_this.onDidDisconnected = _this.onDidDisconnectedEvent.subscribe;
|
|
1193
|
+
var _ref = props || {},
|
|
1194
|
+
description = _ref.description,
|
|
1195
|
+
masterProcessName = _ref.masterProcessName,
|
|
1196
|
+
_ref$connected = _ref.connected,
|
|
1197
|
+
connected = _ref$connected === void 0 ? true : _ref$connected,
|
|
1198
|
+
_ref$serializationFor = _ref.serializationFormat,
|
|
1199
|
+
serializationFormat = _ref$serializationFor === void 0 ? SerializationFormat.JSON : _ref$serializationFor,
|
|
1200
|
+
readBuffer = _ref.readBuffer,
|
|
1201
|
+
writeBuffer = _ref.writeBuffer;
|
|
1202
|
+
_this._description = description;
|
|
1203
|
+
_this._isConnected = connected;
|
|
1204
|
+
_this._masterProcessName = masterProcessName;
|
|
1205
|
+
_this._serializationFormat = serializationFormat;
|
|
1206
|
+
if (readBuffer) {
|
|
1207
|
+
_this._readBuffer = readBuffer;
|
|
1208
|
+
}
|
|
1209
|
+
if (writeBuffer) {
|
|
1210
|
+
_this._writeBuffer = writeBuffer;
|
|
1211
|
+
}
|
|
1212
|
+
_this._key = generateRandomKey();
|
|
1213
|
+
_this.registerDisposable(_this.onDidConnected(_this.didConnected.bind(_assertThisInitialized(_this))));
|
|
1214
|
+
_this._onMessageMiddleware = _this.decorateOnMessageMiddleware(_this._onMessageMiddleware);
|
|
1215
|
+
_this._senderMiddleware = _this.decorateSendMiddleware(_this._senderMiddleware);
|
|
1216
|
+
_this.applyOnMessageMiddleware(_this._onMessageMiddleware);
|
|
1217
|
+
_this.applySendMiddleware(_this._senderMiddleware);
|
|
1218
|
+
return _this;
|
|
1219
|
+
}
|
|
1220
|
+
var _proto = AbstractChannelProtocol.prototype;
|
|
1221
|
+
_proto.setService = function setService(service) {
|
|
1222
|
+
this._service = service;
|
|
1223
|
+
};
|
|
1224
|
+
_proto.setSerializationFormat = function setSerializationFormat(format) {
|
|
1225
|
+
if (this._serializationFormat !== format) {
|
|
1226
|
+
this._serializationFormat = format;
|
|
1227
|
+
this._readBuffer = null;
|
|
1228
|
+
this._writeBuffer = null;
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
_proto.addPendingSendEntry = function addPendingSendEntry(entry) {
|
|
1232
|
+
this.pendingSendEntries.add(entry);
|
|
1233
|
+
};
|
|
1234
|
+
_proto.decorateSendMiddleware = function decorateSendMiddleware(middlewares) {
|
|
1235
|
+
return middlewares;
|
|
1236
|
+
};
|
|
1237
|
+
_proto.decorateOnMessageMiddleware = function decorateOnMessageMiddleware(middlewares) {
|
|
1238
|
+
return middlewares;
|
|
1239
|
+
};
|
|
1240
|
+
_proto.applyOnMessageMiddleware = function applyOnMessageMiddleware(fns) {
|
|
1241
|
+
var _this2 = this;
|
|
1242
|
+
var copy = [].concat(fns);
|
|
1243
|
+
this._onMessageMiddleware = [];
|
|
1244
|
+
copy.forEach(function (fn) {
|
|
1245
|
+
if (typeof fn === 'function') {
|
|
1246
|
+
_this2._onMessageMiddleware.push(fn(_this2));
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
1249
|
+
};
|
|
1250
|
+
_proto.applySendMiddleware = function applySendMiddleware(fns) {
|
|
1251
|
+
var _this3 = this;
|
|
1252
|
+
var copy = [].concat(fns);
|
|
1253
|
+
this._senderMiddleware = [];
|
|
1254
|
+
copy.forEach(function (fn) {
|
|
1255
|
+
if (typeof fn === 'function') {
|
|
1256
|
+
_this3._senderMiddleware.push(fn(_this3));
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
};
|
|
1260
|
+
_proto.isConnected = function isConnected() {
|
|
1261
|
+
return this._isConnected;
|
|
1262
|
+
};
|
|
1263
|
+
_proto.send = function send() {
|
|
1264
|
+
throw new Error('send method is not implemented');
|
|
1265
|
+
};
|
|
1266
|
+
_proto.on = function on() {
|
|
1267
|
+
throw new Error('onMessage method is not implemented');
|
|
1268
|
+
};
|
|
1269
|
+
_proto.resumePendingEntry = function resumePendingEntry() {
|
|
1270
|
+
var _this4 = this;
|
|
1271
|
+
this.pendingSendEntries.forEach(function (entry) {
|
|
1272
|
+
_this4.pendingSendEntries["delete"](entry);
|
|
1273
|
+
resumeMiddlewares(_this4.senderMiddleware, entry);
|
|
1274
|
+
});
|
|
1275
|
+
};
|
|
1276
|
+
_proto.didConnected = function didConnected() {
|
|
1277
|
+
this.resumePendingEntry();
|
|
1278
|
+
};
|
|
1279
|
+
_proto.connect = function connect() {
|
|
1280
|
+
this.onDidConnectedEvent.fire();
|
|
1281
|
+
};
|
|
1282
|
+
_proto.activate = function activate() {
|
|
1283
|
+
this._isConnected = true;
|
|
1284
|
+
this.onDidConnectedEvent.fire();
|
|
1285
|
+
};
|
|
1286
|
+
_proto.disconnect = function disconnect() {
|
|
1287
|
+
this._isConnected = false;
|
|
1288
|
+
this.onDidDisconnectedEvent.fire();
|
|
1289
|
+
};
|
|
1290
|
+
_proto.makeRequest = function makeRequest() {
|
|
1291
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1292
|
+
args[_key] = arguments[_key];
|
|
1293
|
+
}
|
|
1294
|
+
var _runMiddlewares = runMiddlewares(this.senderMiddleware, args),
|
|
1295
|
+
returnValue = _runMiddlewares.returnValue;
|
|
1296
|
+
if (returnValue) return returnValue;
|
|
1297
|
+
};
|
|
1298
|
+
_proto.sendReply = function sendReply() {
|
|
1299
|
+
this.send.apply(this, arguments);
|
|
1300
|
+
};
|
|
1301
|
+
_proto.onMessage = function onMessage() {
|
|
1302
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1303
|
+
args[_key2] = arguments[_key2];
|
|
1304
|
+
}
|
|
1305
|
+
runMiddlewares(this._onMessageMiddleware, args);
|
|
1306
|
+
};
|
|
1307
|
+
_createClass(AbstractChannelProtocol, [{
|
|
1308
|
+
key: "service",
|
|
1309
|
+
get: function get() {
|
|
1310
|
+
return this._service;
|
|
1311
|
+
}
|
|
1312
|
+
}, {
|
|
1313
|
+
key: "senderMiddleware",
|
|
1314
|
+
get: function get() {
|
|
1315
|
+
return this._senderMiddleware;
|
|
1316
|
+
}
|
|
1317
|
+
}, {
|
|
1318
|
+
key: "readBuffer",
|
|
1319
|
+
get: function get() {
|
|
1320
|
+
if (this._readBuffer) {
|
|
1321
|
+
return this._readBuffer;
|
|
1322
|
+
}
|
|
1323
|
+
try {
|
|
1324
|
+
this._readBuffer = BufferFactory.createReadBuffer(this._serializationFormat);
|
|
1325
|
+
} catch (error) {
|
|
1326
|
+
console.warn("[AbstractChannelProtocol] Failed to create read buffer with format \"" + this._serializationFormat + "\", falling back to JSON.", error);
|
|
1327
|
+
this._readBuffer = BufferFactory.createReadBuffer(SerializationFormat.JSON);
|
|
1328
|
+
}
|
|
1329
|
+
return this._readBuffer;
|
|
1330
|
+
}
|
|
1331
|
+
}, {
|
|
1332
|
+
key: "writeBuffer",
|
|
1333
|
+
get: function get() {
|
|
1334
|
+
if (this._writeBuffer) {
|
|
1335
|
+
return this._writeBuffer;
|
|
1336
|
+
}
|
|
1337
|
+
try {
|
|
1338
|
+
this._writeBuffer = BufferFactory.createWriteBuffer(this._serializationFormat);
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
console.warn("[AbstractChannelProtocol] Failed to create write buffer with format \"" + this._serializationFormat + "\", falling back to JSON.", error);
|
|
1341
|
+
this._writeBuffer = BufferFactory.createWriteBuffer(SerializationFormat.JSON);
|
|
1342
|
+
}
|
|
1343
|
+
return this._writeBuffer;
|
|
1344
|
+
}
|
|
1345
|
+
}, {
|
|
1346
|
+
key: "serializationFormat",
|
|
1347
|
+
get: function get() {
|
|
1348
|
+
return this._serializationFormat;
|
|
1349
|
+
}
|
|
1350
|
+
}, {
|
|
1351
|
+
key: "seqId",
|
|
1352
|
+
get: function get() {
|
|
1353
|
+
this._seqId += 1;
|
|
1354
|
+
return this._key + "_" + this._seqId;
|
|
1355
|
+
}
|
|
1356
|
+
}, {
|
|
1357
|
+
key: "description",
|
|
1358
|
+
get: function get() {
|
|
1359
|
+
return this._description;
|
|
1360
|
+
}
|
|
1361
|
+
}, {
|
|
1362
|
+
key: "masterProcessName",
|
|
1363
|
+
get: function get() {
|
|
1364
|
+
return this._masterProcessName;
|
|
1365
|
+
}
|
|
1366
|
+
}]);
|
|
1367
|
+
return AbstractChannelProtocol;
|
|
1368
|
+
}(Disposable);
|
|
1369
|
+
|
|
1370
|
+
var _excluded = ["port", "sender", "targetOrigin"];
|
|
1371
|
+
var RPCMessageChannel = /*#__PURE__*/function (_AbstractChannelProto) {
|
|
1372
|
+
_inheritsLoose(RPCMessageChannel, _AbstractChannelProto);
|
|
1373
|
+
function RPCMessageChannel(options) {
|
|
1374
|
+
var _this;
|
|
1375
|
+
var port = options.port,
|
|
1376
|
+
_options$sender = options.sender,
|
|
1377
|
+
sender = _options$sender === void 0 ? window : _options$sender,
|
|
1378
|
+
_options$targetOrigin = options.targetOrigin,
|
|
1379
|
+
targetOrigin = _options$targetOrigin === void 0 ? '*' : _options$targetOrigin,
|
|
1380
|
+
protocolOptions = _objectWithoutPropertiesLoose(options, _excluded);
|
|
1381
|
+
_this = _AbstractChannelProto.call(this, protocolOptions) || this;
|
|
1382
|
+
_this.port = port;
|
|
1383
|
+
_this.targetOrigin = targetOrigin;
|
|
1384
|
+
_this.sender = sender;
|
|
1385
|
+
if (_this.port.start) {
|
|
1386
|
+
_this.port.start();
|
|
1387
|
+
}
|
|
1388
|
+
return _this;
|
|
1389
|
+
}
|
|
1390
|
+
var _proto = RPCMessageChannel.prototype;
|
|
1391
|
+
_proto.on = function on(listener) {
|
|
1392
|
+
var _this2 = this;
|
|
1393
|
+
var f = function f(ev) {
|
|
1394
|
+
listener(ev);
|
|
1395
|
+
};
|
|
1396
|
+
this.port.addEventListener('message', f);
|
|
1397
|
+
return function () {
|
|
1398
|
+
return _this2.port.removeEventListener('message', f);
|
|
1399
|
+
};
|
|
1400
|
+
};
|
|
1401
|
+
_proto.send = function send(message, transfer) {
|
|
1402
|
+
if (transfer && transfer.length > 0) {
|
|
1403
|
+
this.port.postMessage(message, transfer);
|
|
1404
|
+
} else {
|
|
1405
|
+
this.port.postMessage(message);
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
_proto.decorateSendMiddleware = function decorateSendMiddleware(middlewares) {
|
|
1409
|
+
return middlewares;
|
|
1410
|
+
};
|
|
1411
|
+
_proto.decorateOnMessageMiddleware = function decorateOnMessageMiddleware(middlewares) {
|
|
1412
|
+
return middlewares;
|
|
1413
|
+
};
|
|
1414
|
+
_proto.disconnect = function disconnect() {
|
|
1415
|
+
if (this.port) {
|
|
1416
|
+
this.port.close();
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
return RPCMessageChannel;
|
|
1420
|
+
}(AbstractChannelProtocol);
|
|
1421
|
+
|
|
1422
|
+
var _excluded$1 = ["name"];
|
|
1423
|
+
var WorkerChannel = /*#__PURE__*/function (_AbstractChannelProto) {
|
|
1424
|
+
_inheritsLoose(WorkerChannel, _AbstractChannelProto);
|
|
1425
|
+
function WorkerChannel(worker, options) {
|
|
1426
|
+
var _this;
|
|
1427
|
+
var _ref = options || {},
|
|
1428
|
+
name = _ref.name,
|
|
1429
|
+
protocolOptions = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
1430
|
+
_this = _AbstractChannelProto.call(this, protocolOptions) || this;
|
|
1431
|
+
_this.worker = worker;
|
|
1432
|
+
_this.name = name || 'worker';
|
|
1433
|
+
return _this;
|
|
1434
|
+
}
|
|
1435
|
+
var _proto = WorkerChannel.prototype;
|
|
1436
|
+
_proto.on = function on(listener) {
|
|
1437
|
+
var _this2 = this;
|
|
1438
|
+
var f = function f(ev) {
|
|
1439
|
+
listener(ev);
|
|
1440
|
+
};
|
|
1441
|
+
this.worker.addEventListener('message', f);
|
|
1442
|
+
return function () {
|
|
1443
|
+
return _this2.worker.removeEventListener('message', f);
|
|
1444
|
+
};
|
|
1445
|
+
};
|
|
1446
|
+
_proto.send = function send(data) {
|
|
1447
|
+
this.worker.postMessage(data);
|
|
1448
|
+
};
|
|
1449
|
+
return WorkerChannel;
|
|
1450
|
+
}(AbstractChannelProtocol);
|
|
1451
|
+
|
|
1452
|
+
var _excluded$2 = ["name", "maxReconnectAttempts", "reconnectDelay", "connected"];
|
|
1453
|
+
var WebSocketChannel = /*#__PURE__*/function (_AbstractChannelProto) {
|
|
1454
|
+
_inheritsLoose(WebSocketChannel, _AbstractChannelProto);
|
|
1455
|
+
function WebSocketChannel(socket, options) {
|
|
1456
|
+
var _this;
|
|
1457
|
+
var opts = options || {};
|
|
1458
|
+
var name = opts.name,
|
|
1459
|
+
maxReconnectAttempts = opts.maxReconnectAttempts,
|
|
1460
|
+
reconnectDelay = opts.reconnectDelay,
|
|
1461
|
+
connected = opts.connected,
|
|
1462
|
+
protocolOptions = _objectWithoutPropertiesLoose(opts, _excluded$2);
|
|
1463
|
+
_this = _AbstractChannelProto.call(this, _extends({
|
|
1464
|
+
connected: connected != null ? connected : false
|
|
1465
|
+
}, protocolOptions)) || this;
|
|
1466
|
+
_this.socket = socket;
|
|
1467
|
+
_this.name = name || 'websocket';
|
|
1468
|
+
_this.reconnectAttempts = 0;
|
|
1469
|
+
_this.maxReconnectAttempts = maxReconnectAttempts != null ? maxReconnectAttempts : 5;
|
|
1470
|
+
_this.reconnectDelay = reconnectDelay != null ? reconnectDelay : 1000;
|
|
1471
|
+
_this.setupSocketHandlers();
|
|
1472
|
+
return _this;
|
|
1473
|
+
}
|
|
1474
|
+
var _proto = WebSocketChannel.prototype;
|
|
1475
|
+
_proto.setupSocketHandlers = function setupSocketHandlers() {
|
|
1476
|
+
var _this2 = this;
|
|
1477
|
+
this.socket.addEventListener('open', function () {
|
|
1478
|
+
_this2.activate();
|
|
1479
|
+
});
|
|
1480
|
+
this.socket.addEventListener('close', function () {
|
|
1481
|
+
_AbstractChannelProto.prototype.disconnect.call(_this2);
|
|
1482
|
+
});
|
|
1483
|
+
this.socket.addEventListener('error', function (error) {
|
|
1484
|
+
console.error("[WebSocketChannel " + _this2.name + "] Error:", error);
|
|
1485
|
+
});
|
|
1486
|
+
};
|
|
1487
|
+
_proto.on = function on(listener) {
|
|
1488
|
+
var _this3 = this;
|
|
1489
|
+
var f = function f(ev) {
|
|
1490
|
+
if (ev === undefined || ev === null) {
|
|
1491
|
+
console.warn("[WebSocketChannel " + _this3.name + "] Received undefined/null message event");
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
listener(ev);
|
|
1495
|
+
};
|
|
1496
|
+
if (typeof this.socket.addEventListener === 'function') {
|
|
1497
|
+
this.socket.addEventListener('message', f);
|
|
1498
|
+
return function () {
|
|
1499
|
+
if (typeof _this3.socket.removeEventListener === 'function') {
|
|
1500
|
+
_this3.socket.removeEventListener('message', f);
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
} else {
|
|
1504
|
+
var wsSocket = this.socket;
|
|
1505
|
+
if (typeof wsSocket.on === 'function') {
|
|
1506
|
+
wsSocket.on('message', f);
|
|
1507
|
+
return function () {
|
|
1508
|
+
if (typeof wsSocket.off === 'function') {
|
|
1509
|
+
wsSocket.off('message', f);
|
|
1510
|
+
} else if (typeof wsSocket.removeListener === 'function') {
|
|
1511
|
+
wsSocket.removeListener('message', f);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return function () {};
|
|
1517
|
+
};
|
|
1518
|
+
_proto.send = function send(data) {
|
|
1519
|
+
if (this.socket.readyState === WebSocket.OPEN) {
|
|
1520
|
+
if (typeof data === 'string') {
|
|
1521
|
+
this.socket.send(data);
|
|
1522
|
+
} else if (data instanceof ArrayBuffer || data instanceof Blob) {
|
|
1523
|
+
this.socket.send(data);
|
|
1524
|
+
} else {
|
|
1525
|
+
this.socket.send(JSON.stringify(data));
|
|
1526
|
+
}
|
|
1527
|
+
} else {
|
|
1528
|
+
console.warn("[WebSocketChannel " + this.name + "] Cannot send: WebSocket is not open. State: " + this.socket.readyState);
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
_proto.decorateSendMiddleware = function decorateSendMiddleware(middlewares) {
|
|
1532
|
+
return middlewares;
|
|
1533
|
+
};
|
|
1534
|
+
_proto.decorateOnMessageMiddleware = function decorateOnMessageMiddleware(middlewares) {
|
|
1535
|
+
if (middlewares.length > 0) {
|
|
1536
|
+
return [normalizeWebSocketRawMessage].concat(middlewares.slice(1));
|
|
1537
|
+
}
|
|
1538
|
+
return middlewares;
|
|
1539
|
+
};
|
|
1540
|
+
_proto.disconnect = function disconnect() {
|
|
1541
|
+
if (this.socket) {
|
|
1542
|
+
this.socket.close();
|
|
1543
|
+
}
|
|
1544
|
+
_AbstractChannelProto.prototype.disconnect.call(this);
|
|
1545
|
+
};
|
|
1546
|
+
_proto.isOpen = function isOpen() {
|
|
1547
|
+
return this.socket.readyState === WebSocket.OPEN;
|
|
1548
|
+
};
|
|
1549
|
+
_createClass(WebSocketChannel, [{
|
|
1550
|
+
key: "readyState",
|
|
1551
|
+
get: function get() {
|
|
1552
|
+
return this.socket.readyState;
|
|
1553
|
+
}
|
|
1554
|
+
}]);
|
|
1555
|
+
return WebSocketChannel;
|
|
1556
|
+
}(AbstractChannelProtocol);
|
|
1557
|
+
|
|
1558
|
+
export { ERROR, ErrorResponseInternalError, ErrorResponseInvalidParams, ErrorResponseInvalidRequest, ErrorResponseMapped, ErrorResponseMethodNotFound, ErrorResponseParseError, JSONRPCErrorCode, RPCMessageChannel as MessageChannel, ProxyRPCClient, RPCService, UNDEFINED, WebSocketChannel, WorkerChannel, RPCClientHost$1 as clientHost, defaultErrorMapper, isArray$1 as isArray, isFunction$1 as isFunction, isJSONRPCObject, isObject$1 as isObject, jsonrpc, makeErrorResponse, makeRequest, makeSuccessResponse, RPCServiceHost$1 as serviceHost };
|
|
1559
|
+
//# sourceMappingURL=async-call-rpc.esm.js.map
|