@schukai/monster 2.0.14 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/source/constants.mjs +15 -3
  4. package/source/constraints/abstract.mjs +11 -0
  5. package/source/constraints/abstractoperator.mjs +11 -1
  6. package/source/constraints/andoperator.mjs +11 -1
  7. package/source/constraints/invalid.mjs +11 -1
  8. package/source/constraints/isarray.mjs +11 -1
  9. package/source/constraints/isobject.mjs +11 -1
  10. package/source/constraints/namespace.mjs +5 -0
  11. package/source/constraints/oroperator.mjs +11 -1
  12. package/source/constraints/valid.mjs +11 -1
  13. package/source/data/datasource/namespace.mjs +5 -0
  14. package/source/data/datasource/restapi/namespace.mjs +5 -0
  15. package/source/data/datasource/restapi/writeerror.mjs +10 -1
  16. package/source/data/datasource/restapi.mjs +10 -1
  17. package/source/data/datasource/storage/localstorage.mjs +10 -1
  18. package/source/data/datasource/storage/namespace.mjs +5 -0
  19. package/source/data/datasource/storage/sessionstorage.mjs +10 -1
  20. package/source/data/datasource/storage.mjs +10 -1
  21. package/source/data/datasource.mjs +12 -2
  22. package/source/data/namespace.mjs +5 -0
  23. package/source/dom/customcontrol.mjs +11 -1
  24. package/source/dom/customelement.mjs +11 -1
  25. package/source/dom/focusmanager.mjs +11 -1
  26. package/source/dom/namespace.mjs +5 -0
  27. package/source/dom/resource/data.mjs +11 -1
  28. package/source/dom/resource/link/namespace.mjs +5 -0
  29. package/source/dom/resource/link/stylesheet.mjs +11 -1
  30. package/source/dom/resource/link.mjs +11 -1
  31. package/source/dom/resource/namespace.mjs +5 -0
  32. package/source/dom/resource/script.mjs +10 -1
  33. package/source/dom/resource.mjs +8 -0
  34. package/source/dom/template.mjs +11 -1
  35. package/source/dom/theme.mjs +11 -1
  36. package/source/dom/worker/namespace.mjs +5 -0
  37. package/source/i18n/namespace.mjs +5 -0
  38. package/source/i18n/providers/namespace.mjs +5 -0
  39. package/source/logging/handler/namespace.mjs +5 -0
  40. package/source/logging/namespace.mjs +5 -0
  41. package/source/math/namespace.mjs +5 -0
  42. package/source/text/namespace.mjs +5 -0
  43. package/source/types/base.mjs +100 -0
  44. package/source/types/dataurl.mjs +11 -1
  45. package/source/types/mediatype.mjs +11 -1
  46. package/source/types/namespace.mjs +5 -0
  47. package/source/types/node.mjs +11 -1
  48. package/source/types/nodelist.mjs +11 -1
  49. package/source/types/observer.mjs +11 -1
  50. package/source/types/proxyobserver.mjs +11 -1
  51. package/source/types/queue.mjs +11 -1
  52. package/source/types/stack.mjs +10 -1
  53. package/source/types/version.mjs +14 -2
  54. package/source/util/namespace.mjs +5 -0
  55. package/test/cases/constraint/abstractoperator.mjs +38 -0
  56. package/test/cases/dom/resource.mjs +48 -0
  57. package/test/cases/monster.mjs +1 -1
  58. package/test/cases/types/base.mjs +42 -0
  59. package/test/web/mocha.js +10976 -20806
  60. package/test/web/test.html +3 -3
  61. package/test/web/tests.js +68 -12
@@ -16,7 +16,7 @@ import {
16
16
  TAG_SCRIPT
17
17
  } from "../constants.mjs";
18
18
  import {KEY_DOCUMENT, referenceSymbol, Resource} from "../resource.mjs";
19
-
19
+ import {instanceSymbol} from '../../constants.mjs';
20
20
  export {Script}
21
21
 
