@schukai/monster 1.22.0 → 1.26.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/CHANGELOG +56 -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 +1 -1
  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 +2 -2
  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 +1838 -792
  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 +95 -11
  116. package/source/data/datasource/storage/localstorage.js +15 -8
  117. package/source/data/datasource/storage/sessionstorage.js +16 -12
  118. package/source/data/datasource/storage.js +16 -7
  119. package/source/data/datasource.js +60 -16
  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 +182 -102
  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 +40 -10
  140. package/source/dom/theme.js +3 -3
  141. package/source/dom/updater.js +115 -39
  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 +8 -8
  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 +5 -6
  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 +25 -26
  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 +42 -19
  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,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.22.0/dist/modules/data/datasource/restapi.js';
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.22.0/dist/modules/data/datasource/restapi.js';
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.22.0/dist/modules/data/datasource/restapi.js';
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.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
+ }
143
168
 
169
+ self.set(obj);
144
170
  return response;
145
171
  })
146
172
  }
147
173
 
148
174
  /**
149
175
  * @return {Promise}
150
- * @throws {Error} the data cannot be written
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
- 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);
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
- 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
+
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.22.0/dist/modules/data/datasource/storage/localstorage.js';
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.22.0/dist/modules/data/datasource/storage/localstorage.js';
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.LocalStorage()`.
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.22.0/dist/modules/data/datasource/storage/localstorage.js';
19
- * Monster.Data.Datasource.Storage.LocalStorage()
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 {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.22.0/dist/modules/data/datasource/storage/localstorage.js';
28
- * new LocalStorage()
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.22.0/dist/modules/data/datasource/storage.js';
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.22.0/dist/modules/data/datasource/storage.js';
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.22.0/dist/modules/data/datasource/storage.js';
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 {Datasource}
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(self.get()));
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 {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";
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.for(PROPERTY_KEY_INTERNALDATA);
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.22.0/dist/modules/data/datasource.js';
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.22.0/dist/modules/data/datasource.js';
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.22.0/dist/modules/data/datasource.js';
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 Datasource();
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
- 'options': extend({}, this.defaults),
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[internalDataSymbol].getSubject()['options']).setVia(path, value);
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[internalDataSymbol].getSubject()['options'], self.defaults, options);
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[internalDataSymbol].getRealSubject()['options']).getVia(path);
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
- * @return {*}
193
+ * Returns real object
194
+ *
195
+ * @return {Object|Array}
152
196
  */
153
197
  get() {
154
198
  const self = this;
155
- return clone(self[internalDataSymbol].getRealSubject()['data']);
199
+ return self[internalDataSymbol].getRealSubject();
156
200
  }
157
201
 
158
202
  /**
159
- * @param {*} data
203
+ * @param {Object|Array} data
160
204
  * @return {Datasource}
161
205
  */
162
206
  set(data) {
163
207
  const self = this;
164
- self[internalDataSymbol].getSubject()['data'] = data;
208
+ self[internalDataSymbol].setSubject(data);
165
209
  return self;
166
210
  }
167
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.22.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.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.22.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.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.22.0/dist/modules/data/diff.js';
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 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.22.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.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.22.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.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.22.0/dist/modules/data/pathfinder.js';
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.22.0/dist/modules/data/pathfinder.js';
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.22.0/dist/modules/data/pathfinder.js';
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.22.0/dist/modules/data/pathfinder.js';
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
- 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;