@schukai/monster 2.0.16 → 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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/source/constants.mjs +10 -3
- package/source/constraints/abstract.mjs +11 -0
- package/source/constraints/abstractoperator.mjs +11 -1
- package/source/constraints/andoperator.mjs +11 -1
- package/source/constraints/invalid.mjs +11 -1
- package/source/constraints/isarray.mjs +11 -1
- package/source/constraints/isobject.mjs +11 -1
- package/source/constraints/oroperator.mjs +11 -1
- package/source/constraints/valid.mjs +11 -1
- package/source/data/datasource/restapi/writeerror.mjs +10 -1
- package/source/data/datasource/restapi.mjs +10 -1
- package/source/data/datasource/storage/localstorage.mjs +10 -1
- package/source/data/datasource/storage/sessionstorage.mjs +10 -1
- package/source/data/datasource/storage.mjs +10 -1
- package/source/data/datasource.mjs +12 -2
- package/source/dom/customcontrol.mjs +11 -1
- package/source/dom/customelement.mjs +11 -1
- package/source/dom/focusmanager.mjs +11 -1
- package/source/dom/resource/data.mjs +11 -1
- package/source/dom/resource/link/stylesheet.mjs +11 -1
- package/source/dom/resource/link.mjs +11 -1
- package/source/dom/resource/script.mjs +10 -1
- package/source/dom/resource.mjs +8 -0
- package/source/dom/template.mjs +11 -1
- package/source/dom/theme.mjs +11 -1
- package/source/types/base.mjs +100 -0
- package/source/types/dataurl.mjs +11 -1
- package/source/types/mediatype.mjs +11 -1
- package/source/types/node.mjs +11 -1
- package/source/types/nodelist.mjs +11 -1
- package/source/types/observer.mjs +11 -1
- package/source/types/proxyobserver.mjs +11 -1
- package/source/types/queue.mjs +11 -1
- package/source/types/stack.mjs +10 -1
- package/source/types/version.mjs +14 -2
- package/test/cases/constraint/abstractoperator.mjs +38 -0
- package/test/cases/dom/resource.mjs +48 -0
- package/test/cases/monster.mjs +1 -1
- package/test/cases/types/base.mjs +42 -0
- package/test/web/mocha.js +10976 -20806
- package/test/web/test.html +3 -3
- package/test/web/tests.js +68 -12
package/source/types/base.mjs
CHANGED
@@ -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
|
+
|
package/source/types/dataurl.mjs
CHANGED
@@ -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
|
*/
|
package/source/types/node.mjs
CHANGED
@@ -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
|
*
|
package/source/types/queue.mjs
CHANGED
@@ -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}
|
package/source/types/stack.mjs
CHANGED
@@ -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}
|
package/source/types/version.mjs
CHANGED
@@ -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
|
152
|
+
monsterVersion = new Version('2.1.0')
|
141
153
|
|
142
154
|
return monsterVersion;
|
143
155
|
|
@@ -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
|
+
});
|
package/test/cases/monster.mjs
CHANGED
@@ -2,8 +2,29 @@
|
|
2
2
|
|
3
3
|
import {expect} from "chai"
|
4
4
|
import {Base} from "../../../../application/source/types/base.mjs";
|
5
|
+
import {instanceSymbol} from "../../../../application/source/constants.mjs";
|
5
6
|
|
6
7
|
|
8
|
+
|
9
|
+
class BaseDifferentRealm extends Object {
|
10
|
+
|
11
|
+
|
12
|
+
static get [instanceSymbol]() {
|
13
|
+
return Symbol.for("@schukai/monster/types/base");
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
}
|
18
|
+
|
19
|
+
class Subclass extends BaseDifferentRealm {
|
20
|
+
constructor() {
|
21
|
+
super();
|
22
|
+
}
|
23
|
+
static get [instanceSymbol]() {
|
24
|
+
return Symbol.for("@schukai/monster/types/subclass");
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
7
28
|
describe('Base', function () {
|
8
29
|
|
9
30
|
describe('new Base', function () {
|
@@ -17,5 +38,26 @@ describe('Base', function () {
|
|
17
38
|
});
|
18
39
|
|
19
40
|
})
|
41
|
+
|
42
|
+
describe('instancof', function () {
|
43
|
+
|
44
|
+
it('is instance of Base', function () {
|
45
|
+
expect(new Base).to.be.instanceOf(Base);
|
46
|
+
});
|
47
|
+
|
48
|
+
it('subclass instanceof', function () {
|
49
|
+
|
50
|
+
if (new Subclass instanceof Base) {
|
51
|
+
expect(true).to.be.true;
|
52
|
+
} else {
|
53
|
+
expect(false).to.be.true;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
});
|
59
|
+
|
60
|
+
|
61
|
+
})
|
20
62
|
|
21
63
|
})
|