22
22
  /**
@@ -53,6 +53,15 @@ class Script extends Resource {
53
53
  })
54
54
  }
55
55
 
56
+ /**
57
+ * This method is called by the `instanceof` operator.
58
+ * @returns {symbol}
59
+ * @since 2.1.0
60
+ */
61
+ static get [instanceSymbol]() {
62
+ return Symbol.for("@schukai/monster/dom/resource/script");
63
+ }
64
+
56
65
  /**
57
66
  *
58
67
  * @return {Monster.DOM.Resource.Script}
@@ -14,6 +14,7 @@ import {isString} from "../types/is.mjs";
14
14
  import {Observer} from "../types/observer.mjs";
15
15
  import {ProxyObserver} from "../types/proxyobserver.mjs";
16
16
  import {ATTRIBUTE_CLASS, ATTRIBUTE_ID, ATTRIBUTE_TITLE} from "./constants.mjs";
17
+ import {instanceSymbol} from "../constants.mjs";
17
18
 
18
19
  export {Resource, KEY_DOCUMENT, KEY_QUERY, referenceSymbol}
19
20
 
@@ -190,6 +191,13 @@ class Resource extends BaseWithOptions {
190
191
  static getURLAttribute() {
191
192
  throw new Error("this method must be implemented by derived classes");
192
193
  }
194
+
195
+ /**
196
+ * @return {symbol}
197
+ */
198
+ static get [instanceSymbol]() {
199
+ return Symbol.for("@schukai/monster/dom/resource");
200
+ }
193
201
 
194
202
  }
195
203
 
@@ -10,7 +10,7 @@ import {getGlobalFunction, getGlobalObject} from '../types/global.mjs';
10
10
  import {validateInstance, validateString} from "../types/validate.mjs";
11
11
  import {ATTRIBUTE_TEMPLATE_PREFIX} from "./constants.mjs";
12
12
  import {getDocumentTheme} from "./theme.mjs";
13
-
13
+ import {instanceSymbol} from '../constants.mjs';
14
14
  export {Template}
15
15
 
16
16
  /**
@@ -37,6 +37,16 @@ class Template extends Base {
37
37
  this.template = template;
38
38
  }
39
39
 
40
+ /**
41
+ * This method is called by the `instanceof` operator.
42
+ * @returns {symbol}
43
+ * @since 2.1.0
44
+ */
45
+ static get [instanceSymbol]() {
46
+ return Symbol.for("@schukai/monster/dom/resource/template");
47
+ }
48
+
49
+
40
50
  /**
41
51
  *
42
52
  * @returns {HTMLTemplateElement}
@@ -9,7 +9,7 @@ import {Base} from '../types/base.mjs';
9
9
  import {getGlobalObject} from '../types/global.mjs';
10
10
  import {validateString} from "../types/validate.mjs";
11
11
  import {ATTRIBUTE_THEME_NAME, DEFAULT_THEME} from "./constants.mjs";
12
-
12
+ import {instanceSymbol} from '../constants.mjs';
13
13
  export {Theme, getDocumentTheme}
14
14
 
15
15
  /**
@@ -35,6 +35,16 @@ class Theme extends Base {
35
35
  this.name = name;
36
36
  }
37
37
 
38
+ /**
39
+ * This method is called by the `instanceof` operator.
40
+ * @returns {symbol}
41
+ * @since 2.1.0
42
+ */
43
+ static get [instanceSymbol]() {
44
+ return Symbol.for("@schukai/monster/dom/theme");
45
+ }
46
+
47
+
38
48
  /**
39
49
  *
40
50
  * @returns {string}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * In this namespace you will find classes and methods for handling the DOM.
3
8
  *
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * In this namespace you will find classes and methods for handling locale and localized texts.
3
8
  *
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * In this namespace you will find classes and methods for handling locale and localized texts.
3
8
  *
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * @namespace Monster.Logging.Handler
3
8
  * @memberOf Monster.Logging
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * Namespace for logging.
3
8
  *
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * Namespace for math.
3
8
  *
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * Namespace for texts.
3
8
  *
@@ -5,10 +5,29 @@
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
7
 
8
+ import {instanceSymbol} from "../constants.mjs";
9
+
8
10
  export {Base}
9
11
 
12
+
10
13
  /**
11
14
  * This is the base class from which all monster classes are derived.
15
+ *
16
+ * This class has besides a `toString` which returns the json representation of the object
17
+ * also a functionality to check if an object is an instance of a class.
18
+ *
19
+ * Therefor the class has a static method ` [Symbol.hasInstance](that)` which returns true if the object
20
+ * is an instance of the class.
21
+ * F
22
+ * @see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
23
+ *
24
+ * Derived classes should implement a static getter `instanceSymbol` which returns a unique symbol.
25
+ *
26
+ * ```javascript
27
+ * static get [instanceSymbol]() {
28
+ * return Symbol.for("@schukai/monster/types/base");
29
+ * }
30
+ * ```
12
31
  *
13
32
  * The class was formerly called Object.
14
33
  *
@@ -27,5 +46,86 @@ class Base extends Object {
27
46
  return JSON.stringify(this);
28
47
  };
29
48
 
49
+ /**
50
+ * This method is called by the `instanceof` operator.
51
+ * @returns {symbol}
52
+ * @since 2.1.0
53
+ */
54
+ static get [instanceSymbol]() {
55
+ return Symbol.for("@schukai/monster/types/base");
56
+ }
57
+
58
+ /**
59
+ * This method is called by the `instanceof` operator.
60
+ * @param that
61
+ * @returns {boolean}
62
+ * @since 2.1.0
63
+ */
64
+ static [Symbol.hasInstance](that) {
65
+
66
+ if (that === undefined || that === null || (typeof that !== "object" && typeof that !== "function")) {
67
+ return false;
68
+ }
69
+
70
+ const thatClass = Object.getPrototypeOf(that)
71
+ if (thatClass === undefined || thatClass === null || (typeof thatClass !== "object" && typeof thatClass !== "function")) {
72
+ return false;
73
+ }
74
+
75
+ if (checkInstanceSymbol.apply(this, [thatClass]) === true) {
76
+ return true;
77
+ }
78
+
79
+
80
+ // this call the static method of the super class, if there is one
81
+ return super[Symbol.hasInstance](that);
82
+
83
+ }
84
+
85
+ }
86
+
87
+ /**
88
+ * this function checks if the class has a static getter `instanceSymbol` and if the value of this getter is equal to the
89
+ *
90
+ * @private
91
+ * @param obj
92
+ * @returns {boolean|any|boolean}
93
+ * @since 2.1.0
94
+ */
95
+ function checkInstanceSymbol(obj) {
96
+
97
+ if (this.hasOwnProperty(instanceSymbol) === false) {
98
+ return false;
99
+ }
100
+
101
+ const proto = obj?.constructor;
102
+ if (proto === undefined || proto === null || (typeof proto !== "object" && typeof proto !== "function")) {
103
+ return false;
104
+ }
105
+
106
+ if (proto.hasOwnProperty(instanceSymbol) !== true) {
107
+ return checkInstanceSymbol.apply(this, [obj.__proto__]);
108
+ }
109
+
110
+ const symbol = proto[instanceSymbol];
111
+ if (symbol === undefined) {
112
+
113
+ if (obj.__proto__) {
114
+ return checkInstanceSymbol(obj.__proto__);
115
+ } else {
116
+ return false;
117
+ }
118
+
119
+ }
120
+
121
+ if (symbol === this[instanceSymbol]) {
122
+ return true;
123
+ }
124
+
125
+ return checkInstanceSymbol.apply(this, [obj.__proto__]);
126
+
30
127
 
31
128
  }
