@schukai/monster 3.2.0 → 3.4.0
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.mjs → server/restapi.mjs} +63 -88
- package/source/data/datasource/server/webconnect.mjs +201 -0
- package/source/data/datasource/server.mjs +108 -0
- package/source/i18n/locale.mjs +1 -1
- package/source/monster.mjs +11 -3
- package/source/net/webconnect/message.mjs +55 -0
- package/source/{data/datasource/websocket.mjs → net/webconnect.mjs} +109 -148
- package/source/types/global.mjs +2 -2
- package/source/types/mediatype.mjs +1 -1
- package/source/types/observablequeue.mjs +110 -0
- package/source/types/proxyobserver.mjs +2 -2
- package/source/types/uniquequeue.mjs +9 -6
- package/source/types/version.mjs +1 -1
- package/test/cases/data/datasource/{restapi.mjs → server/restapi.mjs} +19 -13
- package/test/cases/data/datasource/server/websocket.mjs +194 -0
- package/test/cases/data/datasource/server.mjs +53 -0
- package/test/cases/monster.mjs +1 -1
- package/test/cases/net/webconnect/message.mjs +50 -0
- package/test/cases/net/webconnect.mjs +116 -0
- package/test/cases/types/observablequeue.mjs +17 -0
- package/test/cases/types/queue.mjs +4 -1
- package/test/web/import.js +6 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +891 -393
- package/test/cases/data/datasource/websocket.mjs +0 -107
package/README.md
CHANGED
@@ -73,7 +73,7 @@ We do try to work around some browser bugs, but on the whole we don't use polyfi
|
|
73
73
|
However, many functions can be mapped via [polyfill.io](https://polyfill.io/) and thus the compatibility can be increased.
|
74
74
|
|
75
75
|
```html
|
76
|
-
<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"
|
76
|
+
<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"
|
77
77
|
crossorigin="anonymous"
|
78
78
|
referrerpolicy="no-referrer"></script>
|
79
79
|
```
|
package/package.json
CHANGED
@@ -5,41 +5,37 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {internalSymbol,instanceSymbol} from "
|
9
|
-
import {isObject} from "
|
10
|
-
import {
|
11
|
-
import {Pathfinder} from "
|
12
|
-
import {Pipe} from "
|
13
|
-
import {WriteError} from "
|
8
|
+
import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
|
9
|
+
import {isObject} from "../../../types/is.mjs";
|
10
|
+
import {Server} from "../server.mjs";
|
11
|
+
import {Pathfinder} from "../../pathfinder.mjs";
|
12
|
+
import {Pipe} from "../../pipe.mjs";
|
13
|
+
import {WriteError} from "../restapi/writeerror.mjs";
|
14
14
|
|
15
15
|
export {RestAPI}
|
16
16
|
|
17
17
|
/**
|
18
18
|
* The RestAPI is a class that enables a REST API server.
|
19
19
|
*
|
20
|
-
* @externalExample ../../../example/data/storage/restapi.mjs
|
20
|
+
* @externalExample ../../../example/data/storage/restapi.mjs
|
21
21
|
* @license AGPLv3
|
22
22
|
* @since 1.22.0
|
23
23
|
* @copyright schukai GmbH
|
24
|
-
* @memberOf Monster.Data.Datasource
|
24
|
+
* @memberOf Monster.Data.Datasource.Server
|
25
25
|
* @summary The RestAPI is a class that binds a REST API server.
|
26
26
|
*/
|
27
|
-
class RestAPI extends
|
27
|
+
class RestAPI extends Server {
|
28
28
|
|
29
29
|
/**
|
30
30
|
*
|
31
|
-
* @param {Object} [
|
32
|
-
* @param {Object} [writeDefinition] An options object containing any custom settings that you want to apply to the write request.
|
31
|
+
* @param {Object} [options] options contains definitions for the datasource.
|
33
32
|
*/
|
34
|
-
constructor(
|
33
|
+
constructor(options) {
|
35
34
|
super();
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if (isObject(writeDefinition)) options.write = writeDefinition;
|
41
|
-
|
42
|
-
this.setOptions(options);
|
36
|
+
if (isObject(options)) {
|
37
|
+
this.setOptions(options);
|
38
|
+
}
|
43
39
|
|
44
40
|
}
|
45
41
|
|
@@ -49,9 +45,9 @@ class RestAPI extends Datasource {
|
|
49
45
|
* @since 2.1.0
|
50
46
|
*/
|
51
47
|
static get [instanceSymbol]() {
|
52
|
-
return Symbol.for("@schukai/monster/data/datasource/restapi");
|
53
|
-
}
|
54
|
-
|
48
|
+
return Symbol.for("@schukai/monster/data/datasource/server/restapi");
|
49
|
+
}
|
50
|
+
|
55
51
|
/**
|
56
52
|
* @property {Object} write={} Options
|
57
53
|
* @property {Object} write.init={} An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor}
|
@@ -64,9 +60,9 @@ class RestAPI extends Datasource {
|
|
64
60
|
* @property {Monster.Data.Datasource~exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
|
65
61
|
* @property {Object} write.report
|
66
62
|
* @property {String} write.report.path Path to validations
|
67
|
-
* @property {Object} write.sheathing
|
63
|
+
* @property {Object} write.sheathing
|
68
64
|
* @property {Object} write.sheathing.object Object to be wrapped
|
69
|
-
* @property {string} write.sheathing.path Path to the data
|
65
|
+
* @property {string} write.sheathing.path Path to the data
|
70
66
|
* @property {Object} read={} Options
|
71
67
|
* @property {Object} read.init={} An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor}
|
72
68
|
* @property {string} read.init.method=GET
|
@@ -124,45 +120,37 @@ class RestAPI extends Datasource {
|
|
124
120
|
let init = self.getOption('read.init');
|
125
121
|
if (!isObject(init)) init = {};
|
126
122
|
|
127
|
-
return
|
128
|
-
|
123
|
+
return new Promise((resolve, reject) => {
|
124
|
+
fetch(self.getOption('read.url'), init).then(resp => {
|
125
|
+
response = resp;
|
129
126
|
|
130
|
-
|
127
|
+
const acceptedStatus = self.getOption('read.acceptedStatus', [200]);
|
131
128
|
|
132
|
-
|
133
|
-
|
134
|
-
|
129
|
+
if (acceptedStatus.indexOf(resp.status) === -1) {
|
130
|
+
throw Error('the data cannot be read (response ' + resp.status + ')')
|
131
|
+
}
|
135
132
|
|
136
|
-
|
137
|
-
|
133
|
+
return resp.text()
|
134
|
+
}).then(body => {
|
138
135
|
|
139
|
-
|
136
|
+
let obj;
|
140
137
|
|
141
|
-
|
142
|
-
|
138
|
+
try {
|
139
|
+
obj = JSON.parse(body);
|
143
140
|
|
144
|
-
|
141
|
+
} catch (e) {
|
145
142
|
|
146
|
-
|
147
|
-
|
148
|
-
|
143
|
+
if (body.length > 100) {
|
144
|
+
body = body.substring(0, 97) + '...';
|
145
|
+
}
|
149
146
|
|
150
|
-
|
151
|
-
|
147
|
+
throw new Error('the response does not contain a valid json (actual: ' + body + ').');
|
148
|
+
}
|
152
149
|
|
153
|
-
|
154
|
-
|
155
|
-
|
150
|
+
self.set(self.transformServerPayload.call(self, obj));
|
151
|
+
resolve(response);
|
152
|
+
}).catch(reject);
|
156
153
|
|
157
|
-
for (const callback of self.getOption('read.mapping.callbacks')) {
|
158
|
-
pipe.setCallback(callback.constructor.name, callback);
|
159
|
-
}
|
160
|
-
|
161
|
-
obj = pipe.run(obj);
|
162
|
-
}
|
163
|
-
|
164
|
-
self.set(obj);
|
165
|
-
return response;
|
166
154
|
})
|
167
155
|
}
|
168
156
|
|
@@ -173,7 +161,6 @@ class RestAPI extends Datasource {
|
|
173
161
|
write() {
|
174
162
|
const self = this;
|
175
163
|
|
176
|
-
|
177
164
|
let init = self.getOption('write.init');
|
178
165
|
if (!isObject(init)) init = {};
|
179
166
|
if (typeof init['headers'] !== 'object') {
|
@@ -182,42 +169,28 @@ class RestAPI extends Datasource {
|
|
182
169
|
}
|
183
170
|
}
|
184
171
|
|
185
|
-
let obj = self.get();
|
186
|
-
let transformation = self.getOption('write.mapping.transformer');
|
187
|
-
if (transformation !== undefined) {
|
188
|
-
const pipe = new Pipe(transformation);
|
189
|
-
|
190
|
-
for (const callback of self.getOption('write.mapping.callbacks')) {
|
191
|
-
pipe.setCallback(callback.constructor.name, callback);
|
192
|
-
}
|
193
|
-
|
194
|
-
obj = pipe.run(obj);
|
195
|
-
}
|
196
|
-
|
197
|
-
let sheathingObject = self.getOption('write.sheathing.object');
|
198
|
-
let sheathingPath = self.getOption('write.sheathing.path');
|
199
|
-
let reportPath = self.getOption('write.report.path');
|
200
|
-
|
201
|
-
if (sheathingObject && sheathingPath) {
|
202
|
-
const sub = obj;
|
203
|
-
obj = sheathingObject;
|
204
|
-
(new Pathfinder(obj)).setVia(sheathingPath, sub);
|
205
|
-
}
|
206
|
-
|
172
|
+
let obj = self.prepareServerPayload(self.get());
|
207
173
|
init['body'] = JSON.stringify(obj);
|
208
174
|
|
209
|
-
return
|
175
|
+
return new Promise((resolve, reject) => {
|
176
|
+
fetch(self.getOption('write.url'), init).then(response => {
|
177
|
+
const acceptedStatus = self.getOption('write.acceptedStatus', [200, 201]);
|
210
178
|
|
211
|
-
|
212
|
-
|
213
|
-
|
179
|
+
if (acceptedStatus.indexOf(response.status) > -1) {
|
180
|
+
reject(response);
|
181
|
+
return;
|
182
|
+
}
|
214
183
|
|
215
|
-
|
184
|
+
response.text().then((body) => {
|
216
185
|
|
217
|
-
let obj, validation;
|
186
|
+
let obj = {}, validation = {};
|
218
187
|
try {
|
219
188
|
obj = JSON.parse(body);
|
220
|
-
|
189
|
+
|
190
|
+
if (reportPath) {
|
191
|
+
validation = (new Pathfinder(obj)).getVia(reportPath);
|
192
|
+
}
|
193
|
+
|
221
194
|
|
222
195
|
} catch (e) {
|
223
196
|
|
@@ -225,18 +198,20 @@ class RestAPI extends Datasource {
|
|
225
198
|
body = body.substring(0, 97) + '...';
|
226
199
|
}
|
227
200
|
|
228
|
-
|
201
|
+
reject(new Error('the response does not contain a valid json (actual: ' + body + ').'));
|
202
|
+
return;
|
229
203
|
}
|
230
204
|
|
231
|
-
|
205
|
+
reject(new WriteError('the data cannot be written (response ' + response.status + ')', response, validation))
|
206
|
+
return;
|
232
207
|
|
233
|
-
})
|
208
|
+
}).catch(reject);
|
234
209
|
|
235
210
|
|
236
|
-
}
|
211
|
+
}).catch(reject);
|
212
|
+
|
213
|
+
})
|
237
214
|
|
238
|
-
return response;
|
239
|
-
});
|
240
215
|
}
|
241
216
|
|
242
217
|
|
@@ -0,0 +1,201 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
|
3
|
+
* Node module: @schukai/monster
|
4
|
+
* This file is licensed under the AGPLv3 License.
|
5
|
+
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
|
+
*/
|
7
|
+
|
8
|
+
import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
|
9
|
+
import {isString, isObject} from "../../../types/is.mjs";
|
10
|
+
import {WebConnect as NetWebConnect} from "../../../net/webconnect.mjs";
|
11
|
+
import {Message} from "../../../net/webconnect/message.mjs";
|
12
|
+
import {Server} from "../server.mjs";
|
13
|
+
|
14
|
+
|
15
|
+
export {WebConnect}
|
16
|
+
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @private
|
20
|
+
* @type {Symbol}
|
21
|
+
*
|
22
|
+
* hint: this name is used in the tests. if you want to change it, please change it in the tests as well.
|
23
|
+
*/
|
24
|
+
const webConnectSymbol = Symbol("connection");
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
/**
|
29
|
+
* The RestAPI is a class that enables a REST API server.
|
30
|
+
*
|
31
|
+
* @externalExample ../../../example/data/storage/restapi.mjs
|
32
|
+
* @license AGPLv3
|
33
|
+
* @since 3.1.0
|
34
|
+
* @copyright schukai GmbH
|
35
|
+
* @memberOf Monster.Data.Datasource.Server
|
36
|
+
* @summary The LocalStorage class encapsulates the access to data objects.
|
37
|
+
*/
|
38
|
+
class WebConnect extends Server {
|
39
|
+
|
40
|
+
/**
|
41
|
+
*
|
42
|
+
* @param {Object} [options] options contains definitions for the datasource.
|
43
|
+
*/
|
44
|
+
constructor(options) {
|
45
|
+
super();
|
46
|
+
|
47
|
+
const self = this;
|
48
|
+
|
49
|
+
if (isString(options)) {
|
50
|
+
options = {url: options};
|
51
|
+
}
|
52
|
+
|
53
|
+
if (!isObject(options)) options = {};
|
54
|
+
this.setOptions(options);
|
55
|
+
this[webConnectSymbol] = new NetWebConnect({
|
56
|
+
url: self.getOption('url'),
|
57
|
+
connection: {
|
58
|
+
timeout: self.getOption('connection.timeout'),
|
59
|
+
reconnect: {
|
60
|
+
timeout: self.getOption('connection.reconnect.timeout'),
|
61
|
+
attempts: self.getOption('connection.reconnect.attempts'),
|
62
|
+
enabled: self.getOption('connection.reconnect.enabled')
|
63
|
+
}
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
*
|
70
|
+
* @returns {Promise}
|
71
|
+
*/
|
72
|
+
connect() {
|
73
|
+
return this[webConnectSymbol].connect();
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* @returns {boolean}
|
78
|
+
*/
|
79
|
+
isConnected() {
|
80
|
+
return this[webConnectSymbol].isConnected();
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* This method is called by the `instanceof` operator.
|
85
|
+
* @returns {symbol}
|
86
|
+
*/
|
87
|
+
static get [instanceSymbol]() {
|
88
|
+
return Symbol.for("@schukai/monster/data/datasource/server/webconnect");
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* @property {string} url=undefined Defines the resource that you wish to fetch.
|
93
|
+
* @property {Object} connection
|
94
|
+
* @property {Object} connection.timeout=5000 Defines the timeout for the connection.
|
95
|
+
* @property {Number} connection.reconnect.timeout The timeout in milliseconds for the reconnect.
|
96
|
+
* @property {Number} connection.reconnect.attempts The maximum number of reconnects.
|
97
|
+
* @property {Bool} connection.reconnect.enabled If the reconnect is enabled.
|
98
|
+
* @property {Object} write={} Options
|
99
|
+
* @property {Object} write.mapping the mapping is applied before writing.
|
100
|
+
* @property {String} write.mapping.transformer Transformer to select the appropriate entries
|
101
|
+
* @property {Monster.Data.Datasource~exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
|
102
|
+
* @property {Object} write.sheathing
|
103
|
+
* @property {Object} write.sheathing.object Object to be wrapped
|
104
|
+
* @property {string} write.sheathing.path Path to the data
|
105
|
+
* @property {Object} read={} Options
|
106
|
+
* @property {String} read.path Path to data
|
107
|
+
* @property {Object} read.mapping the mapping is applied after reading.
|
108
|
+
* @property {String} read.mapping.transformer Transformer to select the appropriate entries
|
109
|
+
* @property {Monster.Data.Datasource~exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
|
110
|
+
*/
|
111
|
+
get defaults() {
|
112
|
+
return Object.assign({}, super.defaults, {
|
113
|
+
url: undefined,
|
114
|
+
write: {
|
115
|
+
mapping: {
|
116
|
+
transformer: undefined,
|
117
|
+
callbacks: {}
|
118
|
+
},
|
119
|
+
sheathing: {
|
120
|
+
object: undefined,
|
121
|
+
path: undefined,
|
122
|
+
},
|
123
|
+
},
|
124
|
+
read: {
|
125
|
+
mapping: {
|
126
|
+
transformer: undefined,
|
127
|
+
callbacks: {}
|
128
|
+
},
|
129
|
+
path: undefined,
|
130
|
+
},
|
131
|
+
connection: {
|
132
|
+
timeout: 5000,
|
133
|
+
reconnect: {
|
134
|
+
timeout: 1000,
|
135
|
+
attempts: 1,
|
136
|
+
enabled: false,
|
137
|
+
}
|
138
|
+
}
|
139
|
+
});
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* This method closes the connection.
|
144
|
+
*
|
145
|
+
* @returns {Promise}
|
146
|
+
*/
|
147
|
+
close() {
|
148
|
+
return this[webConnectSymbol].close();
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @return {Promise}
|
153
|
+
*/
|
154
|
+
read() {
|
155
|
+
const self = this;
|
156
|
+
|
157
|
+
return new Promise((resolve, reject) => {
|
158
|
+
|
159
|
+
while (this[webConnectSymbol].dataReceived() === true) {
|
160
|
+
let obj = this[webConnectSymbol].poll();
|
161
|
+
if (!isObject(obj)) {
|
162
|
+
reject(new Error('The received data is not an object.'));
|
163
|
+
return;
|
164
|
+
}
|
165
|
+
|
166
|
+
if (!(obj instanceof Message)) {
|
167
|
+
reject(new Error('The received data is not a Message.'));
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
|
171
|
+
obj = obj.getData();
|
172
|
+
obj = self.transformServerPayload.call(self, obj);
|
173
|
+
self.set( obj);
|
174
|
+
}
|
175
|
+
|
176
|
+
resolve(self.get());
|
177
|
+
|
178
|
+
})
|
179
|
+
|
180
|
+
};
|
181
|
+
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @return {Promise}
|
185
|
+
*/
|
186
|
+
write() {
|
187
|
+
const self = this;
|
188
|
+
let obj = self.prepareServerPayload(self.get());
|
189
|
+
return self[webConnectSymbol].send(obj)
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* @return {RestAPI}
|
194
|
+
*/
|
195
|
+
getClone() {
|
196
|
+
const self = this;
|
197
|
+
return new WebConnect(self[internalSymbol].getRealSubject()['options']);
|
198
|
+
}
|
199
|
+
|
200
|
+
}
|
201
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright schukai GmbH and contributors 2022. All Rights Reserved.
|
3
|
+
* Node module: @schukai/monster
|
4
|
+
* This file is licensed under the AGPLv3 License.
|
5
|
+
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
|
+
*/
|
7
|
+
|
8
|
+
import {internalSymbol,instanceSymbol} from "../../constants.mjs";
|
9
|
+
import {isObject} from "../../types/is.mjs";
|
10
|
+
import {Datasource} from "../datasource.mjs";
|
11
|
+
import {Pathfinder} from "../pathfinder.mjs";
|
12
|
+
import {Pipe} from "../pipe.mjs";
|
13
|
+
|
14
|
+
export {Server}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Base class for all server datasources
|
18
|
+
*
|
19
|
+
* @license AGPLv3
|
20
|
+
* @since 3.4.0
|
21
|
+
* @copyright schukai GmbH
|
22
|
+
* @memberOf Monster.Data.Datasource
|
23
|
+
* @summary The Server class encapsulates the access to a server datasource
|
24
|
+
*/
|
25
|
+
class Server extends Datasource {
|
26
|
+
|
27
|
+
/**
|
28
|
+
* This method is called by the `instanceof` operator.
|
29
|
+
* @returns {symbol}
|
30
|
+
*/
|
31
|
+
static get [instanceSymbol]() {
|
32
|
+
return Symbol.for("@schukai/monster/data/datasource/server");
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
/**
|
37
|
+
* This prepares the data that comes from the server.
|
38
|
+
* Should not be called directly.
|
39
|
+
*
|
40
|
+
* @private
|
41
|
+
* @param {Object} payload
|
42
|
+
* @returns {Object}
|
43
|
+
*/
|
44
|
+
transformServerPayload(payload) {
|
45
|
+
const self = this;
|
46
|
+
payload = doTransform.call(self, 'read', payload);
|
47
|
+
|
48
|
+
const dataPath = self.getOption('read.path');
|
49
|
+
if (dataPath) {
|
50
|
+
payload = (new Pathfinder(payload)).getVia(dataPath);
|
51
|
+
}
|
52
|
+
|
53
|
+
return payload;
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* This prepares the data for writing and should not be called directly.
|
58
|
+
*
|
59
|
+
* @private
|
60
|
+
* @param {Object} payload
|
61
|
+
* @returns {Object}
|
62
|
+
*/
|
63
|
+
prepareServerPayload(payload) {
|
64
|
+
const self = this;
|
65
|
+
|
66
|
+
payload = doTransform.call(self, 'write', payload);
|
67
|
+
|
68
|
+
let sheathingObject = self.getOption('write.sheathing.object');
|
69
|
+
let sheathingPath = self.getOption('write.sheathing.path');
|
70
|
+
|
71
|
+
if (sheathingObject && sheathingPath) {
|
72
|
+
const sub = payload;
|
73
|
+
payload = sheathingObject;
|
74
|
+
(new Pathfinder(payload)).setVia(sheathingPath, sub);
|
75
|
+
}
|
76
|
+
|
77
|
+
return payload;
|
78
|
+
}
|
79
|
+
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
/**
|
84
|
+
*
|
85
|
+
* @param self
|
86
|
+
* @param obj
|
87
|
+
* @returns {*}
|
88
|
+
*/
|
89
|
+
function doTransform(type, obj) {
|
90
|
+
const self = this;
|
91
|
+
let transformation = self.getOption(type + '.mapping.transformer');
|
92
|
+
if (transformation !== undefined) {
|
93
|
+
const pipe = new Pipe(transformation);
|
94
|
+
const callbacks = self.getOption(type + '.mapping.callbacks')
|
95
|
+
|
96
|
+
if (isObject(callbacks)) {
|
97
|
+
for (const key in callbacks) {
|
98
|
+
if (callbacks.hasOwnProperty(key) && typeof callbacks[key] === 'function') {
|
99
|
+
pipe.setCallback(key, callbacks[key]);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
obj = pipe.run(obj);
|
105
|
+
}
|
106
|
+
|
107
|
+
return obj;
|
108
|
+
}
|
package/source/i18n/locale.mjs
CHANGED
@@ -191,7 +191,7 @@ class Locale extends Base {
|
|
191
191
|
*
|
192
192
|
* ```
|
193
193
|
* <script type="module">
|
194
|
-
* import {Monster} from '@schukai/monster/source
|
194
|
+
* import {Monster} from '@schukai/monster/source/monster.mjs';
|
195
195
|
* new Monster.I18n.createLocale()
|
196
196
|
* </script>
|
197
197
|
* ```
|
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"
|
193
|
+
export {RestAPI} from "./data/datasource/server/restapi.mjs"
|
194
|
+
export {WebConnect} from "./data/datasource/server/webconnect.mjs"
|
188
195
|
export {WriteError} from "./data/datasource/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
|
/**
|