@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.
Files changed (221) hide show
  1. package/CHANGELOG +53 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +1 -1
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/buildtree.js +2 -0
  15. package/dist/modules/data/datasource/namespace.js +1 -1
  16. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  17. package/dist/modules/data/datasource/restapi.js +2 -2
  18. package/dist/modules/data/datasource/storage/localstorage.js +2 -2
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
  21. package/dist/modules/data/datasource/storage.js +2 -2
  22. package/dist/modules/data/datasource.js +2 -2
  23. package/dist/modules/data/diff.js +2 -2
  24. package/dist/modules/data/extend.js +1 -1
  25. package/dist/modules/data/namespace.js +1 -1
  26. package/dist/modules/data/pathfinder.js +2 -2
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +2 -2
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +1 -1
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +2 -2
  33. package/dist/modules/dom/customelement.js +2 -2
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +2 -0
  36. package/dist/modules/dom/locale.js +1 -1
  37. package/dist/modules/dom/namespace.js +1 -1
  38. package/dist/modules/dom/resource/data.js +2 -0
  39. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  40. package/dist/modules/dom/resource/link.js +2 -0
  41. package/dist/modules/dom/resource/script.js +2 -0
  42. package/dist/modules/dom/resource.js +2 -0
  43. package/dist/modules/dom/resourcemanager.js +2 -0
  44. package/dist/modules/dom/template.js +2 -2
  45. package/dist/modules/dom/theme.js +1 -1
  46. package/dist/modules/dom/updater.js +2 -2
  47. package/dist/modules/dom/util.js +1 -1
  48. package/dist/modules/dom/worker/factory.js +2 -0
  49. package/dist/modules/i18n/formatter.js +2 -0
  50. package/dist/modules/i18n/locale.js +1 -1
  51. package/dist/modules/i18n/namespace.js +1 -1
  52. package/dist/modules/i18n/provider.js +1 -1
  53. package/dist/modules/i18n/providers/fetch.js +2 -2
  54. package/dist/modules/i18n/providers/namespace.js +1 -1
  55. package/dist/modules/i18n/translations.js +1 -1
  56. package/dist/modules/logging/handler/console.js +1 -1
  57. package/dist/modules/logging/handler/namespace.js +1 -1
  58. package/dist/modules/logging/handler.js +1 -1
  59. package/dist/modules/logging/logentry.js +1 -1
  60. package/dist/modules/logging/logger.js +1 -1
  61. package/dist/modules/logging/namespace.js +1 -1
  62. package/dist/modules/math/namespace.js +1 -1
  63. package/dist/modules/math/random.js +2 -2
  64. package/dist/modules/monster.js +1 -1
  65. package/dist/modules/namespace.js +1 -1
  66. package/dist/modules/text/formatter.js +2 -2
  67. package/dist/modules/text/namespace.js +1 -1
  68. package/dist/modules/types/base.js +1 -1
  69. package/dist/modules/types/basewithoptions.js +2 -2
  70. package/dist/modules/types/binary.js +1 -1
  71. package/dist/modules/types/dataurl.js +1 -1
  72. package/dist/modules/types/global.js +1 -1
  73. package/dist/modules/types/id.js +1 -1
  74. package/dist/modules/types/is.js +2 -2
  75. package/dist/modules/types/mediatype.js +1 -1
  76. package/dist/modules/types/namespace.js +1 -1
  77. package/dist/modules/types/node.js +2 -0
  78. package/dist/modules/types/nodelist.js +2 -0
  79. package/dist/modules/types/noderecursiveiterator.js +2 -0
  80. package/dist/modules/types/observer.js +1 -1
  81. package/dist/modules/types/observerlist.js +2 -2
  82. package/dist/modules/types/proxyobserver.js +2 -2
  83. package/dist/modules/types/queue.js +1 -1
  84. package/dist/modules/types/randomid.js +1 -1
  85. package/dist/modules/types/regex.js +2 -0
  86. package/dist/modules/types/stack.js +1 -1
  87. package/dist/modules/types/tokenlist.js +2 -2
  88. package/dist/modules/types/typeof.js +1 -1
  89. package/dist/modules/types/uniquequeue.js +1 -1
  90. package/dist/modules/types/uuid.js +2 -0
  91. package/dist/modules/types/validate.js +1 -1
  92. package/dist/modules/types/version.js +2 -2
  93. package/dist/modules/util/clone.js +1 -1
  94. package/dist/modules/util/comparator.js +2 -2
  95. package/dist/modules/util/freeze.js +1 -1
  96. package/dist/modules/util/namespace.js +1 -1
  97. package/dist/modules/util/processing.js +2 -2
  98. package/dist/modules/util/trimspaces.js +2 -0
  99. package/dist/monster.dev.js +1684 -696
  100. package/dist/monster.dev.js.map +1 -1
  101. package/dist/monster.js +2 -2
  102. package/package.json +13 -2
  103. package/source/constants.js +16 -7
  104. package/source/constraints/abstract.js +5 -0
  105. package/source/constraints/abstractoperator.js +5 -0
  106. package/source/constraints/andoperator.js +10 -5
  107. package/source/constraints/invalid.js +8 -3
  108. package/source/constraints/isarray.js +9 -4
  109. package/source/constraints/isobject.js +8 -3
  110. package/source/constraints/oroperator.js +10 -5
  111. package/source/constraints/valid.js +8 -3
  112. package/source/data/buildmap.js +27 -11
  113. package/source/data/buildtree.js +95 -0
  114. package/source/data/datasource/restapi/writeerror.js +49 -0
  115. package/source/data/datasource/restapi.js +87 -20
  116. package/source/data/datasource/storage/localstorage.js +4 -10
  117. package/source/data/datasource/storage/sessionstorage.js +4 -12
  118. package/source/data/datasource/storage.js +7 -14
  119. package/source/data/datasource.js +55 -17
  120. package/source/data/diff.js +8 -8
  121. package/source/data/extend.js +5 -5
  122. package/source/data/pathfinder.js +12 -6
  123. package/source/data/pipe.js +6 -5
  124. package/source/data/transformer.js +131 -24
  125. package/source/dom/assembler.js +2 -2
  126. package/source/dom/attributes.js +24 -24
  127. package/source/dom/constants.js +305 -12
  128. package/source/dom/customcontrol.js +40 -19
  129. package/source/dom/customelement.js +121 -92
  130. package/source/dom/events.js +6 -6
  131. package/source/dom/focusmanager.js +250 -0
  132. package/source/dom/locale.js +10 -5
  133. package/source/dom/resource/data.js +170 -0
  134. package/source/dom/resource/link/stylesheet.js +54 -0
  135. package/source/dom/resource/link.js +125 -0
  136. package/source/dom/resource/script.js +112 -0
  137. package/source/dom/resource.js +268 -0
  138. package/source/dom/resourcemanager.js +214 -0
  139. package/source/dom/template.js +52 -12
  140. package/source/dom/theme.js +3 -3
  141. package/source/dom/updater.js +47 -33
  142. package/source/dom/util.js +6 -6
  143. package/source/dom/worker/factory.js +134 -0
  144. package/source/i18n/formatter.js +140 -0
  145. package/source/i18n/locale.js +10 -8
  146. package/source/i18n/provider.js +4 -4
  147. package/source/i18n/providers/fetch.js +24 -14
  148. package/source/i18n/translations.js +20 -10
  149. package/source/logging/handler/console.js +2 -2
  150. package/source/logging/handler.js +2 -2
  151. package/source/logging/logentry.js +2 -2
  152. package/source/logging/logger.js +4 -4
  153. package/source/math/random.js +11 -5
  154. package/source/namespace.js +1 -1
  155. package/source/text/formatter.js +244 -27
  156. package/source/types/base.js +4 -4
  157. package/source/types/basewithoptions.js +10 -15
  158. package/source/types/binary.js +4 -4
  159. package/source/types/dataurl.js +6 -6
  160. package/source/types/global.js +9 -7
  161. package/source/types/id.js +6 -3
  162. package/source/types/is.js +103 -85
  163. package/source/types/mediatype.js +4 -4
  164. package/source/types/node.js +179 -0
  165. package/source/types/nodelist.js +125 -0
  166. package/source/types/noderecursiveiterator.js +126 -0
  167. package/source/types/observer.js +3 -3
  168. package/source/types/observerlist.js +3 -3
  169. package/source/types/proxyobserver.js +24 -7
  170. package/source/types/queue.js +6 -6
  171. package/source/types/randomid.js +2 -2
  172. package/source/types/regex.js +49 -0
  173. package/source/types/stack.js +2 -2
  174. package/source/types/tokenlist.js +8 -9
  175. package/source/types/typeof.js +3 -3
  176. package/source/types/uniquequeue.js +4 -4
  177. package/source/types/uuid.js +102 -0
  178. package/source/types/validate.js +20 -20
  179. package/source/types/version.js +6 -6
  180. package/source/util/clone.js +4 -5
  181. package/source/util/comparator.js +5 -5
  182. package/source/util/freeze.js +5 -5
  183. package/source/util/processing.js +33 -36
  184. package/source/util/trimspaces.js +85 -0
  185. package/test/cases/data/buildtree.js +149 -0
  186. package/test/cases/data/datasource/restapi.js +1 -1
  187. package/test/cases/data/datasource.js +4 -4
  188. package/test/cases/data/diff.js +4 -4
  189. package/test/cases/data/pathfinder.js +18 -9
  190. package/test/cases/data/pipe.js +26 -2
  191. package/test/cases/data/transformer.js +41 -10
  192. package/test/cases/dom/attributes.js +18 -14
  193. package/test/cases/dom/customcontrol.js +6 -5
  194. package/test/cases/dom/customelement.js +14 -16
  195. package/test/cases/dom/focusmanager.js +111 -0
  196. package/test/cases/dom/locale.js +1 -4
  197. package/test/cases/dom/resource/data.js +129 -0
  198. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  199. package/test/cases/dom/resource/link.js +101 -0
  200. package/test/cases/dom/resource/script.js +115 -0
  201. package/test/cases/dom/resourcemanager.js +118 -0
  202. package/test/cases/dom/updater.js +28 -4
  203. package/test/cases/dom/worker/factory.js +63 -0
  204. package/test/cases/i18n/formatter.js +66 -0
  205. package/test/cases/monster.js +1 -1
  206. package/test/cases/text/formatter.js +71 -8
  207. package/test/cases/types/node.js +196 -0
  208. package/test/cases/types/nodelist.js +64 -0
  209. package/test/cases/types/noderecursiveiterator.js +54 -0
  210. package/test/cases/types/proxyobserver.js +55 -11
  211. package/test/cases/types/regex.js +32 -0
  212. package/test/cases/types/uuid.js +42 -0
  213. package/test/cases/util/freeze.js +30 -4
  214. package/test/cases/util/trimspaces.js +24 -0
  215. package/test/util/cleanupdom.js +48 -0
  216. package/test/util/jsdom.js +22 -9
  217. package/test/web/import.js +15 -0
  218. package/test/web/monster-dev.html +3 -3
  219. package/test/web/monster.html +2 -2
  220. package/test/web/test.html +3 -3
  221. package/test/web/tests.js +7 -7