129
+
130
+
131
+
@@ -9,7 +9,7 @@ import {Base} from "./base.mjs";
9
9
  import {isString} from "./is.mjs";
10
10
  import {MediaType, parseMediaType} from "./mediatype.mjs";
11
11
  import {validateBoolean, validateInstance, validateString} from "./validate.mjs";
12
-
12
+ import {instanceSymbol} from '../constants.mjs';
13
13
  export {DataUrl, parseDataURL}
14
14
 
15
15
  /**
@@ -52,6 +52,16 @@ class DataUrl extends Base {
52
52
 
53
53
  }
54
54
 
55
+ /**
56
+ * This method is called by the `instanceof` operator.
57
+ * @returns {symbol}
58
+ * @since 2.1.0
59
+ */
60
+ static get [instanceSymbol]() {
61
+ return Symbol.for("@schukai/monster/types/data-url");
62
+ }
63
+
64
+
55
65
  get content() {
56
66
  return this[internal].base64 ? atob(this[internal].content) : this[internal].content;
57
67
  }
@@ -8,7 +8,7 @@
8
8
  import {Base} from "./base.mjs";
9
9
  import {isString} from "./is.mjs";
10
10
  import {validateArray, validateString} from "./validate.mjs";
11
-
11
+ import {instanceSymbol} from '../constants.mjs';
12
12
  export {MediaType, parseMediaType}
13
13
 
14
14
  /**
@@ -57,6 +57,16 @@ class MediaType extends Base {
57
57
 
58
58
  }
59
59
 
60
+ /**
61
+ * This method is called by the `instanceof` operator.
62
+ * @returns {symbol}
63
+ * @since 2.1.0
64
+ */
65
+ static get [instanceSymbol]() {
66
+ return Symbol.for("@schukai/monster/types/media-type");
67
+ }
68
+
69
+
60
70
  /**
61
71
  * @return {String}
62
72
  */
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * Namespace for types.
3
8
  *
