@leyyo/common 1.3.18 → 1.3.20
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/dist/base/index.d.ts +3 -3
- package/dist/base/index.js +3 -3
- package/dist/base/index.types.d.ts +3 -3
- package/dist/base/leyyo.js +1 -1
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +2 -2
- package/dist/class/logger.instance.d.ts +6 -6
- package/dist/class/logger.instance.js +11 -12
- package/dist/common/deploy.common.js +4 -4
- package/dist/common/enum.pool.d.ts +5 -3
- package/dist/common/enum.pool.js +16 -3
- package/dist/common/error.common.js +33 -29
- package/dist/common/error.pool.d.ts +1 -1
- package/dist/common/error.pool.js +2 -3
- package/dist/common/event.common.js +12 -9
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +11 -11
- package/dist/common/index.types.d.ts +18 -9
- package/dist/common/inert.d.ts +1 -1
- package/dist/common/inert.js +35 -35
- package/dist/common/lifecycle.common.js +13 -13
- package/dist/common/literal.pool.d.ts +1 -1
- package/dist/common/literal.pool.js +3 -3
- package/dist/common/log.common.js +68 -63
- package/dist/common/repo.common.js +23 -28
- package/dist/const/index.d.ts +0 -1
- package/dist/const/index.js +28 -29
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +1 -1
- package/dist/enum/log-level.d.ts +1 -1
- package/dist/enum/log-level.js +1 -1
- package/dist/error/developer.error.d.ts +1 -2
- package/dist/error/developer.error.js +6 -15
- package/dist/error/http.error.js +1 -1
- package/dist/error/index.d.ts +7 -7
- package/dist/error/index.js +7 -7
- package/dist/error/index.types.d.ts +1 -1
- package/dist/error/invalid-value.error.js +1 -1
- package/dist/error/leyyo.error.js +25 -21
- package/dist/error/multiple.error.js +2 -2
- package/dist/function/delete-prop.js +6 -6
- package/dist/function/empty-fn.js +1 -2
- package/dist/function/extended-type.js +18 -17
- package/dist/function/get-fqn.js +3 -2
- package/dist/function/get-prop.js +5 -5
- package/dist/function/get-stat.js +7 -2
- package/dist/function/has-fqn.js +3 -2
- package/dist/function/index.d.ts +40 -40
- package/dist/function/index.js +40 -40
- package/dist/function/index.types.d.ts +1 -1
- package/dist/function/is-anonymous-name.js +1 -1
- package/dist/function/is-class.js +2 -2
- package/dist/function/is-empty.js +1 -1
- package/dist/function/is-obj.js +1 -1
- package/dist/function/is-test.js +3 -5
- package/dist/function/is-text.js +1 -1
- package/dist/function/jitter-interval.js +2 -2
- package/dist/function/load-config.js +9 -9
- package/dist/function/on-fqn-set.js +4 -3
- package/dist/function/opt-add.js +2 -2
- package/dist/function/opt-check.js +2 -2
- package/dist/function/opt-field.js +6 -6
- package/dist/function/remove-fqn.js +3 -2
- package/dist/function/run-exporter.js +3 -3
- package/dist/function/secure-clone.js +3 -3
- package/dist/function/secure-json.js +12 -10
- package/dist/function/set-anonymous-fqn.js +5 -4
- package/dist/function/set-anonymous-name.js +14 -14
- package/dist/function/set-fqn.js +9 -8
- package/dist/function/set-prop.js +6 -6
- package/dist/function/stamp-loader.js +1 -1
- package/dist/function/test-case.js +3 -3
- package/dist/function/test-name.js +2 -2
- package/dist/function/trigger-fqn.js +2 -2
- package/dist/index.d.ts +10 -10
- package/dist/index.foretell.js +7 -7
- package/dist/index.js +10 -10
- package/dist/index.loader.js +3 -3
- package/dist/init/index.js +5 -7
- package/dist/sys/index.d.ts +2 -2
- package/dist/sys/index.js +2 -2
- package/dist/sys/leyyo-storage.js +5 -5
- package/dist/sys/package-json.js +5 -5
- package/package.json +16 -31
|
@@ -2,13 +2,13 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { dirname } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import * as yaml from
|
|
5
|
+
import * as yaml from "js-yaml";
|
|
6
6
|
import { isObj } from "./is-obj.js";
|
|
7
7
|
import { getRootStorage } from "../sys/index.js";
|
|
8
8
|
import { isText } from "./is-text.js";
|
|
9
9
|
import { isEmpty } from "./is-empty.js";
|
|
10
10
|
import { secureJson, secureObject } from "./secure-json.js";
|
|
11
|
-
const _NAME =
|
|
11
|
+
const _NAME = "$$leyyo.config";
|
|
12
12
|
export const leyyoConfig = getRootStorage(_NAME, {});
|
|
13
13
|
/**
|
|
14
14
|
* Load config from `.leyyo.yaml` file
|
|
@@ -32,9 +32,9 @@ export const leyyoConfig = getRootStorage(_NAME, {});
|
|
|
32
32
|
export function loadConfig(url) {
|
|
33
33
|
try {
|
|
34
34
|
const __dirname = dirname(dirname(fileURLToPath(url)));
|
|
35
|
-
const yamlPath = path.normalize(__dirname +
|
|
35
|
+
const yamlPath = path.normalize(__dirname + "/.leyyo.yaml");
|
|
36
36
|
if (fs.existsSync(yamlPath)) {
|
|
37
|
-
const input = fs.readFileSync(yamlPath,
|
|
37
|
+
const input = fs.readFileSync(yamlPath, "utf8");
|
|
38
38
|
const data = yaml.load(input);
|
|
39
39
|
if (isObj(data)) {
|
|
40
40
|
for (const [k, v] of Object.entries(data)) {
|
|
@@ -58,19 +58,19 @@ function _behaviour(keyFull) {
|
|
|
58
58
|
if (!isText(keyFull)) {
|
|
59
59
|
return [undefined, undefined];
|
|
60
60
|
}
|
|
61
|
-
if (keyFull.endsWith(
|
|
61
|
+
if (keyFull.endsWith("!")) {
|
|
62
62
|
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
63
63
|
if (!isText(keyFull)) {
|
|
64
64
|
return [undefined, undefined];
|
|
65
65
|
}
|
|
66
|
-
return [
|
|
66
|
+
return ["override", keyFull];
|
|
67
67
|
}
|
|
68
|
-
else if (keyFull.endsWith(
|
|
68
|
+
else if (keyFull.endsWith("?")) {
|
|
69
69
|
keyFull = keyFull.substring(keyFull.length - 1).trim();
|
|
70
70
|
if (!isText(keyFull)) {
|
|
71
71
|
return [undefined, undefined];
|
|
72
72
|
}
|
|
73
|
-
return [
|
|
73
|
+
return ["merge", keyFull];
|
|
74
74
|
}
|
|
75
75
|
return [undefined, keyFull];
|
|
76
76
|
}
|
|
@@ -87,7 +87,7 @@ function _array(source, key, value) {
|
|
|
87
87
|
console.warn(`[leyyoConfig] value empty at (${key}#${index})`);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
|
-
const clonedSource = source.map(item => JSON.stringify(item));
|
|
90
|
+
const clonedSource = source.map((item) => JSON.stringify(item));
|
|
91
91
|
switch (typeof item) {
|
|
92
92
|
case "string":
|
|
93
93
|
case "number":
|
|
@@ -3,13 +3,14 @@ export function onFqnSet(target, callback) {
|
|
|
3
3
|
if (!target) {
|
|
4
4
|
return false;
|
|
5
5
|
}
|
|
6
|
-
if (typeof callback !==
|
|
6
|
+
if (typeof callback !== "function") {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
if (typeof target ===
|
|
9
|
+
if (typeof target === "function") {
|
|
10
|
+
// function, class
|
|
10
11
|
return _item(target, callback);
|
|
11
12
|
}
|
|
12
|
-
else if (typeof target ===
|
|
13
|
+
else if (typeof target === "object") {
|
|
13
14
|
if (Array.isArray(target)) {
|
|
14
15
|
if (target[KEY_LITERAL_NAME]) {
|
|
15
16
|
return _item(target, callback);
|
package/dist/function/opt-add.js
CHANGED
|
@@ -10,10 +10,10 @@ import { isObj } from "./is-obj.js";
|
|
|
10
10
|
* */
|
|
11
11
|
export function optAdd(options, key, value) {
|
|
12
12
|
const o = (isObj(options) ? options : {});
|
|
13
|
-
if (value === undefined || typeof key !==
|
|
13
|
+
if (value === undefined || typeof key !== "string") {
|
|
14
14
|
return o;
|
|
15
15
|
}
|
|
16
|
-
if (key ===
|
|
16
|
+
if (key === "field") {
|
|
17
17
|
return optField(o, value);
|
|
18
18
|
}
|
|
19
19
|
if (o[key] === undefined) {
|
|
@@ -12,7 +12,7 @@ const where = `${FQN}.optCheck`;
|
|
|
12
12
|
* */
|
|
13
13
|
export function optCheck(options) {
|
|
14
14
|
let o = options;
|
|
15
|
-
if (typeof options ===
|
|
15
|
+
if (typeof options === "function") {
|
|
16
16
|
try {
|
|
17
17
|
o = options();
|
|
18
18
|
}
|
|
@@ -21,7 +21,7 @@ export function optCheck(options) {
|
|
|
21
21
|
if (!_leyyo) {
|
|
22
22
|
_leyyo = $$get_leyyo_fn();
|
|
23
23
|
}
|
|
24
|
-
new _leyyo.developerError(
|
|
24
|
+
new _leyyo.developerError("Raised callback run", "optCheck#01", where).log(e);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
else if (!isObj(options)) {
|
|
@@ -10,22 +10,22 @@ import { isObj } from "./is-obj.js";
|
|
|
10
10
|
export function optField(options, field) {
|
|
11
11
|
const o = (isObj(options) ? options : {});
|
|
12
12
|
const t = typeof field;
|
|
13
|
-
if (![
|
|
13
|
+
if (!["string", "number"].includes(t)) {
|
|
14
14
|
return o;
|
|
15
15
|
}
|
|
16
16
|
if (o.field !== undefined) {
|
|
17
|
-
if (typeof o.field !==
|
|
18
|
-
o.field =
|
|
17
|
+
if (typeof o.field !== "string") {
|
|
18
|
+
o.field = "";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
o.field =
|
|
22
|
+
o.field = "";
|
|
23
23
|
}
|
|
24
24
|
if (!o.field) {
|
|
25
|
-
o.field =
|
|
25
|
+
o.field = t === "string" ? field : `$.[${field}]`;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
o.field +=
|
|
28
|
+
o.field += t === "string" ? `.${field}` : `[${field}]`;
|
|
29
29
|
}
|
|
30
30
|
return o;
|
|
31
31
|
}
|
|
@@ -12,10 +12,11 @@ export function removeFqn(target) {
|
|
|
12
12
|
if (!target) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
|
-
if (typeof target ===
|
|
15
|
+
if (typeof target === "function") {
|
|
16
|
+
// function, class
|
|
16
17
|
return _item(target, target.name);
|
|
17
18
|
}
|
|
18
|
-
else if (typeof target ===
|
|
19
|
+
else if (typeof target === "object") {
|
|
19
20
|
if (Array.isArray(target)) {
|
|
20
21
|
if (target[KEY_LITERAL_NAME]) {
|
|
21
22
|
return _item(target, target[KEY_LITERAL_NAME]);
|
|
@@ -11,12 +11,12 @@ export async function runExporter() {
|
|
|
11
11
|
const depot = {
|
|
12
12
|
add(name, value) {
|
|
13
13
|
append(data, name, value, 0);
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
15
|
};
|
|
16
16
|
if (!_leyyo) {
|
|
17
17
|
_leyyo = $$get_leyyo_fn();
|
|
18
18
|
}
|
|
19
|
-
await _leyyo.lifecycleCommon.runStage(
|
|
19
|
+
await _leyyo.lifecycleCommon.runStage("print", depot);
|
|
20
20
|
return data;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -28,7 +28,7 @@ export async function runExporter() {
|
|
|
28
28
|
* @param {number} duplicated
|
|
29
29
|
* */
|
|
30
30
|
const append = (data, name, value, duplicated) => {
|
|
31
|
-
const postfix =
|
|
31
|
+
const postfix = duplicated === 0 ? "" : "#" + duplicated;
|
|
32
32
|
if (data[name + postfix] !== undefined) {
|
|
33
33
|
data[name + postfix] = value;
|
|
34
34
|
}
|
|
@@ -2,7 +2,7 @@ export function _secureClone(value, weakSet) {
|
|
|
2
2
|
if (value === undefined || value === null) {
|
|
3
3
|
return value;
|
|
4
4
|
}
|
|
5
|
-
if (typeof value !==
|
|
5
|
+
if (typeof value !== "object") {
|
|
6
6
|
return value;
|
|
7
7
|
}
|
|
8
8
|
if (weakSet.has(weakSet)) {
|
|
@@ -10,10 +10,10 @@ export function _secureClone(value, weakSet) {
|
|
|
10
10
|
}
|
|
11
11
|
weakSet.add(value);
|
|
12
12
|
if (Array.isArray(value)) {
|
|
13
|
-
return value.map(item => secureClone(item));
|
|
13
|
+
return value.map((item) => secureClone(item));
|
|
14
14
|
}
|
|
15
15
|
if (value instanceof Set) {
|
|
16
|
-
return new Set(Array.from(value.values()).map(item => secureClone(item)));
|
|
16
|
+
return new Set(Array.from(value.values()).map((item) => secureClone(item)));
|
|
17
17
|
}
|
|
18
18
|
if (value instanceof Map) {
|
|
19
19
|
const newMap = new Map();
|
|
@@ -9,8 +9,9 @@ function _secureObject(value, depth, set) {
|
|
|
9
9
|
if ([null, undefined].includes(value)) {
|
|
10
10
|
return value;
|
|
11
11
|
}
|
|
12
|
+
let obj;
|
|
12
13
|
switch (typeof value) {
|
|
13
|
-
case
|
|
14
|
+
case "object":
|
|
14
15
|
if (set.has(value)) {
|
|
15
16
|
return `#circular <${value?.constructor?.name}>`;
|
|
16
17
|
}
|
|
@@ -19,22 +20,22 @@ function _secureObject(value, depth, set) {
|
|
|
19
20
|
}
|
|
20
21
|
set.add(value);
|
|
21
22
|
if (Array.isArray(value)) {
|
|
22
|
-
return value.map(item => _secureObject(item, depth + 1, set));
|
|
23
|
+
return value.map((item) => _secureObject(item, depth + 1, set));
|
|
23
24
|
}
|
|
24
25
|
if (value instanceof Set) {
|
|
25
|
-
return Array.from(value).map(item => _secureObject(item, depth + 1, set));
|
|
26
|
+
return Array.from(value).map((item) => _secureObject(item, depth + 1, set));
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
obj = {};
|
|
28
29
|
if (value instanceof Map) {
|
|
29
30
|
for (const [k, v] of value.entries()) {
|
|
30
|
-
if (typeof k ===
|
|
31
|
+
if (typeof k === "string") {
|
|
31
32
|
obj[k] = _secureObject(v, depth + 1, set);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
else if (value?.constructor === Object) {
|
|
36
37
|
for (const [k, v] of Object.entries(value)) {
|
|
37
|
-
if (typeof k ===
|
|
38
|
+
if (typeof k === "string") {
|
|
38
39
|
obj[k] = _secureObject(v, depth + 1, set);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -42,7 +43,8 @@ function _secureObject(value, depth, set) {
|
|
|
42
43
|
else {
|
|
43
44
|
let exists;
|
|
44
45
|
for (const [k, v] of Object.entries(value)) {
|
|
45
|
-
if (typeof k ===
|
|
46
|
+
if (typeof k === "string" &&
|
|
47
|
+
!["function", "symbol", "undefined"].includes(typeof value)) {
|
|
46
48
|
exists = true;
|
|
47
49
|
obj[k] = _secureObject(v, depth + 1, set);
|
|
48
50
|
}
|
|
@@ -57,9 +59,9 @@ function _secureObject(value, depth, set) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
return obj;
|
|
60
|
-
case
|
|
62
|
+
case "function":
|
|
61
63
|
return `#function <${value.name}> (length: ${value.length})`;
|
|
62
|
-
case
|
|
64
|
+
case "symbol":
|
|
63
65
|
return `#symbol <${value.description}>`;
|
|
64
66
|
}
|
|
65
67
|
return value;
|
|
@@ -112,7 +114,7 @@ export function secureObject(value) {
|
|
|
112
114
|
export function secureJson(value) {
|
|
113
115
|
try {
|
|
114
116
|
const json = _secureObject(value, 0, new WeakSet());
|
|
115
|
-
return
|
|
117
|
+
return typeof json === "string" ? json : JSON.stringify(json);
|
|
116
118
|
}
|
|
117
119
|
catch (e) {
|
|
118
120
|
return `#error <${e.name}> (message: ${e.message})`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KEY_ENUM_NAME, KEY_FQN_NAME, KEY_LITERAL_NAME, VAL_FQN_ANONYMOUS } from "../const/index.js";
|
|
1
|
+
import { KEY_ENUM_NAME, KEY_FQN_NAME, KEY_LITERAL_NAME, VAL_FQN_ANONYMOUS, } from "../const/index.js";
|
|
2
2
|
import { triggerFqn } from "./trigger-fqn.js";
|
|
3
3
|
import { setAnonymousName } from "./set-anonymous-name.js";
|
|
4
4
|
import { isClass } from "./is-class.js";
|
|
@@ -7,13 +7,14 @@ export function setAnonymousFqn(target) {
|
|
|
7
7
|
if (!target) {
|
|
8
8
|
return undefined;
|
|
9
9
|
}
|
|
10
|
-
if (typeof target ===
|
|
10
|
+
if (typeof target === "function") {
|
|
11
|
+
// function, class
|
|
11
12
|
if (!target.name) {
|
|
12
|
-
setAnonymousName(target, isClass(target) ?
|
|
13
|
+
setAnonymousName(target, isClass(target) ? "Class" : "function");
|
|
13
14
|
}
|
|
14
15
|
return _item(target, target.name);
|
|
15
16
|
}
|
|
16
|
-
else if (typeof target ===
|
|
17
|
+
else if (typeof target === "object") {
|
|
17
18
|
if (Array.isArray(target)) {
|
|
18
19
|
if (target[KEY_LITERAL_NAME]) {
|
|
19
20
|
return _item(target, target[KEY_LITERAL_NAME]);
|
|
@@ -9,25 +9,25 @@ let _counter = 0;
|
|
|
9
9
|
const where = `${FQN}.nameFn`;
|
|
10
10
|
let _leyyo;
|
|
11
11
|
export function setAnonymousName(target, prefix) {
|
|
12
|
-
if (typeof target !==
|
|
12
|
+
if (typeof target !== "function") {
|
|
13
13
|
if (!_leyyo) {
|
|
14
14
|
_leyyo = $$get_leyyo_fn();
|
|
15
15
|
}
|
|
16
|
-
throw new _leyyo.developerError(`Invalid target`, testCase(FQN,
|
|
16
|
+
throw new _leyyo.developerError(`Invalid target`, testCase(FQN, "ZZZ"), where);
|
|
17
17
|
}
|
|
18
18
|
if (isText(prefix)) {
|
|
19
19
|
if (!_pattern.test(prefix)) {
|
|
20
20
|
if (!_leyyo) {
|
|
21
21
|
_leyyo = $$get_leyyo_fn();
|
|
22
22
|
}
|
|
23
|
-
throw new _leyyo.developerError(`Invalid anonymous name part [${prefix}]`, testCase(FQN,
|
|
23
|
+
throw new _leyyo.developerError(`Invalid anonymous name part [${prefix}]`, testCase(FQN, "ZZZ"), where);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
prefix = isClass(target) ?
|
|
27
|
+
prefix = isClass(target) ? "Class" : "function";
|
|
28
28
|
}
|
|
29
29
|
_counter++;
|
|
30
|
-
const name = VAL_NAME_ANONYMOUS + [prefix, _counter].join(
|
|
30
|
+
const name = VAL_NAME_ANONYMOUS + [prefix, _counter].join("$");
|
|
31
31
|
_setName(target, name, false);
|
|
32
32
|
return name;
|
|
33
33
|
}
|
|
@@ -36,27 +36,27 @@ function _setName(target, name, checkAnonymous) {
|
|
|
36
36
|
_leyyo = $$get_leyyo_fn();
|
|
37
37
|
}
|
|
38
38
|
if (!isText(name)) {
|
|
39
|
-
throw new _leyyo.developerError(`Invalid name`, testCase(FQN,
|
|
39
|
+
throw new _leyyo.developerError(`Invalid name`, testCase(FQN, "ZZZ"), where);
|
|
40
40
|
}
|
|
41
|
-
if (name.includes(
|
|
42
|
-
throw new _leyyo.developerError(`Invalid name with dot`, testCase(FQN,
|
|
41
|
+
if (name.includes(".")) {
|
|
42
|
+
throw new _leyyo.developerError(`Invalid name with dot`, testCase(FQN, "ZZZ"), where);
|
|
43
43
|
}
|
|
44
44
|
if (checkAnonymous && name.startsWith(VAL_NAME_ANONYMOUS)) {
|
|
45
|
-
throw new _leyyo.developerError(`Invalid name with anonymous`, testCase(FQN,
|
|
45
|
+
throw new _leyyo.developerError(`Invalid name with anonymous`, testCase(FQN, "ZZZ"), where);
|
|
46
46
|
}
|
|
47
|
-
if (typeof target !==
|
|
48
|
-
throw new _leyyo.developerError(`Invalid name [${name}]`, testCase(FQN,
|
|
47
|
+
if (typeof target !== "function") {
|
|
48
|
+
throw new _leyyo.developerError(`Invalid name [${name}]`, testCase(FQN, "ZZZ"), where);
|
|
49
49
|
}
|
|
50
50
|
try {
|
|
51
|
-
Object.defineProperty(target,
|
|
51
|
+
Object.defineProperty(target, "name", {
|
|
52
52
|
value: name,
|
|
53
53
|
configurable: true,
|
|
54
54
|
writable: true,
|
|
55
|
-
enumerable: true
|
|
55
|
+
enumerable: true,
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
59
|
-
new _leyyo.developerError(`Unexpected error during set name [${name}]`, testCase(FQN,
|
|
59
|
+
new _leyyo.developerError(`Unexpected error during set name [${name}]`, testCase(FQN, "ZZZ"), where).log(e);
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
return true;
|
package/dist/function/set-fqn.js
CHANGED
|
@@ -3,7 +3,7 @@ import { $$get_leyyo_fn } from "./leyyo-fn.js";
|
|
|
3
3
|
import { isClass } from "./is-class.js";
|
|
4
4
|
import { isText } from "./is-text.js";
|
|
5
5
|
import { testCase } from "./test-case.js";
|
|
6
|
-
import { KEY_ENUM_NAME, KEY_FQN_NAME, KEY_LITERAL_NAME, VAL_FQN_ANONYMOUS } from "../const/index.js";
|
|
6
|
+
import { KEY_ENUM_NAME, KEY_FQN_NAME, KEY_LITERAL_NAME, VAL_FQN_ANONYMOUS, } from "../const/index.js";
|
|
7
7
|
import { triggerFqn } from "./trigger-fqn.js";
|
|
8
8
|
import { setAnonymousName } from "./set-anonymous-name.js";
|
|
9
9
|
import { getFqn } from "./get-fqn.js";
|
|
@@ -21,28 +21,29 @@ export function setFqn(target, fqn) {
|
|
|
21
21
|
_leyyo = $$get_leyyo_fn();
|
|
22
22
|
}
|
|
23
23
|
if (!isText(fqn)) {
|
|
24
|
-
new _leyyo.developerError(
|
|
24
|
+
new _leyyo.developerError("Invalid fqn name", testCase(FQN, 150), where).log();
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
27
|
-
if (fqn.startsWith(
|
|
28
|
-
new _leyyo.developerError(
|
|
27
|
+
if (fqn.startsWith(".") || fqn.endsWith(".")) {
|
|
28
|
+
new _leyyo.developerError("Invalid fqn name with dots", testCase(FQN, "ZZZ"), where).log();
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
31
|
if (fqn.startsWith(VAL_FQN_ANONYMOUS)) {
|
|
32
|
-
new _leyyo.developerError(
|
|
32
|
+
new _leyyo.developerError("Anonymous fqn is used", testCase(FQN, "ZZZ"), where).log();
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
35
|
if (!target) {
|
|
36
36
|
new _leyyo.developerError(`Empty fqn target [${fqn}]`, testCase(FQN, 151), where).log();
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
if (typeof target ===
|
|
39
|
+
if (typeof target === "function") {
|
|
40
|
+
// function, class
|
|
40
41
|
if (!target.name) {
|
|
41
|
-
setAnonymousName(target, isClass(target) ?
|
|
42
|
+
setAnonymousName(target, isClass(target) ? "Class" : "function");
|
|
42
43
|
}
|
|
43
44
|
return _item(target, target.name, fqn);
|
|
44
45
|
}
|
|
45
|
-
else if (typeof target ===
|
|
46
|
+
else if (typeof target === "object") {
|
|
46
47
|
if (Array.isArray(target)) {
|
|
47
48
|
if (target[KEY_LITERAL_NAME]) {
|
|
48
49
|
return _item(target, target[KEY_LITERAL_NAME], fqn);
|
|
@@ -12,7 +12,7 @@ let _leyyo;
|
|
|
12
12
|
* @return {boolean} - is set?
|
|
13
13
|
* */
|
|
14
14
|
export function setKey(target, key, value) {
|
|
15
|
-
if (typeof key !==
|
|
15
|
+
if (typeof key !== "string") {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
return setProp(target, key, value);
|
|
@@ -26,7 +26,7 @@ export function setKey(target, key, value) {
|
|
|
26
26
|
* @return {boolean} - is set?
|
|
27
27
|
* */
|
|
28
28
|
export function setSymbol(target, key, value) {
|
|
29
|
-
if (typeof key !==
|
|
29
|
+
if (typeof key !== "symbol") {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
return setProp(target, key, value);
|
|
@@ -40,10 +40,10 @@ export function setSymbol(target, key, value) {
|
|
|
40
40
|
* @return {boolean} - is set?
|
|
41
41
|
* */
|
|
42
42
|
export function setProp(target, key, value) {
|
|
43
|
-
if (![
|
|
43
|
+
if (!["symbol", "string"].includes(typeof key)) {
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
|
-
if (!target || ![
|
|
46
|
+
if (!target || !["object", "function"].includes(typeof target)) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
@@ -51,7 +51,7 @@ export function setProp(target, key, value) {
|
|
|
51
51
|
value,
|
|
52
52
|
configurable: false,
|
|
53
53
|
writable: false,
|
|
54
|
-
enumerable: typeof key ===
|
|
54
|
+
enumerable: typeof key === "string",
|
|
55
55
|
});
|
|
56
56
|
return true;
|
|
57
57
|
}
|
|
@@ -59,7 +59,7 @@ export function setProp(target, key, value) {
|
|
|
59
59
|
if (!_leyyo) {
|
|
60
60
|
_leyyo = $$get_leyyo_fn();
|
|
61
61
|
}
|
|
62
|
-
new _leyyo.developerError(`Unexpected error during set name [${key.toString()}]`, testCase(FQN,
|
|
62
|
+
new _leyyo.developerError(`Unexpected error during set name [${key.toString()}]`, testCase(FQN, "ZZZ"), where).log(e);
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -6,7 +6,7 @@ import { KEY_LOADER_EMPTY, KEY_LOADER_STAMP } from "../const/index.js";
|
|
|
6
6
|
* @return {(LeyyoStampLambda | LeyyoStampEmpty)} - stamped function
|
|
7
7
|
* */
|
|
8
8
|
export function stampLoader(fn) {
|
|
9
|
-
if (typeof fn ===
|
|
9
|
+
if (typeof fn === "function") {
|
|
10
10
|
fn[KEY_LOADER_STAMP] = true;
|
|
11
11
|
return fn;
|
|
12
12
|
}
|
|
@@ -8,12 +8,12 @@ import { FQN } from "../internal.js";
|
|
|
8
8
|
* @return {string}
|
|
9
9
|
* */
|
|
10
10
|
export function testCase(pck, caseNo) {
|
|
11
|
-
pck =
|
|
11
|
+
pck = typeof pck === "string" ? pck : FQN;
|
|
12
12
|
let caseStr;
|
|
13
|
-
if (typeof caseNo ===
|
|
13
|
+
if (typeof caseNo === "string") {
|
|
14
14
|
caseStr = caseNo;
|
|
15
15
|
}
|
|
16
|
-
else if (typeof caseNo ===
|
|
16
|
+
else if (typeof caseNo === "number") {
|
|
17
17
|
caseStr = caseNo.toString(10);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
@@ -8,7 +8,7 @@ import { FQN } from "../internal.js";
|
|
|
8
8
|
* @return {string}
|
|
9
9
|
* */
|
|
10
10
|
export function testName(testCase, title) {
|
|
11
|
-
testCase =
|
|
12
|
-
title =
|
|
11
|
+
testCase = typeof testCase === "string" ? testCase : `${FQN}@${randomTestNo()}`;
|
|
12
|
+
title = typeof title === "string" ? title : "???";
|
|
13
13
|
return `[test:${testCase}] >> ${title}`;
|
|
14
14
|
}
|
|
@@ -4,8 +4,8 @@ export function triggerFqn(target, full) {
|
|
|
4
4
|
const arr = target[KEY_FQN_ON_SET];
|
|
5
5
|
delete target[KEY_FQN_ON_SET];
|
|
6
6
|
if (Array.isArray(arr)) {
|
|
7
|
-
arr.forEach(callback => {
|
|
8
|
-
if (typeof callback ===
|
|
7
|
+
arr.forEach((callback) => {
|
|
8
|
+
if (typeof callback === "function") {
|
|
9
9
|
try {
|
|
10
10
|
callback(full);
|
|
11
11
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,13 +7,13 @@ export declare const literalPool: import("./common/index.types.js").LiteralPoolL
|
|
|
7
7
|
export declare const lifecycleCommon: import("./common/index.types.js").LifecycleCommonLike;
|
|
8
8
|
export declare const logCommon: import("./common/index.types.js").LogCommonLike;
|
|
9
9
|
export declare const repoCommon: import("./common/index.types.js").RepoCommonLike;
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
16
|
-
export * from
|
|
17
|
-
export * from
|
|
18
|
-
export * from
|
|
19
|
-
export * from
|
|
10
|
+
export * from "./base/index.js";
|
|
11
|
+
export * from "./class/index.js";
|
|
12
|
+
export * from "./common/index.js";
|
|
13
|
+
export * from "./const/index.js";
|
|
14
|
+
export * from "./enum/index.js";
|
|
15
|
+
export * from "./error/index.js";
|
|
16
|
+
export * from "./function/index.js";
|
|
17
|
+
export * from "./sys/index.js";
|
|
18
|
+
export * from "./index.loader.js";
|
|
19
|
+
export * from "./index.foretell.js";
|
package/dist/index.foretell.js
CHANGED
|
@@ -3,12 +3,12 @@ import { FQN } from "./internal.js";
|
|
|
3
3
|
// noinspection JSUnusedGlobalSymbols
|
|
4
4
|
export const foretell_leyyoCommon = [
|
|
5
5
|
// errors
|
|
6
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
7
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
8
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
9
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
10
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
11
|
-
() => leyyo.errorPool.lazy(FQN,
|
|
6
|
+
() => leyyo.errorPool.lazy(FQN, "CausedError", import("./error/caused.error.js").then((m) => m.CausedError), { i18n: true, emit: true }),
|
|
7
|
+
() => leyyo.errorPool.lazy(FQN, "DeveloperError", import("./error/developer.error.js").then((m) => m.DeveloperError), { i18n: true, emit: true }),
|
|
8
|
+
() => leyyo.errorPool.lazy(FQN, "HttpError", import("./error/http.error.js").then((m) => m.HttpError), { i18n: true, emit: true }),
|
|
9
|
+
() => leyyo.errorPool.lazy(FQN, "InvalidValueError", import("./error/invalid-value.error.js").then((m) => m.InvalidValueError), { i18n: true, emit: true }),
|
|
10
|
+
() => leyyo.errorPool.lazy(FQN, "LeyyoError", import("./error/leyyo.error.js").then((m) => m.LeyyoError), { i18n: true, emit: false }),
|
|
11
|
+
() => leyyo.errorPool.lazy(FQN, "MultipleError", import("./error/multiple.error.js").then((m) => m.MultipleError), { i18n: true, emit: true }),
|
|
12
12
|
// enums
|
|
13
|
-
() => leyyo.literalPool.lazy(FQN,
|
|
13
|
+
() => leyyo.literalPool.lazy(FQN, "LogLevel", import("./enum/log-level.js").then((m) => m.LogLevelItems), { i18n: true }),
|
|
14
14
|
];
|
package/dist/index.js
CHANGED
|
@@ -26,13 +26,13 @@ setFqn(logCommon.constructor, FQN);
|
|
|
26
26
|
setFqn(repoCommon.constructor, FQN);
|
|
27
27
|
setFqn(LoggerInstance, FQN);
|
|
28
28
|
setFqn(List, FQN);
|
|
29
|
-
export * from
|
|
30
|
-
export * from
|
|
31
|
-
export * from
|
|
32
|
-
export * from
|
|
33
|
-
export * from
|
|
34
|
-
export * from
|
|
35
|
-
export * from
|
|
36
|
-
export * from
|
|
37
|
-
export * from
|
|
38
|
-
export * from
|
|
29
|
+
export * from "./base/index.js";
|
|
30
|
+
export * from "./class/index.js";
|
|
31
|
+
export * from "./common/index.js";
|
|
32
|
+
export * from "./const/index.js";
|
|
33
|
+
export * from "./enum/index.js";
|
|
34
|
+
export * from "./error/index.js";
|
|
35
|
+
export * from "./function/index.js";
|
|
36
|
+
export * from "./sys/index.js";
|
|
37
|
+
export * from "./index.loader.js";
|
|
38
|
+
export * from "./index.foretell.js";
|
package/dist/index.loader.js
CHANGED
|
@@ -3,8 +3,8 @@ import { FQN } from "./internal.js";
|
|
|
3
3
|
// noinspection JSUnusedGlobalSymbols
|
|
4
4
|
export const loader_leyyoCommon = defineLoader(FQN,
|
|
5
5
|
// errors
|
|
6
|
-
() => import(
|
|
6
|
+
() => import("./error/caused.error.js").then((m) => m.CausedError), () => import("./error/developer.error.js").then((m) => m.DeveloperError), () => import("./error/http.error.js").then((m) => m.HttpError), () => import("./error/invalid-value.error.js").then((m) => m.InvalidValueError), () => import("./error/leyyo.error.js").then((m) => m.LeyyoError), () => import("./error/multiple.error.js").then((m) => m.MultipleError),
|
|
7
7
|
// enums
|
|
8
|
-
() => import(
|
|
8
|
+
() => import("./enum/log-level.js").then((m) => m.LogLevelItems),
|
|
9
9
|
// classes
|
|
10
|
-
() => import(
|
|
10
|
+
() => import("./class/list.js").then((m) => m.List), () => import("./class/logger.instance.js").then((m) => m.LoggerInstance));
|
package/dist/init/index.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
export function init() {
|
|
2
2
|
if (global.console) {
|
|
3
|
-
global.console[
|
|
3
|
+
global.console["fatal"] = (...args) => console.error(...args);
|
|
4
4
|
}
|
|
5
5
|
if (console) {
|
|
6
|
-
console[
|
|
6
|
+
console["fatal"] = (...args) => console.error(...args);
|
|
7
7
|
}
|
|
8
8
|
if (global?.leyyo_is_testing) {
|
|
9
|
-
[
|
|
9
|
+
["log", "debug", "trace", "info", "warn", "error", "fatal"].forEach((name) => {
|
|
10
10
|
if (global?.console) {
|
|
11
|
-
global.console[name] = () => {
|
|
12
|
-
};
|
|
11
|
+
global.console[name] = () => { };
|
|
13
12
|
}
|
|
14
13
|
if (console) {
|
|
14
|
+
console[name] = () => { };
|
|
15
15
|
}
|
|
16
|
-
console[name] = () => {
|
|
17
|
-
};
|
|
18
16
|
});
|
|
19
17
|
}
|
|
20
18
|
}
|
package/dist/sys/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./package-json.js";
|
|
2
|
+
export * from "./leyyo-storage.js";
|