@schukai/monster 1.23.0 → 1.26.1
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/CHANGELOG +53 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1684 -696
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +87 -20
- package/source/data/datasource/storage/localstorage.js +4 -10
- package/source/data/datasource/storage/sessionstorage.js +4 -12
- package/source/data/datasource/storage.js +7 -14
- package/source/data/datasource.js +55 -17
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +121 -92
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +52 -12
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +47 -33
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +4 -5
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +14 -16
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +28 -4
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +7 -7
|
@@ -4,25 +4,20 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
|
8
8
|
import {assignToNamespace, Monster} from '../../namespace.js';
|
|
9
9
|
import {isObject} from "../../types/is.js";
|
|
10
10
|
import {Datasource} from "../datasource.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @private
|
|
16
|
-
* @type {symbol}
|
|
17
|
-
*/
|
|
18
|
-
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
11
|
+
import {Pathfinder} from "../pathfinder.js";
|
|
12
|
+
import {Pipe} from "../pipe.js";
|
|
13
|
+
import {WriteError} from "./restapi/writeerror.js";
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.RestAPI()`.
|
|
22
17
|
*
|
|
23
18
|
* ```
|
|
24
19
|
* <script type="module">
|
|
25
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
26
21
|
* Monster.Data.Datasource.RestAPI()
|
|
27
22
|
* </script>
|
|
28
23
|
* ```
|
|
@@ -31,14 +26,14 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
31
26
|
*
|
|
32
27
|
* ```
|
|
33
28
|
* <script type="module">
|
|
34
|
-
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
29
|
+
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/restapi.js';
|
|
35
30
|
* new RestAPI()
|
|
36
31
|
* </script>
|
|
37
32
|
* ```
|
|
38
33
|
*
|
|
39
34
|
* @example
|
|
40
35
|
*
|
|
41
|
-
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
36
|
+
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/restapi.js';
|
|
42
37
|
*
|
|
43
38
|
* const ds = new RestAPI({
|
|
44
39
|
* url: 'https://httpbin.org/get'
|
|
@@ -82,10 +77,18 @@ class RestAPI extends Datasource {
|
|
|
82
77
|
* @property {string} write.init.method=POST
|
|
83
78
|
* @property {string} write.acceptedStatus=[200,201]
|
|
84
79
|
* @property {string} write.url URL
|
|
80
|
+
* @property {Object} write.mapping the mapping is applied before writing.
|
|
81
|
+
* @property {String} write.mapping.transformer Transformer to select the appropriate entries
|
|
82
|
+
* @property {Object} write.report
|
|
83
|
+
* @property {String} write.report.path Path to validations
|
|
84
|
+
* @property {Monster.Data.Datasource~exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
|
|
85
85
|
* @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}
|
|
86
86
|
* @property {string} read.init.method=GET
|
|
87
87
|
* @property {string} read.acceptedStatus=[200]
|
|
88
88
|
* @property {string} read.url URL
|
|
89
|
+
* @property {Object} read.mapping the mapping is applied after reading.
|
|
90
|
+
* @property {String} read.mapping.transformer Transformer to select the appropriate entries
|
|
91
|
+
* @property {Monster.Data.Datasource~exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
|
|
89
92
|
*/
|
|
90
93
|
get defaults() {
|
|
91
94
|
return Object.assign({}, super.defaults, {
|
|
@@ -94,14 +97,25 @@ class RestAPI extends Datasource {
|
|
|
94
97
|
method: 'POST',
|
|
95
98
|
},
|
|
96
99
|
acceptedStatus: [200, 201],
|
|
97
|
-
url: undefined
|
|
100
|
+
url: undefined,
|
|
101
|
+
mapping: {
|
|
102
|
+
transformer: undefined,
|
|
103
|
+
callbacks: []
|
|
104
|
+
},
|
|
105
|
+
report: {
|
|
106
|
+
path: undefined
|
|
107
|
+
}
|
|
98
108
|
},
|
|
99
109
|
read: {
|
|
100
110
|
init: {
|
|
101
111
|
method: 'GET'
|
|
102
112
|
},
|
|
103
113
|
acceptedStatus: [200],
|
|
104
|
-
url: undefined
|
|
114
|
+
url: undefined,
|
|
115
|
+
mapping: {
|
|
116
|
+
transformer: undefined,
|
|
117
|
+
callbacks: []
|
|
118
|
+
},
|
|
105
119
|
},
|
|
106
120
|
|
|
107
121
|
});
|
|
@@ -143,19 +157,23 @@ class RestAPI extends Datasource {
|
|
|
143
157
|
body = body.substring(0, 97) + '...';
|
|
144
158
|
}
|
|
145
159
|
|
|
146
|
-
|
|
147
160
|
throw new Error('the response does not contain a valid json (actual: ' + body + ').');
|
|
148
161
|
}
|
|
149
162
|
|
|
150
|
-
self.
|
|
163
|
+
let transformation = self.getOption('read.mapping.transformer');
|
|
164
|
+
if (transformation !== undefined) {
|
|
165
|
+
const pipe = new Pipe(transformation);
|
|
166
|
+
obj = pipe.run(obj);
|
|
167
|
+
}
|
|
151
168
|
|
|
169
|
+
self.set(obj);
|
|
152
170
|
return response;
|
|
153
171
|
})
|
|
154
172
|
}
|
|
155
173
|
|
|
156
174
|
/**
|
|
157
175
|
* @return {Promise}
|
|
158
|
-
* @throws {
|
|
176
|
+
* @throws {WriteError} the data cannot be written
|
|
159
177
|
*/
|
|
160
178
|
write() {
|
|
161
179
|
const self = this;
|
|
@@ -169,14 +187,52 @@ class RestAPI extends Datasource {
|
|
|
169
187
|
}
|
|
170
188
|
}
|
|
171
189
|
|
|
172
|
-
|
|
190
|
+
let obj = self.get();
|
|
191
|
+
let transformation = self.getOption('write.mapping.transformer');
|
|
192
|
+
if (transformation !== undefined) {
|
|
193
|
+
const pipe = new Pipe(transformation);
|
|
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
|
+
|
|
207
|
+
init['body'] = JSON.stringify(obj);
|
|
173
208
|
|
|
174
209
|
return fetch(self.getOption('write.url'), init).then(response => {
|
|
175
210
|
|
|
176
211
|
const acceptedStatus = self.getOption('write.acceptedStatus', [200, 2001]);
|
|
177
212
|
|
|
178
213
|
if (acceptedStatus.indexOf(response.status) === -1) {
|
|
179
|
-
|
|
214
|
+
|
|
215
|
+
return response.text().then((body) => {
|
|
216
|
+
|
|
217
|
+
let obj, validation;
|
|
218
|
+
try {
|
|
219
|
+
obj = JSON.parse(body);
|
|
220
|
+
validation = new Pathfinder(obj).getVia(reportPath)
|
|
221
|
+
|
|
222
|
+
} catch (e) {
|
|
223
|
+
|
|
224
|
+
if (body.length > 100) {
|
|
225
|
+
body = body.substring(0, 97) + '...';
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
throw new Error('the response does not contain a valid json (actual: ' + body + ').');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
throw new WriteError('the data cannot be written (response ' + response.status + ')', response, validation)
|
|
232
|
+
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
|
|
180
236
|
}
|
|
181
237
|
|
|
182
238
|
return response;
|
|
@@ -189,11 +245,22 @@ class RestAPI extends Datasource {
|
|
|
189
245
|
*/
|
|
190
246
|
getClone() {
|
|
191
247
|
const self = this;
|
|
192
|
-
return new RestAPI(self[
|
|
248
|
+
return new RestAPI(self[internalSymbol].getRealSubject()['options'].read, self[internalSymbol].getRealSubject()['options'].write);
|
|
193
249
|
}
|
|
194
250
|
|
|
195
251
|
}
|
|
196
252
|
|
|
197
253
|
|
|
254
|
+
/**
|
|
255
|
+
* This callback can be passed to a datasource and is used to adapt data structures.
|
|
256
|
+
*
|
|
257
|
+
* @callback Monster.Data.Datasource~exampleCallback
|
|
258
|
+
* @param {*} value Value
|
|
259
|
+
* @param {string} key Key
|
|
260
|
+
* @memberOf Monster.Data
|
|
261
|
+
* @see Monster.Data.Datasource
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
|
|
198
265
|
assignToNamespace('Monster.Data.Datasource', RestAPI);
|
|
199
266
|
export {Monster, RestAPI}
|
|
@@ -4,19 +4,13 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {internalSymbol} from "../../../constants.js";
|
|
8
8
|
import {assignToNamespace, Monster} from '../../../namespace.js';
|
|
9
9
|
import {getGlobalObject} from "../../../types/global.js";
|
|
10
10
|
import {Datasource} from "../../datasource.js";
|
|
11
11
|
import {Storage, storageObjectSymbol} from "../storage.js";
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* @private
|
|
16
|
-
* @type {symbol}
|
|
17
|
-
*/
|
|
18
|
-
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
19
|
-
|
|
20
14
|
/**
|
|
21
15
|
*
|
|
22
16
|
*
|
|
@@ -24,7 +18,7 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
24
18
|
*
|
|
25
19
|
* ```
|
|
26
20
|
* <script type="module">
|
|
27
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
28
22
|
* Monster.Data.Datasource.Storage.LocalStorage()
|
|
29
23
|
* </script>
|
|
30
24
|
* ```
|
|
@@ -33,7 +27,7 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
33
27
|
*
|
|
34
28
|
* ```
|
|
35
29
|
* <script type="module">
|
|
36
|
-
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
30
|
+
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/storage/localstorage.js';
|
|
37
31
|
* new LocalStorage()
|
|
38
32
|
* </script>
|
|
39
33
|
* ```
|
|
@@ -60,7 +54,7 @@ class LocalStorage extends Storage {
|
|
|
60
54
|
*/
|
|
61
55
|
getClone() {
|
|
62
56
|
const self = this;
|
|
63
|
-
return new LocalStorage(self[
|
|
57
|
+
return new LocalStorage(self[internalSymbol].getRealSubject()['options'].key);
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
|
|
@@ -4,26 +4,18 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {internalSymbol} from "../../../constants.js";
|
|
8
8
|
import {assignToNamespace, Monster} from '../../../namespace.js';
|
|
9
9
|
import {getGlobalObject} from "../../../types/global.js";
|
|
10
10
|
import {Datasource} from "../../datasource.js";
|
|
11
11
|
import {Storage, storageObjectSymbol} from "../storage.js";
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @private
|
|
17
|
-
* @type {symbol}
|
|
18
|
-
*/
|
|
19
|
-
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
20
|
-
|
|
21
13
|
/**
|
|
22
14
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.SessionStorage()`.
|
|
23
15
|
*
|
|
24
16
|
* ```
|
|
25
17
|
* <script type="module">
|
|
26
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
27
19
|
* Monster.Data.Datasource.Storage.SessionStorage()
|
|
28
20
|
* </script>
|
|
29
21
|
* ```
|
|
@@ -32,7 +24,7 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
32
24
|
*
|
|
33
25
|
* ```
|
|
34
26
|
* <script type="module">
|
|
35
|
-
* import {SessionStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
27
|
+
* import {SessionStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/storage/sessionstorage.js';
|
|
36
28
|
* new SessionStorage()
|
|
37
29
|
* </script>
|
|
38
30
|
* ```
|
|
@@ -60,7 +52,7 @@ class SessionStorage extends Storage {
|
|
|
60
52
|
*/
|
|
61
53
|
getClone() {
|
|
62
54
|
const self = this;
|
|
63
|
-
return new SessionStorage(self[
|
|
55
|
+
return new SessionStorage(self[internalSymbol].getRealSubject()['options'].key);
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
}
|
|
@@ -4,18 +4,11 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
|
8
8
|
import {assignToNamespace, Monster} from '../../namespace.js';
|
|
9
9
|
import {validateString} from "../../types/validate.js";
|
|
10
10
|
import {Datasource} from "../datasource.js";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @private
|
|
15
|
-
* @type {symbol}
|
|
16
|
-
*/
|
|
17
|
-
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
18
|
-
|
|
19
12
|
/**
|
|
20
13
|
* @private
|
|
21
14
|
* @type {symbol}
|
|
@@ -27,7 +20,7 @@ const storageObjectSymbol = Symbol('storageObject');
|
|
|
27
20
|
*
|
|
28
21
|
* ```
|
|
29
22
|
* <script type="module">
|
|
30
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
31
24
|
* Monster.Data.Datasource.Storage()
|
|
32
25
|
* </script>
|
|
33
26
|
* ```
|
|
@@ -36,14 +29,14 @@ const storageObjectSymbol = Symbol('storageObject');
|
|
|
36
29
|
*
|
|
37
30
|
* ```
|
|
38
31
|
* <script type="module">
|
|
39
|
-
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
32
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/storage.js';
|
|
40
33
|
* new Storage()
|
|
41
34
|
* </script>
|
|
42
35
|
* ```
|
|
43
36
|
*
|
|
44
37
|
* @example
|
|
45
38
|
*
|
|
46
|
-
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
39
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource/storage.js';
|
|
47
40
|
*
|
|
48
41
|
* new Datasource();
|
|
49
42
|
*
|
|
@@ -95,7 +88,7 @@ class Storage extends Datasource {
|
|
|
95
88
|
|
|
96
89
|
return new Promise(function (resolve) {
|
|
97
90
|
const data = JSON.parse(storage.getItem(self.getOption('key')));
|
|
98
|
-
self.set(data);
|
|
91
|
+
self.set(data??{});
|
|
99
92
|
resolve();
|
|
100
93
|
})
|
|
101
94
|
|
|
@@ -116,7 +109,7 @@ class Storage extends Datasource {
|
|
|
116
109
|
if (data === undefined) {
|
|
117
110
|
storage.removeItem(self.getOption('key'));
|
|
118
111
|
} else {
|
|
119
|
-
storage.setItem(self.getOption('key'), JSON.stringify(
|
|
112
|
+
storage.setItem(self.getOption('key'), JSON.stringify(data));
|
|
120
113
|
}
|
|
121
114
|
|
|
122
115
|
resolve();
|
|
@@ -128,7 +121,7 @@ class Storage extends Datasource {
|
|
|
128
121
|
*/
|
|
129
122
|
getClone() {
|
|
130
123
|
const self=this;
|
|
131
|
-
return new Storage(self[
|
|
124
|
+
return new Storage(self[internalSymbol].getRealSubject()['options'].key);
|
|
132
125
|
}
|
|
133
126
|
|
|
134
127
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {internalSymbol} from "../constants.js";
|
|
8
8
|
import {assignToNamespace, Monster} from '../namespace.js';
|
|
9
9
|
import {Base} from "../types/base.js";
|
|
10
10
|
import {parseDataURL} from "../types/dataurl.js";
|
|
@@ -18,18 +18,20 @@ import {Pathfinder} from "./pathfinder.js";
|
|
|
18
18
|
/**
|
|
19
19
|
* @private
|
|
20
20
|
* @type {symbol}
|
|
21
|
+
* @memberOf Monster.Data
|
|
22
|
+
* @since 1.24.0
|
|
21
23
|
*/
|
|
22
|
-
const internalDataSymbol = Symbol
|
|
24
|
+
const internalDataSymbol = Symbol('internalData');
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* The datasource class is the basis for dealing with different data sources.
|
|
26
28
|
* It provides a unified interface for accessing data
|
|
27
|
-
*
|
|
29
|
+
*
|
|
28
30
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource()`.
|
|
29
31
|
*
|
|
30
32
|
* ```
|
|
31
33
|
* <script type="module">
|
|
32
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
34
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
33
35
|
* Monster.Data.Datasource()
|
|
34
36
|
* </script>
|
|
35
37
|
* ```
|
|
@@ -38,19 +40,19 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
38
40
|
*
|
|
39
41
|
* ```
|
|
40
42
|
* <script type="module">
|
|
41
|
-
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
43
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource.js';
|
|
42
44
|
* new Datasource()
|
|
43
45
|
* </script>
|
|
44
46
|
* ```
|
|
45
47
|
*
|
|
46
48
|
* @example
|
|
47
49
|
*
|
|
48
|
-
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
49
|
-
*
|
|
50
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/datasource.js'
|
|
51
|
+
*
|
|
50
52
|
* class MyDatasource extends Datasource {
|
|
51
53
|
*
|
|
52
54
|
* }
|
|
53
|
-
*
|
|
55
|
+
*
|
|
54
56
|
* const ds = new MyDatasource();
|
|
55
57
|
*
|
|
56
58
|
* @since 1.22.0
|
|
@@ -65,11 +67,45 @@ class Datasource extends Base {
|
|
|
65
67
|
*/
|
|
66
68
|
constructor() {
|
|
67
69
|
super();
|
|
70
|
+
this[internalSymbol] = new ProxyObserver({
|
|
71
|
+
'options': extend({}, this.defaults)
|
|
72
|
+
});
|
|
73
|
+
|
|
68
74
|
this[internalDataSymbol] = new ProxyObserver({
|
|
69
|
-
|
|
70
|
-
'data': undefined
|
|
75
|
+
|
|
71
76
|
});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* attach a new observer
|
|
83
|
+
*
|
|
84
|
+
* @param {Observer} observer
|
|
85
|
+
* @returns {Datasource}
|
|
86
|
+
*/
|
|
87
|
+
attachObserver(observer) {
|
|
88
|
+
this[internalDataSymbol].attachObserver(observer)
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
72
91
|
|
|
92
|
+
/**
|
|
93
|
+
* detach a observer
|
|
94
|
+
*
|
|
95
|
+
* @param {Observer} observer
|
|
96
|
+
* @returns {Datasource}
|
|
97
|
+
*/
|
|
98
|
+
detachObserver(observer) {
|
|
99
|
+
this[internalDataSymbol].detachObserver(observer)
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {Observer} observer
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
containsObserver(observer) {
|
|
108
|
+
return this[internalDataSymbol].containsObserver(observer);
|
|
73
109
|
}
|
|
74
110
|
|
|
75
111
|
/**
|
|
@@ -95,7 +131,7 @@ class Datasource extends Base {
|
|
|
95
131
|
* @return {Datasource}
|
|
96
132
|
*/
|
|
97
133
|
setOption(path, value) {
|
|
98
|
-
new Pathfinder(this[
|
|
134
|
+
new Pathfinder(this[internalSymbol].getSubject()['options']).setVia(path, value);
|
|
99
135
|
return this;
|
|
100
136
|
}
|
|
101
137
|
|
|
@@ -111,7 +147,7 @@ class Datasource extends Base {
|
|
|
111
147
|
}
|
|
112
148
|
|
|
113
149
|
const self = this;
|
|
114
|
-
extend(self[
|
|
150
|
+
extend(self[internalSymbol].getSubject()['options'], self.defaults, options);
|
|
115
151
|
|
|
116
152
|
return self;
|
|
117
153
|
}
|
|
@@ -127,7 +163,7 @@ class Datasource extends Base {
|
|
|
127
163
|
let value;
|
|
128
164
|
|
|
129
165
|
try {
|
|
130
|
-
value = new Pathfinder(this[
|
|
166
|
+
value = new Pathfinder(this[internalSymbol].getRealSubject()['options']).getVia(path);
|
|
131
167
|
} catch (e) {
|
|
132
168
|
|
|
133
169
|
}
|
|
@@ -154,20 +190,22 @@ class Datasource extends Base {
|
|
|
154
190
|
|
|
155
191
|
|
|
156
192
|
/**
|
|
157
|
-
*
|
|
193
|
+
* Returns real object
|
|
194
|
+
*
|
|
195
|
+
* @return {Object|Array}
|
|
158
196
|
*/
|
|
159
197
|
get() {
|
|
160
198
|
const self = this;
|
|
161
|
-
return self[internalDataSymbol].
|
|
199
|
+
return self[internalDataSymbol].getRealSubject();
|
|
162
200
|
}
|
|
163
201
|
|
|
164
202
|
/**
|
|
165
|
-
* @param {
|
|
203
|
+
* @param {Object|Array} data
|
|
166
204
|
* @return {Datasource}
|
|
167
205
|
*/
|
|
168
206
|
set(data) {
|
|
169
207
|
const self = this;
|
|
170
|
-
self[internalDataSymbol].
|
|
208
|
+
self[internalDataSymbol].setSubject(data);
|
|
171
209
|
return self;
|
|
172
210
|
}
|
|
173
211
|
|
package/source/data/diff.js
CHANGED
|
@@ -17,8 +17,8 @@ import {typeOf} from "../types/typeof.js";
|
|
|
17
17
|
*
|
|
18
18
|
* ```
|
|
19
19
|
* <script type="module">
|
|
20
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
21
|
-
*
|
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
21
|
+
* Monster.Data.Diff(a, b)
|
|
22
22
|
* </script>
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
@@ -26,14 +26,14 @@ import {typeOf} from "../types/typeof.js";
|
|
|
26
26
|
*
|
|
27
27
|
* ```
|
|
28
28
|
* <script type="module">
|
|
29
|
-
* import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
30
|
-
*
|
|
29
|
+
* import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/diff.js';
|
|
30
|
+
* Diff(a, b)
|
|
31
31
|
* </script>
|
|
32
32
|
* ```
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
*
|
|
36
|
-
* import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
36
|
+
* import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/diff.js';
|
|
37
37
|
*
|
|
38
38
|
* // given are two objects x and y.
|
|
39
39
|
*
|
|
@@ -80,7 +80,7 @@ import {typeOf} from "../types/typeof.js";
|
|
|
80
80
|
* @copyright schukai GmbH
|
|
81
81
|
* @memberOf Monster.Data
|
|
82
82
|
*/
|
|
83
|
-
function
|
|
83
|
+
function diff(first, second) {
|
|
84
84
|
return doDiff(first, second)
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -245,5 +245,5 @@ function getOperator(a, b) {
|
|
|
245
245
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
assignToNamespace('Monster.Data',
|
|
249
|
-
export {Monster,
|
|
248
|
+
assignToNamespace('Monster.Data', diff);
|
|
249
|
+
export {Monster, diff}
|
package/source/data/extend.js
CHANGED
|
@@ -8,15 +8,15 @@ import {isArray, isObject} from "../types/is.js";
|
|
|
8
8
|
import {typeOf} from "../types/typeof.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Extend copies all enumerable own properties from one or
|
|
12
12
|
* more source objects to a target object. It returns the modified target object.
|
|
13
13
|
*
|
|
14
14
|
* You can call the method via the monster namespace `Monster.Data.extend()`.
|
|
15
15
|
*
|
|
16
16
|
* ```
|
|
17
17
|
* <script type="module">
|
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
19
|
-
*
|
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
19
|
+
* Monster.Data.extend(a, b)
|
|
20
20
|
* </script>
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
@@ -24,8 +24,8 @@ import {typeOf} from "../types/typeof.js";
|
|
|
24
24
|
*
|
|
25
25
|
* ```
|
|
26
26
|
* <script type="module">
|
|
27
|
-
* import {extend} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
28
|
-
*
|
|
27
|
+
* import {extend} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/extend.js';
|
|
28
|
+
* extend(a, b)
|
|
29
29
|
* </script>
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
@@ -27,7 +27,7 @@ export const WILDCARD = '*';
|
|
|
27
27
|
*
|
|
28
28
|
* ```
|
|
29
29
|
* <script type="module">
|
|
30
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
30
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
31
31
|
* console.log(new Monster.Data.Pathfinder())
|
|
32
32
|
* </script>
|
|
33
33
|
* ```
|
|
@@ -36,7 +36,7 @@ export const WILDCARD = '*';
|
|
|
36
36
|
*
|
|
37
37
|
* ```
|
|
38
38
|
* <script type="module">
|
|
39
|
-
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
39
|
+
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/pathfinder.js';
|
|
40
40
|
* console.log(new Pathfinder())
|
|
41
41
|
* </script>
|
|
42
42
|
* ```
|
|
@@ -78,7 +78,7 @@ export const WILDCARD = '*';
|
|
|
78
78
|
*
|
|
79
79
|
* @example
|
|
80
80
|
*
|
|
81
|
-
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
81
|
+
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/pathfinder.js';
|
|
82
82
|
*
|
|
83
83
|
* let value = new Pathfinder({
|
|
84
84
|
* a: {
|
|
@@ -104,7 +104,7 @@ export const WILDCARD = '*';
|
|
|
104
104
|
*
|
|
105
105
|
* @example
|
|
106
106
|
*
|
|
107
|
-
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
107
|
+
* import {Pathfinder} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/data/pathfinder.js';
|
|
108
108
|
*
|
|
109
109
|
* let p = new Pathfinder({
|
|
110
110
|
* a: {
|
|
@@ -317,8 +317,14 @@ function getValueViaPath(subject, path, check) {
|
|
|
317
317
|
throw Error("the journey is not at its end (" + parts.join(DELIMITER) + ")");
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
|
|
321
|
+
if (check === true) {
|
|
322
|
+
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(subject), current);
|
|
323
|
+
|
|
324
|
+
if (!subject.hasOwnProperty(current) && descriptor === undefined) {
|
|
325
|
+
throw Error('unknown value');
|
|
326
|
+
}
|
|
327
|
+
|
|
322
328
|
}
|
|
323
329
|
|
|
324
330
|
return anchor;
|