@@ -9,7 +9,7 @@ import {Base} from './base.mjs';
9
9
  import {isPrimitive} from "./is.mjs";
10
10
  import {NodeList} from './nodelist.mjs';
11
11
  import {validateInstance} from './validate.mjs';
12
-
12
+ import {instanceSymbol} from '../constants.mjs';
13
13
  export {Node}
14
14
 
15
15
  /**
@@ -52,6 +52,16 @@ class Node extends Base {
52
52
 
53
53
  }
54
54
 
55
+ /**
56
+ * This method is called by the `instanceof` operator.
57
+ * @returns {symbol}
58
+ * @since 2.1.0
59
+ */
60
+ static get [instanceSymbol]() {
61
+ return Symbol.for("@schukai/monster/types/node");
62
+ }
63
+
64
+
55
65
  /**
56
66
  * @property {*}
57
67
  */
@@ -8,7 +8,7 @@
8
8
  import {isArray, isInstance} from "./is.mjs";
9
9
  import {Node} from "./node.mjs";
10
10
  import {validateInstance} from "./validate.mjs";
11
-
11
+ import {instanceSymbol} from '../constants.mjs';
12
12
  export {NodeList}
13
13
 
14
14
  /**
@@ -44,6 +44,16 @@ class NodeList extends Set {
44
44
  }
45
45
  }
46
46
 
47
+ /**
48
+ * This method is called by the `instanceof` operator.
49
+ * @returns {symbol}
50
+ * @since 2.1.0
51
+ */
52
+ static get [instanceSymbol]() {
53
+ return Symbol.for("@schukai/monster/types/node-list");
54
+ }
55
+
56
+
47
57
  /**
48
58
  *
49
59
  * @param {Node} node
@@ -9,7 +9,7 @@ import {Base} from './base.mjs';
9
9
  import {isObject} from './is.mjs';
10
10
  import {TokenList} from './tokenlist.mjs';
11
11
  import {UniqueQueue} from './uniquequeue.mjs';
12
-
12
+ import {instanceSymbol} from '../constants.mjs';
13
13
  export {Observer}
14
14
 
15
15
  /**
@@ -64,6 +64,16 @@ class Observer extends Base {
64
64
  this.queue = new UniqueQueue();
65
65
  }
66
66
 
67
+ /**
68
+ * This method is called by the `instanceof` operator.
69
+ * @returns {symbol}
70
+ * @since 2.1.0
71
+ */
72
+ static get [instanceSymbol]() {
73
+ return Symbol.for("@schukai/monster/types/observer");
74
+ }
75
+
76
+
67
77
  /**
68
78
  *
69
79
  * @param {string} tag
@@ -11,7 +11,7 @@ import {Observer} from "./observer.mjs";
11
11
  import {ObserverList} from "./observerlist.mjs";
12
12
  import {validateObject} from "./validate.mjs";
13
13
  import {extend} from "../data/extend.mjs";
14
-
14
+ import {instanceSymbol} from '../constants.mjs';
15
15
  export {ProxyObserver}
16
16
 
17
17
  /**
@@ -50,6 +50,16 @@ export {ProxyObserver}
50
50
  this.observers = new ObserverList;
51
51
  }
52
52
 
53
+ /**
54
+ * This method is called by the `instanceof` operator.
55
+ * @returns {symbol}
56
+ * @since 2.1.0
57
+ */
58
+ static get [instanceSymbol]() {
59
+ return Symbol.for("@schukai/monster/types/proxy-observer");
60
+ }
61
+
62
+
53
63
  /**
54
64
  * get the real object
55
65
  *
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import {Base} from './base.mjs';
9
-
9
+ import {instanceSymbol} from '../constants.mjs';
10
10
  export {Queue}
11
11
 
12
12
  /**
@@ -29,6 +29,16 @@ class Queue extends Base {
29
29
  this.data = [];
30
30
  }
31
31
 
32
+ /**
33
+ * This method is called by the `instanceof` operator.
34
+ * @returns {symbol}
35
+ * @since 2.1.0
36
+ */
37
+ static get [instanceSymbol]() {
38
+ return Symbol.for("@schukai/monster/types/queue");
39
+ }
40
+
41
+
32
42
 
