@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.
Files changed (205) hide show
  1. package/CHANGELOG +48 -1
  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 +1 -1
  14. package/dist/modules/data/datasource/namespace.js +2 -0
  15. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  16. package/dist/modules/data/datasource/restapi.js +2 -0
  17. package/dist/modules/data/datasource/storage/localstorage.js +2 -0
  18. package/dist/modules/data/datasource/storage/namespace.js +2 -0
  19. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -0
  20. package/dist/modules/data/datasource/storage.js +2 -0
  21. package/dist/modules/data/datasource.js +2 -0
  22. package/dist/modules/data/diff.js +2 -2
  23. package/dist/modules/data/extend.js +1 -1
  24. package/dist/modules/data/namespace.js +1 -1
  25. package/dist/modules/data/pathfinder.js +2 -2
  26. package/dist/modules/data/pipe.js +1 -1
  27. package/dist/modules/data/transformer.js +2 -2
  28. package/dist/modules/dom/assembler.js +1 -1
  29. package/dist/modules/dom/attributes.js +1 -1
  30. package/dist/modules/dom/constants.js +2 -2
  31. package/dist/modules/dom/customcontrol.js +2 -2
  32. package/dist/modules/dom/customelement.js +2 -2
  33. package/dist/modules/dom/events.js +1 -1
  34. package/dist/modules/dom/focusmanager.js +2 -0
  35. package/dist/modules/dom/locale.js +1 -1
  36. package/dist/modules/dom/namespace.js +1 -1
  37. package/dist/modules/dom/resource/data.js +2 -0
  38. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  39. package/dist/modules/dom/resource/link.js +2 -0
  40. package/dist/modules/dom/resource/script.js +2 -0
  41. package/dist/modules/dom/resource.js +2 -0
  42. package/dist/modules/dom/resourcemanager.js +2 -0
  43. package/dist/modules/dom/template.js +1 -1
  44. package/dist/modules/dom/theme.js +1 -1
  45. package/dist/modules/dom/updater.js +2 -2
  46. package/dist/modules/dom/util.js +1 -1
  47. package/dist/modules/dom/worker/factory.js +2 -0
  48. package/dist/modules/i18n/locale.js +1 -1
  49. package/dist/modules/i18n/namespace.js +1 -1
  50. package/dist/modules/i18n/provider.js +1 -1
  51. package/dist/modules/i18n/providers/fetch.js +2 -2
  52. package/dist/modules/i18n/providers/namespace.js +1 -1
  53. package/dist/modules/i18n/translations.js +1 -1
  54. package/dist/modules/logging/handler/console.js +1 -1
  55. package/dist/modules/logging/handler/namespace.js +1 -1
  56. package/dist/modules/logging/handler.js +1 -1
  57. package/dist/modules/logging/logentry.js +1 -1
  58. package/dist/modules/logging/logger.js +1 -1
  59. package/dist/modules/logging/namespace.js +1 -1
  60. package/dist/modules/math/namespace.js +1 -1
  61. package/dist/modules/math/random.js +2 -2
  62. package/dist/modules/monster.js +1 -1
  63. package/dist/modules/namespace.js +1 -1
  64. package/dist/modules/text/formatter.js +2 -2
  65. package/dist/modules/text/namespace.js +1 -1
  66. package/dist/modules/types/base.js +1 -1
  67. package/dist/modules/types/basewithoptions.js +2 -2
  68. package/dist/modules/types/binary.js +1 -1
  69. package/dist/modules/types/dataurl.js +1 -1
  70. package/dist/modules/types/global.js +1 -1
  71. package/dist/modules/types/id.js +1 -1
  72. package/dist/modules/types/is.js +1 -1
  73. package/dist/modules/types/mediatype.js +1 -1
  74. package/dist/modules/types/namespace.js +1 -1
  75. package/dist/modules/types/observer.js +1 -1
  76. package/dist/modules/types/observerlist.js +2 -2
  77. package/dist/modules/types/proxyobserver.js +2 -2
  78. package/dist/modules/types/queue.js +1 -1
  79. package/dist/modules/types/randomid.js +1 -1
  80. package/dist/modules/types/stack.js +1 -1
  81. package/dist/modules/types/tokenlist.js +2 -2
  82. package/dist/modules/types/typeof.js +1 -1
  83. package/dist/modules/types/uniquequeue.js +1 -1
  84. package/dist/modules/types/uuid.js +2 -0
  85. package/dist/modules/types/validate.js +1 -1
  86. package/dist/modules/types/version.js +2 -2
  87. package/dist/modules/util/clone.js +2 -2
  88. package/dist/modules/util/comparator.js +2 -2
  89. package/dist/modules/util/freeze.js +1 -1
  90. package/dist/modules/util/namespace.js +1 -1
  91. package/dist/modules/util/processing.js +2 -2
  92. package/dist/modules/util/trimspaces.js +2 -0
  93. package/dist/monster.dev.js +1499 -732
  94. package/dist/monster.dev.js.map +1 -1
  95. package/dist/monster.js +2 -2
  96. package/package.json +1 -1
  97. package/source/constants.js +16 -7
  98. package/source/constraints/andoperator.js +5 -5
  99. package/source/constraints/invalid.js +3 -3
  100. package/source/constraints/isarray.js +3 -3
  101. package/source/constraints/isobject.js +3 -3
  102. package/source/constraints/oroperator.js +5 -5
  103. package/source/constraints/valid.js +3 -3
  104. package/source/data/buildmap.js +6 -6
  105. package/source/data/datasource/namespace.js +16 -0
  106. package/source/data/datasource/restapi/writeerror.js +49 -0
  107. package/source/data/datasource/restapi.js +266 -0
  108. package/source/data/datasource/storage/localstorage.js +64 -0
  109. package/source/data/datasource/storage/namespace.js +16 -0
  110. package/source/data/datasource/storage/sessionstorage.js +61 -0
  111. package/source/data/datasource/storage.js +131 -0
  112. package/source/data/datasource.js +246 -0
  113. package/source/data/diff.js +8 -8
  114. package/source/data/extend.js +5 -5
  115. package/source/data/pathfinder.js +12 -6
  116. package/source/data/pipe.js +6 -5
  117. package/source/data/transformer.js +131 -24
  118. package/source/dom/assembler.js +2 -2
  119. package/source/dom/attributes.js +24 -24
  120. package/source/dom/constants.js +305 -12
  121. package/source/dom/customcontrol.js +40 -19
  122. package/source/dom/customelement.js +182 -103
  123. package/source/dom/events.js +6 -6
  124. package/source/dom/focusmanager.js +251 -0
  125. package/source/dom/locale.js +4 -3
  126. package/source/dom/resource/data.js +170 -0
  127. package/source/dom/resource/link/stylesheet.js +54 -0
  128. package/source/dom/resource/link.js +125 -0
  129. package/source/dom/resource/script.js +112 -0
  130. package/source/dom/resource.js +268 -0
  131. package/source/dom/resourcemanager.js +214 -0
  132. package/source/dom/template.js +40 -10
  133. package/source/dom/theme.js +3 -3
  134. package/source/dom/updater.js +114 -58
  135. package/source/dom/util.js +6 -6
  136. package/source/dom/worker/factory.js +134 -0
  137. package/source/i18n/locale.js +8 -8
  138. package/source/i18n/provider.js +4 -4
  139. package/source/i18n/providers/fetch.js +8 -13
  140. package/source/i18n/translations.js +6 -5
  141. package/source/logging/handler/console.js +2 -2
  142. package/source/logging/handler.js +2 -2
  143. package/source/logging/logentry.js +2 -2
  144. package/source/logging/logger.js +4 -4
  145. package/source/math/random.js +11 -5
  146. package/source/namespace.js +1 -1
  147. package/source/text/formatter.js +82 -7
  148. package/source/types/base.js +4 -4
  149. package/source/types/basewithoptions.js +10 -15
  150. package/source/types/binary.js +8 -8
  151. package/source/types/dataurl.js +6 -6
  152. package/source/types/global.js +9 -7
  153. package/source/types/id.js +2 -2
  154. package/source/types/is.js +23 -23
  155. package/source/types/mediatype.js +4 -4
  156. package/source/types/observer.js +3 -3
  157. package/source/types/observerlist.js +3 -3
  158. package/source/types/proxyobserver.js +24 -7
  159. package/source/types/queue.js +5 -5
  160. package/source/types/randomid.js +2 -2
  161. package/source/types/stack.js +2 -2
  162. package/source/types/tokenlist.js +8 -9
  163. package/source/types/typeof.js +3 -3
  164. package/source/types/uniquequeue.js +4 -4
  165. package/source/types/uuid.js +102 -0
  166. package/source/types/validate.js +20 -20
  167. package/source/types/version.js +6 -6
  168. package/source/util/clone.js +5 -6
  169. package/source/util/comparator.js +5 -5
  170. package/source/util/freeze.js +5 -5
  171. package/source/util/processing.js +33 -36
  172. package/source/util/trimspaces.js +85 -0
  173. package/test/cases/data/datasource/restapi.js +89 -0
  174. package/test/cases/data/datasource/storage/localstorage.js +47 -0
  175. package/test/cases/data/datasource/storage/sessionstorage.js +47 -0
  176. package/test/cases/data/datasource.js +60 -0
  177. package/test/cases/data/diff.js +4 -4
  178. package/test/cases/data/pathfinder.js +18 -9
  179. package/test/cases/data/pipe.js +26 -2
  180. package/test/cases/data/transformer.js +41 -10
  181. package/test/cases/dom/customcontrol.js +6 -5
  182. package/test/cases/dom/customelement.js +25 -26
  183. package/test/cases/dom/focusmanager.js +111 -0
  184. package/test/cases/dom/locale.js +1 -4
  185. package/test/cases/dom/resource/data.js +129 -0
  186. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  187. package/test/cases/dom/resource/link.js +101 -0
  188. package/test/cases/dom/resource/script.js +115 -0
  189. package/test/cases/dom/resourcemanager.js +118 -0
  190. package/test/cases/dom/updater.js +42 -19
  191. package/test/cases/dom/worker/factory.js +63 -0
  192. package/test/cases/monster.js +1 -1
  193. package/test/cases/text/formatter.js +38 -6
  194. package/test/cases/types/proxyobserver.js +55 -11
  195. package/test/cases/types/uuid.js +42 -0
  196. package/test/cases/util/freeze.js +30 -4
  197. package/test/cases/util/trimspaces.js +24 -0
  198. package/test/util/cleanupdom.js +48 -0
  199. package/test/util/jsdom.js +23 -9
  200. package/test/util/localstorage.js +81 -0
  201. package/test/web/import.js +13 -0
  202. package/test/web/monster-dev.html +3 -3
  203. package/test/web/monster.html +2 -2
  204. package/test/web/test.html +3 -3
  205. package/test/web/tests.js +7 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "1.21.1",
