@schukai/monster 1.22.0 → 1.26.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/CHANGELOG +56 -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 +1 -1
- 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 +2 -2
- 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 +1838 -792
- 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 +95 -11
- package/source/data/datasource/storage/localstorage.js +15 -8
- package/source/data/datasource/storage/sessionstorage.js +16 -12
- package/source/data/datasource/storage.js +16 -7
- package/source/data/datasource.js +60 -16
- 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 +182 -102
- 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 +40 -10
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +115 -39
- 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 +8 -8
- 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 +5 -6
- 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 +25 -26
- 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 +42 -19
- 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,17 +4,20 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
|
7
8
|
import {assignToNamespace, Monster} from '../../namespace.js';
|
|
8
9
|
import {isObject} from "../../types/is.js";
|
|
9
10
|
import {Datasource} from "../datasource.js";
|
|
10
|
-
|
|
11
|
+
import {Pathfinder} from "../pathfinder.js";
|
|
12
|
+
import {Pipe} from "../pipe.js";
|
|
13
|
+
import {WriteError} from "./restapi/writeerror.js";
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.RestAPI()`.
|
|
14
17
|
*
|
|
15
18
|
* ```
|
|
16
19
|
* <script type="module">
|
|
17
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
20
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
|
18
21
|
* Monster.Data.Datasource.RestAPI()
|
|
19
22
|
* </script>
|
|
20
23
|
* ```
|
|
@@ -23,14 +26,14 @@ import {Datasource} from "../datasource.js";
|
|
|
23
26
|
*
|
|
24
27
|
* ```
|
|
25
28
|
* <script type="module">
|
|
26
|
-
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
29
|
+
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/restapi.js';
|
|
27
30
|
* new RestAPI()
|
|
28
31
|
* </script>
|
|
29
32
|
* ```
|
|
30
33
|
*
|
|
31
34
|
* @example
|
|
32
35
|
*
|
|
33
|
-
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
36
|
+
* import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/restapi.js';
|
|
34
37
|
*
|
|
35
38
|
* const ds = new RestAPI({
|
|
36
39
|
* url: 'https://httpbin.org/get'
|
|
@@ -74,10 +77,18 @@ class RestAPI extends Datasource {
|
|
|
74
77
|
* @property {string} write.init.method=POST
|
|
75
78
|
* @property {string} write.acceptedStatus=[200,201]
|
|
76
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.
|
|
77
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}
|
|
78
86
|
* @property {string} read.init.method=GET
|
|
79
87
|
* @property {string} read.acceptedStatus=[200]
|
|
80
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.
|
|
81
92
|
*/
|
|
82
93
|
get defaults() {
|
|
83
94
|
return Object.assign({}, super.defaults, {
|
|
@@ -86,14 +97,25 @@ class RestAPI extends Datasource {
|
|
|
86
97
|
method: 'POST',
|
|
87
98
|
},
|
|
88
99
|
acceptedStatus: [200, 201],
|
|
89
|
-
url: undefined
|
|
100
|
+
url: undefined,
|
|
101
|
+
mapping: {
|
|
102
|
+
transformer: undefined,
|
|
103
|
+
callbacks: []
|
|
104
|
+
},
|
|
105
|
+
report: {
|
|
106
|
+
path: undefined
|
|
107
|
+
}
|
|
90
108
|
},
|
|
91
109
|
read: {
|
|
92
110
|
init: {
|
|
93
111
|
method: 'GET'
|
|
94
112
|
},
|
|
95
113
|
acceptedStatus: [200],
|
|
96
|
-
url: undefined
|
|
114
|
+
url: undefined,
|
|
115
|
+
mapping: {
|
|
116
|
+
transformer: undefined,
|
|
117
|
+
callbacks: []
|
|
118
|
+
},
|
|
97
119
|
},
|
|
98
120
|
|
|
99
121
|
});
|
|
@@ -135,19 +157,23 @@ class RestAPI extends Datasource {
|
|
|
135
157
|
body = body.substring(0, 97) + '...';
|
|
136
158
|
}
|
|
137
159
|
|
|
138
|
-
|
|
139
160
|
throw new Error('the response does not contain a valid json (actual: ' + body + ').');
|
|
140
161
|
}
|
|
141
162
|
|
|
142
|
-
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
|
+
}
|
|
143
168
|
|
|
169
|
+
self.set(obj);
|
|
144
170
|
return response;
|
|
145
171
|
})
|
|
146
172
|
}
|
|
147
173
|
|
|
148
174
|
/**
|
|
149
175
|
* @return {Promise}
|
|
150
|
-
* @throws {
|
|
176
|
+
* @throws {WriteError} the data cannot be written
|
|
151
177
|
*/
|
|
152
178
|
write() {
|
|
153
179
|
const self = this;
|
|
@@ -161,22 +187,80 @@ class RestAPI extends Datasource {
|
|
|
161
187
|
}
|
|
162
188
|
}
|
|
163
189
|
|
|
164
|
-
|
|
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);
|
|
165
208
|
|
|
166
209
|
return fetch(self.getOption('write.url'), init).then(response => {
|
|
167
210
|
|
|
168
211
|
const acceptedStatus = self.getOption('write.acceptedStatus', [200, 2001]);
|
|
169
212
|
|
|
170
213
|
if (acceptedStatus.indexOf(response.status) === -1) {
|
|
171
|
-
|
|
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
|
+
|
|
172
236
|
}
|
|
173
237
|
|
|
174
238
|
return response;
|
|
175
239
|
});
|
|
176
240
|
}
|
|
177
241
|
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @return {RestAPI}
|
|
245
|
+
*/
|
|
246
|
+
getClone() {
|
|
247
|
+
const self = this;
|
|
248
|
+
return new RestAPI(self[internalSymbol].getRealSubject()['options'].read, self[internalSymbol].getRealSubject()['options'].write);
|
|
249
|
+
}
|
|
250
|
+
|
|
178
251
|
}
|
|
179
252
|
|
|
180
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
|
+
|
|
181
265
|
assignToNamespace('Monster.Data.Datasource', RestAPI);
|
|
182
266
|
export {Monster, RestAPI}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {internalSymbol} from "../../../constants.js";
|
|
7
8
|
import {assignToNamespace, Monster} from '../../../namespace.js';
|
|
8
9
|
import {getGlobalObject} from "../../../types/global.js";
|
|
9
10
|
import {Datasource} from "../../datasource.js";
|
|
@@ -11,11 +12,13 @@ import {Storage, storageObjectSymbol} from "../storage.js";
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
15
|
+
*
|
|
16
|
+
*
|
|
14
17
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.LocalStorage()`.
|
|
15
18
|
*
|
|
16
19
|
* ```
|
|
17
20
|
* <script type="module">
|
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
21
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
|
19
22
|
* Monster.Data.Datasource.Storage.LocalStorage()
|
|
20
23
|
* </script>
|
|
21
24
|
* ```
|
|
@@ -24,17 +27,11 @@ import {Storage, storageObjectSymbol} from "../storage.js";
|
|
|
24
27
|
*
|
|
25
28
|
* ```
|
|
26
29
|
* <script type="module">
|
|
27
|
-
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
30
|
+
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/storage/localstorage.js';
|
|
28
31
|
* new LocalStorage()
|
|
29
32
|
* </script>
|
|
30
33
|
* ```
|
|
31
34
|
*
|
|
32
|
-
* @example
|
|
33
|
-
*
|
|
34
|
-
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.22.0/dist/modules/data/datasource/storage/localstorage.js';
|
|
35
|
-
*
|
|
36
|
-
* new Datasource();
|
|
37
|
-
*
|
|
38
35
|
* @since 1.22.0
|
|
39
36
|
* @copyright schukai GmbH
|
|
40
37
|
* @memberOf Monster.Data.Datasource.Storage
|
|
@@ -51,6 +48,16 @@ class LocalStorage extends Storage {
|
|
|
51
48
|
return getGlobalObject('localStorage');
|
|
52
49
|
}
|
|
53
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Create clone
|
|
53
|
+
* @return {LocalStorage}
|
|
54
|
+
*/
|
|
55
|
+
getClone() {
|
|
56
|
+
const self = this;
|
|
57
|
+
return new LocalStorage(self[internalSymbol].getRealSubject()['options'].key);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
assignToNamespace('Monster.Data.Datasource.Storage', LocalStorage);
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {internalSymbol} from "../../../constants.js";
|
|
7
8
|
import {assignToNamespace, Monster} from '../../../namespace.js';
|
|
8
9
|
import {getGlobalObject} from "../../../types/global.js";
|
|
9
10
|
import {Datasource} from "../../datasource.js";
|
|
10
11
|
import {Storage, storageObjectSymbol} from "../storage.js";
|
|
11
12
|
|
|
12
|
-
|
|
13
13
|
/**
|
|
14
|
-
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.
|
|
14
|
+
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.SessionStorage()`.
|
|
15
15
|
*
|
|
16
16
|
* ```
|
|
17
17
|
* <script type="module">
|
|
18
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
19
|
-
* Monster.Data.Datasource.Storage.
|
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
|
19
|
+
* Monster.Data.Datasource.Storage.SessionStorage()
|
|
20
20
|
* </script>
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
@@ -24,17 +24,11 @@ import {Storage, storageObjectSymbol} from "../storage.js";
|
|
|
24
24
|
*
|
|
25
25
|
* ```
|
|
26
26
|
* <script type="module">
|
|
27
|
-
* import {
|
|
28
|
-
* new
|
|
27
|
+
* import {SessionStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/storage/sessionstorage.js';
|
|
28
|
+
* new SessionStorage()
|
|
29
29
|
* </script>
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
|
-
* @example
|
|
33
|
-
*
|
|
34
|
-
* import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.22.0/dist/modules/data/datasource/storage/localstorage.js';
|
|
35
|
-
*
|
|
36
|
-
* new Datasource();
|
|
37
|
-
*
|
|
38
32
|
* @since 1.22.0
|
|
39
33
|
* @copyright schukai GmbH
|
|
40
34
|
* @memberOf Monster.Data.Datasource.Storage
|
|
@@ -51,6 +45,16 @@ class SessionStorage extends Storage {
|
|
|
51
45
|
return getGlobalObject('sessionStorage');
|
|
52
46
|
}
|
|
53
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Create Clone
|
|
50
|
+
*
|
|
51
|
+
* @return {SessionStorage}
|
|
52
|
+
*/
|
|
53
|
+
getClone() {
|
|
54
|
+
const self = this;
|
|
55
|
+
return new SessionStorage(self[internalSymbol].getRealSubject()['options'].key);
|
|
56
|
+
}
|
|
57
|
+
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
assignToNamespace('Monster.Data.Datasource.Storage', SessionStorage);
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
|
7
8
|
import {assignToNamespace, Monster} from '../../namespace.js';
|
|
8
9
|
import {validateString} from "../../types/validate.js";
|
|
9
10
|
import {Datasource} from "../datasource.js";
|
|
10
11
|
|
|
11
|
-
|
|
12
12
|
/**
|
|
13
13
|
* @private
|
|
14
14
|
* @type {symbol}
|
|
@@ -20,7 +20,7 @@ const storageObjectSymbol = Symbol('storageObject');
|
|
|
20
20
|
*
|
|
21
21
|
* ```
|
|
22
22
|
* <script type="module">
|
|
23
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
|
24
24
|
* Monster.Data.Datasource.Storage()
|
|
25
25
|
* </script>
|
|
26
26
|
* ```
|
|
@@ -29,14 +29,14 @@ const storageObjectSymbol = Symbol('storageObject');
|
|
|
29
29
|
*
|
|
30
30
|
* ```
|
|
31
31
|
* <script type="module">
|
|
32
|
-
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
32
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/storage.js';
|
|
33
33
|
* new Storage()
|
|
34
34
|
* </script>
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
38
|
*
|
|
39
|
-
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
39
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource/storage.js';
|
|
40
40
|
*
|
|
41
41
|
* new Datasource();
|
|
42
42
|
*
|
|
@@ -88,14 +88,14 @@ class Storage extends Datasource {
|
|
|
88
88
|
|
|
89
89
|
return new Promise(function (resolve) {
|
|
90
90
|
const data = JSON.parse(storage.getItem(self.getOption('key')));
|
|
91
|
-
self.set(data);
|
|
91
|
+
self.set(data??{});
|
|
92
92
|
resolve();
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* @return {
|
|
98
|
+
* @return {Storage}
|
|
99
99
|
* @throws {Error} the data cannot be written
|
|
100
100
|
*/
|
|
101
101
|
write() {
|
|
@@ -109,12 +109,21 @@ class Storage extends Datasource {
|
|
|
109
109
|
if (data === undefined) {
|
|
110
110
|
storage.removeItem(self.getOption('key'));
|
|
111
111
|
} else {
|
|
112
|
-
storage.setItem(self.getOption('key'), JSON.stringify(
|
|
112
|
+
storage.setItem(self.getOption('key'), JSON.stringify(data));
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
resolve();
|
|
116
116
|
})
|
|
117
117
|
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @return {Storage}
|
|
121
|
+
*/
|
|
122
|
+
getClone() {
|
|
123
|
+
const self=this;
|
|
124
|
+
return new Storage(self[internalSymbol].getRealSubject()['options'].key);
|
|
125
|
+
}
|
|
126
|
+
|
|
118
127
|
}
|
|
119
128
|
|
|
120
129
|
|
|
@@ -4,12 +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 {Base} from "../types/base.js";
|
|
10
10
|
import {parseDataURL} from "../types/dataurl.js";
|
|
11
11
|
import {isString} from "../types/is.js";
|
|
12
|
-
import {clone} from "../util/clone.js";
|
|
13
12
|
import {ProxyObserver} from "../types/proxyobserver.js";
|
|
14
13
|
import {validateObject} from "../types/validate.js";
|
|
15
14
|
import {extend} from "./extend.js";
|
|
@@ -19,15 +18,20 @@ import {Pathfinder} from "./pathfinder.js";
|
|
|
19
18
|
/**
|
|
20
19
|
* @private
|
|
21
20
|
* @type {symbol}
|
|
21
|
+
* @memberOf Monster.Data
|
|
22
|
+
* @since 1.24.0
|
|
22
23
|
*/
|
|
23
|
-
const internalDataSymbol = Symbol
|
|
24
|
+
const internalDataSymbol = Symbol('internalData');
|
|
24
25
|
|
|
25
26
|
/**
|
|
27
|
+
* The datasource class is the basis for dealing with different data sources.
|
|
28
|
+
* It provides a unified interface for accessing data
|
|
29
|
+
*
|
|
26
30
|
* You can create an object of this class using the monster namespace `Monster.Data.Datasource()`.
|
|
27
31
|
*
|
|
28
32
|
* ```
|
|
29
33
|
* <script type="module">
|
|
30
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
34
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/monster.js';
|
|
31
35
|
* Monster.Data.Datasource()
|
|
32
36
|
* </script>
|
|
33
37
|
* ```
|
|
@@ -36,16 +40,20 @@ const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
|
36
40
|
*
|
|
37
41
|
* ```
|
|
38
42
|
* <script type="module">
|
|
39
|
-
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
43
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource.js';
|
|
40
44
|
* new Datasource()
|
|
41
45
|
* </script>
|
|
42
46
|
* ```
|
|
43
47
|
*
|
|
44
48
|
* @example
|
|
45
49
|
*
|
|
46
|
-
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
50
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.0/dist/modules/data/datasource.js'
|
|
51
|
+
*
|
|
52
|
+
* class MyDatasource extends Datasource {
|
|
53
|
+
*
|
|
54
|
+
* }
|
|
47
55
|
*
|
|
48
|
-
* new
|
|
56
|
+
* const ds = new MyDatasource();
|
|
49
57
|
*
|
|
50
58
|
* @since 1.22.0
|
|
51
59
|
* @copyright schukai GmbH
|
|
@@ -59,11 +67,45 @@ class Datasource extends Base {
|
|
|
59
67
|
*/
|
|
60
68
|
constructor() {
|
|
61
69
|
super();
|
|
70
|
+
this[internalSymbol] = new ProxyObserver({
|
|
71
|
+
'options': extend({}, this.defaults)
|
|
72
|
+
});
|
|
73
|
+
|
|
62
74
|
this[internalDataSymbol] = new ProxyObserver({
|
|
63
|
-
|
|
64
|
-
'data': undefined
|
|
75
|
+
|
|
65
76
|
});
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
}
|
|
66
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
|
+
}
|
|
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);
|
|
67
109
|
}
|
|
68
110
|
|
|
69
111
|
/**
|
|
@@ -89,7 +131,7 @@ class Datasource extends Base {
|
|
|
89
131
|
* @return {Datasource}
|
|
90
132
|
*/
|
|
91
133
|
setOption(path, value) {
|
|
92
|
-
new Pathfinder(this[
|
|
134
|
+
new Pathfinder(this[internalSymbol].getSubject()['options']).setVia(path, value);
|
|
93
135
|
return this;
|
|
94
136
|
}
|
|
95
137
|
|
|
@@ -105,7 +147,7 @@ class Datasource extends Base {
|
|
|
105
147
|
}
|
|
106
148
|
|
|
107
149
|
const self = this;
|
|
108
|
-
extend(self[
|
|
150
|
+
extend(self[internalSymbol].getSubject()['options'], self.defaults, options);
|
|
109
151
|
|
|
110
152
|
return self;
|
|
111
153
|
}
|
|
@@ -121,7 +163,7 @@ class Datasource extends Base {
|
|
|
121
163
|
let value;
|
|
122
164
|
|
|
123
165
|
try {
|
|
124
|
-
value = new Pathfinder(this[
|
|
166
|
+
value = new Pathfinder(this[internalSymbol].getRealSubject()['options']).getVia(path);
|
|
125
167
|
} catch (e) {
|
|
126
168
|
|
|
127
169
|
}
|
|
@@ -148,20 +190,22 @@ class Datasource extends Base {
|
|
|
148
190
|
|
|
149
191
|
|
|
150
192
|
/**
|
|
151
|
-
*
|
|
193
|
+
* Returns real object
|
|
194
|
+
*
|
|
195
|
+
* @return {Object|Array}
|
|
152
196
|
*/
|
|
153
197
|
get() {
|
|
154
198
|
const self = this;
|
|
155
|
-
return
|
|
199
|
+
return self[internalDataSymbol].getRealSubject();
|
|
156
200
|
}
|
|
157
201
|
|
|
158
202
|
/**
|
|
159
|
-
* @param {
|
|
203
|
+
* @param {Object|Array} data
|
|
160
204
|
* @return {Datasource}
|
|
161
205
|
*/
|
|
162
206
|
set(data) {
|
|
163
207
|
const self = this;
|
|
164
|
-
self[internalDataSymbol].
|
|
208
|
+
self[internalDataSymbol].setSubject(data);
|
|
165
209
|
return self;
|
|
166
210
|
}
|
|
167
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.0/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.0/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.0/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.0/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.0/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.0/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.0/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.0/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.0/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;
|