@schukai/monster 3.1.0 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -16,14 +16,14 @@ export {WebSocketDatasource}
|
|
16
16
|
|
17
17
|
/**
|
18
18
|
* @private
|
19
|
-
* @type {
|
19
|
+
* @type {Symbol}
|
20
20
|
*/
|
21
21
|
const receiveQueueSymbol = Symbol("queue");
|
22
22
|
|
23
23
|
|
24
24
|
/**
|
25
25
|
* @private
|
26
|
-
* @type {
|
26
|
+
* @type {Symbol}
|
27
27
|
*
|
28
28
|
* hint: this name is used in the tests. if you want to change it, please change it in the tests as well.
|
29
29
|
*/
|
@@ -231,14 +231,15 @@ class WebSocketDatasource extends Datasource {
|
|
231
231
|
|
232
232
|
/**
|
233
233
|
* @return {Promise}
|
234
|
-
* @throws {Error} the options does not contain a valid json definition
|
235
|
-
* @throws {Error} the data cannot be read
|
236
|
-
* @throws {TypeError} value is not an object
|
237
234
|
*/
|
238
235
|
read() {
|
239
236
|
const self = this;
|
240
237
|
let response;
|
241
238
|
|
239
|
+
if (self[connectionSymbol]?.socket?.readyState!==1) {
|
240
|
+
return Promise.reject('The connection is not established.');
|
241
|
+
}
|
242
|
+
|
242
243
|
return new Promise((resolve, reject) => {
|
243
244
|
if (self[receiveQueueSymbol].isEmpty()) {
|
244
245
|
resolve();
|
@@ -290,6 +291,10 @@ class WebSocketDatasource extends Datasource {
|
|
290
291
|
*/
|
291
292
|
write() {
|
292
293
|
const self = this;
|
294
|
+
|
295
|
+
if (self[connectionSymbol]?.socket?.readyState!==1) {
|
296
|
+
return Promise.reject('The connection is not established.');
|
297
|
+
}
|
293
298
|
|
294
299
|
let obj = self.get();
|
295
300
|
let transformation = self.getOption('write.mapping.transformer');
|
@@ -330,7 +335,7 @@ class WebSocketDatasource extends Datasource {
|
|
330
335
|
*/
|
331
336
|
getClone() {
|
332
337
|
const self = this;
|
333
|
-
return new
|
338
|
+
return new WebSocketDatasource(self[internalSymbol].getRealSubject()['options']);
|
334
339
|
}
|
335
340
|
|
336
341
|
}
|
package/source/types/version.mjs
CHANGED
@@ -37,6 +37,16 @@ describe('Websocket', function () {
|
|
37
37
|
done()
|
38
38
|
});
|
39
39
|
|
40
|
+
it('should get clone', function () {
|
41
|
+
|
42
|
+
ds = new WebSocketDatasource(testUrl)
|
43
|
+
const clone = ds.getClone()
|
44
|
+
|
45
|
+
expect(clone).to.be.an.instanceof(WebSocketDatasource)
|
46
|
+
|
47
|
+
|
48
|
+
})
|
49
|
+
|
40
50
|
it('should connect', function (done) {
|
41
51
|
ds = new WebSocketDatasource({
|
42
52
|
url: testUrl,
|
@@ -88,7 +98,8 @@ describe('Websocket', function () {
|
|
88
98
|
}).catch((err) => {
|
89
99
|
done(new Error(err));
|
90
100
|
})
|
91
|
-
},
|
101
|
+
},
|
102
|
+
500)
|
92
103
|
|
93
104
|
|
94
105
|
}).timeout(10000);
|
package/test/cases/monster.mjs
CHANGED