3
+ "version": "1.25.0",
4
4
  "types": "./source/types/package.d.ts",
5
5
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
6
6
  "keywords": [
@@ -7,16 +7,25 @@ import {Monster} from './namespace.js';
7
7
  */
8
8
 
9
9
  /**
10
- * formerly known as PROPERTY_KEY_OPTIONS
11
- *
10
+ * @private
11
+ * @type {symbol}
12
12
  * @memberOf Monster
13
- * @type {string}
14
- * @since 1.15.0
13
+ * @since 1.24.0
15
14
  */
16
- const PROPERTY_KEY_INTERNALDATA = 'monsterInternalData';
15
+ const internalSymbol = Symbol('internalData');
16
+
17
+ /**
18
+ * @private
19
+ * @type {symbol}
20
+ * @memberOf Monster
21
+ * @since 1.25.0
22
+ */
23
+ const internalStateSymbol = Symbol('state');
17
24
 
18
25
 
19
26
  export {
20
27
  Monster,
21
- PROPERTY_KEY_INTERNALDATA
22
- }
28
+ internalSymbol,
29
+ internalStateSymbol
30
+ }
31
+
@@ -12,7 +12,7 @@ import {AbstractOperator} from "./abstractoperator.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/andoperator.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/andoperator.js';
16
16
  * new Monster.Constraint.AndOperator();