@@ -4,25 +4,20 @@
4
4
  * @author schukai GmbH
5
5
  */
6
6
 
7
- import {PROPERTY_KEY_INTERNALDATA} from "../../constants.js";
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.23.0/dist/modules/data/datasource/restapi.js';
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.23.0/dist/modules/data/datasource/restapi.js';
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.23.0/dist/modules/data/datasource/restapi.js';
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.set(obj);
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 {Error} the data cannot be written
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
- init['body'] = JSON.stringify(self.get());
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
- throw Error('the data cannot be written (response ' + response.status + ')')
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[internalDataSymbol].getRealSubject()['options'].read, self[internalDataSymbol].getRealSubject()['options'].write);
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 {PROPERTY_KEY_INTERNALDATA} from "../../../constants.js";
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.23.0/dist/modules/data/datasource/storage/localstorage.js';
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.23.0/dist/modules/data/datasource/storage/localstorage.js';
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[internalDataSymbol].getRealSubject()['options'].key);
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 {PROPERTY_KEY_INTERNALDATA} from "../../../constants.js";
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.23.0/dist/modules/data/datasource/storage/sessionstorage.js';
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.23.0/dist/modules/data/datasource/storage/sessionstorage.js';
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[internalDataSymbol].getRealSubject()['options'].key);
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 {PROPERTY_KEY_INTERNALDATA} from "../../constants.js";
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.0/dist/modules/data/datasource/storage.js';
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.23.0/dist/modules/data/datasource/storage.js';
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.23.0/dist/modules/data/datasource/storage.js';
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(self.get()));
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[internalDataSymbol].getRealSubject()['options'].key);
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 {PROPERTY_KEY_INTERNALDATA} from "../constants.js";
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.for(PROPERTY_KEY_INTERNALDATA);
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.23.0/dist/modules/data/datasource.js';
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.23.0/dist/modules/data/datasource.js';
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.23.0/dist/modules/data/datasource.js'
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
- 'options': extend({}, this.defaults),
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[internalDataSymbol].getSubject()['options']).setVia(path, value);
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[internalDataSymbol].getSubject()['options'], self.defaults, options);
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[internalDataSymbol].getRealSubject()['options']).getVia(path);
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
- * @return {*}
193
+ * Returns real object
194
+ *
195
+ * @return {Object|Array}
158
196
  */
