@leyyo/common 1.3.18 → 1.3.19
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 -70
- package/dist/base/index.types.js +0 -32
- package/dist/base/leyyo.d.ts +0 -3
- package/dist/base/leyyo.js +8 -19
- package/dist/class/index.d.ts +2 -2
- package/dist/class/index.js +2 -2
- package/dist/class/index.types.d.ts +0 -20
- package/dist/class/list.d.ts +0 -6
- package/dist/class/list.js +0 -6
- package/dist/class/logger.instance.d.ts +6 -11
- package/dist/class/logger.instance.js +11 -25
- package/dist/common/deploy.common.d.ts +0 -16
- package/dist/common/deploy.common.js +4 -21
- package/dist/common/enum.pool.d.ts +5 -13
- package/dist/common/enum.pool.js +16 -17
- package/dist/common/error.common.d.ts +0 -30
- package/dist/common/error.common.js +33 -69
- package/dist/common/error.pool.d.ts +1 -10
- package/dist/common/error.pool.js +2 -13
- package/dist/common/event.common.d.ts +0 -8
- package/dist/common/event.common.js +15 -25
- package/dist/common/index.d.ts +11 -11
- package/dist/common/index.js +11 -11
- package/dist/common/index.types.d.ts +12 -435
- package/dist/common/index.types.js +0 -1
- package/dist/common/inert.d.ts +1 -49
- package/dist/common/inert.js +35 -64
- package/dist/common/lifecycle.common.d.ts +0 -14
- package/dist/common/lifecycle.common.js +13 -29
- package/dist/common/literal.pool.d.ts +1 -12
- package/dist/common/literal.pool.js +3 -18
- package/dist/common/log.common.d.ts +0 -54
- package/dist/common/log.common.js +62 -147
- package/dist/common/repo.common.d.ts +0 -188
- package/dist/common/repo.common.js +23 -239
- package/dist/const/index.d.ts +0 -7
- package/dist/const/index.js +28 -36
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.js +1 -1
- package/dist/enum/log-level.d.ts +1 -4
- package/dist/enum/log-level.js +1 -1
- package/dist/error/caused.error.d.ts +0 -10
- package/dist/error/caused.error.js +0 -10
- package/dist/error/developer.error.d.ts +1 -10
- package/dist/error/developer.error.js +6 -25
- package/dist/error/http.error.d.ts +0 -13
- package/dist/error/http.error.js +1 -8
- package/dist/error/index.d.ts +7 -7
- package/dist/error/index.js +7 -7
- package/dist/error/index.types.d.ts +1 -150
- package/dist/error/invalid-value.error.d.ts +0 -3
- package/dist/error/invalid-value.error.js +1 -4
- package/dist/error/leyyo.error.d.ts +0 -33
- package/dist/error/leyyo.error.js +25 -57
- package/dist/error/multiple.error.d.ts +0 -6
- package/dist/error/multiple.error.js +2 -9
- package/dist/function/define-loader.d.ts +0 -6
- package/dist/function/define-loader.js +0 -6
- package/dist/function/delay.d.ts +0 -8
- package/dist/function/delay.js +0 -9
- package/dist/function/delete-prop.d.ts +0 -21
- package/dist/function/delete-prop.js +6 -28
- package/dist/function/empty-fn.d.ts +0 -6
- package/dist/function/empty-fn.js +1 -9
- package/dist/function/extended-type.d.ts +0 -6
- package/dist/function/extended-type.js +18 -24
- package/dist/function/get-fqn.d.ts +0 -6
- package/dist/function/get-fqn.js +2 -8
- package/dist/function/get-prop.d.ts +0 -21
- package/dist/function/get-prop.js +5 -26
- package/dist/function/get-stat.d.ts +0 -20
- package/dist/function/get-stat.js +7 -2
- package/dist/function/has-fqn.d.ts +0 -6
- package/dist/function/has-fqn.js +2 -8
- 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.d.ts +0 -6
- package/dist/function/is-class.js +2 -20
- package/dist/function/is-empty.d.ts +0 -11
- package/dist/function/is-empty.js +1 -12
- package/dist/function/is-filled-arr.d.ts +0 -9
- package/dist/function/is-filled-arr.js +0 -9
- package/dist/function/is-filled-obj.d.ts +0 -9
- package/dist/function/is-filled-obj.js +0 -9
- package/dist/function/is-obj.d.ts +0 -8
- package/dist/function/is-obj.js +1 -9
- package/dist/function/is-test.d.ts +0 -8
- package/dist/function/is-test.js +3 -19
- package/dist/function/is-text.d.ts +0 -10
- package/dist/function/is-text.js +1 -11
- package/dist/function/jitter-interval.d.ts +0 -9
- package/dist/function/jitter-interval.js +2 -18
- package/dist/function/load-config.d.ts +0 -19
- package/dist/function/load-config.js +10 -61
- package/dist/function/on-fqn-set.js +3 -3
- package/dist/function/one-or-more.d.ts +0 -6
- package/dist/function/one-or-more.js +0 -7
- package/dist/function/opt-add.d.ts +0 -8
- package/dist/function/opt-add.js +2 -10
- package/dist/function/opt-append.d.ts +0 -7
- package/dist/function/opt-append.js +0 -7
- package/dist/function/opt-check.d.ts +0 -6
- package/dist/function/opt-check.js +2 -9
- package/dist/function/opt-clone.d.ts +0 -6
- package/dist/function/opt-clone.js +0 -7
- package/dist/function/opt-field.d.ts +0 -8
- package/dist/function/opt-field.js +6 -14
- package/dist/function/opt-fn.d.ts +0 -6
- package/dist/function/opt-fn.js +0 -7
- package/dist/function/random-test-no.d.ts +0 -5
- package/dist/function/random-test-no.js +0 -5
- package/dist/function/remove-fqn.d.ts +0 -8
- package/dist/function/remove-fqn.js +3 -12
- package/dist/function/run-exporter.d.ts +0 -5
- package/dist/function/run-exporter.js +3 -17
- package/dist/function/secure-clone.js +3 -3
- package/dist/function/secure-json.d.ts +0 -35
- package/dist/function/secure-json.js +12 -54
- package/dist/function/set-anonymous-fqn.js +4 -5
- package/dist/function/set-anonymous-name.js +14 -14
- package/dist/function/set-fqn.d.ts +0 -7
- package/dist/function/set-fqn.js +8 -15
- package/dist/function/set-prop.d.ts +0 -24
- package/dist/function/set-prop.js +6 -30
- package/dist/function/stamp-loader.d.ts +0 -6
- package/dist/function/stamp-loader.js +1 -7
- package/dist/function/test-case.d.ts +0 -7
- package/dist/function/test-case.js +3 -10
- package/dist/function/test-name.d.ts +0 -7
- package/dist/function/test-name.js +2 -9
- package/dist/function/trigger-fqn.js +2 -3
- package/dist/index.d.ts +10 -10
- package/dist/index.foretell.js +7 -10
- package/dist/index.js +10 -11
- package/dist/index.loader.js +1 -8
- 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.d.ts +0 -7
- package/dist/sys/leyyo-storage.js +5 -28
- package/dist/sys/package-json.js +5 -5
- package/package.json +16 -31
|
@@ -8,51 +8,21 @@ export declare class ErrorCommon implements ErrorCommonLike {
|
|
|
8
8
|
private _stats;
|
|
9
9
|
readonly started: Date;
|
|
10
10
|
constructor(leyyo: LeyyoLike);
|
|
11
|
-
/**
|
|
12
|
-
* Transform error as a bare object
|
|
13
|
-
*
|
|
14
|
-
* @param {Error} err - error instance
|
|
15
|
-
* @param {Opt} existing - existing parameters
|
|
16
|
-
* @param {boolean} ignoreNameMessage - ignore name & message?
|
|
17
|
-
* @param {WeakSet} weakSet - weak set to prevent duplicates
|
|
18
|
-
* @return {Opt?} - bare error object
|
|
19
|
-
* */
|
|
20
11
|
private _toErrorJson;
|
|
21
|
-
/**
|
|
22
|
-
* Build error info part as `<part1/part2>`
|
|
23
|
-
*
|
|
24
|
-
* @param {Array<string|number>} parts - parts for info
|
|
25
|
-
* @return {string}
|
|
26
|
-
* */
|
|
27
12
|
private _buildTextParts;
|
|
28
|
-
/** @inheritDoc */
|
|
29
13
|
setConfigItem(clazz: ClassLike, conf: ErrorItemConfig): void;
|
|
30
|
-
/** @inheritDoc */
|
|
31
14
|
getConfigItem(clazz: ClassLike): ErrorItemConfig;
|
|
32
|
-
/** @inheritDoc */
|
|
33
15
|
emit(err: Error): void;
|
|
34
|
-
/** @inheritDoc */
|
|
35
16
|
buildStack(source: Error, force?: boolean): void;
|
|
36
|
-
/** @inheritDoc */
|
|
37
17
|
toJsonBasic(err: Error, existing?: Opt): Opt;
|
|
38
|
-
/** @inheritDoc */
|
|
39
18
|
toJsonFull(err: Error, existing: Opt): Opt;
|
|
40
|
-
/** @inheritDoc */
|
|
41
19
|
cast<E extends LeyyoErrorLike>(e: Error, params?: Opt): E;
|
|
42
|
-
/** @inheritDoc */
|
|
43
20
|
forcedCast<E extends LeyyoErrorLike>(clazz: ClassLike, e: Error, params?: Opt): E;
|
|
44
|
-
/** @inheritDoc */
|
|
45
21
|
addKnownPackage(packageName: string, shortName: string): void;
|
|
46
|
-
/** @inheritDoc */
|
|
47
22
|
bareObj(err: Error): ErrorObject;
|
|
48
|
-
/** @inheritDoc */
|
|
49
23
|
text(err: Error, ...parts: Array<string | number>): string;
|
|
50
|
-
/** @inheritDoc */
|
|
51
24
|
addStat(p1: Error | ErrorCtor): number;
|
|
52
|
-
/** @inheritDoc */
|
|
53
25
|
getStat(p1: Error | ErrorCtor): number;
|
|
54
|
-
/** @inheritDoc */
|
|
55
26
|
clearStats(): void;
|
|
56
|
-
/** @inheritDoc */
|
|
57
27
|
listStats(): Record<string, number>;
|
|
58
28
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getFqn, getSymbol, isClass, isEmpty, isFilledArr, isFilledObj, isObj, isText, secureJson, setSymbol, testCase } from "../function/index.js";
|
|
1
|
+
import { getFqn, getSymbol, isClass, isEmpty, isFilledArr, isFilledObj, isObj, isText, secureJson, setSymbol, testCase, } from "../function/index.js";
|
|
2
2
|
import * as stackTraceParser from "stacktrace-parser";
|
|
3
3
|
import { FQN } from "../internal.js";
|
|
4
|
-
import { KEY_ERROR_DEFAULT_MESSAGE, KEY_ERROR_EMIT, KEY_ERROR_EMITTED, KEY_ERROR_I18N, KEY_ERROR_RAISED, VAL_ERROR_UNKNOWN_MESSAGE, VAL_ERROR_UNKNOWN_NAME } from "../const/index.js";
|
|
4
|
+
import { KEY_ERROR_DEFAULT_MESSAGE, KEY_ERROR_EMIT, KEY_ERROR_EMITTED, KEY_ERROR_I18N, KEY_ERROR_RAISED, VAL_ERROR_UNKNOWN_MESSAGE, VAL_ERROR_UNKNOWN_NAME, } from "../const/index.js";
|
|
5
5
|
const where = `${FQN}.ErrorCommon`;
|
|
6
|
-
// noinspection JSUnusedGlobalSymbols
|
|
7
6
|
export class ErrorCommon {
|
|
8
7
|
leyyo;
|
|
9
8
|
_knownPackages;
|
|
@@ -12,16 +11,6 @@ export class ErrorCommon {
|
|
|
12
11
|
constructor(leyyo) {
|
|
13
12
|
this.leyyo = leyyo;
|
|
14
13
|
}
|
|
15
|
-
// region private
|
|
16
|
-
/**
|
|
17
|
-
* Transform error as a bare object
|
|
18
|
-
*
|
|
19
|
-
* @param {Error} err - error instance
|
|
20
|
-
* @param {Opt} existing - existing parameters
|
|
21
|
-
* @param {boolean} ignoreNameMessage - ignore name & message?
|
|
22
|
-
* @param {WeakSet} weakSet - weak set to prevent duplicates
|
|
23
|
-
* @return {Opt?} - bare error object
|
|
24
|
-
* */
|
|
25
14
|
_toErrorJson(err, existing, ignoreNameMessage, weakSet) {
|
|
26
15
|
if (!(err instanceof Error)) {
|
|
27
16
|
return undefined;
|
|
@@ -36,20 +25,22 @@ export class ErrorCommon {
|
|
|
36
25
|
result = { ...result, ...leyyoError.params };
|
|
37
26
|
}
|
|
38
27
|
for (const [k, v] of Object.entries(err)) {
|
|
39
|
-
if (typeof k !==
|
|
28
|
+
if (typeof k !== "string" ||
|
|
29
|
+
["undefined", "symbol", "function"].includes(typeof v) ||
|
|
30
|
+
v === null) {
|
|
40
31
|
continue;
|
|
41
32
|
}
|
|
42
33
|
switch (k) {
|
|
43
|
-
case
|
|
44
|
-
case
|
|
34
|
+
case "name":
|
|
35
|
+
case "message":
|
|
45
36
|
if (!ignoreNameMessage) {
|
|
46
37
|
result[k] = v;
|
|
47
38
|
}
|
|
48
39
|
break;
|
|
49
|
-
case
|
|
50
|
-
case
|
|
40
|
+
case "stack":
|
|
41
|
+
case "params":
|
|
51
42
|
break;
|
|
52
|
-
case
|
|
43
|
+
case "causedBy":
|
|
53
44
|
if (v instanceof Error) {
|
|
54
45
|
const causedBy = this._toErrorJson(v, {}, false, weakSet);
|
|
55
46
|
if (causedBy) {
|
|
@@ -59,7 +50,7 @@ export class ErrorCommon {
|
|
|
59
50
|
else if (isFilledArr(v)) {
|
|
60
51
|
const errors = v;
|
|
61
52
|
const causedErrors = [];
|
|
62
|
-
errors.forEach(e => {
|
|
53
|
+
errors.forEach((e) => {
|
|
63
54
|
const causedError = this._toErrorJson(e, {}, false, weakSet);
|
|
64
55
|
if (causedError) {
|
|
65
56
|
causedErrors.push(causedError);
|
|
@@ -76,36 +67,29 @@ export class ErrorCommon {
|
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Build error info part as `<part1/part2>`
|
|
81
|
-
*
|
|
82
|
-
* @param {Array<string|number>} parts - parts for info
|
|
83
|
-
* @return {string}
|
|
84
|
-
* */
|
|
85
70
|
_buildTextParts(parts) {
|
|
86
|
-
parts = parts
|
|
87
|
-
|
|
71
|
+
parts = parts
|
|
72
|
+
.map((p) => {
|
|
73
|
+
if (typeof p === "string") {
|
|
88
74
|
p = p.trim();
|
|
89
|
-
return
|
|
75
|
+
return p ? p : undefined;
|
|
90
76
|
}
|
|
91
|
-
else if (typeof p ===
|
|
77
|
+
else if (typeof p === "number") {
|
|
92
78
|
return p.toString(10);
|
|
93
79
|
}
|
|
94
80
|
else {
|
|
95
81
|
return undefined;
|
|
96
82
|
}
|
|
97
|
-
})
|
|
98
|
-
|
|
83
|
+
})
|
|
84
|
+
.filter(Boolean);
|
|
85
|
+
return parts.length > 0 ? "<" + parts.join("/") + "> " : "";
|
|
99
86
|
}
|
|
100
|
-
// endregion private
|
|
101
|
-
// region public
|
|
102
|
-
/** @inheritDoc */
|
|
103
87
|
setConfigItem(clazz, conf) {
|
|
104
88
|
if (!isClass(clazz)) {
|
|
105
|
-
throw new this.leyyo.developerError(
|
|
89
|
+
throw new this.leyyo.developerError("Invalid package name", testCase(FQN, 230), where);
|
|
106
90
|
}
|
|
107
91
|
if (!isObj(conf)) {
|
|
108
|
-
throw new this.leyyo.developerError(
|
|
92
|
+
throw new this.leyyo.developerError("Invalid package name", testCase(FQN, 230), where);
|
|
109
93
|
}
|
|
110
94
|
if (isText(conf.message)) {
|
|
111
95
|
setSymbol(clazz, KEY_ERROR_DEFAULT_MESSAGE, conf.message);
|
|
@@ -117,7 +101,6 @@ export class ErrorCommon {
|
|
|
117
101
|
setSymbol(clazz, KEY_ERROR_I18N, conf.i18n);
|
|
118
102
|
}
|
|
119
103
|
}
|
|
120
|
-
/** @inheritDoc */
|
|
121
104
|
getConfigItem(clazz) {
|
|
122
105
|
return {
|
|
123
106
|
message: getSymbol(clazz, KEY_ERROR_DEFAULT_MESSAGE),
|
|
@@ -125,25 +108,20 @@ export class ErrorCommon {
|
|
|
125
108
|
i18n: getSymbol(clazz, KEY_ERROR_I18N),
|
|
126
109
|
};
|
|
127
110
|
}
|
|
128
|
-
/** @inheritDoc */
|
|
129
111
|
emit(err) {
|
|
130
112
|
if (!(err instanceof Error)) {
|
|
131
113
|
return;
|
|
132
114
|
}
|
|
133
|
-
// already emitted
|
|
134
115
|
if (getSymbol(err, KEY_ERROR_EMITTED)) {
|
|
135
116
|
return;
|
|
136
117
|
}
|
|
137
118
|
const clazz = err.constructor;
|
|
138
|
-
// error does not support to emit
|
|
139
119
|
if (!getSymbol(clazz, KEY_ERROR_EMIT)) {
|
|
140
120
|
return;
|
|
141
121
|
}
|
|
142
|
-
// prevent duplicated emits
|
|
143
122
|
setSymbol(err, KEY_ERROR_EMITTED, true);
|
|
144
|
-
this.leyyo.eventCommon.emit(
|
|
123
|
+
this.leyyo.eventCommon.emit("error:emit", err);
|
|
145
124
|
}
|
|
146
|
-
/** @inheritDoc */
|
|
147
125
|
buildStack(source, force) {
|
|
148
126
|
const err = source;
|
|
149
127
|
if (!force && Array.isArray(err.stackTrace)) {
|
|
@@ -164,12 +142,12 @@ export class ErrorCommon {
|
|
|
164
142
|
if (original) {
|
|
165
143
|
const frames = stackTraceParser.parse(original);
|
|
166
144
|
if (Array.isArray(frames)) {
|
|
167
|
-
frames.forEach(frame => {
|
|
168
|
-
if ([
|
|
145
|
+
frames.forEach((frame) => {
|
|
146
|
+
if (["<unknown>", "Object.<anonymous>"].includes(frame.methodName)) {
|
|
169
147
|
frame.methodName = undefined;
|
|
170
148
|
}
|
|
171
149
|
if (frame.file) {
|
|
172
|
-
if (frame.file.startsWith(
|
|
150
|
+
if (frame.file.startsWith("node:")) {
|
|
173
151
|
frame.file = `@ ` + frame.file.substring(5);
|
|
174
152
|
}
|
|
175
153
|
else {
|
|
@@ -178,10 +156,10 @@ export class ErrorCommon {
|
|
|
178
156
|
const index = frame.file.indexOf(pck);
|
|
179
157
|
if (index >= 0) {
|
|
180
158
|
let part = frame.file.substring(index + pck.length);
|
|
181
|
-
if (part.startsWith(
|
|
159
|
+
if (part.startsWith("/")) {
|
|
182
160
|
part = part.substring(1);
|
|
183
161
|
}
|
|
184
|
-
if (part.startsWith(
|
|
162
|
+
if (part.startsWith("dist/")) {
|
|
185
163
|
part = part.substring(5);
|
|
186
164
|
}
|
|
187
165
|
frame.file = `#${short} ` + part;
|
|
@@ -190,7 +168,7 @@ export class ErrorCommon {
|
|
|
190
168
|
}
|
|
191
169
|
}
|
|
192
170
|
}
|
|
193
|
-
if (frame.file.endsWith(
|
|
171
|
+
if (frame.file.endsWith(".js") || frame.file.endsWith(".ts")) {
|
|
194
172
|
frame.file.substring(0, frame.file.length - 3);
|
|
195
173
|
}
|
|
196
174
|
}
|
|
@@ -202,7 +180,7 @@ export class ErrorCommon {
|
|
|
202
180
|
line.method = frame.methodName;
|
|
203
181
|
}
|
|
204
182
|
if (frame.lineNumber !== undefined && frame.column !== undefined) {
|
|
205
|
-
line.pos = `${frame.lineNumber ??
|
|
183
|
+
line.pos = `${frame.lineNumber ?? ""}:${frame.column ?? ""}`;
|
|
206
184
|
}
|
|
207
185
|
err.stackTrace.push(line);
|
|
208
186
|
});
|
|
@@ -210,18 +188,14 @@ export class ErrorCommon {
|
|
|
210
188
|
}
|
|
211
189
|
}
|
|
212
190
|
catch (e) {
|
|
213
|
-
// none
|
|
214
191
|
}
|
|
215
192
|
}
|
|
216
|
-
/** @inheritDoc */
|
|
217
193
|
toJsonBasic(err, existing) {
|
|
218
194
|
return this._toErrorJson(err, existing, true, new WeakSet());
|
|
219
195
|
}
|
|
220
|
-
/** @inheritDoc */
|
|
221
196
|
toJsonFull(err, existing) {
|
|
222
197
|
return this._toErrorJson(err, existing, false, new WeakSet());
|
|
223
198
|
}
|
|
224
|
-
/** @inheritDoc */
|
|
225
199
|
cast(e, params) {
|
|
226
200
|
if (!(e instanceof Error)) {
|
|
227
201
|
return new this.leyyo.leyyoError(secureJson(e));
|
|
@@ -234,7 +208,6 @@ export class ErrorCommon {
|
|
|
234
208
|
err.causedBy = e;
|
|
235
209
|
return err;
|
|
236
210
|
}
|
|
237
|
-
/** @inheritDoc */
|
|
238
211
|
forcedCast(clazz, e, params) {
|
|
239
212
|
if (!(e instanceof Error)) {
|
|
240
213
|
return new this.leyyo.leyyoError(secureJson(e));
|
|
@@ -250,10 +223,9 @@ export class ErrorCommon {
|
|
|
250
223
|
err.causedBy = e;
|
|
251
224
|
return err;
|
|
252
225
|
}
|
|
253
|
-
/** @inheritDoc */
|
|
254
226
|
addKnownPackage(packageName, shortName) {
|
|
255
227
|
if (!isText(packageName)) {
|
|
256
|
-
throw new this.leyyo.developerError(
|
|
228
|
+
throw new this.leyyo.developerError("Invalid package name", testCase(FQN, 230), where);
|
|
257
229
|
}
|
|
258
230
|
if (!isText(shortName)) {
|
|
259
231
|
throw new this.leyyo.developerError(`Invalid short name [${packageName}]`, testCase(FQN, 231), where);
|
|
@@ -266,7 +238,6 @@ export class ErrorCommon {
|
|
|
266
238
|
}
|
|
267
239
|
this._knownPackages.set(packageName, shortName);
|
|
268
240
|
}
|
|
269
|
-
/** @inheritDoc */
|
|
270
241
|
bareObj(err) {
|
|
271
242
|
if (err instanceof Error) {
|
|
272
243
|
return {
|
|
@@ -279,15 +250,13 @@ export class ErrorCommon {
|
|
|
279
250
|
message: VAL_ERROR_UNKNOWN_MESSAGE,
|
|
280
251
|
};
|
|
281
252
|
}
|
|
282
|
-
/** @inheritDoc */
|
|
283
253
|
text(err, ...parts) {
|
|
284
|
-
const info = parts.length > 0 ? this._buildTextParts(parts) :
|
|
254
|
+
const info = parts.length > 0 ? this._buildTextParts(parts) : "";
|
|
285
255
|
if (err instanceof Error) {
|
|
286
256
|
return `${info}[err:${err?.name ?? VAL_ERROR_UNKNOWN_NAME}] => ^/${err?.message ?? VAL_ERROR_UNKNOWN_MESSAGE}/$`;
|
|
287
257
|
}
|
|
288
258
|
return `${info}[err:${VAL_ERROR_UNKNOWN_NAME}] => ^/${VAL_ERROR_UNKNOWN_MESSAGE}/$`;
|
|
289
259
|
}
|
|
290
|
-
/** @inheritDoc */
|
|
291
260
|
addStat(p1) {
|
|
292
261
|
let num = -1;
|
|
293
262
|
try {
|
|
@@ -300,7 +269,7 @@ export class ErrorCommon {
|
|
|
300
269
|
err[KEY_ERROR_RAISED] = true;
|
|
301
270
|
clazz = err.constructor;
|
|
302
271
|
}
|
|
303
|
-
else if (typeof p1 ===
|
|
272
|
+
else if (typeof p1 === "function") {
|
|
304
273
|
clazz = p1;
|
|
305
274
|
}
|
|
306
275
|
else {
|
|
@@ -319,18 +288,16 @@ export class ErrorCommon {
|
|
|
319
288
|
this._stats.set(clazz, num);
|
|
320
289
|
}
|
|
321
290
|
catch (e) {
|
|
322
|
-
// nothing
|
|
323
291
|
}
|
|
324
292
|
return num;
|
|
325
293
|
}
|
|
326
|
-
/** @inheritDoc */
|
|
327
294
|
getStat(p1) {
|
|
328
295
|
try {
|
|
329
296
|
let clazz;
|
|
330
297
|
if (isObj(p1)) {
|
|
331
298
|
clazz = p1.constructor;
|
|
332
299
|
}
|
|
333
|
-
else if (typeof p1 ===
|
|
300
|
+
else if (typeof p1 === "function") {
|
|
334
301
|
clazz = p1;
|
|
335
302
|
}
|
|
336
303
|
else {
|
|
@@ -342,18 +309,15 @@ export class ErrorCommon {
|
|
|
342
309
|
return this._stats.get(clazz) ?? 0;
|
|
343
310
|
}
|
|
344
311
|
catch (e) {
|
|
345
|
-
// nothing
|
|
346
312
|
}
|
|
347
313
|
return 0;
|
|
348
314
|
}
|
|
349
|
-
/** @inheritDoc */
|
|
350
315
|
clearStats() {
|
|
351
316
|
if (!this._stats) {
|
|
352
317
|
return;
|
|
353
318
|
}
|
|
354
319
|
this._stats.clear();
|
|
355
320
|
}
|
|
356
|
-
/** @inheritDoc */
|
|
357
321
|
listStats() {
|
|
358
322
|
if (!this._stats) {
|
|
359
323
|
return {};
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
2
|
import { ErrorPoolItem, ErrorPoolLike, ErrorPoolOpt } from "./index.types.js";
|
|
3
3
|
import { ClassLike, LeyyoLike } from "../base/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* Error pool for call with name and lazy loading
|
|
6
|
-
* */
|
|
7
4
|
export declare class ErrorPool extends Inert<ErrorPoolItem, ClassLike, ErrorPoolOpt> implements ErrorPoolLike {
|
|
8
5
|
protected leyyo: LeyyoLike;
|
|
9
6
|
constructor(leyyo: LeyyoLike);
|
|
10
|
-
/** @inheritDoc */
|
|
11
7
|
protected _getName(target: ClassLike): string;
|
|
12
|
-
/** @inheritDoc */
|
|
13
8
|
protected _nextLoad(_item: ErrorPoolItem): Promise<void>;
|
|
14
|
-
/** @inheritDoc */
|
|
15
9
|
protected _setName(target: ClassLike, _name: string): string;
|
|
16
|
-
/** @inheritDoc */
|
|
17
10
|
protected _afterTargetFound(item: ErrorPoolItem): void;
|
|
18
|
-
/** @inheritDoc */
|
|
19
11
|
protected _validate(target: ClassLike): boolean;
|
|
20
|
-
|
|
21
|
-
define(fqn: string, target: ClassLike, opt?: Omit<ErrorPoolOpt, 'name' | 'target' | 'lazyTarget' | 'fqn'>): void;
|
|
12
|
+
define(fqn: string, target: ClassLike, opt?: Omit<ErrorPoolOpt, "name" | "target" | "lazyTarget" | "fqn">): void;
|
|
22
13
|
}
|
|
@@ -1,27 +1,18 @@
|
|
|
1
1
|
import { Inert } from "./inert.js";
|
|
2
2
|
import { isClass } from "../function/index.js";
|
|
3
|
-
// noinspection JSUnusedGlobalSymbols
|
|
4
|
-
/**
|
|
5
|
-
* Error pool for call with name and lazy loading
|
|
6
|
-
* */
|
|
7
3
|
export class ErrorPool extends Inert {
|
|
8
4
|
leyyo;
|
|
9
5
|
constructor(leyyo) {
|
|
10
|
-
super(leyyo,
|
|
6
|
+
super(leyyo, "error", { anonymousName: "Error" });
|
|
11
7
|
this.leyyo = leyyo;
|
|
12
8
|
}
|
|
13
|
-
/** @inheritDoc */
|
|
14
9
|
_getName(target) {
|
|
15
10
|
return target?.name;
|
|
16
11
|
}
|
|
17
|
-
|
|
18
|
-
async _nextLoad(_item) {
|
|
19
|
-
}
|
|
20
|
-
/** @inheritDoc */
|
|
12
|
+
async _nextLoad(_item) { }
|
|
21
13
|
_setName(target, _name) {
|
|
22
14
|
return target?.name;
|
|
23
15
|
}
|
|
24
|
-
/** @inheritDoc */
|
|
25
16
|
_afterTargetFound(item) {
|
|
26
17
|
if (item.lazyTarget) {
|
|
27
18
|
delete item.lazyTarget;
|
|
@@ -32,11 +23,9 @@ export class ErrorPool extends Inert {
|
|
|
32
23
|
i18n: item.i18n,
|
|
33
24
|
});
|
|
34
25
|
}
|
|
35
|
-
/** @inheritDoc */
|
|
36
26
|
_validate(target) {
|
|
37
27
|
return isClass(target);
|
|
38
28
|
}
|
|
39
|
-
/** @inheritDoc */
|
|
40
29
|
define(fqn, target, opt) {
|
|
41
30
|
this.register({ ...(opt ?? {}), fqn, target });
|
|
42
31
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { EventCommonLike, EventType } from "./index.types.js";
|
|
2
2
|
import { Fnc, LeyyoLike } from "../base/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Event common interface
|
|
5
|
-
* */
|
|
6
3
|
export declare class EventCommon<T extends string> implements EventCommonLike<T> {
|
|
7
4
|
private leyyo;
|
|
8
5
|
private readonly _emitter;
|
|
@@ -11,14 +8,9 @@ export declare class EventCommon<T extends string> implements EventCommonLike<T>
|
|
|
11
8
|
private readonly _removedEvents;
|
|
12
9
|
private readonly _deactivatedEvents;
|
|
13
10
|
constructor(leyyo: LeyyoLike);
|
|
14
|
-
/** @inheritDoc */
|
|
15
11
|
fork<F extends string>(): EventCommonLike<T | F>;
|
|
16
|
-
/** @inheritDoc */
|
|
17
12
|
emit(name: T, ...values: Array<unknown>): boolean;
|
|
18
|
-
/** @inheritDoc */
|
|
19
13
|
listen<T extends string = string>(name: EventType | T, callback: Fnc): void;
|
|
20
|
-
/** @inheritDoc */
|
|
21
14
|
deactivate(name: string): boolean;
|
|
22
|
-
/** @inheritDoc */
|
|
23
15
|
activate(name: string): boolean;
|
|
24
16
|
}
|
|
@@ -2,16 +2,12 @@ import { FQN } from "../internal.js";
|
|
|
2
2
|
import { isText, testCase } from "../function/index.js";
|
|
3
3
|
import EventEmitter from "node:events";
|
|
4
4
|
const where = `${FQN}.EventCommon`;
|
|
5
|
-
// noinspection JSUnusedGlobalSymbols
|
|
6
|
-
/**
|
|
7
|
-
* Event common interface
|
|
8
|
-
* */
|
|
9
5
|
export class EventCommon {
|
|
10
6
|
leyyo;
|
|
11
7
|
_emitter = new EventEmitter();
|
|
12
8
|
_listenedEvents;
|
|
13
9
|
_waitingEvents;
|
|
14
|
-
_removedEvents;
|
|
10
|
+
_removedEvents;
|
|
15
11
|
_deactivatedEvents;
|
|
16
12
|
constructor(leyyo) {
|
|
17
13
|
this.leyyo = leyyo;
|
|
@@ -20,17 +16,14 @@ export class EventCommon {
|
|
|
20
16
|
this._removedEvents = this.leyyo.repoCommon.newMap(`${where}.removedEvents`);
|
|
21
17
|
this._deactivatedEvents = this.leyyo.repoCommon.newSet(`${where}.deactivatedEvents`);
|
|
22
18
|
}
|
|
23
|
-
/** @inheritDoc */
|
|
24
19
|
fork() {
|
|
25
20
|
return this;
|
|
26
21
|
}
|
|
27
|
-
/** @inheritDoc */
|
|
28
22
|
emit(name, ...values) {
|
|
29
23
|
if (!isText(name)) {
|
|
30
|
-
throw new this.leyyo.developerError(
|
|
24
|
+
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 130), where);
|
|
31
25
|
}
|
|
32
26
|
if (!this._emitter.emit(name, ...values)) {
|
|
33
|
-
// It is deactivated, no collect it anymore
|
|
34
27
|
if (this._deactivatedEvents.has(name)) {
|
|
35
28
|
return true;
|
|
36
29
|
}
|
|
@@ -45,28 +38,26 @@ export class EventCommon {
|
|
|
45
38
|
parts = [item.length, item.length + 1];
|
|
46
39
|
this.leyyo.logger.warn(`Removed message. name: ${name}, times: ${parts[1]}`, {
|
|
47
40
|
where,
|
|
48
|
-
eventName: name
|
|
41
|
+
eventName: name,
|
|
49
42
|
});
|
|
50
43
|
item.shift();
|
|
51
44
|
this._removedEvents.set(name, parts);
|
|
52
45
|
}
|
|
53
46
|
else if (parts[0] >= 10_000) {
|
|
54
|
-
// there are too many events, and there is no any listener, close it
|
|
55
47
|
if (parts[1] > 50_000) {
|
|
56
48
|
this.deactivate(name);
|
|
57
49
|
return false;
|
|
58
50
|
}
|
|
59
|
-
// clear half of it
|
|
60
51
|
parts[0] = 5_000;
|
|
61
52
|
item.splice(0, 5_000);
|
|
62
|
-
parts[1]++;
|
|
53
|
+
parts[1]++;
|
|
63
54
|
this.leyyo.logger.warn(`Removed all messages. name: ${name}, times: ${parts[1]}`, {
|
|
64
55
|
where,
|
|
65
|
-
eventName: name
|
|
56
|
+
eventName: name,
|
|
66
57
|
});
|
|
67
58
|
}
|
|
68
59
|
else {
|
|
69
|
-
parts[1]++;
|
|
60
|
+
parts[1]++;
|
|
70
61
|
item.shift();
|
|
71
62
|
}
|
|
72
63
|
}
|
|
@@ -75,12 +66,11 @@ export class EventCommon {
|
|
|
75
66
|
}
|
|
76
67
|
return true;
|
|
77
68
|
}
|
|
78
|
-
/** @inheritDoc */
|
|
79
69
|
listen(name, callback) {
|
|
80
70
|
if (!isText(name)) {
|
|
81
|
-
throw new this.leyyo.developerError(
|
|
71
|
+
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 130), where);
|
|
82
72
|
}
|
|
83
|
-
if (typeof callback !==
|
|
73
|
+
if (typeof callback !== "function") {
|
|
84
74
|
throw new this.leyyo.developerError(`Invalid listener callback [${name}]`, testCase(FQN, 131), where);
|
|
85
75
|
}
|
|
86
76
|
const exists = this._listenedEvents.has(name);
|
|
@@ -88,25 +78,26 @@ export class EventCommon {
|
|
|
88
78
|
this._emitter.removeAllListeners(name);
|
|
89
79
|
}
|
|
90
80
|
this._emitter.on(name, callback);
|
|
91
|
-
// if there is a listener, event will be activated automatically
|
|
92
81
|
this.activate(name);
|
|
93
82
|
this._listenedEvents.set(name, callback);
|
|
94
83
|
if (!exists) {
|
|
95
84
|
if (this._waitingEvents.has(name)) {
|
|
96
|
-
this._waitingEvents.get(name).forEach(values => {
|
|
85
|
+
this._waitingEvents.get(name).forEach((values) => {
|
|
97
86
|
this._emitter.emit(name, ...values);
|
|
98
87
|
});
|
|
99
88
|
this._waitingEvents.delete(name);
|
|
100
89
|
}
|
|
101
90
|
}
|
|
102
91
|
}
|
|
103
|
-
/** @inheritDoc */
|
|
104
92
|
deactivate(name) {
|
|
105
93
|
if (!isText(name)) {
|
|
106
|
-
throw new this.leyyo.developerError(
|
|
94
|
+
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 132), where);
|
|
107
95
|
}
|
|
108
96
|
if (this._waitingEvents.has(name)) {
|
|
109
|
-
this.leyyo.logger.warn(`Deactivated and cleared all messages. name: ${name}`, {
|
|
97
|
+
this.leyyo.logger.warn(`Deactivated and cleared all messages. name: ${name}`, {
|
|
98
|
+
where,
|
|
99
|
+
eventName: name,
|
|
100
|
+
});
|
|
110
101
|
this._waitingEvents.delete(name);
|
|
111
102
|
}
|
|
112
103
|
if (this._removedEvents.has(name)) {
|
|
@@ -118,10 +109,9 @@ export class EventCommon {
|
|
|
118
109
|
this._deactivatedEvents.add(name);
|
|
119
110
|
return true;
|
|
120
111
|
}
|
|
121
|
-
/** @inheritDoc */
|
|
122
112
|
activate(name) {
|
|
123
113
|
if (!isText(name)) {
|
|
124
|
-
throw new this.leyyo.developerError(
|
|
114
|
+
throw new this.leyyo.developerError("Invalid event name", testCase(FQN, 133), where);
|
|
125
115
|
}
|
|
126
116
|
if (this._deactivatedEvents.has(name)) {
|
|
127
117
|
this._deactivatedEvents.delete(name);
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./deploy.common.js";
|
|
3
|
+
export * from "./enum.pool.js";
|
|
4
|
+
export * from "./error.common.js";
|
|
5
|
+
export * from "./error.pool.js";
|
|
6
|
+
export * from "./event.common.js";
|
|
7
|
+
export * from "./inert.js";
|
|
8
|
+
export * from "./lifecycle.common.js";
|
|
9
|
+
export * from "./literal.pool.js";
|
|
10
|
+
export * from "./log.common.js";
|
|
11
|
+
export * from "./repo.common.js";
|
package/dist/common/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./deploy.common.js";
|
|
3
|
+
export * from "./enum.pool.js";
|
|
4
|
+
export * from "./error.common.js";
|
|
5
|
+
export * from "./error.pool.js";
|
|
6
|
+
export * from "./event.common.js";
|
|
7
|
+
export * from "./inert.js";
|
|
8
|
+
export * from "./lifecycle.common.js";
|
|
9
|
+
export * from "./literal.pool.js";
|
|
10
|
+
export * from "./log.common.js";
|
|
11
|
+
export * from "./repo.common.js";
|