17
17
  * </script>
18
18
  * ```
@@ -21,16 +21,16 @@ import {AbstractOperator} from "./abstractoperator.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/andoperator.js';
24
+ * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/andoperator.js';
25
25
  * new AndOperator();
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/valid.js';
32
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/invalid.js';
33
- * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/andoperator.js';
31
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/valid.js';
32
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/invalid.js';
33
+ * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/andoperator.js';
34
34
  *
35
35
  * new AndOperator(
36
36
  * new Valid(), new Valid()).isValid()
@@ -13,7 +13,7 @@ import {AbstractConstraint} from "./abstract.js";
13
13
  *
14
14
  * ```
15
15
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/invalid.js';
16
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/invalid.js';
17
17
  * new Monster.Constraint.Invalid();
18
18
  * </script>
19
19
  * ```
@@ -22,14 +22,14 @@ import {AbstractConstraint} from "./abstract.js";
22
22
  *
23
23
  * ```
24
24
  * <script type="module">
25
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/invalid.js';
25
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/invalid.js';
26
26
  * new Invalid();
27
27
  * </script>
28
28
  * ```
29
29
  *
30
30
  * @example
31
31
  *
32
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/invalid.js';
32
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/invalid.js';
33
33
  *
34
34
  * new Invalid().isValid()
35
35
  * .then(()=>console.log(true))
@@ -12,7 +12,7 @@ import {AbstractConstraint} from "./abstract.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isarray.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isarray.js';
16
16
  * console.log(new Monster.Constraint.IsArray())
17
17
  * </script>
18
18
  * ```