159
197
  get() {
160
198
  const self = this;
161
- return self[internalDataSymbol].getSubject()['data'];
199
+ return self[internalDataSymbol].getRealSubject();
162
200
  }
163
201
 
164
202
  /**
165
- * @param {*} data
203
+ * @param {Object|Array} data
166
204
  * @return {Datasource}
167
205
  */
168
206
  set(data) {
169
207
  const self = this;
170
- self[internalDataSymbol].getSubject()['data'] = data;
208
+ self[internalDataSymbol].setSubject(data);
171
209
  return self;
172
210
  }
173
211
 
@@ -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.23.0/dist/modules/data/diff.js';
21
- * console.log(Monster.Data.Diff(a, b))
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.23.0/dist/modules/data/diff.js';
30
- * console.log(Diff(a, b))
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.23.0/dist/modules/data/diff.js';
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 Diff(first, second) {
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', Diff);
249
- export {Monster, Diff}
248
+ assignToNamespace('Monster.Data', diff);
249
+ export {Monster, diff}
@@ -8,15 +8,15 @@ import {isArray, isObject} from "../types/is.js";
8
8
  import {typeOf} from "../types/typeof.js";
9
9
 
10
10
  /**
11
- * extend copies all enumerable own properties from one or
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.23.0/dist/modules/data/extend.js';
19
- * console.log(Monster.Data.extend(a, b))
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.23.0/dist/modules/data/extend.js';
28
- * console.log(extend(a, b))
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.23.0/dist/modules/data/pathfinder.js';
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.23.0/dist/modules/data/pathfinder.js';
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.23.0/dist/modules/data/pathfinder.js';
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.23.0/dist/modules/data/pathfinder.js';
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
- if (check === true && !subject.hasOwnProperty(current)) {
321
- throw Error('unknown value');
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;