@adminide-stack/extension-api 1.1.1-alpha.23 → 1.1.1-alpha.253
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/connections/jsonrpc2/connection.test.d.ts +1 -0
- package/lib/connections/jsonrpc2/connection.test.js +452 -0
- package/lib/connections/jsonrpc2/connection.test.js.map +1 -0
- package/lib/connections/jsonrpc2/linkedMap.test.d.ts +1 -0
- package/lib/connections/jsonrpc2/linkedMap.test.js +62 -0
- package/lib/connections/jsonrpc2/linkedMap.test.js.map +1 -0
- package/lib/connections/proxy/proxy.js +0 -1
- package/lib/connections/proxy/proxy.js.map +1 -1
- package/lib/connections/proxy/proxy.test.d.ts +1 -0
- package/lib/connections/proxy/proxy.test.js +64 -0
- package/lib/connections/proxy/proxy.test.js.map +1 -0
- package/lib/connections/remote-rpc/browser-server-rpc.test.d.ts +1 -0
- package/lib/connections/remote-rpc/browser-server-rpc.test.js +323 -0
- package/lib/connections/remote-rpc/browser-server-rpc.test.js.map +1 -0
- package/lib/core/expr/evaluator.test.d.ts +1 -0
- package/lib/core/expr/evaluator.test.js +52 -0
- package/lib/core/expr/evaluator.test.js.map +1 -0
- package/lib/interfaces/generated-models.d.ts +7 -7
- package/lib/protocol/rpc-protocol.test.d.ts +1 -0
- package/lib/protocol/rpc-protocol.test.js +171 -0
- package/lib/protocol/rpc-protocol.test.js.map +1 -0
- package/lib/utils/rxjs/combineLatestOrDefault.test.d.ts +1 -0
- package/lib/utils/rxjs/combineLatestOrDefault.test.js +52 -0
- package/lib/utils/rxjs/combineLatestOrDefault.test.js.map +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const assert = require("assert");
|
|
13
|
+
const rxjs_1 = require("rxjs");
|
|
14
|
+
const operators_1 = require("rxjs/operators");
|
|
15
|
+
const connection_1 = require("../jsonrpc2/connection");
|
|
16
|
+
const test_helper_1 = require("../jsonrpc2/test-helper");
|
|
17
|
+
const proxy_1 = require("./proxy");
|
|
18
|
+
// import 'jest';
|
|
19
|
+
function createTestProxy(handler) {
|
|
20
|
+
Object.setPrototypeOf(handler, null);
|
|
21
|
+
const [clientTransports, serverTransports] = test_helper_1.createMessageTransports();
|
|
22
|
+
const client = connection_1.createConnection(clientTransports);
|
|
23
|
+
const server = connection_1.createConnection(serverTransports);
|
|
24
|
+
const proxy = proxy_1.createProxy(client, 'prefix');
|
|
25
|
+
proxy_1.handleRequests(server, 'prefix', handler);
|
|
26
|
+
client.listen();
|
|
27
|
+
server.listen();
|
|
28
|
+
return proxy;
|
|
29
|
+
}
|
|
30
|
+
describe('Proxy', () => {
|
|
31
|
+
describe('proxies calls', () => {
|
|
32
|
+
const proxy = createTestProxy({
|
|
33
|
+
$a: (n) => n + 1,
|
|
34
|
+
$b: (n) => Promise.resolve(n + 2),
|
|
35
|
+
$c: (m, n) => m + n,
|
|
36
|
+
$d: (...args) => args.reduce((sum, n) => sum + n, 0),
|
|
37
|
+
$e: () => Promise.reject('e'),
|
|
38
|
+
$f: () => {
|
|
39
|
+
throw new Error('f');
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
it('to functions', () => __awaiter(void 0, void 0, void 0, function* () { return assert.strictEqual(yield proxy.$a(1), 2); }));
|
|
43
|
+
it('to async functions', () => __awaiter(void 0, void 0, void 0, function* () { return assert.strictEqual(yield proxy.$b(1), 3); }));
|
|
44
|
+
it('with multiple arguments ', () => __awaiter(void 0, void 0, void 0, function* () { return assert.strictEqual(yield proxy.$c(2, 3), 5); }));
|
|
45
|
+
it('with variadic arguments ', () => __awaiter(void 0, void 0, void 0, function* () { return assert.strictEqual(yield proxy.$d(...[2, 3, 4]), 9); }));
|
|
46
|
+
it('to functions returning a rejected promise', () => __awaiter(void 0, void 0, void 0, function* () { return assert.rejects(() => proxy.$e()); }));
|
|
47
|
+
it('to functions throwing an error', () => __awaiter(void 0, void 0, void 0, function* () { return assert.rejects(() => proxy.$f()); }));
|
|
48
|
+
});
|
|
49
|
+
it('proxies Observables', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
const proxy = createTestProxy({
|
|
51
|
+
$observe: (...args) => new rxjs_1.Observable(observer => {
|
|
52
|
+
for (const arg of args) {
|
|
53
|
+
observer.next(arg + 1);
|
|
54
|
+
}
|
|
55
|
+
observer.complete();
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
assert.deepStrictEqual(yield proxy
|
|
59
|
+
.$observe(1, 2, 3, 4)
|
|
60
|
+
.pipe(operators_1.bufferCount(4))
|
|
61
|
+
.toPromise(), [2, 3, 4, 5]);
|
|
62
|
+
}));
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=proxy.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.test.js","sourceRoot":"","sources":["../../../src/connections/proxy/proxy.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAiC;AACjC,+BAAkC;AAClC,8CAA6C;AAC7C,uDAA0D;AAC1D,yDAAkE;AAClE,mCAAsD;AACtD,iBAAiB;AAEjB,SAAS,eAAe,CAAI,OAAU;IAClC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC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,CAAC;iBAC1B;gBACD,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACxB,CAAC,CAAC;SACT,CAAC,CAAC;QACH,MAAM,CAAC,eAAe,CAClB,MAAM,KAAK;aACN,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;aACpB,IAAI,CAAC,uBAAW,CAAC,CAAC,CAAC,CAAC;aACpB,SAAS,EAAE,EAChB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CACf,CAAC;IACN,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const abort_controller_1 = require("abort-controller");
|
|
14
|
+
const mock_socket_1 = require("mock-socket");
|
|
15
|
+
const connection_1 = require("../jsonrpc2/connection");
|
|
16
|
+
const assert = require("assert");
|
|
17
|
+
const browser_remote_rpc_1 = require("./browser-remote-rpc");
|
|
18
|
+
const utils_1 = require("../../utils");
|
|
19
|
+
const extension_module_server_1 = require("@workbench-stack/extension-module-server");
|
|
20
|
+
const rpc_protocol_1 = require("../../protocol/rpc-protocol");
|
|
21
|
+
const event_1 = require("@vscode-alt/monaco-editor/esm/vs/base/common/event");
|
|
22
|
+
const rpc_logger_1 = require("../../protocol/rpc-logger");
|
|
23
|
+
const test_helper_1 = require("../jsonrpc2/test-helper");
|
|
24
|
+
const proxy_1 = require("../proxy/proxy");
|
|
25
|
+
// import 'jest';
|
|
26
|
+
const protocol_1 = require("../../protocol");
|
|
27
|
+
const buffer_1 = require("@vscode-alt/monaco-editor/esm/vs/base/common/buffer");
|
|
28
|
+
const consoleLogger = {
|
|
29
|
+
error(message) {
|
|
30
|
+
console.error(message);
|
|
31
|
+
},
|
|
32
|
+
warn(message) {
|
|
33
|
+
console.warn(message);
|
|
34
|
+
},
|
|
35
|
+
info(message) {
|
|
36
|
+
// tslint:disable-next-line:no-console
|
|
37
|
+
console.info(message);
|
|
38
|
+
},
|
|
39
|
+
log(message) {
|
|
40
|
+
// tslint:disable-next-line:no-console
|
|
41
|
+
console.log(message);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
class MessagePassingProtocol {
|
|
45
|
+
constructor(hostId = 0 /* ServerExtHost */) {
|
|
46
|
+
this._onNativeMessage = new event_1.Emitter();
|
|
47
|
+
this.onMessage = this._onNativeMessage.event;
|
|
48
|
+
this._localHostId = hostId;
|
|
49
|
+
}
|
|
50
|
+
setPair(other) {
|
|
51
|
+
this._pair = other;
|
|
52
|
+
}
|
|
53
|
+
send(buffer, hostIdentifier) {
|
|
54
|
+
console.log('--send From Ext', hostIdentifier);
|
|
55
|
+
const headerBuf = buffer_1.VSBuffer.alloc(2);
|
|
56
|
+
// add destination host id
|
|
57
|
+
headerBuf.writeUInt8(hostIdentifier, 0);
|
|
58
|
+
// add sender host id
|
|
59
|
+
headerBuf.writeUInt8(this._localHostId, 1);
|
|
60
|
+
const cocatBuf = buffer_1.VSBuffer.concat([headerBuf, buffer]);
|
|
61
|
+
process.nextTick(() => {
|
|
62
|
+
this._pair._onNativeMessage.fire(cocatBuf);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
class MultiMessagePassingProtocol {
|
|
67
|
+
constructor(hostId = 1 /* ServerMainThread */) {
|
|
68
|
+
this._wsProtocol = new extension_module_server_1.WsProtocol();
|
|
69
|
+
this._onNativeMessage = new event_1.Emitter();
|
|
70
|
+
this._onMessage = new event_1.EventMultiplexer();
|
|
71
|
+
this.onMessage = this._onMessage.event;
|
|
72
|
+
this._localHostId = hostId;
|
|
73
|
+
this._onMessage.add(this._onNativeMessage.event);
|
|
74
|
+
this._onMessage.add(this._wsProtocol.onMessage);
|
|
75
|
+
}
|
|
76
|
+
connect(socket) {
|
|
77
|
+
this._wsProtocol.connect(socket);
|
|
78
|
+
}
|
|
79
|
+
setPair(other) {
|
|
80
|
+
this._pair = other;
|
|
81
|
+
}
|
|
82
|
+
send(buffer, hostIdentifier) {
|
|
83
|
+
const transportType = this.getRequestTypeRouting(hostIdentifier);
|
|
84
|
+
const headerBuf = buffer_1.VSBuffer.alloc(2);
|
|
85
|
+
// add destination host id
|
|
86
|
+
headerBuf.writeUInt8(hostIdentifier, 0);
|
|
87
|
+
// add sender host id
|
|
88
|
+
headerBuf.writeUInt8(this._localHostId, 1);
|
|
89
|
+
const cocatBuf = buffer_1.VSBuffer.concat([headerBuf, buffer]);
|
|
90
|
+
this._send(cocatBuf, transportType);
|
|
91
|
+
}
|
|
92
|
+
_send(buffer, transportType) {
|
|
93
|
+
console.log('---_send fromMulitp transportType websocket', transportType === 1 /* WebSocket */);
|
|
94
|
+
if (transportType === 1 /* WebSocket */) {
|
|
95
|
+
this.webSend(buffer);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.nativeSend(buffer);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
forward(buffer, hostIdentifier) {
|
|
102
|
+
console.log('---forward the request to hostId', hostIdentifier);
|
|
103
|
+
const transportType = this.getRequestTypeRouting(hostIdentifier);
|
|
104
|
+
if (transportType === 1 /* WebSocket */) {
|
|
105
|
+
this._send(buffer, 1 /* WebSocket */);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this._send(buffer, 0 /* Socket */);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
webSend(buffer) {
|
|
112
|
+
return this._wsProtocol.send(buffer);
|
|
113
|
+
}
|
|
114
|
+
nativeSend(buffer) {
|
|
115
|
+
process.nextTick(() => {
|
|
116
|
+
this._pair._onNativeMessage.fire(buffer);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
getRequestTypeRouting(hostIdentifier) {
|
|
120
|
+
if (hostIdentifier === 0 /* ServerExtHost */) {
|
|
121
|
+
return 0 /* Socket */;
|
|
122
|
+
}
|
|
123
|
+
else if (hostIdentifier === 2 /* BrowserExtHost */) {
|
|
124
|
+
return 1 /* WebSocket */;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return 0 /* Socket */;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
describe('Websocket RPC', () => {
|
|
132
|
+
let fakeURL;
|
|
133
|
+
let mockServer;
|
|
134
|
+
let socket1;
|
|
135
|
+
let delegate;
|
|
136
|
+
let bProxyFromA;
|
|
137
|
+
let bProdyFromC;
|
|
138
|
+
let aProxyFromB;
|
|
139
|
+
let aProxyFromC;
|
|
140
|
+
let cProxyFromA;
|
|
141
|
+
class AClass {
|
|
142
|
+
$m(a1, a2) {
|
|
143
|
+
return Promise.resolve(delegate.call(null, a1, a2));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
class BClass {
|
|
147
|
+
$n(a1, a2) {
|
|
148
|
+
return Promise.resolve(delegate.call(null, a1, a2));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
class CClass {
|
|
152
|
+
$o(a1, a2) {
|
|
153
|
+
return Promise.resolve(delegate.call(null, a1, a2));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
beforeEach((done) => {
|
|
157
|
+
fakeURL = 'ws://localhost:8080';
|
|
158
|
+
mockServer = new mock_socket_1.Server(fakeURL);
|
|
159
|
+
let b_protocol = new browser_remote_rpc_1.BrowserRemoteRPC();
|
|
160
|
+
b_protocol.connect(fakeURL, () => {
|
|
161
|
+
socket1 = new mock_socket_1.WebSocket(fakeURL);
|
|
162
|
+
socket1.binaryType = 'arraybuffer';
|
|
163
|
+
return socket1;
|
|
164
|
+
});
|
|
165
|
+
mockServer.on('connection', socket => {
|
|
166
|
+
console.log('---SOCKET MOCK SErver', socket);
|
|
167
|
+
let a_protocol = new MultiMessagePassingProtocol();
|
|
168
|
+
a_protocol.connect(socket);
|
|
169
|
+
let c_protocol = new MessagePassingProtocol();
|
|
170
|
+
c_protocol.setPair(a_protocol);
|
|
171
|
+
a_protocol.setPair(c_protocol);
|
|
172
|
+
let A = new rpc_protocol_1.RPCProtocol(a_protocol, 1 /* ServerMainThread */, new rpc_logger_1.RPCLogger(), null);
|
|
173
|
+
let B = new rpc_protocol_1.RPCProtocol(b_protocol, 2 /* BrowserExtHost */, new rpc_logger_1.RPCLogger(), null);
|
|
174
|
+
let C = new rpc_protocol_1.RPCProtocol(c_protocol, 0 /* ServerExtHost */, new rpc_logger_1.RPCLogger(), null);
|
|
175
|
+
const bIdentifier = new protocol_1.ProxyIdentifier(false, 'bb', 2 /* BrowserExtHost */);
|
|
176
|
+
const bInstance = new BClass();
|
|
177
|
+
const aIdentifier = new protocol_1.ProxyIdentifier(false, 'aa', 1 /* ServerMainThread */);
|
|
178
|
+
const aInstance = new AClass();
|
|
179
|
+
const cIdentifer = new protocol_1.ProxyIdentifier(false, 'cc', 0 /* ServerExtHost */);
|
|
180
|
+
const cInstance = new CClass();
|
|
181
|
+
B.set(bIdentifier, bInstance);
|
|
182
|
+
A.set(aIdentifier, aInstance);
|
|
183
|
+
C.set(cIdentifer, cInstance);
|
|
184
|
+
bProxyFromA = A.getProxy(bIdentifier);
|
|
185
|
+
aProxyFromC = C.getProxy(aIdentifier);
|
|
186
|
+
aProxyFromB = B.getProxy(aIdentifier);
|
|
187
|
+
cProxyFromA = A.getProxy(cIdentifer);
|
|
188
|
+
bProdyFromC = C.getProxy(bIdentifier);
|
|
189
|
+
cProxyFromA = A.getProxy(cIdentifer);
|
|
190
|
+
done();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
afterEach(() => {
|
|
194
|
+
socket1.close();
|
|
195
|
+
mockServer.close();
|
|
196
|
+
});
|
|
197
|
+
test('simple call C -> A', function (done) {
|
|
198
|
+
delegate = (a1, a2) => a1 + a2;
|
|
199
|
+
aProxyFromC.$m(4, 1).then((res) => {
|
|
200
|
+
assert.equal(res, 5);
|
|
201
|
+
done();
|
|
202
|
+
}, done.fail);
|
|
203
|
+
});
|
|
204
|
+
test('simple call B -> A', function (done) {
|
|
205
|
+
delegate = (a1, a2) => a1 + a2;
|
|
206
|
+
aProxyFromB.$m(4, 1).then((res) => {
|
|
207
|
+
assert.equal(res, 5);
|
|
208
|
+
done();
|
|
209
|
+
}, done.fail);
|
|
210
|
+
});
|
|
211
|
+
test('simple call C -> B', function (done) {
|
|
212
|
+
delegate = (a1, a2) => a1 + a2;
|
|
213
|
+
bProdyFromC.$n(4, 1).then((res) => {
|
|
214
|
+
assert.equal(res, 5);
|
|
215
|
+
done();
|
|
216
|
+
}, done.fail);
|
|
217
|
+
});
|
|
218
|
+
test('simple call A -> C', function (done) {
|
|
219
|
+
delegate = (a1, a2) => a1 + a2;
|
|
220
|
+
cProxyFromA.$o(4, 1).then((res) => {
|
|
221
|
+
assert.equal(res, 5);
|
|
222
|
+
done();
|
|
223
|
+
}, done.fail);
|
|
224
|
+
});
|
|
225
|
+
test('test buffer', function () {
|
|
226
|
+
const b1 = Buffer.allocUnsafe(2);
|
|
227
|
+
const b2 = Buffer.allocUnsafe(1);
|
|
228
|
+
b1.writeUInt8(10, 0);
|
|
229
|
+
b1.writeUInt8(99, 1);
|
|
230
|
+
b2.writeUInt8(20, 0);
|
|
231
|
+
const buf = Buffer.concat([b1, b2]);
|
|
232
|
+
const a1 = buf.readUInt8(0);
|
|
233
|
+
// const bufNew = buf.slice(3);
|
|
234
|
+
const a2 = buf.readUInt8(2);
|
|
235
|
+
console.log('---a1', a1);
|
|
236
|
+
console.log('---a2', a2);
|
|
237
|
+
});
|
|
238
|
+
test('simple call A->C', function (done) {
|
|
239
|
+
delegate = (a1, a2) => a1 + a2;
|
|
240
|
+
cProxyFromA.$o(6, 1).then((res) => {
|
|
241
|
+
assert.equal(res, 7);
|
|
242
|
+
done();
|
|
243
|
+
}, done.fail);
|
|
244
|
+
});
|
|
245
|
+
test('works', () => {
|
|
246
|
+
const result = [];
|
|
247
|
+
const m = new event_1.EventMultiplexer();
|
|
248
|
+
m.event(r => result.push(r));
|
|
249
|
+
const e1 = new event_1.Emitter();
|
|
250
|
+
m.add(e1.event);
|
|
251
|
+
assert.deepEqual(result, []);
|
|
252
|
+
e1.fire(0);
|
|
253
|
+
assert.deepEqual(result, [0]);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
xdescribe('Connection', () => {
|
|
257
|
+
let delegate;
|
|
258
|
+
let aProxy;
|
|
259
|
+
class AClass {
|
|
260
|
+
$m(a1, a2) {
|
|
261
|
+
return Promise.resolve(delegate.call(null, a1, a2));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
class BClass {
|
|
265
|
+
$m(b1, b2) {
|
|
266
|
+
return Promise.resolve(delegate.call(null, b1, b2));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Polyfill
|
|
270
|
+
;
|
|
271
|
+
global.AbortController = abort_controller_1.default;
|
|
272
|
+
let mockServer, socket1;
|
|
273
|
+
const aIdentifier = new protocol_1.ProxyIdentifier(false, 'aa');
|
|
274
|
+
let A, B;
|
|
275
|
+
beforeEach((done) => {
|
|
276
|
+
});
|
|
277
|
+
afterEach(() => {
|
|
278
|
+
socket1.close();
|
|
279
|
+
mockServer.close();
|
|
280
|
+
});
|
|
281
|
+
xtest('handle single request', (done) => __awaiter(void 0, void 0, void 0, function* () {
|
|
282
|
+
const [serverTransports, clientTransports] = test_helper_1.createMessageTransports();
|
|
283
|
+
delegate = (a1, a2) => a1 + a2;
|
|
284
|
+
const server = connection_1.createConnection(serverTransports, consoleLogger);
|
|
285
|
+
proxy_1.handleServerProxyRequest(server, B, aIdentifier);
|
|
286
|
+
server.listen();
|
|
287
|
+
server.onClose(event => done());
|
|
288
|
+
const client = connection_1.createConnection(clientTransports);
|
|
289
|
+
client.listen();
|
|
290
|
+
const signal = new abort_controller_1.default().signal;
|
|
291
|
+
const result = yield client.sendRequest('aa/$m', [4, 1], signal);
|
|
292
|
+
expect(result).toBe(5);
|
|
293
|
+
done();
|
|
294
|
+
}));
|
|
295
|
+
xit('abort undispatched request', (done) => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
|
+
const [serverTransports, clientTransports] = test_helper_1.createMessageTransports();
|
|
297
|
+
const b1 = utils_1.createBarrier();
|
|
298
|
+
const b2 = utils_1.createBarrier();
|
|
299
|
+
delegate = (a1, a2) => a1 + a2;
|
|
300
|
+
const server = connection_1.createConnection(serverTransports, consoleLogger);
|
|
301
|
+
server.onRequest('block', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
302
|
+
b2.done();
|
|
303
|
+
yield b1.wait;
|
|
304
|
+
}));
|
|
305
|
+
// server.onRequest('undispatched', () => {
|
|
306
|
+
// throw new Error('handler should not be called')
|
|
307
|
+
// })
|
|
308
|
+
proxy_1.handleServerProxyRequest(server, B, aIdentifier);
|
|
309
|
+
server.listen();
|
|
310
|
+
const client = connection_1.createConnection(clientTransports);
|
|
311
|
+
client.listen();
|
|
312
|
+
server.onClose(event => done());
|
|
313
|
+
client.sendRequest('block').catch(null);
|
|
314
|
+
yield b2.wait;
|
|
315
|
+
const abortController = new abort_controller_1.default();
|
|
316
|
+
// const result = client.sendRequest('undispatched', ['foo'], abortController.signal)
|
|
317
|
+
const result = client.sendRequest('aa/$m', [4, 1], abortController.signal);
|
|
318
|
+
abortController.abort();
|
|
319
|
+
b1.done();
|
|
320
|
+
yield assert.rejects(result, (err /** : AbortError*/) => err.name === 'AbortError');
|
|
321
|
+
}));
|
|
322
|
+
});
|
|
323
|
+
//# sourceMappingURL=browser-server-rpc.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-server-rpc.test.js","sourceRoot":"","sources":["../../../src/connections/remote-rpc/browser-server-rpc.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAA0B;AAC1B,uDAA+C;AAC/C,6CAAgD;AAChD,uDAAkE;AAClE,iCAAiC;AACjC,6DAAwD;AACxD,uCAA4C;AAC5C,sFAAsE;AACtE,8DAAsF;AAItF,8EAAsG;AACtG,0DAAsD;AACtD,yDAAqF;AACrF,0CAA0D;AAC1D,iBAAiB;AACjB,6CAA6F;AAC7F,gFAA+E;AAC/E,MAAM,aAAa,GAAW;IAC1B,KAAK,CAAC,OAAe;QACjB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,CAAC,OAAe;QAChB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,CAAC,OAAe;QAChB,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IACD,GAAG,CAAC,OAAe;QACf,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;CACJ,CAAC;AAIF,MAAM,sBAAsB;IAOxB,YAAY,8BAAqD;QAJjD,qBAAgB,GAAG,IAAI,eAAO,EAAY,CAAC;QAC3C,cAAS,GAAoB,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAIrE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC;IAC/B,CAAC;IAEM,OAAO,CAAC,KAAkC;QAC7C,IAAI,CAAC,KAAK,GAAG,KAAK,CAA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
|
4
|
+
const FIXTURE_CONTEXT = {
|
|
5
|
+
a: 1,
|
|
6
|
+
b: 1,
|
|
7
|
+
c: 2,
|
|
8
|
+
x: 'y',
|
|
9
|
+
o: { k: 'v' },
|
|
10
|
+
array: [7],
|
|
11
|
+
};
|
|
12
|
+
describe('Expression', () => {
|
|
13
|
+
const TESTS = {
|
|
14
|
+
a: 1,
|
|
15
|
+
'a + b': 2,
|
|
16
|
+
'a == b': true,
|
|
17
|
+
'a != b': false,
|
|
18
|
+
'a + b == c': true,
|
|
19
|
+
x: 'y',
|
|
20
|
+
'd === false': false,
|
|
21
|
+
'd !== false': true,
|
|
22
|
+
'!a': false,
|
|
23
|
+
'!!a': true,
|
|
24
|
+
'a && c': 2,
|
|
25
|
+
'a || b': 1,
|
|
26
|
+
'(a + b) * 2': 4,
|
|
27
|
+
'x == "y"': true,
|
|
28
|
+
'json(o)': '{"k":"v"}',
|
|
29
|
+
// TODO: Support operator precedence. See ./parser.test.ts for a commented-out precedence test case.
|
|
30
|
+
//
|
|
31
|
+
// 'x == "y" || x == "z"': true,
|
|
32
|
+
'x == "y" && x == "z"': false,
|
|
33
|
+
'x == "y" && x != "z"': true,
|
|
34
|
+
'`a`': 'a',
|
|
35
|
+
'`${x}`': 'y',
|
|
36
|
+
'`a${x}b`': 'ayb',
|
|
37
|
+
'`_${x}_${a}_${a+b}`': '_y_1_2',
|
|
38
|
+
'`_${`-${x}-`}_`': '_-y-_',
|
|
39
|
+
'a || isnotdefined': 1,
|
|
40
|
+
'get(array, 0)': 7,
|
|
41
|
+
'get(array, 1)': undefined,
|
|
42
|
+
'get(context, "c")': 2,
|
|
43
|
+
};
|
|
44
|
+
for (const [expression, want] of Object.entries(TESTS)) {
|
|
45
|
+
test(expression, () => {
|
|
46
|
+
const value = evaluator_1.parse(expression).exec(FIXTURE_CONTEXT);
|
|
47
|
+
console.log('--Value---', value, expression, want);
|
|
48
|
+
expect(value).toBe(want);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=evaluator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluator.test.js","sourceRoot":"","sources":["../../../src/core/expr/evaluator.test.ts"],"names":[],"mappings":";;AACA,2CAAmD;AAEnD,MAAM,eAAe,GAAmB;IACpC,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE;IACb,KAAK,EAAE,CAAC,CAAC,CAAC;CACb,CAAC;AAGF,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IACxB,MAAM,KAAK,GAAG;QACV,CAAC,EAAE,CAAC;QACJ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,IAAI;QAClB,CAAC,EAAE,GAAG;QACN,aAAa,EAAE,KAAK;QACpB,aAAa,EAAE,IAAI;QACnB,IAAI,EAAE,KAAK;QACX,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,WAAW;QACtB,oGAAoG;QACpG,EAAE;QACF,gCAAgC;QAChC,sBAAsB,EAAE,KAAK;QAC7B,sBAAsB,EAAE,IAAI;QAC5B,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,GAAG;QACb,UAAU,EAAE,KAAK;QACjB,qBAAqB,EAAE,QAAQ;QAC/B,iBAAiB,EAAE,OAAO;QAC1B,mBAAmB,EAAE,CAAC;QACtB,eAAe,EAAE,CAAC;QAClB,eAAe,EAAE,SAAS;QAC1B,mBAAmB,EAAE,CAAC;KACzB,CAAC;IACF,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACpD,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;YAClB,MAAM,KAAK,GAAG,iBAAK,CAAU,UAAU,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;YACnD,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAA;KACL;AACL,CAAC,CAAC,CAAA"}
|
|
@@ -2119,7 +2119,7 @@ export declare const CopyDocument: Apollo.DocumentNode;
|
|
|
2119
2119
|
*/
|
|
2120
2120
|
export declare function useCopyMutation(baseOptions?: Apollo.MutationHookOptions<ICopyMutation, ICopyMutationVariables>): Apollo.MutationTuple<ICopyMutation, Exact<{
|
|
2121
2121
|
value?: string;
|
|
2122
|
-
}
|
|
2122
|
+
}>>;
|
|
2123
2123
|
export declare type CopyMutationHookResult = ReturnType<typeof useCopyMutation>;
|
|
2124
2124
|
export declare type CopyMutationResult = Apollo.MutationResult<ICopyMutation>;
|
|
2125
2125
|
export declare type CopyMutationOptions = Apollo.BaseMutationOptions<ICopyMutation, ICopyMutationVariables>;
|
|
@@ -2143,7 +2143,7 @@ export declare const RunMenuActionDocument: Apollo.DocumentNode;
|
|
|
2143
2143
|
*/
|
|
2144
2144
|
export declare function useRunMenuActionMutation(baseOptions?: Apollo.MutationHookOptions<IRunMenuActionMutation, IRunMenuActionMutationVariables>): Apollo.MutationTuple<IRunMenuActionMutation, Exact<{
|
|
2145
2145
|
argument?: IContributionActionRun_input;
|
|
2146
|
-
}
|
|
2146
|
+
}>>;
|
|
2147
2147
|
export declare type RunMenuActionMutationHookResult = ReturnType<typeof useRunMenuActionMutation>;
|
|
2148
2148
|
export declare type RunMenuActionMutationResult = Apollo.MutationResult<IRunMenuActionMutation>;
|
|
2149
2149
|
export declare type RunMenuActionMutationOptions = Apollo.BaseMutationOptions<IRunMenuActionMutation, IRunMenuActionMutationVariables>;
|
|
@@ -2166,7 +2166,7 @@ export declare const HideContextMenuDocument: Apollo.DocumentNode;
|
|
|
2166
2166
|
*/
|
|
2167
2167
|
export declare function useHideContextMenuMutation(baseOptions?: Apollo.MutationHookOptions<IHideContextMenuMutation, IHideContextMenuMutationVariables>): Apollo.MutationTuple<IHideContextMenuMutation, Exact<{
|
|
2168
2168
|
[key: string]: never;
|
|
2169
|
-
}
|
|
2169
|
+
}>>;
|
|
2170
2170
|
export declare type HideContextMenuMutationHookResult = ReturnType<typeof useHideContextMenuMutation>;
|
|
2171
2171
|
export declare type HideContextMenuMutationResult = Apollo.MutationResult<IHideContextMenuMutation>;
|
|
2172
2172
|
export declare type HideContextMenuMutationOptions = Apollo.BaseMutationOptions<IHideContextMenuMutation, IHideContextMenuMutationVariables>;
|
|
@@ -2190,7 +2190,7 @@ export declare const ShowContextMenuDocument: Apollo.DocumentNode;
|
|
|
2190
2190
|
*/
|
|
2191
2191
|
export declare function useShowContextMenuMutation(baseOptions?: Apollo.MutationHookOptions<IShowContextMenuMutation, IShowContextMenuMutationVariables>): Apollo.MutationTuple<IShowContextMenuMutation, Exact<{
|
|
2192
2192
|
delegate?: IContextMenu_input;
|
|
2193
|
-
}
|
|
2193
|
+
}>>;
|
|
2194
2194
|
export declare type ShowContextMenuMutationHookResult = ReturnType<typeof useShowContextMenuMutation>;
|
|
2195
2195
|
export declare type ShowContextMenuMutationResult = Apollo.MutationResult<IShowContextMenuMutation>;
|
|
2196
2196
|
export declare type ShowContextMenuMutationOptions = Apollo.BaseMutationOptions<IShowContextMenuMutation, IShowContextMenuMutationVariables>;
|
|
@@ -2214,7 +2214,7 @@ export declare const installDocument: Apollo.DocumentNode;
|
|
|
2214
2214
|
*/
|
|
2215
2215
|
export declare function useinstallMutation(baseOptions?: Apollo.MutationHookOptions<IinstallMutation, IinstallMutationVariables>): Apollo.MutationTuple<IinstallMutation, Exact<{
|
|
2216
2216
|
vsix: string;
|
|
2217
|
-
}
|
|
2217
|
+
}>>;
|
|
2218
2218
|
export declare type installMutationHookResult = ReturnType<typeof useinstallMutation>;
|
|
2219
2219
|
export declare type installMutationResult = Apollo.MutationResult<IinstallMutation>;
|
|
2220
2220
|
export declare type installMutationOptions = Apollo.BaseMutationOptions<IinstallMutation, IinstallMutationVariables>;
|
|
@@ -2238,7 +2238,7 @@ export declare const providerDefinitionDocument: Apollo.DocumentNode;
|
|
|
2238
2238
|
*/
|
|
2239
2239
|
export declare function useproviderDefinitionMutation(baseOptions?: Apollo.MutationHookOptions<IproviderDefinitionMutation, IproviderDefinitionMutationVariables>): Apollo.MutationTuple<IproviderDefinitionMutation, Exact<{
|
|
2240
2240
|
params?: ITextDocumentPositionParamsInput;
|
|
2241
|
-
}
|
|
2241
|
+
}>>;
|
|
2242
2242
|
export declare type providerDefinitionMutationHookResult = ReturnType<typeof useproviderDefinitionMutation>;
|
|
2243
2243
|
export declare type providerDefinitionMutationResult = Apollo.MutationResult<IproviderDefinitionMutation>;
|
|
2244
2244
|
export declare type providerDefinitionMutationOptions = Apollo.BaseMutationOptions<IproviderDefinitionMutation, IproviderDefinitionMutationVariables>;
|
|
@@ -2262,7 +2262,7 @@ export declare const removeDocument: Apollo.DocumentNode;
|
|
|
2262
2262
|
*/
|
|
2263
2263
|
export declare function useremoveMutation(baseOptions?: Apollo.MutationHookOptions<IremoveMutation, IremoveMutationVariables>): Apollo.MutationTuple<IremoveMutation, Exact<{
|
|
2264
2264
|
id: string;
|
|
2265
|
-
}
|
|
2265
|
+
}>>;
|
|
2266
2266
|
export declare type removeMutationHookResult = ReturnType<typeof useremoveMutation>;
|
|
2267
2267
|
export declare type removeMutationResult = Apollo.MutationResult<IremoveMutation>;
|
|
2268
2268
|
export declare type removeMutationOptions = Apollo.BaseMutationOptions<IremoveMutation, IremoveMutationVariables>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|