@schukai/monster 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  import {expect} from "chai"
4
- import {RestAPI} from "../../../../../application/source/data/datasource/restapi.mjs";
5
- import {validateObject} from "../../../../../application/source/types/validate.mjs";
4
+ import {RestAPI} from "../../../../../../application/source/data/datasource/server/restapi.mjs";
5
+ import {validateObject} from "../../../../../../application/source/types/validate.mjs";
6
6
 
7
7
 
8
8
  describe('RestAPI', function () {
@@ -18,16 +18,19 @@ describe('RestAPI', function () {
18
18
 
19
19
  returnStatus = 200;
20
20
  fetchReference = globalThis['fetch'];
21
- globalThis['fetch'] = function (url, options) {
22
-
23
- if (!url) throw new Error('missing url')
21
+ globalThis['fetch'] = function (options) {
24
22
 
25
23
  return new Promise((resolve, reject) => {
26
24
  resolve({
27
25
  text: function () {
28
- return JSON.stringify({
29
- a: "test"
30
- })
26
+ return new Promise((resolve, reject) => {
27
+ resolve(JSON.stringify({
28
+ a: "test"
29
+ }));
30
+ });
31
+
32
+
33
+
31
34
  },
32
35
  status: returnStatus
33
36
  });
@@ -52,11 +55,14 @@ describe('RestAPI', function () {
52
55
  });
53
56
 
54
57
  it('write should ', function (done) {
55
- const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'}, {url: 'https://monsterjs.org/assets/world.json'})
58
+ const ds = new RestAPI({url: 'https://monsterjs.org/assets/world.json'},
59
+ {
60
+ url: 'https://monsterjs.org/assets/world.json',
61
+ acceptedStatus: [99]
62
+ })
56
63
  ds.write().then(data => {
57
- validateObject(data);
58
- done();
59
- }).catch(e => done(e));
64
+ done("should not be here");
65
+ }).catch(e => done());
60
66
  });
61
67
 
62
68
 
@@ -86,4 +92,4 @@ describe('RestAPI', function () {
86
92
  })
87
93
 
88
94
 
89
- })
95
+ })
@@ -1,6 +1,6 @@
1
1
  import {expect} from "chai"
2
- import {WebSocketDatasource} from "../../../../../application/source/data/datasource/websocket.mjs";
3
- import {initWebSocket} from "../../../util/websocket.mjs";
2
+ import {WebConnect} from "../../../../../../application/source/data/datasource/server/webconnect.mjs";
3
+ import {initWebSocket} from "../../../../util/websocket.mjs";
4
4
 
5
5
  const testUrl = "wss://ws.postman-echo.com/raw"
6
6
 
@@ -33,7 +33,9 @@ describe('Websocket', function () {
33
33
  if (sym2.toString() === 'Symbol(connection)') {
34
34
  const socket = connection[sym2]?.socket;
35
35
  if (socket) {
36
- socket.terminate()
36
+ if (typeof socket?.terminate === 'function') {
37
+ socket?.['terminate']()
38
+ }
37
39
  }
38
40
  }
39
41
  }
@@ -45,10 +47,10 @@ describe('Websocket', function () {
45
47
 
46
48
  it('should get clone', function () {
47
49
 
48
- ds = new WebSocketDatasource(testUrl)
50
+ ds = new WebConnect(testUrl)
49
51
  const clone = ds.getClone()
50
52
 
51
- expect(clone).to.be.an.instanceof(WebSocketDatasource)
53
+ expect(clone).to.be.an.instanceof(WebConnect)
52
54
 
53
55
 
54
56
  })
@@ -58,7 +60,7 @@ describe('Websocket', function () {
58
60
  let writeCallbackCalled = false
59
61
  let readCallbackCalled = false
60
62
 
61
- ds = new WebSocketDatasource({
63
+ ds = new WebConnect({
62
64
  url: testUrl,
63
65
  write: {
64
66
  mapping: {
@@ -132,7 +134,7 @@ describe('Websocket', function () {
132
134
  })
133
135
 
134
136
  it('should connect', function (done) {
135
- ds = new WebSocketDatasource({
137
+ ds = new WebConnect({
136
138
  url: testUrl,
137
139
  reconnect: {
138
140
  enabled: false
@@ -148,7 +150,7 @@ describe('Websocket', function () {
148
150
  })
149
151
 
150
152
  it('should send message', function (done) {
151
- ds = new WebSocketDatasource({
153
+ ds = new WebConnect({
152
154
  url: testUrl,
153
155
  reconnect: {
154
156
  enabled: false
@@ -0,0 +1,53 @@
1
+ import {expect} from "chai"
2
+ import {Server} from "../../../../../application/source/data/datasource/server.mjs";
3
+
4
+
5
+ describe('Server', function () {
6
+
7
+ it('should transform data', function () {
8
+
9
+ let writeCallbackCalled = false
10
+ let readCallbackCalled = false
11
+
12
+ const server = new Server({
13
+ write: {
14
+ mapping: {
15
+ transformer: "call:onWrite",
16
+ callbacks: {
17
+ onWrite: (data) => {
18
+ writeCallbackCalled = true
19
+ return data
20
+ }
21
+ }
22
+ },
23
+ sheathing: {
24
+ object: {
25
+ demo: 1,
26
+ data: {
27
+ xyz: undefined
28
+ }
29
+ },
30
+ path: "data.xyz",
31
+ },
32
+ },
33
+ read: {
34
+ mapping: {
35
+ transformer: "call:onRead",
36
+ callbacks: {
37
+ onRead: (data) => {
38
+ readCallbackCalled = true
39
+ return data
40
+ }
41
+ }
42
+ },
43
+ path: 'data.xyz',
44
+ }
45
+ })
46
+
47
+ expect(server.transformServerPayload({demo: 1, data: {xyz: 2}})).to.deep.equal({demo: 1, data: {xyz: 2}})
48
+ expect(server.prepareServerPayload({demo: 1, data: {xyz: 2}})).to.deep.equal({demo: 1, data: {xyz: 2}})
49
+
50
+
51
+ })
52
+
53
+ });
@@ -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.3.0')
10
+ monsterVersion = new Version('3.4.0')
11
11
 
12
12
  let m = getMonsterVersion();
13
13
 
@@ -26,7 +26,7 @@ describe('Websocket', function () {
26
26
  // without this, the node test will hang
27
27
  for (const sym of Object.getOwnPropertySymbols(ds)) {
28
28
  if (sym.toString() === 'Symbol(connection)') {
29
- if (ds[sym]?.socket?.['terminate']) {
29
+ if (typeof ds[sym]?.socket?.terminate === 'function') {
30
30
  ds[sym]?.socket?.['terminate']()
31
31
  }
32
32
  }
@@ -30,10 +30,13 @@ import "../cases/i18n/locale.mjs";
30
30
  import "../cases/i18n/formatter.mjs";
31
31
  import "../cases/i18n/providers/fetch.mjs";
32
32
  import "../cases/i18n/provider.mjs";
33
+ import "../cases/net/webconnect/message.mjs";
34
+ import "../cases/net/webconnect.mjs";
33
35
  import "../cases/types/mediatype.mjs";
34
36
  import "../cases/types/typeof.mjs";
35
37
  import "../cases/types/observerlist.mjs";
36
38
  import "../cases/types/randomid.mjs";
39
+ import "../cases/types/observablequeue.mjs";
37
40
  import "../cases/types/uuid.mjs";
38
41
  import "../cases/types/observer.mjs";
39
42
  import "../cases/types/tokenlist.mjs";
@@ -75,8 +78,9 @@ import "../cases/data/buildtree.mjs";
75
78
  import "../cases/data/transformer.mjs";
76
79
  import "../cases/data/pathfinder.mjs";
77
80
  import "../cases/data/diff.mjs";
78
- import "../cases/data/datasource/restapi.mjs";
81
+ import "../cases/data/datasource/server.mjs";
79
82
  import "../cases/data/datasource/storage/sessionstorage.mjs";
80
83
  import "../cases/data/datasource/storage/localstorage.mjs";
81
- import "../cases/data/datasource/webservice.mjs";
84
+ import "../cases/data/datasource/server/restapi.mjs";
85
+ import "../cases/data/datasource/server/websocket.mjs";
82
86
  import "../cases/math/random.mjs";
@@ -5,7 +5,7 @@
5
5
  <title>Mocha Monster</title>
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
7
7
  <link rel="stylesheet" href="mocha.css"/>
8
- <script id="polyfill" src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Array.isArray,Array.prototype.entries,Array.prototype.fill,Array.prototype.filter,Array.prototype.forEach,Array.prototype.indexOf,Array.prototype.keys,Array.prototype.lastIndexOf,Array.prototype.map,Array.prototype.reduce,Array.prototype.sort,ArrayBuffer,atob,CustomEvent,DataView,document,Document,DocumentFragment,Element,Event,fetch,globalThis,HTMLDocument,HTMLTemplateElement,Intl,JSON,Map,Math.log2,Number.isInteger,Object.assign,Object.defineProperty,Object.entries,Object.freeze,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.keys,Promise,Reflect,Reflect.defineProperty,Reflect.get,Reflect.getOwnPropertyDescriptor,Reflect.setPrototypeOf,Set,String.prototype.endsWith,String.prototype.matchAll,String.prototype.padStart,String.prototype.startsWith,String.prototype.trim,Symbol,Symbol.for,Symbol.hasInstance,Symbol.iterator,Uint16Array,Uint8Array,URL,WeakMap,WeakSet"
8
+ <script id="polyfill" src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Array.isArray,Array.prototype.entries,Array.prototype.fill,Array.prototype.filter,Array.prototype.forEach,Array.prototype.indexOf,Array.prototype.keys,Array.prototype.lastIndexOf,Array.prototype.map,Array.prototype.reduce,Array.prototype.sort,ArrayBuffer,atob,Blob,CustomEvent,DataView,document,Document,DocumentFragment,Element,Event,fetch,globalThis,HTMLDocument,HTMLTemplateElement,Intl,JSON,Map,Math.log2,Number.isInteger,Object.assign,Object.defineProperty,Object.entries,Object.freeze,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.keys,Promise,Reflect,Reflect.defineProperty,Reflect.get,Reflect.getOwnPropertyDescriptor,Reflect.setPrototypeOf,Set,String.prototype.endsWith,String.prototype.matchAll,String.prototype.padStart,String.prototype.startsWith,String.prototype.trim,Symbol,Symbol.for,Symbol.hasInstance,Symbol.iterator,Uint16Array,Uint8Array,URL,WeakMap,WeakSet"
9
9
  src="https://polyfill.io/v3/polyfill.min.js?features=Array.from,Array.isArray,Array.prototype.entries,Array.prototype.fill,Array.prototype.forEach,Array.prototype.indexOf,Array.prototype.keys,Array.prototype.lastIndexOf,Array.prototype.map,Array.prototype.reduce,Array.prototype.sort,ArrayBuffer,atob,DataView,document,DocumentFragment,Element,Event,globalThis,HTMLDocument,HTMLTemplateElement,JSON,Map,Math.log2,Number.isInteger,Object.assign,Object.defineProperty,Object.entries,Object.getOwnPropertyDescriptor,Object.getPrototypeOf,Object.keys,Promise,Reflect,Reflect.defineProperty,Reflect.get,Reflect.getOwnPropertyDescriptor,Reflect.setPrototypeOf,Set,String.prototype.endsWith,String.prototype.matchAll,String.prototype.padStart,String.prototype.startsWith,String.prototype.trim,Symbol,Symbol.iterator,WeakMap,WeakSet"
10
10
  crossorigin="anonymous"
11
11
  referrerpolicy="no-referrer"></script>
@@ -14,8 +14,8 @@
14
14
  </head>
15
15
  <body>
16
16
  <div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
17
- <h1 style='margin-bottom: 0.1em;'>Monster 3.0.0</h1>
18
- <div id="lastupdate" style='font-size:0.7em'>last update Fr 6. Jan 12:54:47 CET 2023</div>
17
+ <h1 style='margin-bottom: 0.1em;'>Monster 3.3.0</h1>
18
+ <div id="lastupdate" style='font-size:0.7em'>last update So 8. Jan 17:05:05 CET 2023</div>
19
19
  </div>
20
20
  <div id="mocks"></div>
21
21
  <div id="mocha"></div>