@schukai/monster 3.3.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/package.json +1 -1
- package/source/data/datasource/{restapi → server}/namespace.mjs +2 -2
- package/source/data/datasource/server/restapi/namespace.mjs +13 -0
- package/source/data/datasource/{restapi → server/restapi}/writeerror.mjs +3 -3
- package/source/data/datasource/{restapi.mjs → server/restapi.mjs} +62 -87
- package/source/data/datasource/{websocket.mjs → server/webconnect.mjs} +11 -130
- package/source/data/datasource/server.mjs +108 -0
- package/source/i18n/locale.mjs +1 -1
- package/source/monster.mjs +12 -4
- package/source/types/global.mjs +2 -2
- package/source/types/mediatype.mjs +1 -1
- package/source/types/version.mjs +1 -1
- package/test/cases/data/datasource/{restapi.mjs → server/restapi.mjs} +19 -13
- package/test/cases/data/datasource/{websocket.mjs → server/websocket.mjs} +10 -8
- package/test/cases/data/datasource/server.mjs +53 -0
- package/test/cases/monster.mjs +1 -1
- package/test/cases/net/webconnect.mjs +1 -1
- package/test/web/import.js +6 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +892 -394
package/source/monster.mjs
CHANGED
@@ -31,7 +31,7 @@ export {Stylesheet} from "./dom/resource/link/stylesheet.mjs"
|
|
31
31
|
export {Data} from "./dom/resource/data.mjs"
|
32
32
|
export {Link} from "./dom/resource/link.mjs"
|
33
33
|
export {Script} from "./dom/resource/script.mjs"
|
34
|
-
export {Updater} from "./dom/updater.mjs"
|
34
|
+
export {Updater, addObjectWithUpdaterToElement} from "./dom/updater.mjs"
|
35
35
|
export {CustomControl} from "./dom/customcontrol.mjs"
|
36
36
|
export {getLocaleOfDocument} from "./dom/locale.mjs"
|
37
37
|
export {Theme, getDocumentTheme} from "./dom/theme.mjs"
|
@@ -91,6 +91,7 @@ export {
|
|
91
91
|
ATTRIBUTE_EXPORTPARTS,
|
92
92
|
ATTRIBUTE_HIDDEN,
|
93
93
|
objectUpdaterLinkSymbol,
|
94
|
+
customElementUpdaterLinkSymbol
|
94
95
|
|
95
96
|
} from "./dom/constants.mjs"
|
96
97
|
export {
|
@@ -127,14 +128,18 @@ export {Locale, parseLocale} from "./i18n/locale.mjs"
|
|
127
128
|
export {Formatter as I18nFormatter} from "./i18n/formatter.mjs"
|
128
129
|
export {Fetch} from "./i18n/providers/fetch.mjs"
|
129
130
|
export {Provider} from "./i18n/provider.mjs"
|
131
|
+
export {Message} from "./net/webconnect/message.mjs"
|
132
|
+
export {WebConnect as NetWebConnect} from "./net/webconnect.mjs"
|
130
133
|
export {
|
131
134
|
internalSymbol,
|
132
|
-
internalStateSymbol
|
135
|
+
internalStateSymbol,
|
136
|
+
instanceSymbol
|
133
137
|
} from "./constants.mjs"
|
134
138
|
export {MediaType, parseMediaType} from "./types/mediatype.mjs"
|
135
139
|
export {typeOf} from "./types/typeof.mjs"
|
136
140
|
export {ObserverList} from "./types/observerlist.mjs"
|
137
141
|
export {RandomID} from "./types/randomid.mjs"
|
142
|
+
export {ObservableQueue} from "./types/observablequeue.mjs"
|
138
143
|
export {UUID} from "./types/uuid.mjs"
|
139
144
|
export {Observer} from "./types/observer.mjs"
|
140
145
|
export {TokenList} from "./types/tokenlist.mjs"
|
@@ -182,13 +187,16 @@ export {buildTree} from "./data/buildtree.mjs"
|
|
182
187
|
export {Transformer} from "./data/transformer.mjs"
|
183
188
|
export {Pathfinder, DELIMITER, WILDCARD} from "./data/pathfinder.mjs"
|
184
189
|
export {diff} from "./data/diff.mjs"
|
185
|
-
export {
|
190
|
+
export {Server} from "./data/datasource/server.mjs"
|
186
191
|
export {SessionStorage} from "./data/datasource/storage/sessionstorage.mjs"
|
187
192
|
export {LocalStorage} from "./data/datasource/storage/localstorage.mjs"
|
188
|
-
export {
|
193
|
+
export {RestAPI} from "./data/datasource/server/restapi.mjs"
|
194
|
+
export {WebConnect} from "./data/datasource/server/webconnect.mjs"
|
195
|
+
export {WriteError} from "./data/datasource/server/restapi/writeerror.mjs"
|
189
196
|
export {Storage, storageObjectSymbol} from "./data/datasource/storage.mjs"
|
190
197
|
export {random} from "./math/random.mjs"
|
191
198
|
|
199
|
+
|
192
200
|
export {Monster}
|
193
201
|
|
194
202
|
/**
|
package/source/types/global.mjs
CHANGED
@@ -84,7 +84,7 @@ function getGlobal() {
|
|
84
84
|
*
|
85
85
|
* ```
|
86
86
|
* <script type="module">
|
87
|
-
* import {Monster} from '
|
87
|
+
* import {Monster} from '@schukai/monster/source/monster.mjs';
|
88
88
|
* Monster.Types.getGlobalObject('document')
|
89
89
|
* // ↦ { }
|
90
90
|
* </script>
|
@@ -124,7 +124,7 @@ function getGlobalObject(name) {
|
|
124
124
|
*
|
125
125
|
* ```
|
126
126
|
* <script type="module">
|
127
|
-
* import {Monster} from '
|
127
|
+
* import {Monster} from '@schukai/monster/source/monster.mjs';
|
128
128
|
* console.log(Monster.Types.getGlobalFunction('parseInt')) // ↦ f parseInt() { }
|
129
129
|
* </script>
|
130
130
|
* ```
|
@@ -134,7 +134,7 @@ class MediaType extends Base {
|
|
134
134
|
*
|
135
135
|
* ```
|
136
136
|
* <script type="module">
|
137
|
-
* import {Monster} from '@schukai/monster/source
|
137
|
+
* import {Monster} from '@schukai/monster/source/monster.mjs';
|
138
138
|
* console.log(Monster.Types.parseMediaType())
|
139
139
|
* </script>
|
140
140
|
* ```
|
package/source/types/version.mjs
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
import {expect} from "chai"
|
4
|
-
import {RestAPI} from "
|
5
|
-
import {validateObject} from "
|
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 (
|
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
|
29
|
-
|
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'},
|
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
|
-
|
58
|
-
|
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 {
|
3
|
-
import {initWebSocket} from "
|
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
|
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
|
50
|
+
ds = new WebConnect(testUrl)
|
49
51
|
const clone = ds.getClone()
|
50
52
|
|
51
|
-
expect(clone).to.be.an.instanceof(
|
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
|
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
|
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
|
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
|
+
});
|
package/test/cases/monster.mjs
CHANGED
@@ -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?.
|
29
|
+
if (typeof ds[sym]?.socket?.terminate === 'function') {
|
30
30
|
ds[sym]?.socket?.['terminate']()
|
31
31
|
}
|
32
32
|
}
|
package/test/web/import.js
CHANGED
@@ -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/
|
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/
|
84
|
+
import "../cases/data/datasource/server/restapi.mjs";
|
85
|
+
import "../cases/data/datasource/server/websocket.mjs";
|
82
86
|
import "../cases/math/random.mjs";
|
package/test/web/test.html
CHANGED
@@ -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.
|
18
|
-
<div id="lastupdate" style='font-size:0.7em'>last update
|
17
|
+
<h1 style='margin-bottom: 0.1em;'>Monster 3.4.0</h1>
|
18
|
+
<div id="lastupdate" style='font-size:0.7em'>last update So 8. Jan 17:17:24 CET 2023</div>
|
19
19
|
</div>
|
20
20
|
<div id="mocks"></div>
|
21
21
|
<div id="mocha"></div>
|