33
43
  /**
34
44
  * @return {boolean}
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import {Base} from './base.mjs';
9
-
9
+ import {instanceSymbol} from '../constants.mjs';
10
10
  export {Stack}
11
11
 
12
12
  /**
@@ -27,6 +27,15 @@ class Stack extends Base {
27
27
  this.data = [];
28
28
  }
29
29
 
30
+ /**
31
+ * This method is called by the `instanceof` operator.
32
+ * @returns {symbol}
33
+ * @since 2.1.0
34
+ */
35
+ static get [instanceSymbol]() {
36
+ return Symbol.for("@schukai/monster/types/stack");
37
+ }
38
+
30
39
 
31
40
  /**
32
41
  * @return {boolean}
@@ -6,9 +6,11 @@
6
6
  */
7
7
 
8
8
  import {Base} from './base.mjs';
9
+ import {instanceSymbol} from '../constants.mjs';
9
10
 
10
11
  export {Version, getMonsterVersion}
11
12
 
13
+
12
14
  /**
13
15
  * The version object contains a semantic version number
14
16
  *
@@ -72,6 +74,16 @@ class Version extends Base {
72
74
 
73
75
  }
74
76
 
77
+ /**
78
+ * This method is called by the `instanceof` operator.
79
+ * @returns {symbol}
80
+ * @since 2.1.0
81
+ */
82
+ static get [instanceSymbol]() {
83
+ return Symbol.for("@schukai/monster/types/version");
84
+ }
85
+
86
+
75
87
  /**
76
88
  *
77
89
  * @returns {string}
@@ -135,9 +147,9 @@ function getMonsterVersion() {
135
147
  if (monsterVersion instanceof Version) {
136
148
  return monsterVersion;
137
149
  }
138
-
150
+
139
151
  /** don't touch, replaced by make with package.json version */
140
- monsterVersion = new Version('2.0.14')
152
+ monsterVersion = new Version('2.1.0')
141
153
 
142
154
  return monsterVersion;
143
155
 
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Copyright 2022 schukai GmbH
3
+ * SPDX-License-Identifier: AGPL-3.0
4
+ */
5
+
1
6
  /**
2
7
  * Namespace for utilities.
3
8
  *
@@ -0,0 +1,38 @@
1
+ import {Base} from "../../../../application/source/types/base.mjs";
2
+ import {AbstractOperator} from "../../../../application/source/constraints/abstractoperator.mjs";
3
+ import {expect} from "chai"
4
+
5
+ class AbstractConstraintMock extends Base {
6
+
7
+ constructor() {
8
+ super();
9
+ }
10
+
11
+ isValid(value) {
12
+ return Promise.reject(value);
13
+ }
14
+ }
15
+
16
+
17
+ describe('AbstractOperator', function () {
18
+ it('should throw an error when the constraint is not call with parameter', function (done) {
19
+ try {
20
+ new AbstractOperator()
21
+ } catch (e) {
22
+ done();
23
+ }
24
+ });
25
+
26
+ it('should throw not an error when the constraint is not call with parameter', function (done) {
27
+
28
+ try {
29
+ const c = new AbstractOperator(new AbstractConstraintMock(), new AbstractConstraintMock())
30
+ } catch (e) {
31
+ done();
32
+ }
33
+
34
+
35
+
36
+ });
37
+ });
38
+
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+
4
+ import {initJSDOM} from "../../util/jsdom.mjs";
5
+ import {expect} from "chai"
6
+ let Resource,DerivedResource;
7
+
8
+
9
+
10
+ describe('Resource', function() {
11
+
12
+ before(function (done) {
13
+ initJSDOM().then(() => {
14
+
15
+ import("../../../../application/source/dom/resource.mjs").then((m) => {
16
+ Resource = m['Resource'];
17
+
18
+
19
+ DerivedResource = class extends Resource {
20
+ constructor() {
21
+ super({
22
+ "data-url": "http://example.com",
23
+ });
24
+ }
25
+
26
+ static getURLAttribute() {
27
+ return 'data-url';
28
+ }
29
+ }
30
+
31
+ done()
32
+ });
33
+
34
+ });
35
+
36
+
37
+ })
38
+
39
+ describe('DerivedResource', function () {
40
+
41
+ it('should instanceof Resource', function () {
42
+ expect(new DerivedResource()).to.be.an.instanceof(Resource);
43
+ });
44
+
45
+ });
46
+
47
+
48
+ });
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version('2.0.14')
10
+ monsterVersion = new Version('2.1.0')
11
11
 
12
12
  let m = getMonsterVersion();
13
13