@@ -21,14 +21,14 @@ import {AbstractConstraint} from "./abstract.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isarray.js';
24
+ * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isarray.js';
25
25
  * console.log(new IsArray())
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isarray.js';
31
+ * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isarray.js';
32
32
  *
33
33
  * new IsArray()
34
34
  * .isValid([])
@@ -12,7 +12,7 @@ import {AbstractConstraint} from "./abstract.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isobject.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isobject.js';
16
16
  * console.log(new Monster.Constraint.IsObject())
17
17
  * </script>
18
18
  * ```
@@ -21,14 +21,14 @@ import {AbstractConstraint} from "./abstract.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isobject.js';
24
+ * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isobject.js';
25
25
  * console.log(new IsObject())
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/isobject.js';
31
+ * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/isobject.js';
32
32
  *
33
33
  * new IsObject()
34
34
  * .isValid({})
@@ -11,7 +11,7 @@ import {AbstractOperator} from "./abstractoperator.js";
11
11
  *
12
12
  * ```
13
13
  * <script type="module">
14
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraint/oroperator.js';
14
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraint/oroperator.js';
15
15
  * new Monster.Constraint.OrOperator();
16
16
  * </script>
17
17
  * ```
@@ -20,16 +20,16 @@ import {AbstractOperator} from "./abstractoperator.js";
20
20
  *
21
21
  * ```
22
22
  * <script type="module">
23
- * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraint/oroperator.js';
23
+ * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraint/oroperator.js';
24
24
  * new OrOperator();
25
25
  * </script>
26
26
  * ```
27
27
  *
28
28
  * @example
29
29
  *
30
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/valid.js';
31
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/invalid.js';
32
- * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/oroperator.js';
30
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/valid.js';
31
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/invalid.js';
32
+ * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/oroperator.js';
33
33
  *
34
34
  * new OrOperator(
35
35
  * new Valid(), new Invalid()).isValid()
@@ -13,7 +13,7 @@ import {AbstractConstraint} from "./abstract.js";
13
13
  *
14
14
  * ```
