@schukai/monster 3.4.2 → 3.7.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.
- package/example/i18n/providers/embed.mjs +5 -0
- package/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +17 -21
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +40 -67
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +30 -48
- package/source/dom/locale.mjs +41 -10
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +40 -42
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +115 -0
- package/source/i18n/providers/fetch.mjs +33 -38
- package/source/i18n/translations.mjs +16 -20
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- package/test/cases/dom/locale.mjs +15 -0
- package/test/cases/i18n/providers/embed.mjs +72 -0
- package/test/cases/monster.mjs +1 -1
|
@@ -5,13 +5,13 @@
|
|
|
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 "../../../../constants.mjs";
|
|
8
|
+
import { internalSymbol, instanceSymbol } from "../../../../constants.mjs";
|
|
9
9
|
|
|
10
|
-
export {WriteError}
|
|
10
|
+
export { WriteError };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Error message for API requests with extension of request and validation.
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @license AGPLv3
|
|
16
16
|
* @since 1.24.0
|
|
17
17
|
* @copyright schukai GmbH
|
|
@@ -28,7 +28,7 @@ class WriteError extends Error {
|
|
|
28
28
|
super(message);
|
|
29
29
|
this[internalSymbol] = {
|
|
30
30
|
response: response,
|
|
31
|
-
validation: validation
|
|
31
|
+
validation: validation,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -45,13 +45,13 @@ class WriteError extends Error {
|
|
|
45
45
|
* @return {Response}
|
|
46
46
|
*/
|
|
47
47
|
getResponse() {
|
|
48
|
-
return this[internalSymbol][
|
|
48
|
+
return this[internalSymbol]["response"];
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @return {Object}
|
|
53
53
|
*/
|
|
54
54
|
getValidation() {
|
|
55
|
-
return this[internalSymbol][
|
|
55
|
+
return this[internalSymbol]["validation"];
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -5,14 +5,14 @@
|
|
|
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 "../../../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";
|
|
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
|
-
export {RestAPI}
|
|
15
|
+
export { RestAPI };
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The RestAPI is a class that enables a REST API server.
|
|
@@ -25,7 +25,6 @@ export {RestAPI}
|
|
|
25
25
|
* @summary The RestAPI is a class that binds a REST API server.
|
|
26
26
|
*/
|
|
27
27
|
class RestAPI extends Server {
|
|
28
|
-
|
|
29
28
|
/**
|
|
30
29
|
*
|
|
31
30
|
* @param {Object} [options] options contains definitions for the datasource.
|
|
@@ -36,7 +35,6 @@ class RestAPI extends Server {
|
|
|
36
35
|
if (isObject(options)) {
|
|
37
36
|
this.setOptions(options);
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
/**
|
|
@@ -76,34 +74,33 @@ class RestAPI extends Server {
|
|
|
76
74
|
return Object.assign({}, super.defaults, {
|
|
77
75
|
write: {
|
|
78
76
|
init: {
|
|
79
|
-
method:
|
|
77
|
+
method: "POST",
|
|
80
78
|
},
|
|
81
79
|
acceptedStatus: [200, 201],
|
|
82
80
|
url: undefined,
|
|
83
81
|
mapping: {
|
|
84
82
|
transformer: undefined,
|
|
85
|
-
callbacks: []
|
|
83
|
+
callbacks: [],
|
|
86
84
|
},
|
|
87
85
|
sheathing: {
|
|
88
86
|
object: undefined,
|
|
89
87
|
path: undefined,
|
|
90
88
|
},
|
|
91
89
|
report: {
|
|
92
|
-
path: undefined
|
|
93
|
-
}
|
|
90
|
+
path: undefined,
|
|
91
|
+
},
|
|
94
92
|
},
|
|
95
93
|
read: {
|
|
96
94
|
init: {
|
|
97
|
-
method:
|
|
95
|
+
method: "GET",
|
|
98
96
|
},
|
|
99
97
|
acceptedStatus: [200],
|
|
100
98
|
url: undefined,
|
|
101
99
|
mapping: {
|
|
102
100
|
transformer: undefined,
|
|
103
|
-
callbacks: []
|
|
101
|
+
callbacks: [],
|
|
104
102
|
},
|
|
105
103
|
},
|
|
106
|
-
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
106
|
|
|
@@ -114,17 +111,15 @@ class RestAPI extends Server {
|
|
|
114
111
|
* @throws {Error} the data cannot be read
|
|
115
112
|
*/
|
|
116
113
|
read() {
|
|
117
|
-
|
|
118
114
|
const self = this;
|
|
119
115
|
|
|
120
|
-
let init = self.getOption(
|
|
116
|
+
let init = self.getOption("read.init");
|
|
121
117
|
if (!isObject(init)) init = {};
|
|
122
|
-
if (!init[
|
|
118
|
+
if (!init["method"]) init["method"] = "GET";
|
|
123
119
|
|
|
124
|
-
return fetchData.call(this,
|
|
120
|
+
return fetchData.call(this, "read", (obj) => {
|
|
125
121
|
self.set(self.transformServerPayload.call(self, obj));
|
|
126
122
|
});
|
|
127
|
-
|
|
128
123
|
}
|
|
129
124
|
|
|
130
125
|
/**
|
|
@@ -132,76 +127,67 @@ class RestAPI extends Server {
|
|
|
132
127
|
* @throws {WriteError} the data cannot be written
|
|
133
128
|
*/
|
|
134
129
|
write() {
|
|
135
|
-
|
|
136
130
|
const self = this;
|
|
137
131
|
|
|
138
|
-
let init = self.getOption(
|
|
132
|
+
let init = self.getOption("write.init");
|
|
139
133
|
if (!isObject(init)) init = {};
|
|
140
|
-
if (typeof init[
|
|
141
|
-
init[
|
|
142
|
-
|
|
143
|
-
}
|
|
134
|
+
if (typeof init["headers"] !== "object") {
|
|
135
|
+
init["headers"] = {
|
|
136
|
+
"Content-Type": "application/json",
|
|
137
|
+
};
|
|
144
138
|
}
|
|
145
|
-
if (!init[
|
|
139
|
+
if (!init["method"]) init["method"] = "POST";
|
|
146
140
|
|
|
147
141
|
let obj = self.prepareServerPayload(self.get());
|
|
148
|
-
init[
|
|
142
|
+
init["body"] = JSON.stringify(obj);
|
|
149
143
|
|
|
150
|
-
return fetchData.call(this, init,
|
|
144
|
+
return fetchData.call(this, init, "write");
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
|
|
154
147
|
/**
|
|
155
148
|
* @return {RestAPI}
|
|
156
149
|
*/
|
|
157
150
|
getClone() {
|
|
158
151
|
const self = this;
|
|
159
|
-
return new RestAPI(
|
|
152
|
+
return new RestAPI(
|
|
153
|
+
self[internalSymbol].getRealSubject()["options"].read,
|
|
154
|
+
self[internalSymbol].getRealSubject()["options"].write,
|
|
155
|
+
);
|
|
160
156
|
}
|
|
161
|
-
|
|
162
157
|
}
|
|
163
158
|
|
|
164
|
-
|
|
165
159
|
function fetchData(init, key, callback) {
|
|
166
|
-
|
|
167
160
|
const self = this;
|
|
168
161
|
let response;
|
|
169
162
|
|
|
163
|
+
return fetch(self.getOption(`${key}.url`), init)
|
|
164
|
+
.then((resp) => {
|
|
165
|
+
response = resp;
|
|
170
166
|
|
|
171
|
-
|
|
172
|
-
response = resp;
|
|
173
|
-
|
|
174
|
-
const acceptedStatus = self.getOption(key + '.acceptedStatus', [200]);
|
|
167
|
+
const acceptedStatus = self.getOption(`${key}.acceptedStatus`, [200]);
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return resp.text()
|
|
181
|
-
}).then(body => {
|
|
182
|
-
|
|
183
|
-
let obj;
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
obj = JSON.parse(body);
|
|
187
|
-
|
|
188
|
-
} catch (e) {
|
|
189
|
-
|
|
190
|
-
if (body.length > 100) {
|
|
191
|
-
body = body.substring(0, 97) + '...';
|
|
169
|
+
if (acceptedStatus.indexOf(resp.status) === -1) {
|
|
170
|
+
throw Error(`the data cannot be ${key} (response ${resp.status})`);
|
|
192
171
|
}
|
|
193
172
|
|
|
194
|
-
|
|
195
|
-
}
|
|
173
|
+
return resp.text();
|
|
174
|
+
})
|
|
175
|
+
.then((body) => {
|
|
176
|
+
let obj;
|
|
196
177
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
178
|
+
try {
|
|
179
|
+
obj = JSON.parse(body);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
if (body.length > 100) {
|
|
182
|
+
body = `${body.substring(0, 97)}...`;
|
|
183
|
+
}
|
|
203
184
|
|
|
185
|
+
throw new Error(`the response does not contain a valid json (actual: ${body}).`);
|
|
186
|
+
}
|
|
204
187
|
|
|
188
|
+
if (callback && isFunction(callback)) {
|
|
189
|
+
callback(obj);
|
|
190
|
+
}
|
|
191
|
+
return response;
|
|
192
|
+
});
|
|
205
193
|
}
|
|
206
|
-
|
|
207
|
-
|
|
@@ -5,13 +5,13 @@
|
|
|
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 "../../../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";
|
|
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
13
|
|
|
14
|
-
export {WebConnect}
|
|
14
|
+
export { WebConnect };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @private
|
|
@@ -21,8 +21,6 @@ export {WebConnect}
|
|
|
21
21
|
*/
|
|
22
22
|
const webConnectSymbol = Symbol("connection");
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
/**
|
|
27
25
|
* The RestAPI is a class that enables a REST API server.
|
|
28
26
|
*
|
|
@@ -34,32 +32,31 @@ const webConnectSymbol = Symbol("connection");
|
|
|
34
32
|
* @summary The LocalStorage class encapsulates the access to data objects.
|
|
35
33
|
*/
|
|
36
34
|
class WebConnect extends Server {
|
|
37
|
-
|
|
38
35
|
/**
|
|
39
36
|
*
|
|
40
37
|
* @param {Object} [options] options contains definitions for the datasource.
|
|
41
38
|
*/
|
|
42
39
|
constructor(options) {
|
|
43
40
|
super();
|
|
44
|
-
|
|
41
|
+
|
|
45
42
|
const self = this;
|
|
46
43
|
|
|
47
44
|
if (isString(options)) {
|
|
48
|
-
options = {url: options};
|
|
45
|
+
options = { url: options };
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
if (!isObject(options)) options = {};
|
|
52
49
|
this.setOptions(options);
|
|
53
50
|
this[webConnectSymbol] = new NetWebConnect({
|
|
54
|
-
url: self.getOption(
|
|
51
|
+
url: self.getOption("url"),
|
|
55
52
|
connection: {
|
|
56
|
-
timeout: self.getOption(
|
|
53
|
+
timeout: self.getOption("connection.timeout"),
|
|
57
54
|
reconnect: {
|
|
58
|
-
timeout: self.getOption(
|
|
59
|
-
attempts: self.getOption(
|
|
60
|
-
enabled: self.getOption(
|
|
61
|
-
}
|
|
62
|
-
}
|
|
55
|
+
timeout: self.getOption("connection.reconnect.timeout"),
|
|
56
|
+
attempts: self.getOption("connection.reconnect.attempts"),
|
|
57
|
+
enabled: self.getOption("connection.reconnect.enabled"),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
63
60
|
});
|
|
64
61
|
}
|
|
65
62
|
|
|
@@ -112,7 +109,7 @@ class WebConnect extends Server {
|
|
|
112
109
|
write: {
|
|
113
110
|
mapping: {
|
|
114
111
|
transformer: undefined,
|
|
115
|
-
callbacks: {}
|
|
112
|
+
callbacks: {},
|
|
116
113
|
},
|
|
117
114
|
sheathing: {
|
|
118
115
|
object: undefined,
|
|
@@ -122,7 +119,7 @@ class WebConnect extends Server {
|
|
|
122
119
|
read: {
|
|
123
120
|
mapping: {
|
|
124
121
|
transformer: undefined,
|
|
125
|
-
callbacks: {}
|
|
122
|
+
callbacks: {},
|
|
126
123
|
},
|
|
127
124
|
path: undefined,
|
|
128
125
|
},
|
|
@@ -132,8 +129,8 @@ class WebConnect extends Server {
|
|
|
132
129
|
timeout: 1000,
|
|
133
130
|
attempts: 1,
|
|
134
131
|
enabled: false,
|
|
135
|
-
}
|
|
136
|
-
}
|
|
132
|
+
},
|
|
133
|
+
},
|
|
137
134
|
});
|
|
138
135
|
}
|
|
139
136
|
|
|
@@ -153,30 +150,26 @@ class WebConnect extends Server {
|
|
|
153
150
|
const self = this;
|
|
154
151
|
|
|
155
152
|
return new Promise((resolve, reject) => {
|
|
156
|
-
|
|
157
153
|
while (this[webConnectSymbol].dataReceived() === true) {
|
|
158
154
|
let obj = this[webConnectSymbol].poll();
|
|
159
155
|
if (!isObject(obj)) {
|
|
160
|
-
reject(new Error(
|
|
156
|
+
reject(new Error("The received data is not an object."));
|
|
161
157
|
return;
|
|
162
158
|
}
|
|
163
159
|
|
|
164
160
|
if (!(obj instanceof Message)) {
|
|
165
|
-
reject(new Error(
|
|
161
|
+
reject(new Error("The received data is not a Message."));
|
|
166
162
|
return;
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
obj = obj.getData();
|
|
170
166
|
obj = self.transformServerPayload.call(self, obj);
|
|
171
|
-
self.set(
|
|
167
|
+
self.set(obj);
|
|
172
168
|
}
|
|
173
169
|
|
|
174
170
|
resolve(self.get());
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
179
|
-
|
|
171
|
+
});
|
|
172
|
+
}
|
|
180
173
|
|
|
181
174
|
/**
|
|
182
175
|
* @return {Promise}
|
|
@@ -184,7 +177,7 @@ class WebConnect extends Server {
|
|
|
184
177
|
write() {
|
|
185
178
|
const self = this;
|
|
186
179
|
let obj = self.prepareServerPayload(self.get());
|
|
187
|
-
return self[webConnectSymbol].send(obj)
|
|
180
|
+
return self[webConnectSymbol].send(obj);
|
|
188
181
|
}
|
|
189
182
|
|
|
190
183
|
/**
|
|
@@ -192,8 +185,6 @@ class WebConnect extends Server {
|
|
|
192
185
|
*/
|
|
193
186
|
getClone() {
|
|
194
187
|
const self = this;
|
|
195
|
-
return new WebConnect(self[internalSymbol].getRealSubject()[
|
|
188
|
+
return new WebConnect(self[internalSymbol].getRealSubject()["options"]);
|
|
196
189
|
}
|
|
197
|
-
|
|
198
190
|
}
|
|
199
|
-
|
|
@@ -5,13 +5,13 @@
|
|
|
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 "../../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";
|
|
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
13
|
|
|
14
|
-
export {Server}
|
|
14
|
+
export { Server };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Base class for all server datasources
|
|
@@ -23,7 +23,6 @@ export {Server}
|
|
|
23
23
|
* @summary The Server class encapsulates the access to a server datasource
|
|
24
24
|
*/
|
|
25
25
|
class Server extends Datasource {
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* This method is called by the `instanceof` operator.
|
|
29
28
|
* @returns {symbol}
|
|
@@ -32,7 +31,6 @@ class Server extends Datasource {
|
|
|
32
31
|
return Symbol.for("@schukai/monster/data/datasource/server");
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
|
|
36
34
|
/**
|
|
37
35
|
* This prepares the data that comes from the server.
|
|
38
36
|
* Should not be called directly.
|
|
@@ -43,11 +41,11 @@ class Server extends Datasource {
|
|
|
43
41
|
*/
|
|
44
42
|
transformServerPayload(payload) {
|
|
45
43
|
const self = this;
|
|
46
|
-
payload = doTransform.call(self,
|
|
44
|
+
payload = doTransform.call(self, "read", payload);
|
|
47
45
|
|
|
48
|
-
const dataPath = self.getOption(
|
|
46
|
+
const dataPath = self.getOption("read.path");
|
|
49
47
|
if (dataPath) {
|
|
50
|
-
payload =
|
|
48
|
+
payload = new Pathfinder(payload).getVia(dataPath);
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
return payload;
|
|
@@ -63,39 +61,37 @@ class Server extends Datasource {
|
|
|
63
61
|
prepareServerPayload(payload) {
|
|
64
62
|
const self = this;
|
|
65
63
|
|
|
66
|
-
payload = doTransform.call(self,
|
|
64
|
+
payload = doTransform.call(self, "write", payload);
|
|
67
65
|
|
|
68
|
-
let sheathingObject = self.getOption(
|
|
69
|
-
let sheathingPath = self.getOption(
|
|
66
|
+
let sheathingObject = self.getOption("write.sheathing.object");
|
|
67
|
+
let sheathingPath = self.getOption("write.sheathing.path");
|
|
70
68
|
|
|
71
69
|
if (sheathingObject && sheathingPath) {
|
|
72
70
|
const sub = payload;
|
|
73
71
|
payload = sheathingObject;
|
|
74
|
-
|
|
72
|
+
new Pathfinder(payload).setVia(sheathingPath, sub);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
return payload;
|
|
78
76
|
}
|
|
79
|
-
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
|
|
83
79
|
/**
|
|
84
|
-
*
|
|
80
|
+
* @private
|
|
85
81
|
* @param self
|
|
86
82
|
* @param obj
|
|
87
83
|
* @returns {*}
|
|
88
84
|
*/
|
|
89
85
|
function doTransform(type, obj) {
|
|
90
86
|
const self = this;
|
|
91
|
-
let transformation = self.getOption(type
|
|
87
|
+
let transformation = self.getOption(`${type}.mapping.transformer`);
|
|
92
88
|
if (transformation !== undefined) {
|
|
93
89
|
const pipe = new Pipe(transformation);
|
|
94
|
-
const callbacks = self.getOption(type
|
|
90
|
+
const callbacks = self.getOption(`${type}.mapping.callbacks`);
|
|
95
91
|
|
|
96
92
|
if (isObject(callbacks)) {
|
|
97
93
|
for (const key in callbacks) {
|
|
98
|
-
if (callbacks.hasOwnProperty(key) && typeof callbacks[key] ===
|
|
94
|
+
if (callbacks.hasOwnProperty(key) && typeof callbacks[key] === "function") {
|
|
99
95
|
pipe.setCallback(key, callbacks[key]);
|
|
100
96
|
}
|
|
101
97
|
}
|
|
@@ -5,16 +5,16 @@
|
|
|
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 "../../../constants.mjs";
|
|
9
|
-
import {getGlobalObject} from "../../../types/global.mjs";
|
|
10
|
-
import {Datasource} from "../../datasource.mjs";
|
|
11
|
-
import {Storage, storageObjectSymbol} from "../storage.mjs";
|
|
8
|
+
import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
|
|
9
|
+
import { getGlobalObject } from "../../../types/global.mjs";
|
|
10
|
+
import { Datasource } from "../../datasource.mjs";
|
|
11
|
+
import { Storage, storageObjectSymbol } from "../storage.mjs";
|
|
12
12
|
|
|
13
|
-
export {LocalStorage}
|
|
13
|
+
export { LocalStorage };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The LocalStorage Datasource provides a data store in the browser localStorage.
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* @license AGPLv3
|
|
19
19
|
* @since 1.22.0
|
|
20
20
|
* @copyright schukai GmbH
|
|
@@ -22,14 +22,13 @@ export {LocalStorage}
|
|
|
22
22
|
* @summary The LocalStorage class encapsulates the access to data objects.
|
|
23
23
|
*/
|
|
24
24
|
class LocalStorage extends Storage {
|
|
25
|
-
|
|
26
25
|
/**
|
|
27
26
|
* @throws {Error} this method must be implemented by derived classes.
|
|
28
27
|
* @return {external:localStorage}
|
|
29
28
|
* @private
|
|
30
29
|
*/
|
|
31
30
|
[storageObjectSymbol]() {
|
|
32
|
-
return getGlobalObject(
|
|
31
|
+
return getGlobalObject("localStorage");
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/**
|
|
@@ -47,8 +46,6 @@ class LocalStorage extends Storage {
|
|
|
47
46
|
*/
|
|
48
47
|
getClone() {
|
|
49
48
|
const self = this;
|
|
50
|
-
return new LocalStorage(self[internalSymbol].getRealSubject()[
|
|
49
|
+
return new LocalStorage(self[internalSymbol].getRealSubject()["options"].key);
|
|
51
50
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
51
|
}
|
|
@@ -5,12 +5,12 @@
|
|
|
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 "../../../constants.mjs";
|
|
9
|
-
import {getGlobalObject} from "../../../types/global.mjs";
|
|
10
|
-
import {Datasource} from "../../datasource.mjs";
|
|
11
|
-
import {Storage, storageObjectSymbol} from "../storage.mjs";
|
|
8
|
+
import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
|
|
9
|
+
import { getGlobalObject } from "../../../types/global.mjs";
|
|
10
|
+
import { Datasource } from "../../datasource.mjs";
|
|
11
|
+
import { Storage, storageObjectSymbol } from "../storage.mjs";
|
|
12
12
|
|
|
13
|
-
export {SessionStorage}
|
|
13
|
+
export { SessionStorage };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The SessionStorage class provides a data source that uses the SessionStorage API on the client.
|
|
@@ -22,14 +22,13 @@ export {SessionStorage}
|
|
|
22
22
|
* @summary The LocalStorage class encapsulates the access to data objects.
|
|
23
23
|
*/
|
|
24
24
|
class SessionStorage extends Storage {
|
|
25
|
-
|
|
26
25
|
/**
|
|
27
26
|
* @throws {Error} this method must be implemented by derived classes.
|
|
28
27
|
* @return {external:sessionStorage}
|
|
29
28
|
* @private
|
|
30
29
|
*/
|
|
31
30
|
[storageObjectSymbol]() {
|
|
32
|
-
return getGlobalObject(
|
|
31
|
+
return getGlobalObject("sessionStorage");
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
/**
|
|
@@ -43,12 +42,11 @@ class SessionStorage extends Storage {
|
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Create Clone
|
|
46
|
-
*
|
|
45
|
+
*
|
|
47
46
|
* @return {SessionStorage}
|
|
48
47
|
*/
|
|
49
48
|
getClone() {
|
|
50
49
|
const self = this;
|
|
51
|
-
return new SessionStorage(self[internalSymbol].getRealSubject()[
|
|
50
|
+
return new SessionStorage(self[internalSymbol].getRealSubject()["options"].key);
|
|
52
51
|
}
|
|
53
|
-
|
|
54
52
|
}
|