@schukai/monster 3.4.2 → 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/example/i18n/providers/embed.mjs +5 -0
- 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 +17 -21
- 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 +41 -10
- 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 +115 -0
- package/source/i18n/providers/fetch.mjs +33 -38
- package/source/i18n/translations.mjs +16 -20
- 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/dom/locale.mjs +15 -0
- package/test/cases/i18n/providers/embed.mjs +72 -0
- package/test/cases/monster.mjs +1 -1
|
@@ -5,21 +5,21 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {internalSymbol} from "../../constants.mjs";
|
|
9
|
-
import {extend} from "../../data/extend.mjs";
|
|
10
|
-
import {Formatter} from "../../text/formatter.mjs";
|
|
11
|
-
import {getGlobalFunction} from "../../types/global.mjs";
|
|
12
|
-
import {isInstance, isString} from "../../types/is.mjs";
|
|
13
|
-
import {validateObject, validateString} from "../../types/validate.mjs";
|
|
14
|
-
import {parseLocale} from "../locale.mjs";
|
|
15
|
-
import {Provider} from "../provider.mjs";
|
|
16
|
-
import {Translations} from "../translations.mjs";
|
|
17
|
-
|
|
18
|
-
export {Fetch}
|
|
8
|
+
import { internalSymbol } from "../../constants.mjs";
|
|
9
|
+
import { extend } from "../../data/extend.mjs";
|
|
10
|
+
import { Formatter } from "../../text/formatter.mjs";
|
|
11
|
+
import { getGlobalFunction } from "../../types/global.mjs";
|
|
12
|
+
import { isInstance, isString } from "../../types/is.mjs";
|
|
13
|
+
import { validateObject, validateString } from "../../types/validate.mjs";
|
|
14
|
+
import { parseLocale } from "../locale.mjs";
|
|
15
|
+
import { Provider } from "../provider.mjs";
|
|
16
|
+
import { Translations } from "../translations.mjs";
|
|
17
|
+
|
|
18
|
+
export { Fetch };
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* The fetch provider retrieves a JSON file from the given URL and returns a translation object.
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* @externalExample ../../../example/i18n/providers/fetch.mjs
|
|
24
24
|
* @license AGPLv3
|
|
25
25
|
* @since 1.13.0
|
|
@@ -28,17 +28,16 @@ export {Fetch}
|
|
|
28
28
|
* @see {@link https://datatracker.ietf.org/doc/html/rfc3066}
|
|
29
29
|
* @tutorial i18n-locale-and-formatter
|
|
30
30
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
class Fetch extends Provider {
|
|
33
32
|
/**
|
|
34
33
|
* As options the key `fetch` can be passed. This config object is passed to the fetch method as init.
|
|
35
|
-
*
|
|
34
|
+
*
|
|
36
35
|
* The url may contain placeholders (language, script, region, variants, extlang, privateUse), so you can specify one url for all translations.
|
|
37
|
-
*
|
|
36
|
+
*
|
|
38
37
|
* ```
|
|
39
38
|
* new Fetch('https://www.example.com/assets/${language}.json')
|
|
40
39
|
* ```
|
|
41
|
-
*
|
|
40
|
+
*
|
|
42
41
|
* @param {string|URL} url
|
|
43
42
|
* @param {Object} options see {@link Monster.I18n.Providers.Fetch#defaults}
|
|
44
43
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
|
@@ -66,7 +65,6 @@ export {Fetch}
|
|
|
66
65
|
* @property {Object} options
|
|
67
66
|
*/
|
|
68
67
|
this[internalSymbol] = extend({}, super.defaults, this.defaults, validateObject(options));
|
|
69
|
-
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
/**
|
|
@@ -83,18 +81,19 @@ export {Fetch}
|
|
|
83
81
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API}
|
|
84
82
|
*/
|
|
85
83
|
get defaults() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
return extend(
|
|
85
|
+
{
|
|
86
|
+
fetch: {
|
|
87
|
+
method: "GET", // *GET, POST, PUT, DELETE, etc.
|
|
88
|
+
mode: "cors", // no-cors, *cors, same-origin
|
|
89
|
+
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
|
90
|
+
credentials: "omit", // include, *same-origin, omit
|
|
91
|
+
redirect: "follow", // manual, *follow, error
|
|
92
|
+
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
super.defaults,
|
|
96
|
+
);
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
/**
|
|
@@ -103,20 +102,16 @@ export {Fetch}
|
|
|
103
102
|
* @return {Promise}
|
|
104
103
|
*/
|
|
105
104
|
getTranslations(locale) {
|
|
106
|
-
|
|
107
105
|
if (isString(locale)) {
|
|
108
106
|
locale = parseLocale(locale);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
|
-
let formatter = new Formatter(locale.getMap())
|
|
109
|
+
let formatter = new Formatter(locale.getMap());
|
|
112
110
|
|
|
113
|
-
return getGlobalFunction(
|
|
114
|
-
.then((response) => response.json())
|
|
111
|
+
return getGlobalFunction("fetch")(formatter.format(this.url), this.getOption("fetch", {}))
|
|
112
|
+
.then((response) => response.json())
|
|
113
|
+
.then((data) => {
|
|
115
114
|
return new Translations(locale).assignTranslations(data);
|
|
116
115
|
});
|
|
117
|
-
|
|
118
116
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
117
|
}
|
|
122
|
-
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Base} from "../types/base.mjs";
|
|
9
|
-
import {isObject, isString} from "../types/is.mjs";
|
|
10
|
-
import {validateInstance, validateInteger, validateObject, validateString} from "../types/validate.mjs";
|
|
11
|
-
import {Locale, parseLocale} from "./locale.mjs";
|
|
8
|
+
import { Base } from "../types/base.mjs";
|
|
9
|
+
import { isObject, isString } from "../types/is.mjs";
|
|
10
|
+
import { validateInstance, validateInteger, validateObject, validateString } from "../types/validate.mjs";
|
|
11
|
+
import { Locale, parseLocale } from "./locale.mjs";
|
|
12
12
|
|
|
13
|
-
export {Translations}
|
|
13
|
+
export { Translations };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* With this class you can manage translations and access the keys.
|
|
@@ -23,7 +23,6 @@ export {Translations}
|
|
|
23
23
|
* @see https://datatracker.ietf.org/doc/html/rfc3066
|
|
24
24
|
*/
|
|
25
25
|
class Translations extends Base {
|
|
26
|
-
|
|
27
26
|
/**
|
|
28
27
|
*
|
|
29
28
|
* @param {Locale} locale
|
|
@@ -37,10 +36,8 @@ class Translations extends Base {
|
|
|
37
36
|
|
|
38
37
|
this.locale = validateInstance(locale, Locale);
|
|
39
38
|
this.storage = new Map();
|
|
40
|
-
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
|
|
44
41
|
/**
|
|
45
42
|
* Fetches a text using the specified key.
|
|
46
43
|
* If no suitable key is found, `defaultText` is taken.
|
|
@@ -53,7 +50,7 @@ class Translations extends Base {
|
|
|
53
50
|
getText(key, defaultText) {
|
|
54
51
|
if (!this.storage.has(key)) {
|
|
55
52
|
if (defaultText === undefined) {
|
|
56
|
-
throw new Error(
|
|
53
|
+
throw new Error(`key ${key} not found`);
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
return validateString(defaultText);
|
|
@@ -61,7 +58,7 @@ class Translations extends Base {
|
|
|
61
58
|
|
|
62
59
|
let r = this.storage.get(key);
|
|
63
60
|
if (isObject(r)) {
|
|
64
|
-
return this.getPluralRuleText(key,
|
|
61
|
+
return this.getPluralRuleText(key, "other", defaultText);
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
return this.storage.get(key);
|
|
@@ -92,8 +89,8 @@ class Translations extends Base {
|
|
|
92
89
|
count = validateInteger(count);
|
|
93
90
|
if (count === 0) {
|
|
94
91
|
// special handlig for zero count
|
|
95
|
-
if (r.hasOwnProperty(
|
|
96
|
-
return validateString(r[
|
|
92
|
+
if (r.hasOwnProperty("zero")) {
|
|
93
|
+
return validateString(r["zero"]);
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
96
|
|
|
@@ -131,24 +128,25 @@ class Translations extends Base {
|
|
|
131
128
|
* @throws {TypeError} value is not a string or object
|
|
132
129
|
*/
|
|
133
130
|
setText(key, text) {
|
|
134
|
-
|
|
135
131
|
if (isString(text) || isObject(text)) {
|
|
136
132
|
this.storage.set(validateString(key), text);
|
|
137
133
|
return this;
|
|
138
134
|
}
|
|
139
135
|
|
|
140
|
-
throw new TypeError(
|
|
141
|
-
|
|
136
|
+
throw new TypeError("value is not a string or object");
|
|
142
137
|
}
|
|
143
138
|
|
|
144
139
|
/**
|
|
145
|
-
* This method can be used to transfer overlays from an object. The keys are transferred and the values are entered
|
|
140
|
+
* This method can be used to transfer overlays from an object. The keys are transferred, and the values are entered
|
|
141
|
+
* as text.
|
|
146
142
|
*
|
|
147
|
-
* The values can either be character strings or, in the case of texts with plural forms, objects. The plural forms
|
|
143
|
+
* The values can either be character strings or, in the case of texts with plural forms, objects. The plural forms
|
|
144
|
+
* must be stored as text via a standard key "zero", "one", "two", "few", "many" and "other".
|
|
148
145
|
*
|
|
149
146
|
* Additionally, the key default can be specified, which will be used if no other key fits.
|
|
150
147
|
*
|
|
151
|
-
* In some languages, like for example in
|
|
148
|
+
* In some languages, like for example in German, there is no own more number at the value 0. In these languages,
|
|
149
|
+
* the function applies additionally zero.
|
|
152
150
|
*
|
|
153
151
|
* ```
|
|
154
152
|
* translations.assignTranslations({
|
|
@@ -173,7 +171,5 @@ class Translations extends Base {
|
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
return this;
|
|
176
|
-
|
|
177
174
|
}
|
|
178
|
-
|
|
179
175
|
}
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {getGlobalObject} from "../../types/global.mjs";
|
|
9
|
-
import {Handler} from
|
|
10
|
-
import {LogEntry} from "../logentry.mjs";
|
|
11
|
-
import {TRACE, WARN, DEBUG, ERROR, FATAL, INFO} from "../logger.mjs";
|
|
8
|
+
import { getGlobalObject } from "../../types/global.mjs";
|
|
9
|
+
import { Handler } from "../handler.mjs";
|
|
10
|
+
import { LogEntry } from "../logentry.mjs";
|
|
11
|
+
import { TRACE, WARN, DEBUG, ERROR, FATAL, INFO } from "../logger.mjs";
|
|
12
12
|
|
|
13
|
-
export {ConsoleHandler}
|
|
13
|
+
export { ConsoleHandler };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* You can create an object of the class simply by using the namespace `new Monster.Logging.Handler.ConsoleHandler()`.
|
|
@@ -36,7 +36,7 @@ class ConsoleHandler extends Handler {
|
|
|
36
36
|
*/
|
|
37
37
|
log(entry) {
|
|
38
38
|
if (super.log(entry)) {
|
|
39
|
-
let console = getGlobalObject(
|
|
39
|
+
let console = getGlobalObject("console");
|
|
40
40
|
if (!console) return false;
|
|
41
41
|
|
|
42
42
|
if (!console.error) console.error = console.log;
|
|
@@ -58,7 +58,6 @@ class ConsoleHandler extends Handler {
|
|
|
58
58
|
default:
|
|
59
59
|
console.log(entry.toString());
|
|
60
60
|
break;
|
|
61
|
-
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
return true;
|
|
@@ -66,7 +65,4 @@ class ConsoleHandler extends Handler {
|
|
|
66
65
|
|
|
67
66
|
return false;
|
|
68
67
|
}
|
|
69
|
-
|
|
70
68
|
}
|
|
71
|
-
|
|
72
|
-
|
|
@@ -5,12 +5,12 @@
|
|
|
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 {validateInstance, validateInteger} from "../types/validate.mjs";
|
|
10
|
-
import {LogEntry} from "./logentry.mjs";
|
|
11
|
-
import {ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN} from "./logger.mjs";
|
|
8
|
+
import { Base } from "../types/base.mjs";
|
|
9
|
+
import { validateInstance, validateInteger } from "../types/validate.mjs";
|
|
10
|
+
import { LogEntry } from "./logentry.mjs";
|
|
11
|
+
import { ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN } from "./logger.mjs";
|
|
12
12
|
|
|
13
|
-
export {Handler}
|
|
13
|
+
export { Handler };
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The log handler is the interface between the log entries and the log listeners.
|
|
@@ -20,7 +20,7 @@ export {Handler}
|
|
|
20
20
|
* @copyright schukai GmbH
|
|
21
21
|
* @memberOf Monster.Logging
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
class Handler extends Base {
|
|
24
24
|
constructor() {
|
|
25
25
|
super();
|
|
26
26
|
|
|
@@ -59,7 +59,7 @@ export {Handler}
|
|
|
59
59
|
* @since 1.5.0
|
|
60
60
|
*/
|
|
61
61
|
setLogLevel(loglevel) {
|
|
62
|
-
validateInteger(loglevel)
|
|
62
|
+
validateInteger(loglevel);
|
|
63
63
|
this.loglevel = loglevel;
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
@@ -83,7 +83,7 @@ export {Handler}
|
|
|
83
83
|
setAll() {
|
|
84
84
|
this.setLogLevel(ALL);
|
|
85
85
|
return this;
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Set log level to Trace
|
|
@@ -94,7 +94,7 @@ export {Handler}
|
|
|
94
94
|
setTrace() {
|
|
95
95
|
this.setLogLevel(TRACE);
|
|
96
96
|
return this;
|
|
97
|
-
}
|
|
97
|
+
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Set log level to Debug
|
|
@@ -105,7 +105,7 @@ export {Handler}
|
|
|
105
105
|
setDebug() {
|
|
106
106
|
this.setLogLevel(DEBUG);
|
|
107
107
|
return this;
|
|
108
|
-
}
|
|
108
|
+
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
111
|
* Set log level to Info
|
|
@@ -116,7 +116,7 @@ export {Handler}
|
|
|
116
116
|
setInfo() {
|
|
117
117
|
this.setLogLevel(INFO);
|
|
118
118
|
return this;
|
|
119
|
-
}
|
|
119
|
+
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Set log level to Warn
|
|
@@ -127,7 +127,7 @@ export {Handler}
|
|
|
127
127
|
setWarn() {
|
|
128
128
|
this.setLogLevel(WARN);
|
|
129
129
|
return this;
|
|
130
|
-
}
|
|
130
|
+
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
133
|
* Set log level to Error
|
|
@@ -138,7 +138,7 @@ export {Handler}
|
|
|
138
138
|
setError() {
|
|
139
139
|
this.setLogLevel(ERROR);
|
|
140
140
|
return this;
|
|
141
|
-
}
|
|
141
|
+
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
144
|
* Set log level to Fatal
|
|
@@ -149,8 +149,7 @@ export {Handler}
|
|
|
149
149
|
setFatal() {
|
|
150
150
|
this.setLogLevel(FATAL);
|
|
151
151
|
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
152
|
+
}
|
|
154
153
|
|
|
155
154
|
/**
|
|
156
155
|
* Set log level to Off
|
|
@@ -161,7 +160,5 @@ export {Handler}
|
|
|
161
160
|
setOff() {
|
|
162
161
|
this.setLogLevel(OFF);
|
|
163
162
|
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
}
|
|
167
164
|
}
|
|
@@ -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 {Base} from
|
|
9
|
-
import {validateInteger} from
|
|
8
|
+
import { Base } from "../types/base.mjs";
|
|
9
|
+
import { validateInteger } from "../types/validate.mjs";
|
|
10
10
|
|
|
11
|
-
export {LogEntry}
|
|
11
|
+
export { LogEntry };
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A log entry for the logger
|
|
@@ -18,7 +18,7 @@ export {LogEntry}
|
|
|
18
18
|
* @copyright schukai GmbH
|
|
19
19
|
* @memberOf Monster.Logging
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
class LogEntry extends Base {
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
* @param {Integer} loglevel
|
|
@@ -28,8 +28,8 @@ export {LogEntry}
|
|
|
28
28
|
super();
|
|
29
29
|
validateInteger(loglevel);
|
|
30
30
|
|
|
31
|
-
this.loglevel = loglevel
|
|
32
|
-
this.arguments = args
|
|
31
|
+
this.loglevel = loglevel;
|
|
32
|
+
this.arguments = args;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -37,7 +37,7 @@ export {LogEntry}
|
|
|
37
37
|
* @returns {integerr}
|
|
38
38
|
*/
|
|
39
39
|
getLogLevel() {
|
|
40
|
-
return this.loglevel
|
|
40
|
+
return this.loglevel;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -45,7 +45,6 @@ export {LogEntry}
|
|
|
45
45
|
* @returns {array}
|
|
46
46
|
*/
|
|
47
47
|
getArguments() {
|
|
48
|
-
return this.arguments
|
|
48
|
+
return this.arguments;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
50
|
}
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {Handler} from
|
|
9
|
-
import {LogEntry} from
|
|
8
|
+
import { Handler } from "../logging/handler.mjs";
|
|
9
|
+
import { LogEntry } from "../logging/logentry.mjs";
|
|
10
10
|
|
|
11
|
-
import {Base} from
|
|
12
|
-
import {validateInteger, validateObject, validateString} from
|
|
11
|
+
import { Base } from "../types/base.mjs";
|
|
12
|
+
import { validateInteger, validateObject, validateString } from "../types/validate.mjs";
|
|
13
13
|
|
|
14
|
-
export {Logger, ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF};
|
|
14
|
+
export { Logger, ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* ALL > TRACE > DEBUG > INFO > WARN > ERROR > FATAL > OFF
|
|
@@ -71,13 +71,12 @@ const OFF = 0;
|
|
|
71
71
|
* @memberOf Monster.Logging
|
|
72
72
|
*/
|
|
73
73
|
class Logger extends Base {
|
|
74
|
-
|
|
75
74
|
/**
|
|
76
75
|
*
|
|
77
76
|
*/
|
|
78
77
|
constructor() {
|
|
79
78
|
super();
|
|
80
|
-
this.handler = new Set;
|
|
79
|
+
this.handler = new Set();
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
/**
|
|
@@ -87,12 +86,12 @@ class Logger extends Base {
|
|
|
87
86
|
* @throws {Error} the handler must be an instance of Handler
|
|
88
87
|
*/
|
|
89
88
|
addHandler(handler) {
|
|
90
|
-
validateObject(handler)
|
|
89
|
+
validateObject(handler);
|
|
91
90
|
if (!(handler instanceof Handler)) {
|
|
92
|
-
throw new Error("the handler must be an instance of Handler")
|
|
91
|
+
throw new Error("the handler must be an instance of Handler");
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
this.handler.add(handler)
|
|
94
|
+
this.handler.add(handler);
|
|
96
95
|
return this;
|
|
97
96
|
}
|
|
98
97
|
|
|
@@ -103,9 +102,9 @@ class Logger extends Base {
|
|
|
103
102
|
* @throws {Error} the handler must be an instance of Handler
|
|
104
103
|
*/
|
|
105
104
|
removeHandler(handler) {
|
|
106
|
-
validateObject(handler)
|
|
105
|
+
validateObject(handler);
|
|
107
106
|
if (!(handler instanceof Handler)) {
|
|
108
|
-
throw new Error("the handler must be an instance of Handler")
|
|
107
|
+
throw new Error("the handler must be an instance of Handler");
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
this.handler.delete(handler);
|
|
@@ -121,10 +120,14 @@ class Logger extends Base {
|
|
|
121
120
|
* @returns {Logger}
|
|
122
121
|
* @since 1.5.0
|
|
123
122
|
*/
|
|
124
|
-
logTrace() {
|
|
125
|
-
|
|
123
|
+
logTrace(...args) {
|
|
124
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
125
|
+
throw new Error("the first argument must be an object");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
triggerLog.apply(this, [TRACE, ...args]);
|
|
126
129
|
return this;
|
|
127
|
-
}
|
|
130
|
+
}
|
|
128
131
|
|
|
129
132
|
/**
|
|
130
133
|
* log Debug message
|
|
@@ -135,10 +138,14 @@ class Logger extends Base {
|
|
|
135
138
|
* @returns {Logger}
|
|
136
139
|
* @since 1.5.0
|
|
137
140
|
*/
|
|
138
|
-
logDebug() {
|
|
139
|
-
|
|
141
|
+
logDebug(...args) {
|
|
142
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
143
|
+
throw new Error("the first argument must be an object");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
triggerLog.apply(this, [DEBUG, ...args]);
|
|
140
147
|
return this;
|
|
141
|
-
}
|
|
148
|
+
}
|
|
142
149
|
|
|
143
150
|
/**
|
|
144
151
|
* log Info message
|
|
@@ -150,10 +157,14 @@ class Logger extends Base {
|
|
|
150
157
|
* @returns {Logger}
|
|
151
158
|
* @since 1.5.0
|
|
152
159
|
*/
|
|
153
|
-
logInfo() {
|
|
154
|
-
|
|
160
|
+
logInfo(...args) {
|
|
161
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
162
|
+
throw new Error("the first argument must be an object");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
triggerLog.apply(this, [INFO, ...args]);
|
|
155
166
|
return this;
|
|
156
|
-
}
|
|
167
|
+
}
|
|
157
168
|
|
|
158
169
|
/**
|
|
159
170
|
* log Warn message
|
|
@@ -164,10 +175,14 @@ class Logger extends Base {
|
|
|
164
175
|
* @returns {Logger}
|
|
165
176
|
* @since 1.5.0
|
|
166
177
|
*/
|
|
167
|
-
logWarn() {
|
|
168
|
-
|
|
178
|
+
logWarn(...args) {
|
|
179
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
180
|
+
throw new Error("the first argument must be an object");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
triggerLog.apply(this, [WARN, ...args]);
|
|
169
184
|
return this;
|
|
170
|
-
}
|
|
185
|
+
}
|
|
171
186
|
|
|
172
187
|
/**
|
|
173
188
|
* log Error message
|
|
@@ -178,10 +193,14 @@ class Logger extends Base {
|
|
|
178
193
|
* @returns {Logger}
|
|
179
194
|
* @since 1.5.0
|
|
180
195
|
*/
|
|
181
|
-
logError() {
|
|
182
|
-
|
|
196
|
+
logError(...args) {
|
|
197
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
198
|
+
throw new Error("the first argument must be an object");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
triggerLog.apply(this, [ERROR, ...args]);
|
|
183
202
|
return this;
|
|
184
|
-
}
|
|
203
|
+
}
|
|
185
204
|
|
|
186
205
|
/**
|
|
187
206
|
* log Fatal message
|
|
@@ -192,11 +211,14 @@ class Logger extends Base {
|
|
|
192
211
|
* @returns {Logger}
|
|
193
212
|
* @since 1.5.0
|
|
194
213
|
*/
|
|
195
|
-
logFatal() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
214
|
+
logFatal(...args) {
|
|
215
|
+
if (typeof args !== "object" || args[0] === null) {
|
|
216
|
+
throw new Error("the first argument must be an object");
|
|
217
|
+
}
|
|
199
218
|
|
|
219
|
+
triggerLog.apply(this, [FATAL, ...args]);
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
200
222
|
|
|
201
223
|
/**
|
|
202
224
|
* Labels
|
|
@@ -207,17 +229,17 @@ class Logger extends Base {
|
|
|
207
229
|
getLabel(level) {
|
|
208
230
|
validateInteger(level);
|
|
209
231
|
|
|
210
|
-
if (level === ALL) return
|
|
211
|
-
if (level === TRACE) return
|
|
212
|
-
if (level === DEBUG) return
|
|
213
|
-
if (level === INFO) return
|
|
214
|
-
if (level === WARN) return
|
|
215
|
-
if (level === ERROR) return
|
|
216
|
-
if (level === FATAL) return
|
|
217
|
-
if (level === OFF) return
|
|
232
|
+
if (level === ALL) return "ALL";
|
|
233
|
+
if (level === TRACE) return "TRACE";
|
|
234
|
+
if (level === DEBUG) return "DEBUG";
|
|
235
|
+
if (level === INFO) return "INFO";
|
|
236
|
+
if (level === WARN) return "WARN";
|
|
237
|
+
if (level === ERROR) return "ERROR";
|
|
238
|
+
if (level === FATAL) return "FATAL";
|
|
239
|
+
if (level === OFF) return "OFF";
|
|
218
240
|
|
|
219
|
-
return
|
|
220
|
-
}
|
|
241
|
+
return "unknown";
|
|
242
|
+
}
|
|
221
243
|
|
|
222
244
|
/**
|
|
223
245
|
* Level
|
|
@@ -228,22 +250,19 @@ class Logger extends Base {
|
|
|
228
250
|
getLevel(label) {
|
|
229
251
|
validateString(label);
|
|
230
252
|
|
|
231
|
-
if (label ===
|
|
232
|
-
if (label ===
|
|
233
|
-
if (label ===
|
|
234
|
-
if (label ===
|
|
235
|
-
if (label ===
|
|
236
|
-
if (label ===
|
|
237
|
-
if (label ===
|
|
238
|
-
if (label ===
|
|
253
|
+
if (label === "ALL") return ALL;
|
|
254
|
+
if (label === "TRACE") return TRACE;
|
|
255
|
+
if (label === "DEBUG") return DEBUG;
|
|
256
|
+
if (label === "INFO") return INFO;
|
|
257
|
+
if (label === "WARN") return WARN;
|
|
258
|
+
if (label === "ERROR") return ERROR;
|
|
259
|
+
if (label === "FATAL") return FATAL;
|
|
260
|
+
if (label === "OFF") return OFF;
|
|
239
261
|
|
|
240
262
|
return 0;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
263
|
+
}
|
|
244
264
|
}
|
|
245
265
|
|
|
246
|
-
|
|
247
266
|
/**
|
|
248
267
|
* Log triggern
|
|
249
268
|
*
|
|
@@ -256,9 +275,8 @@ function triggerLog(loglevel, ...args) {
|
|
|
256
275
|
var logger = this;
|
|
257
276
|
|
|
258
277
|
for (let handler of logger.handler) {
|
|
259
|
-
handler.log(new LogEntry(loglevel, args))
|
|
278
|
+
handler.log(new LogEntry(loglevel, args));
|
|
260
279
|
}
|
|
261
280
|
|
|
262
281
|
return logger;
|
|
263
|
-
|
|
264
282
|
}
|