15
15
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/valid.js';
16
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/valid.js';
17
17
  * new Monster.Constraint.Valid();
18
18
  * </script>
19
19
  * ```
@@ -22,14 +22,14 @@ import {AbstractConstraint} from "./abstract.js";
22
22
  *
23
23
  * ```
24
24
  * <script type="module">
25
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/valid.js';
25
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/valid.js';
26
26
  * new Valid();
27
27
  * </script>
28
28
  * ```
29
29
  *
30
30
  * @example
31
31
  *
32
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/constraints/valid.js';
32
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/constraints/valid.js';
33
33
  *
34
34
  * new Valid().isValid()
35
35
  * .then(()=>console.log(true))
@@ -20,7 +20,7 @@ import {DELIMITER, Pathfinder, WILDCARD} from "./pathfinder.js";
20
20
  *
21
21
  * ```
22
22
  * <script type="module">
23
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/data/buildmap.js';
23
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/buildmap.js';
24
24
  * console.log(Monster.Data.buildMap())
25
25
  * </script>
26
26
  * ```
@@ -29,18 +29,18 @@ import {DELIMITER, Pathfinder, WILDCARD} from "./pathfinder.js";
29
29
  *
30
30
  * ```
31
31
  * <script type="module">
32
- * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/data/buildmap.js';
32
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/buildmap.js';
33
33
  * console.log(buildMap())
34
34
  * </script>
