@schukai/monster 3.5.0 → 3.7.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/package.json +1 -1
- package/source/constants.mjs +4 -9
- package/source/constraints/abstract.mjs +4 -6
- package/source/constraints/abstractoperator.mjs +6 -12
- package/source/constraints/andoperator.mjs +3 -6
- package/source/constraints/invalid.mjs +3 -6
- package/source/constraints/isarray.mjs +6 -9
- package/source/constraints/isobject.mjs +4 -7
- package/source/constraints/namespace.mjs +1 -3
- package/source/constraints/oroperator.mjs +26 -25
- package/source/constraints/valid.mjs +3 -6
- package/source/data/buildmap.mjs +20 -36
- package/source/data/buildtree.mjs +29 -29
- package/source/data/datasource/namespace.mjs +1 -1
- package/source/data/datasource/server/restapi/writeerror.mjs +6 -6
- package/source/data/datasource/server/restapi.mjs +51 -65
- package/source/data/datasource/server/webconnect.mjs +26 -35
- package/source/data/datasource/server.mjs +16 -20
- package/source/data/datasource/storage/localstorage.mjs +8 -11
- package/source/data/datasource/storage/sessionstorage.mjs +8 -10
- package/source/data/datasource/storage.mjs +18 -22
- package/source/data/datasource.mjs +27 -43
- package/source/data/diff.mjs +20 -32
- package/source/data/extend.mjs +20 -14
- package/source/data/namespace.mjs +1 -3
- package/source/data/pathfinder.mjs +40 -67
- package/source/data/pipe.mjs +6 -10
- package/source/data/transformer.mjs +141 -157
- package/source/dom/assembler.mjs +6 -9
- package/source/dom/attributes.mjs +36 -48
- package/source/dom/constants.mjs +55 -71
- package/source/dom/customcontrol.mjs +16 -21
- package/source/dom/customelement.mjs +140 -164
- package/source/dom/events.mjs +17 -24
- package/source/dom/focusmanager.mjs +30 -48
- package/source/dom/locale.mjs +16 -19
- package/source/dom/namespace.mjs +1 -1
- package/source/dom/ready.mjs +7 -10
- package/source/dom/resource/data.mjs +38 -46
- package/source/dom/resource/link/namespace.mjs +1 -3
- package/source/dom/resource/link/stylesheet.mjs +7 -11
- package/source/dom/resource/link.mjs +36 -17
- package/source/dom/resource/namespace.mjs +1 -1
- package/source/dom/resource/script.mjs +23 -13
- package/source/dom/resource.mjs +47 -60
- package/source/dom/resourcemanager.mjs +36 -43
- package/source/dom/template.mjs +17 -24
- package/source/dom/theme.mjs +8 -12
- package/source/dom/updater.mjs +150 -196
- package/source/dom/util.mjs +11 -12
- package/source/dom/worker/factory.mjs +21 -25
- package/source/dom/worker/namespace.mjs +1 -1
- package/source/i18n/formatter.mjs +20 -24
- package/source/i18n/locale.mjs +40 -42
- package/source/i18n/namespace.mjs +1 -1
- package/source/i18n/provider.mjs +4 -7
- package/source/i18n/providers/embed.mjs +16 -26
- package/source/i18n/providers/fetch.mjs +30 -36
- package/source/i18n/translations.mjs +15 -22
- package/source/logging/handler/console.mjs +6 -10
- package/source/logging/handler.mjs +15 -18
- package/source/logging/logentry.mjs +8 -9
- package/source/logging/logger.mjs +73 -55
- package/source/logging/namespace.mjs +1 -1
- package/source/math/namespace.mjs +1 -1
- package/source/math/random.mjs +13 -14
- package/source/monster.mjs +132 -100
- package/source/net/namespace.mjs +1 -3
- package/source/net/webconnect/message.mjs +6 -8
- package/source/net/webconnect/namespace.mjs +1 -3
- package/source/net/webconnect.mjs +28 -39
- package/source/text/formatter.mjs +44 -55
- package/source/types/base.mjs +16 -26
- package/source/types/basewithoptions.mjs +8 -14
- package/source/types/binary.mjs +4 -5
- package/source/types/dataurl.mjs +19 -27
- package/source/types/global.mjs +14 -26
- package/source/types/id.mjs +4 -6
- package/source/types/is.mjs +11 -16
- package/source/types/mediatype.mjs +29 -44
- package/source/types/namespace.mjs +0 -1
- package/source/types/node.mjs +16 -22
- package/source/types/nodelist.mjs +10 -14
- package/source/types/noderecursiveiterator.mjs +11 -14
- package/source/types/observablequeue.mjs +13 -16
- package/source/types/observer.mjs +16 -23
- package/source/types/observerlist.mjs +18 -21
- package/source/types/proxyobserver.mjs +24 -37
- package/source/types/queue.mjs +8 -13
- package/source/types/randomid.mjs +10 -10
- package/source/types/regex.mjs +3 -5
- package/source/types/stack.mjs +4 -8
- package/source/types/tokenlist.mjs +24 -31
- package/source/types/typeof.mjs +5 -7
- package/source/types/uniquequeue.mjs +8 -13
- package/source/types/uuid.mjs +18 -25
- package/source/types/validate.mjs +26 -27
- package/source/types/version.mjs +17 -25
- package/source/util/clone.mjs +23 -32
- package/source/util/comparator.mjs +7 -15
- package/source/util/deadmansswitch.mjs +16 -23
- package/source/util/freeze.mjs +5 -7
- package/source/util/namespace.mjs +1 -1
- package/source/util/processing.mjs +33 -39
- package/source/util/trimspaces.mjs +17 -24
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
package/source/constants.mjs
CHANGED
|
@@ -8,11 +8,7 @@
|
|
|
8
8
|
* @author schukai GmbH
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
export {
|
|
12
|
-
internalSymbol,
|
|
13
|
-
internalStateSymbol,
|
|
14
|
-
instanceSymbol
|
|
15
|
-
}
|
|
11
|
+
export { internalSymbol, internalStateSymbol, instanceSymbol };
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
14
|
* @private
|
|
@@ -21,7 +17,7 @@ export {
|
|
|
21
17
|
* @license AGPLv3
|
|
22
18
|
* @since 1.24.0
|
|
23
19
|
*/
|
|
24
|
-
const internalSymbol = Symbol.for(
|
|
20
|
+
const internalSymbol = Symbol.for("@schukai/monster/internal");
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* @private
|
|
@@ -30,11 +26,10 @@ const internalSymbol = Symbol.for('@schukai/monster/internal');
|
|
|
30
26
|
* @license AGPLv3
|
|
31
27
|
* @since 1.25.0
|
|
32
28
|
*/
|
|
33
|
-
const internalStateSymbol = Symbol.for(
|
|
29
|
+
const internalStateSymbol = Symbol.for("@schukai/monster/state");
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* @private
|
|
37
33
|
* @type {symbol}
|
|
38
34
|
*/
|
|
39
|
-
const instanceSymbol = Symbol.for(
|
|
40
|
-
|
|
35
|
+
const instanceSymbol = Symbol.for("@schukai/monster/instance");
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Base} from
|
|
9
|
-
import {instanceSymbol} from
|
|
8
|
+
import { Base } from "../types/base.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
10
|
|
|
11
|
-
export {AbstractConstraint}
|
|
11
|
+
export { AbstractConstraint };
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
15
15
|
*
|
|
16
16
|
* The uniform API of the constraints allows chains to be formed.
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* The abstract constraint defines the api for all constraints. mainly the method isValid() is defined.
|
|
19
19
|
*
|
|
20
20
|
* Derived classes must implement the method isValid().
|
|
@@ -26,7 +26,6 @@ export {AbstractConstraint}
|
|
|
26
26
|
* @summary The abstract constraint
|
|
27
27
|
*/
|
|
28
28
|
class AbstractConstraint extends Base {
|
|
29
|
-
|
|
30
29
|
/**
|
|
31
30
|
*
|
|
32
31
|
*/
|
|
@@ -52,5 +51,4 @@ class AbstractConstraint extends Base {
|
|
|
52
51
|
static get [instanceSymbol]() {
|
|
53
52
|
return Symbol.for("@schukai/monster/constraints/abstract-constraint");
|
|
54
53
|
}
|
|
55
|
-
|
|
56
54
|
}
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {AbstractConstraint} from "./abstract.mjs";
|
|
9
|
-
import {instanceSymbol} from
|
|
10
|
-
export {AbstractOperator}
|
|
8
|
+
import { AbstractConstraint } from "./abstract.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
|
+
export { AbstractOperator };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
14
14
|
*
|
|
15
15
|
* The uniform API of the constraints allows chains to be formed.
|
|
16
16
|
*
|
|
17
|
-
* Operators allow you to link constraints together. for example, you can check whether a value is
|
|
17
|
+
* Operators allow you to link constraints together. for example, you can check whether a value is
|
|
18
18
|
* an object or an array. each operator has two operands that are linked together.
|
|
19
19
|
*
|
|
20
20
|
* @license AGPLv3
|
|
@@ -24,7 +24,6 @@ export {AbstractOperator}
|
|
|
24
24
|
* @summary The abstract operator constraint
|
|
25
25
|
*/
|
|
26
26
|
class AbstractOperator extends AbstractConstraint {
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
*
|
|
30
29
|
* @param {AbstractConstraint} operantA
|
|
@@ -34,13 +33,12 @@ class AbstractOperator extends AbstractConstraint {
|
|
|
34
33
|
constructor(operantA, operantB) {
|
|
35
34
|
super();
|
|
36
35
|
|
|
37
|
-
if (!(operantA instanceof AbstractConstraint
|
|
38
|
-
throw new TypeError("parameters must be from type AbstractConstraint")
|
|
36
|
+
if (!(operantA instanceof AbstractConstraint && operantB instanceof AbstractConstraint)) {
|
|
37
|
+
throw new TypeError("parameters must be from type AbstractConstraint");
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
this.operantA = operantA;
|
|
42
41
|
this.operantB = operantB;
|
|
43
|
-
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
/**
|
|
@@ -51,8 +49,4 @@ class AbstractOperator extends AbstractConstraint {
|
|
|
51
49
|
static get [instanceSymbol]() {
|
|
52
50
|
return Symbol.for("@schukai/monster/constraints/abstract-operator");
|
|
53
51
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
52
|
}
|
|
58
|
-
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {AbstractOperator} from "./abstractoperator.mjs";
|
|
9
|
-
import {instanceSymbol} from
|
|
10
|
-
export {AndOperator}
|
|
8
|
+
import { AbstractOperator } from "./abstractoperator.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
|
+
export { AndOperator };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
@@ -24,7 +24,6 @@ export {AndOperator}
|
|
|
24
24
|
* @summary A and operator constraint
|
|
25
25
|
*/
|
|
26
26
|
class AndOperator extends AbstractOperator {
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* this method return a promise containing the result of the check.
|
|
30
29
|
*
|
|
@@ -43,6 +42,4 @@ class AndOperator extends AbstractOperator {
|
|
|
43
42
|
static get [instanceSymbol]() {
|
|
44
43
|
return Symbol.for("@schukai/monster/constraints/and-operator");
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {AbstractConstraint} from "./abstract.mjs";
|
|
9
|
-
import {instanceSymbol} from
|
|
10
|
-
export {Invalid}
|
|
8
|
+
import { AbstractConstraint } from "./abstract.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
|
+
export { Invalid };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
@@ -24,7 +24,6 @@ export {Invalid}
|
|
|
24
24
|
* @summary A constraint that always invalid
|
|
25
25
|
*/
|
|
26
26
|
class Invalid extends AbstractConstraint {
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* this method return a rejected promise
|
|
30
29
|
*
|
|
@@ -43,6 +42,4 @@ class Invalid extends AbstractConstraint {
|
|
|
43
42
|
static get [instanceSymbol]() {
|
|
44
43
|
return Symbol.for("@schukai/monster/constraints/invalid");
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
}
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {isArray} from "../types/is.mjs";
|
|
9
|
-
import {AbstractConstraint} from "./abstract.mjs";
|
|
10
|
-
import {instanceSymbol} from
|
|
11
|
-
export {IsArray}
|
|
8
|
+
import { isArray } from "../types/is.mjs";
|
|
9
|
+
import { AbstractConstraint } from "./abstract.mjs";
|
|
10
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
11
|
+
export { IsArray };
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* The uniform API of the constraints allows chains to be formed.
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* @externalExample ../../example/constraints/isarray.mjs
|
|
19
19
|
* @license AGPLv3
|
|
20
20
|
* @since 1.3.0
|
|
@@ -23,7 +23,6 @@ export {IsArray}
|
|
|
23
23
|
* @summary A constraint to check if a value is an array
|
|
24
24
|
*/
|
|
25
25
|
class IsArray extends AbstractConstraint {
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* this method return a promise containing the result of the check.
|
|
29
28
|
*
|
|
@@ -46,6 +45,4 @@ class IsArray extends AbstractConstraint {
|
|
|
46
45
|
static get [instanceSymbol]() {
|
|
47
46
|
return Symbol.for("@schukai/monster/constraint/is-array");
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
48
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {isObject} from "../types/is.mjs";
|
|
9
|
-
import {AbstractConstraint} from "./abstract.mjs";
|
|
10
|
-
import {instanceSymbol} from
|
|
11
|
-
export {IsObject}
|
|
8
|
+
import { isObject } from "../types/is.mjs";
|
|
9
|
+
import { AbstractConstraint } from "./abstract.mjs";
|
|
10
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
11
|
+
export { IsObject };
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
@@ -23,7 +23,6 @@ export {IsObject}
|
|
|
23
23
|
* @summary A constraint to check if a value is an object
|
|
24
24
|
*/
|
|
25
25
|
class IsObject extends AbstractConstraint {
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
* this method return a promise containing the result of the check.
|
|
29
28
|
*
|
|
@@ -46,6 +45,4 @@ class IsObject extends AbstractConstraint {
|
|
|
46
45
|
static get [instanceSymbol]() {
|
|
47
46
|
return Symbol.for("@schukai/monster/constraint/is-object");
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
48
|
}
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* SPDX-License-Identifier: AGPL-3.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Constraints are used to define conditions that must be met by the value of a variable so that the value can be transferred to the system.
|
|
10
8
|
*
|
|
@@ -12,4 +10,4 @@
|
|
|
12
10
|
* @memberOf Monster
|
|
13
11
|
* @author schukai GmbH
|
|
14
12
|
*/
|
|
15
|
-
const ns = {};
|
|
13
|
+
const ns = {};
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {AbstractOperator} from "./abstractoperator.mjs";
|
|
9
|
-
import {instanceSymbol} from
|
|
10
|
-
export {OrOperator}
|
|
8
|
+
import { AbstractOperator } from "./abstractoperator.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
|
+
export { OrOperator };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
@@ -21,10 +21,9 @@ export {OrOperator}
|
|
|
21
21
|
* @since 1.3.0
|
|
22
22
|
* @copyright schukai GmbH
|
|
23
23
|
* @memberOf Monster.Constraints
|
|
24
|
-
* @summary A or operator
|
|
24
|
+
* @summary A or operator
|
|
25
25
|
*/
|
|
26
26
|
class OrOperator extends AbstractOperator {
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* this method return a promise containing the result of the check.
|
|
30
29
|
*
|
|
@@ -35,29 +34,34 @@ class OrOperator extends AbstractOperator {
|
|
|
35
34
|
var self = this;
|
|
36
35
|
|
|
37
36
|
return new Promise(function (resolve, reject) {
|
|
38
|
-
let a
|
|
37
|
+
let a;
|
|
38
|
+
let b;
|
|
39
39
|
|
|
40
|
-
self.operantA
|
|
40
|
+
self.operantA
|
|
41
|
+
.isValid(value)
|
|
41
42
|
.then(function () {
|
|
42
43
|
resolve();
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
})
|
|
45
|
+
.catch(function () {
|
|
46
|
+
a = false;
|
|
47
|
+
/** b has already been evaluated and was not true */
|
|
48
|
+
if (b === false) {
|
|
49
|
+
reject();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
50
52
|
|
|
51
|
-
self.operantB
|
|
53
|
+
self.operantB
|
|
54
|
+
.isValid(value)
|
|
52
55
|
.then(function () {
|
|
53
56
|
resolve();
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
})
|
|
58
|
+
.catch(function () {
|
|
59
|
+
b = false;
|
|
60
|
+
/** b has already been evaluated and was not true */
|
|
61
|
+
if (a === false) {
|
|
62
|
+
reject();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -69,7 +73,4 @@ class OrOperator extends AbstractOperator {
|
|
|
69
73
|
static get [instanceSymbol]() {
|
|
70
74
|
return Symbol.for("@schukai/monster/constraints/or-operator");
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
76
|
}
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {AbstractConstraint} from "./abstract.mjs";
|
|
9
|
-
import {instanceSymbol} from
|
|
10
|
-
export {Valid}
|
|
8
|
+
import { AbstractConstraint } from "./abstract.mjs";
|
|
9
|
+
import { instanceSymbol } from "../constants.mjs";
|
|
10
|
+
export { Valid };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constraints are used to define conditions that must be met by the value of a variable.
|
|
@@ -24,7 +24,6 @@ export {Valid}
|
|
|
24
24
|
* @summary A constraint that always valid
|
|
25
25
|
*/
|
|
26
26
|
class Valid extends AbstractConstraint {
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* this method return a promise containing the result of the check.
|
|
30
29
|
*
|
|
@@ -43,6 +42,4 @@ class Valid extends AbstractConstraint {
|
|
|
43
42
|
static get [instanceSymbol]() {
|
|
44
43
|
return Symbol.for("@schukai/monster/constraints/valid");
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
}
|
package/source/data/buildmap.mjs
CHANGED
|
@@ -5,19 +5,18 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {isFunction, isObject, isString} from "../types/is.mjs";
|
|
9
|
-
import {validateString} from "../types/validate.mjs";
|
|
10
|
-
import {clone} from "../util/clone.mjs";
|
|
11
|
-
import {DELIMITER, Pathfinder, WILDCARD} from "./pathfinder.mjs";
|
|
8
|
+
import { isFunction, isObject, isString } from "../types/is.mjs";
|
|
9
|
+
import { validateString } from "../types/validate.mjs";
|
|
10
|
+
import { clone } from "../util/clone.mjs";
|
|
11
|
+
import { DELIMITER, Pathfinder, WILDCARD } from "./pathfinder.mjs";
|
|
12
12
|
|
|
13
|
-
export {buildMap, PARENT, assembleParts}
|
|
13
|
+
export { buildMap, PARENT, assembleParts };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @type {string}
|
|
17
17
|
* @memberOf Monster.Data
|
|
18
18
|
*/
|
|
19
|
-
const PARENT =
|
|
20
|
-
|
|
19
|
+
const PARENT = "^";
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* With the help of the function `buildMap()`, maps can be easily created from data objects.
|
|
@@ -47,10 +46,8 @@ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
|
|
|
47
46
|
v = build(v, valueTemplate);
|
|
48
47
|
this.set(k, v);
|
|
49
48
|
});
|
|
50
|
-
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
|
|
54
51
|
/**
|
|
55
52
|
* @private
|
|
56
53
|
* @param {*} subject
|
|
@@ -61,20 +58,19 @@ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
|
|
|
61
58
|
* @throws {TypeError} selector is neither a string nor a function
|
|
62
59
|
*/
|
|
63
60
|
function assembleParts(subject, selector, filter, callback) {
|
|
64
|
-
|
|
65
61
|
const result = new Map();
|
|
66
62
|
|
|
67
63
|
let map;
|
|
68
64
|
if (isFunction(selector)) {
|
|
69
|
-
map = selector(subject)
|
|
65
|
+
map = selector(subject);
|
|
70
66
|
if (!(map instanceof Map)) {
|
|
71
|
-
throw new TypeError(
|
|
67
|
+
throw new TypeError("the selector callback must return a map");
|
|
72
68
|
}
|
|
73
69
|
} else if (isString(selector)) {
|
|
74
|
-
map = new Map;
|
|
70
|
+
map = new Map();
|
|
75
71
|
buildFlatMap.call(map, subject, selector);
|
|
76
72
|
} else {
|
|
77
|
-
throw new TypeError(
|
|
73
|
+
throw new TypeError("selector is neither a string nor a function");
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
if (!(map instanceof Map)) {
|
|
@@ -87,7 +83,6 @@ function assembleParts(subject, selector, filter, callback) {
|
|
|
87
83
|
}
|
|
88
84
|
|
|
89
85
|
callback.call(result, v, k, m);
|
|
90
|
-
|
|
91
86
|
});
|
|
92
87
|
|
|
93
88
|
return result;
|
|
@@ -102,23 +97,21 @@ function assembleParts(subject, selector, filter, callback) {
|
|
|
102
97
|
* @return {*}
|
|
103
98
|
*/
|
|
104
99
|
function buildFlatMap(subject, selector, key, parentMap) {
|
|
105
|
-
|
|
106
100
|
const result = this;
|
|
107
|
-
const currentMap = new Map;
|
|
101
|
+
const currentMap = new Map();
|
|
108
102
|
|
|
109
103
|
const resultLength = result.size;
|
|
110
104
|
|
|
111
105
|
if (key === undefined) key = [];
|
|
112
106
|
|
|
113
107
|
let parts = selector.split(DELIMITER);
|
|
114
|
-
let current = ""
|
|
108
|
+
let current = "";
|
|
109
|
+
let currentPath = [];
|
|
115
110
|
do {
|
|
116
|
-
|
|
117
111
|
current = parts.shift();
|
|
118
112
|
currentPath.push(current);
|
|
119
113
|
|
|
120
114
|
if (current === WILDCARD) {
|
|
121
|
-
|
|
122
115
|
let finder = new Pathfinder(subject);
|
|
123
116
|
let map;
|
|
124
117
|
|
|
@@ -130,12 +123,11 @@ function buildFlatMap(subject, selector, key, parentMap) {
|
|
|
130
123
|
}
|
|
131
124
|
|
|
132
125
|
for (const [k, o] of map) {
|
|
133
|
-
|
|
134
126
|
let copyKey = clone(key);
|
|
135
127
|
|
|
136
128
|
currentPath.map((a) => {
|
|
137
|
-
copyKey.push(
|
|
138
|
-
})
|
|
129
|
+
copyKey.push(a === WILDCARD ? k : a);
|
|
130
|
+
});
|
|
139
131
|
|
|
140
132
|
let kk = copyKey.join(DELIMITER);
|
|
141
133
|
let sub = buildFlatMap.call(result, o, parts.join(DELIMITER), copyKey, o);
|
|
@@ -146,10 +138,7 @@ function buildFlatMap(subject, selector, key, parentMap) {
|
|
|
146
138
|
|
|
147
139
|
currentMap.set(kk, sub);
|
|
148
140
|
}
|
|
149
|
-
|
|
150
141
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
142
|
} while (parts.length > 0);
|
|
154
143
|
|
|
155
144
|
// no set in child run
|
|
@@ -160,10 +149,8 @@ function buildFlatMap(subject, selector, key, parentMap) {
|
|
|
160
149
|
}
|
|
161
150
|
|
|
162
151
|
return subject;
|
|
163
|
-
|
|
164
152
|
}
|
|
165
153
|
|
|
166
|
-
|
|
167
154
|
/**
|
|
168
155
|
* With the help of this filter callback, values can be filtered out. Only if the filter function returns true, the value is taken for the map.
|
|
169
156
|
*
|
|
@@ -318,7 +305,7 @@ function build(subject, definition, defaultValue) {
|
|
|
318
305
|
if (definition === undefined) return defaultValue ? defaultValue : subject;
|
|
319
306
|
validateString(definition);
|
|
320
307
|
|
|
321
|
-
const regexp = /(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm
|
|
308
|
+
const regexp = /(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm;
|
|
322
309
|
const array = [...definition.matchAll(regexp)];
|
|
323
310
|
|
|
324
311
|
let finder = new Pathfinder(subject);
|
|
@@ -328,20 +315,17 @@ function build(subject, definition, defaultValue) {
|
|
|
328
315
|
}
|
|
329
316
|
|
|
330
317
|
array.forEach((a) => {
|
|
331
|
-
let groups = a?.[
|
|
332
|
-
let placeholder = groups?.[
|
|
318
|
+
let groups = a?.["groups"];
|
|
319
|
+
let placeholder = groups?.["placeholder"];
|
|
333
320
|
if (placeholder === undefined) return;
|
|
334
321
|
|
|
335
|
-
let path = groups?.[
|
|
322
|
+
let path = groups?.["path"];
|
|
336
323
|
|
|
337
324
|
let v = finder.getVia(path);
|
|
338
325
|
if (v === undefined) v = defaultValue;
|
|
339
326
|
|
|
340
327
|
definition = definition.replaceAll(placeholder, v);
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
})
|
|
328
|
+
});
|
|
344
329
|
|
|
345
330
|
return definition;
|
|
346
|
-
|
|
347
331
|
}
|
|
@@ -5,25 +5,25 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {isArray, isObject} from "../types/is.mjs";
|
|
9
|
-
import {Node} from "../types/node.mjs";
|
|
10
|
-
import {NodeList} from "../types/nodelist.mjs";
|
|
11
|
-
import {assembleParts} from "./buildmap.mjs";
|
|
12
|
-
import {extend} from "./extend.mjs";
|
|
8
|
+
import { isArray, isObject } from "../types/is.mjs";
|
|
9
|
+
import { Node } from "../types/node.mjs";
|
|
10
|
+
import { NodeList } from "../types/nodelist.mjs";
|
|
11
|
+
import { assembleParts } from "./buildmap.mjs";
|
|
12
|
+
import { extend } from "./extend.mjs";
|
|
13
13
|
|
|
14
|
-
export {buildTree}
|
|
14
|
+
export { buildTree };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @private
|
|
18
18
|
* @type {symbol}
|
|
19
19
|
*/
|
|
20
|
-
const parentSymbol = Symbol(
|
|
20
|
+
const parentSymbol = Symbol("parent");
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @private
|
|
24
24
|
* @type {symbol}
|
|
25
25
|
*/
|
|
26
|
-
const rootSymbol = Symbol(
|
|
26
|
+
const rootSymbol = Symbol("root");
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @typedef {Object} buildTreeOptions
|
|
@@ -49,17 +49,20 @@ const rootSymbol = Symbol('root');
|
|
|
49
49
|
* @since 1.26.0
|
|
50
50
|
*/
|
|
51
51
|
function buildTree(subject, selector, idKey, parentIDKey, options) {
|
|
52
|
-
|
|
53
|
-
const nodes = new Map;
|
|
52
|
+
const nodes = new Map();
|
|
54
53
|
|
|
55
54
|
if (!isObject(options)) {
|
|
56
|
-
options = {}
|
|
55
|
+
options = {};
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
options = extend(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
options = extend(
|
|
59
|
+
{},
|
|
60
|
+
{
|
|
61
|
+
rootReferences: [null, undefined],
|
|
62
|
+
filter: undefined,
|
|
63
|
+
},
|
|
64
|
+
options,
|
|
65
|
+
);
|
|
63
66
|
|
|
64
67
|
const filter = options?.filter;
|
|
65
68
|
let rootReferences = options.rootReferences;
|
|
@@ -68,13 +71,12 @@ function buildTree(subject, selector, idKey, parentIDKey, options) {
|
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
const childMap = assembleParts(subject, selector, filter, function (o, k, m) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let ref = o?.[parentIDKey]
|
|
74
|
+
const key = o?.[idKey];
|
|
75
|
+
let ref = o?.[parentIDKey];
|
|
74
76
|
if (rootReferences.indexOf(ref) !== -1) ref = rootSymbol;
|
|
75
77
|
|
|
76
78
|
if (key === undefined) {
|
|
77
|
-
throw new Error(
|
|
79
|
+
throw new Error("the object has no value for the specified id");
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
o[parentSymbol] = ref;
|
|
@@ -82,28 +84,26 @@ function buildTree(subject, selector, idKey, parentIDKey, options) {
|
|
|
82
84
|
const node = new Node(o);
|
|
83
85
|
this.has(ref) ? this.get(ref).add(node) : this.set(ref, new NodeList().add(node));
|
|
84
86
|
nodes.set(key, node);
|
|
87
|
+
});
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
nodes.forEach(node => {
|
|
89
|
-
|
|
90
|
-
let id = node?.['value']?.[idKey];
|
|
89
|
+
nodes.forEach((node) => {
|
|
90
|
+
let id = node?.["value"]?.[idKey];
|
|
91
91
|
|
|
92
92
|
if (childMap.has(id)) {
|
|
93
93
|
node.childNodes = childMap.get(id);
|
|
94
|
-
childMap.delete(id)
|
|
94
|
+
childMap.delete(id);
|
|
95
95
|
}
|
|
96
|
-
})
|
|
96
|
+
});
|
|
97
97
|
|
|
98
|
-
const list = new NodeList;
|
|
98
|
+
const list = new NodeList();
|
|
99
99
|
|
|
100
100
|
childMap.forEach((s) => {
|
|
101
101
|
if (s instanceof Set) {
|
|
102
102
|
s.forEach((n) => {
|
|
103
103
|
list.add(n);
|
|
104
|
-
})
|
|
104
|
+
});
|
|
105
105
|
}
|
|
106
|
-
})
|
|
106
|
+
});
|
|
107
107
|
|
|
108
108
|
return list;
|
|
109
109
|
}
|