@schukai/monster 1.21.1 → 1.25.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +48 -1
- 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 +1 -1
- package/dist/modules/data/datasource/namespace.js +2 -0
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -0
- package/dist/modules/data/datasource/storage/localstorage.js +2 -0
- package/dist/modules/data/datasource/storage/namespace.js +2 -0
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -0
- package/dist/modules/data/datasource/storage.js +2 -0
- package/dist/modules/data/datasource.js +2 -0
- 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/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 +1 -1
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- 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/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 +1499 -732
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +1 -1
- package/source/constants.js +16 -7
- package/source/constraints/andoperator.js +5 -5
- package/source/constraints/invalid.js +3 -3
- package/source/constraints/isarray.js +3 -3
- package/source/constraints/isobject.js +3 -3
- package/source/constraints/oroperator.js +5 -5
- package/source/constraints/valid.js +3 -3
- package/source/data/buildmap.js +6 -6
- package/source/data/datasource/namespace.js +16 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +266 -0
- package/source/data/datasource/storage/localstorage.js +64 -0
- package/source/data/datasource/storage/namespace.js +16 -0
- package/source/data/datasource/storage/sessionstorage.js +61 -0
- package/source/data/datasource/storage.js +131 -0
- package/source/data/datasource.js +246 -0
- 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 -103
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +251 -0
- package/source/dom/locale.js +4 -3
- 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 +114 -58
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/locale.js +8 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +8 -13
- package/source/i18n/translations.js +6 -5
- 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 +82 -7
- 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 +2 -2
- package/source/types/is.js +23 -23
- package/source/types/mediatype.js +4 -4
- 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 +5 -5
- package/source/types/randomid.js +2 -2
- 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/datasource/restapi.js +89 -0
- package/test/cases/data/datasource/storage/localstorage.js +47 -0
- package/test/cases/data/datasource/storage/sessionstorage.js +47 -0
- package/test/cases/data/datasource.js +60 -0
- 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/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/monster.js +1 -1
- package/test/cases/text/formatter.js +38 -6
- package/test/cases/types/proxyobserver.js +55 -11
- 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 +23 -9
- package/test/util/localstorage.js +81 -0
- package/test/web/import.js +13 -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
@@ -0,0 +1,61 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
|
7
|
+
import {internalSymbol} from "../../../constants.js";
|
8
|
+
import {assignToNamespace, Monster} from '../../../namespace.js';
|
9
|
+
import {getGlobalObject} from "../../../types/global.js";
|
10
|
+
import {Datasource} from "../../datasource.js";
|
11
|
+
import {Storage, storageObjectSymbol} from "../storage.js";
|
12
|
+
|
13
|
+
/**
|
14
|
+
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.SessionStorage()`.
|
15
|
+
*
|
16
|
+
* ```
|
17
|
+
* <script type="module">
|
18
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage/sessionstorage.js';
|
19
|
+
* Monster.Data.Datasource.Storage.SessionStorage()
|
20
|
+
* </script>
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* Alternatively you can import the class directly
|
24
|
+
*
|
25
|
+
* ```
|
26
|
+
* <script type="module">
|
27
|
+
* import {SessionStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage/sessionstorage.js';
|
28
|
+
* new SessionStorage()
|
29
|
+
* </script>
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* @since 1.22.0
|
33
|
+
* @copyright schukai GmbH
|
34
|
+
* @memberOf Monster.Data.Datasource.Storage
|
35
|
+
* @summary The LocalStorage class encapsulates the access to data objects.
|
36
|
+
*/
|
37
|
+
class SessionStorage extends Storage {
|
38
|
+
|
39
|
+
/**
|
40
|
+
* @throws {Error} this method must be implemented by derived classes.
|
41
|
+
* @return {external:sessionStorage}
|
42
|
+
* @private
|
43
|
+
*/
|
44
|
+
[storageObjectSymbol]() {
|
45
|
+
return getGlobalObject('sessionStorage');
|
46
|
+
}
|
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
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
assignToNamespace('Monster.Data.Datasource.Storage', SessionStorage);
|
61
|
+
export {Monster, SessionStorage}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
|
7
|
+
import {internalSymbol} from "../../constants.js";
|
8
|
+
import {assignToNamespace, Monster} from '../../namespace.js';
|
9
|
+
import {validateString} from "../../types/validate.js";
|
10
|
+
import {Datasource} from "../datasource.js";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @private
|
14
|
+
* @type {symbol}
|
15
|
+
*/
|
16
|
+
const storageObjectSymbol = Symbol('storageObject');
|
17
|
+
|
18
|
+
/**
|
19
|
+
* You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage()`.
|
20
|
+
*
|
21
|
+
* ```
|
22
|
+
* <script type="module">
|
23
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage.js';
|
24
|
+
* Monster.Data.Datasource.Storage()
|
25
|
+
* </script>
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* Alternatively you can import the class directly
|
29
|
+
*
|
30
|
+
* ```
|
31
|
+
* <script type="module">
|
32
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage.js';
|
33
|
+
* new Storage()
|
34
|
+
* </script>
|
35
|
+
* ```
|
36
|
+
*
|
37
|
+
* @example
|
38
|
+
*
|
39
|
+
* import {Storage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage.js';
|
40
|
+
*
|
41
|
+
* new Datasource();
|
42
|
+
*
|
43
|
+
* @since 1.22.0
|
44
|
+
* @copyright schukai GmbH
|
45
|
+
* @memberOf Monster.Data.Datasource
|
46
|
+
* @summary The Storage class encapsulates the access to data objects over WebStorageAPI.
|
47
|
+
*/
|
48
|
+
class Storage extends Datasource {
|
49
|
+
|
50
|
+
/**
|
51
|
+
*
|
52
|
+
* @param {string} key LocalStorage Key
|
53
|
+
* @throws {TypeError} value is not a string
|
54
|
+
*/
|
55
|
+
constructor(key) {
|
56
|
+
super();
|
57
|
+
this.setOption('key', validateString(key));
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @property {string} key=undefined LocalStorage Key
|
62
|
+
*/
|
63
|
+
get defaults() {
|
64
|
+
return Object.assign({}, super.defaults, {
|
65
|
+
key: undefined,
|
66
|
+
});
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @throws {Error} this method must be implemented by derived classes.
|
71
|
+
* @return {external:Storage}
|
72
|
+
* @private
|
73
|
+
*/
|
74
|
+
[storageObjectSymbol]() {
|
75
|
+
throw new Error("this method must be implemented by derived classes")
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @return {Promise}
|
80
|
+
* @throws {Error} the options does not contain a valid json definition
|
81
|
+
* @throws {TypeError} value is not a object
|
82
|
+
* @throws {Error} the data cannot be read
|
83
|
+
*/
|
84
|
+
read() {
|
85
|
+
const self = this;
|
86
|
+
|
87
|
+
const storage = self[storageObjectSymbol]();
|
88
|
+
|
89
|
+
return new Promise(function (resolve) {
|
90
|
+
const data = JSON.parse(storage.getItem(self.getOption('key')));
|
91
|
+
self.set(data??{});
|
92
|
+
resolve();
|
93
|
+
})
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* @return {Storage}
|
99
|
+
* @throws {Error} the data cannot be written
|
100
|
+
*/
|
101
|
+
write() {
|
102
|
+
const self = this;
|
103
|
+
|
104
|
+
const storage = self[storageObjectSymbol]();
|
105
|
+
|
106
|
+
return new Promise(function (resolve) {
|
107
|
+
|
108
|
+
const data = self.get();
|
109
|
+
if (data === undefined) {
|
110
|
+
storage.removeItem(self.getOption('key'));
|
111
|
+
} else {
|
112
|
+
storage.setItem(self.getOption('key'), JSON.stringify(data));
|
113
|
+
}
|
114
|
+
|
115
|
+
resolve();
|
116
|
+
})
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* @return {Storage}
|
121
|
+
*/
|
122
|
+
getClone() {
|
123
|
+
const self=this;
|
124
|
+
return new Storage(self[internalSymbol].getRealSubject()['options'].key);
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
assignToNamespace('Monster.Data.Datasource', Storage);
|
131
|
+
export {Monster, Storage, storageObjectSymbol}
|
@@ -0,0 +1,246 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @author schukai GmbH
|
5
|
+
*/
|
6
|
+
|
7
|
+
import {internalSymbol} from "../constants.js";
|
8
|
+
import {assignToNamespace, Monster} from '../namespace.js';
|
9
|
+
import {Base} from "../types/base.js";
|
10
|
+
import {parseDataURL} from "../types/dataurl.js";
|
11
|
+
import {isString} from "../types/is.js";
|
12
|
+
import {ProxyObserver} from "../types/proxyobserver.js";
|
13
|
+
import {validateObject} from "../types/validate.js";
|
14
|
+
import {extend} from "./extend.js";
|
15
|
+
import {Pathfinder} from "./pathfinder.js";
|
16
|
+
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @private
|
20
|
+
* @type {symbol}
|
21
|
+
* @memberOf Monster.Data
|
22
|
+
* @since 1.24.0
|
23
|
+
*/
|
24
|
+
const internalDataSymbol = Symbol('internalData');
|
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
|
+
*
|
30
|
+
* You can create an object of this class using the monster namespace `Monster.Data.Datasource()`.
|
31
|
+
*
|
32
|
+
* ```
|
33
|
+
* <script type="module">
|
34
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource.js';
|
35
|
+
* Monster.Data.Datasource()
|
36
|
+
* </script>
|
37
|
+
* ```
|
38
|
+
*
|
39
|
+
* Alternatively you can import the class directly
|
40
|
+
*
|
41
|
+
* ```
|
42
|
+
* <script type="module">
|
43
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource.js';
|
44
|
+
* new Datasource()
|
45
|
+
* </script>
|
46
|
+
* ```
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
*
|
50
|
+
* import {Datasource} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource.js'
|
51
|
+
*
|
52
|
+
* class MyDatasource extends Datasource {
|
53
|
+
*
|
54
|
+
* }
|
55
|
+
*
|
56
|
+
* const ds = new MyDatasource();
|
57
|
+
*
|
58
|
+
* @since 1.22.0
|
59
|
+
* @copyright schukai GmbH
|
60
|
+
* @memberOf Monster.Data
|
61
|
+
* @summary The datasource class encapsulates the access to data objects.
|
62
|
+
*/
|
63
|
+
class Datasource extends Base {
|
64
|
+
|
65
|
+
/**
|
66
|
+
*
|
67
|
+
*/
|
68
|
+
constructor() {
|
69
|
+
super();
|
70
|
+
this[internalSymbol] = new ProxyObserver({
|
71
|
+
'options': extend({}, this.defaults)
|
72
|
+
});
|
73
|
+
|
74
|
+
this[internalDataSymbol] = new ProxyObserver({
|
75
|
+
|
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
|
+
}
|
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);
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Derived classes can override and extend this method as follows.
|
113
|
+
*
|
114
|
+
* ```
|
115
|
+
* get defaults() {
|
116
|
+
* return Object.assign({}, super.defaults, {
|
117
|
+
* myValue:true
|
118
|
+
* });
|
119
|
+
* }
|
120
|
+
* ```
|
121
|
+
*/
|
122
|
+
get defaults() {
|
123
|
+
return {};
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Set option
|
128
|
+
*
|
129
|
+
* @param {string} path
|
130
|
+
* @param {*} value
|
131
|
+
* @return {Datasource}
|
132
|
+
*/
|
133
|
+
setOption(path, value) {
|
134
|
+
new Pathfinder(this[internalSymbol].getSubject()['options']).setVia(path, value);
|
135
|
+
return this;
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* @param {string|object} options
|
140
|
+
* @return {Datasource}
|
141
|
+
* @throws {Error} the options does not contain a valid json definition
|
142
|
+
*/
|
143
|
+
setOptions(options) {
|
144
|
+
|
145
|
+
if (isString(options)) {
|
146
|
+
options = parseOptionsJSON(options)
|
147
|
+
}
|
148
|
+
|
149
|
+
const self = this;
|
150
|
+
extend(self[internalSymbol].getSubject()['options'], self.defaults, options);
|
151
|
+
|
152
|
+
return self;
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* nested options can be specified by path `a.b.c`
|
157
|
+
*
|
158
|
+
* @param {string} path
|
159
|
+
* @param {*} defaultValue
|
160
|
+
* @return {*}
|
161
|
+
*/
|
162
|
+
getOption(path, defaultValue) {
|
163
|
+
let value;
|
164
|
+
|
165
|
+
try {
|
166
|
+
value = new Pathfinder(this[internalSymbol].getRealSubject()['options']).getVia(path);
|
167
|
+
} catch (e) {
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
if (value === undefined) return defaultValue;
|
172
|
+
return value;
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* @throws {Error} this method must be implemented by derived classes.
|
177
|
+
* @return {Promise}
|
178
|
+
*/
|
179
|
+
read() {
|
180
|
+
throw new Error("this method must be implemented by derived classes")
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* @throws {Error} this method must be implemented by derived classes.
|
185
|
+
* @return {Promise}
|
186
|
+
*/
|
187
|
+
write() {
|
188
|
+
throw new Error("this method must be implemented by derived classes")
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Returns real object
|
194
|
+
*
|
195
|
+
* @return {Object|Array}
|
196
|
+
*/
|
197
|
+
get() {
|
198
|
+
const self = this;
|
199
|
+
return self[internalDataSymbol].getRealSubject();
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* @param {Object|Array} data
|
204
|
+
* @return {Datasource}
|
205
|
+
*/
|
206
|
+
set(data) {
|
207
|
+
const self = this;
|
208
|
+
self[internalDataSymbol].setSubject(data);
|
209
|
+
return self;
|
210
|
+
}
|
211
|
+
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* @private
|
216
|
+
* @param data
|
217
|
+
* @return {Object}
|
218
|
+
* @throws {Error} the options does not contain a valid json definition
|
219
|
+
*/
|
220
|
+
function parseOptionsJSON(data) {
|
221
|
+
if (isString(data)) {
|
222
|
+
|
223
|
+
// the configuration can be specified as a data url.
|
224
|
+
try {
|
225
|
+
let dataUrl = parseDataURL(data);
|
226
|
+
data = dataUrl.content;
|
227
|
+
} catch (e) {
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
try {
|
233
|
+
let obj = JSON.parse(data);
|
234
|
+
validateObject(obj);
|
235
|
+
return obj;
|
236
|
+
} catch (e) {
|
237
|
+
throw new Error('the options does not contain a valid json definition (actual: ' + data + ').');
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
return {};
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
assignToNamespace('Monster.Data', Datasource);
|
246
|
+
export {Monster, Datasource}
|
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.25.0/dist/modules/data/diff.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.25.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.25.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.25.0/dist/modules/data/extend.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.25.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.25.0/dist/modules/data/pathfinder.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.25.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.25.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.25.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;
|
package/source/data/pipe.js
CHANGED
@@ -19,8 +19,8 @@ const DELIMITER = '|';
|
|
19
19
|
*
|
20
20
|
* ```
|
21
21
|
* <script type="module">
|
22
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
23
|
-
*
|
22
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/pipe.js';
|
23
|
+
* new Monster.Data.Pipe()
|
24
24
|
* </script>
|
25
25
|
* ```
|
26
26
|
*
|
@@ -28,8 +28,8 @@ const DELIMITER = '|';
|
|
28
28
|
*
|
29
29
|
* ```
|
30
30
|
* <script type="module">
|
31
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
32
|
-
*
|
31
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/pipe.js';
|
32
|
+
* new Pipe()
|
33
33
|
* </script>
|
34
34
|
* ```
|
35
35
|
*
|
@@ -39,7 +39,7 @@ const DELIMITER = '|';
|
|
39
39
|
* the word is then converted to uppercase letters and a prefix Hello is added. the two backslash safe the space char.
|
40
40
|
*
|
41
41
|
* @example
|
42
|
-
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
42
|
+
* import {Pipe} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/pipe.js';
|
43
43
|
*
|
44
44
|
* let obj = {
|
45
45
|
* a: {
|
@@ -68,6 +68,7 @@ class Pipe extends Base {
|
|
68
68
|
constructor(pipe) {
|
69
69
|
super();
|
70
70
|
validateString(pipe);
|
71
|
+
|
71
72
|
this.pipe = pipe.split(DELIMITER).map((v) => {
|
72
73
|
return new Transformer(v);
|
73
74
|
});
|