@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -16,14 +16,14 @@ export {WebSocketDatasource}
16
16
 
17
17
  /**
18
18
  * @private
19
- * @type {symbol}
19
+ * @type {Symbol}
20
20
  */
21
21
  const receiveQueueSymbol = Symbol("queue");
22
22
 
23
23
 
24
24
  /**
25
25
  * @private
26
- * @type {symbol}
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 Websocketdatasource(self[internalSymbol].getRealSubject()['options']);
338
+ return new WebSocketDatasource(self[internalSymbol].getRealSubject()['options']);
334
339
  }
335
340
 
336
341
  }
@@ -149,7 +149,7 @@ function getMonsterVersion() {
149
149
  }
150
150
 
151
151
  /** don't touch, replaced by make with package.json version */
152
- monsterVersion = new Version('3.1.0')
152
+ monsterVersion = new Version('3.1.2')
153
153
 
154
154
  return monsterVersion;
155
155
 
@@ -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
- }, 1000)
101
+ },
102
+ 500)
92
103
 
93
104
 
94
105
  }).timeout(10000);
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version('3.1.0')
10
+ monsterVersion = new Version('3.1.2')
11
11
 
12
12
  let m = getMonsterVersion();
13
13