35
35
  * ```
36
- *
36
+ *
37
37
  * The templates determine the appearance of the keys and the value of the map. Either a single value `id` can be taken or a composite key `${id} ${name}` can be used.
38
- *
38
+ *
39
39
  * If you want to access values of the parent data set, you have to use the `^` character `${id} ${^.name}`.
40
40
  *
41
41
  * @example
42
42
  *
43
- * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/data/buildmap.js';
43
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/buildmap.js';
44
44
  * // a typical data structure as reported by an api
45
45
  *
46
46
  * let map;
@@ -239,7 +239,7 @@ function buildFlatMap(subject, selector, key, parentMap) {
239
239
  * Alternatively to a string selector a callback can be specified. this must return a map.
240
240
  *
241
241
  * @example
242
- * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.21.1/dist/modules/data/buildmap.js';
242
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/buildmap.js';
243
243
  *
244
244
  * let obj = {
245
245
  * "data": [
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Namespace for datasources
5
+ *
6
+ * @namespace Monster.Data.Datasource
7
+ * @memberOf Monster.Data
8
+ * @author schukai GmbH
9
+ */
10
+
11
+
12
+ /**
13
+ * @private
14
+ * @type {string}
15
+ */
16
+ export const namespace = "Monster.Data.Datasource";
@@ -0,0 +1,49 @@
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
+
10
+ /**
11
+ * Error message for API requests with extension of request and validation.
12
+ *
13
+ * @since 1.24.0
14
+ * @copyright schukai GmbH
15
+ * @memberOf Monster.Data.Datasource.RestAPI
16
+ * @summary the error is thrown by the rest api in case of error
17
+ */
18
+ class WriteError extends Error {
19
+ /**
20
+ *
21
+ * @param {string} message
22
+ * @param {Response} response
23
+ */
24
+ constructor(message, response, validation) {
25
+ super(message);
26
+ this[internalSymbol] = {
27
+ response: response,
28
+ validation: validation
29
+ };
30
+ }
31
+
32
+ /**
33
+ * @return {Response}
34
+ */
35
+ getResponse() {
36
+ return this[internalSymbol]['response']
37
+ }
38
+
39
+ /**
40
+ * @return {Object}
41
+ */
42
+ getValidation() {
43
+ return this[internalSymbol]['validation']
44
+ }
45
+ }
46
+
47
+
48
+ assignToNamespace('Monster.Data.Datasource.RestAPI', WriteError);
49
+ export {Monster, WriteError}
@@ -0,0 +1,266 @@
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 {isObject} from "../../types/is.js";
10
+ import {Datasource} from "../datasource.js";
11
+ import {Pathfinder} from "../pathfinder.js";
12
+ import {Pipe} from "../pipe.js";
13
+ import {WriteError} from "./restapi/writeerror.js";
14
+
15
+ /**
16
+ * You can create an object of this class using the monster namespace `Monster.Data.Datasource.RestAPI()`.
17
+ *
18
+ * ```
19
+ * <script type="module">
20
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/restapi.js';
21
+ * Monster.Data.Datasource.RestAPI()
22
+ * </script>
23
+ * ```
24
+ *
25
+ * Alternatively you can import the class directly
26
+ *
27
+ * ```
28
+ * <script type="module">
29
+ * import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/restapi.js';
30
+ * new RestAPI()
31
+ * </script>
32
+ * ```
33
+ *
34
+ * @example
35
+ *
36
+ * import {RestAPI} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/restapi.js';
37
+ *
38
+ * const ds = new RestAPI({
39
+ * url: 'https://httpbin.org/get'
40
+ * },{
41
+ * url: 'https://httpbin.org/post'
42
+ * });
43
+ *
44
+ * ds.set({flag:true})
45
+ * ds.write().then(()=>console.log('done'));
46
+ * ds.read().then(()=>console.log('done'));
47
+ *
48
+ * @since 1.22.0
49
+ * @copyright schukai GmbH
50
+ * @memberOf Monster.Data.Datasource
51
+ * @summary The LocalStorage class encapsulates the access to data objects.
52
+ */
53
+ class RestAPI extends Datasource {
54
+
55
+ /**
56
+ *
57
+ * @param {Object} [readDefinition] An options object containing any custom settings that you want to apply to the read request.
58
+ * @param {Object} [writeDefinition] An options object containing any custom settings that you want to apply to the write request.
59
+ * @throws {TypeError} value is not a string
60
+ */
61
+ constructor(readDefinition, writeDefinition) {
62
+ super();
63
+
64
+ const options = {}
65
+
66
+ if (isObject(readDefinition)) options.read = readDefinition;
67
+ if (isObject(writeDefinition)) options.write = writeDefinition;
68
+
69
+ this.setOptions(options);
70
+
71
+ }
72
+
73
+ /**
74
+ * @property {string} url=undefined Defines the resource that you wish to fetch.
75
+ * @property {Object} write={} Options
76
+ * @property {Object} write.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}
77
+ * @property {string} write.init.method=POST
78
+ * @property {string} write.acceptedStatus=[200,201]
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
+ * @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
+ * @property {string} read.init.method=GET
87
+ * @property {string} read.acceptedStatus=[200]
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.
92
+ */
93
+ get defaults() {
94
+ return Object.assign({}, super.defaults, {
95
+ write: {
96
+ init: {
97
+ method: 'POST',
98
+ },
99
+ acceptedStatus: [200, 201],
100
+ url: undefined,
101
+ mapping: {
102
+ transformer: undefined,
103
+ callbacks: []
104
+ },
105
+ report: {
106
+ path: undefined
107
+ }
108
+ },
109
+ read: {
110
+ init: {
111
+ method: 'GET'
112
+ },
113
+ acceptedStatus: [200],
114
+ url: undefined,
115
+ mapping: {
116
+ transformer: undefined,
117
+ callbacks: []
118
+ },
119
+ },
120
+
121
+ });
122
+ }
123
+
124
+ /**
125
+ * @return {Promise}
126
+ * @throws {Error} the options does not contain a valid json definition
127
+ * @throws {TypeError} value is not a object
128
+ * @throws {Error} the data cannot be read
129
+ */
130
+ read() {
131
+ const self = this;
132
+ let response;
133
+
134
+ let init = self.getOption('read.init');
135
+ if (!isObject(init)) init = {};
136
+
137
+ return fetch(self.getOption('read.url'), init).then(resp => {
138
+ response = resp;
139
+
140
+ const acceptedStatus = self.getOption('read.acceptedStatus', [200]);
141
+
142
+ if (acceptedStatus.indexOf(resp.status) === -1) {
143
+ throw Error('the data cannot be read (response ' + resp.status + ')')
144
+ }
145
+
146
+ return resp.text()
147
+ }).then(body => {
148
+
149
+ let obj;
150
+
151
+ try {
152
+ obj = JSON.parse(body);
153
+
154
+ } catch (e) {
155
+
156
+ if (body.length > 100) {
157
+ body = body.substring(0, 97) + '...';
158
+ }
159
+
160
+ throw new Error('the response does not contain a valid json (actual: ' + body + ').');
161
+ }
162
+
163
+ let transformation = self.getOption('read.mapping.transformer');
164
+ if (transformation !== undefined) {
165
+ const pipe = new Pipe(transformation);
166
+ obj = pipe.run(obj);
167
+ }
168
+
169
+ self.set(obj);
170
+ return response;
171
+ })
172
+ }
173
+
174
+ /**
175
+ * @return {Promise}
176
+ * @throws {WriteError} the data cannot be written
177
+ */
178
+ write() {
179
+ const self = this;
180
+
181
+
182
+ let init = self.getOption('write.init');
183
+ if (!isObject(init)) init = {};
184
+ if (typeof init['headers'] !== 'object') {
185
+ init['headers'] = {
186
+ 'Content-Type': 'application/json'
187
+ }
188
+ }
189
+
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);
208
+
209
+ return fetch(self.getOption('write.url'), init).then(response => {
210
+
211
+ const acceptedStatus = self.getOption('write.acceptedStatus', [200, 2001]);
212
+
213
+ if (acceptedStatus.indexOf(response.status) === -1) {
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
+
236
+ }
237
+
238
+ return response;
239
+ });
240
+ }
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
+
251
+ }
252
+
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
+
265
+ assignToNamespace('Monster.Data.Datasource', RestAPI);
266
+ export {Monster, RestAPI}
@@ -0,0 +1,64 @@
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
+ /**
15
+ *
16
+ *
17
+ * You can create an object of this class using the monster namespace `Monster.Data.Datasource.Storage.LocalStorage()`.
18
+ *
19
+ * ```
20
+ * <script type="module">
21
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage/localstorage.js';
22
+ * Monster.Data.Datasource.Storage.LocalStorage()
23
+ * </script>
24
+ * ```
25
+ *
26
+ * Alternatively you can import the class directly
27
+ *
28
+ * ```
29
+ * <script type="module">
30
+ * import {LocalStorage} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.25.0/dist/modules/data/datasource/storage/localstorage.js';
31
+ * new LocalStorage()
32
+ * </script>
33
+ * ```
34
+ *
35
+ * @since 1.22.0
36
+ * @copyright schukai GmbH
37
+ * @memberOf Monster.Data.Datasource.Storage
38
+ * @summary The LocalStorage class encapsulates the access to data objects.
39
+ */
40
+ class LocalStorage extends Storage {
41
+
42
+ /**
43
+ * @throws {Error} this method must be implemented by derived classes.
44
+ * @return {external:localStorage}
45
+ * @private
46
+ */
47
+ [storageObjectSymbol]() {
48
+ return getGlobalObject('localStorage');
49
+ }
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
+
61
+ }
62
+
63
+ assignToNamespace('Monster.Data.Datasource.Storage', LocalStorage);
64
+ export {Monster, LocalStorage}
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Namespace for storages
5
+ *
6
+ * @namespace Monster.Data.Datasource.Storage
7
+ * @memberOf Monster.Data.Datasource
8
+ * @author schukai GmbH
9
+ */
10
+
11
+
12
+ /**
13
+ * @private
14
+ * @type {string}
15
+ */
16
+ export const namespace = "Monster.Data.Datasource.Storage";