@leyyo/common 1.3.11 → 1.3.13
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/common/error.common.d.ts +9 -1
- package/dist/common/error.common.js +58 -2
- package/dist/common/index.types.d.ts +27 -0
- package/dist/const/index.d.ts +1 -0
- package/dist/const/index.js +2 -1
- package/dist/error/leyyo.error.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +15 -1
- package/package.json +1 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { ErrorCommonLike, ErrorItemConfig, ErrorObject } from "./index.types.js";
|
|
1
|
+
import { ErrorCommonLike, ErrorCtor, ErrorItemConfig, ErrorObject } from "./index.types.js";
|
|
2
2
|
import { ClassLike, LeyyoLike } from "../base/index.js";
|
|
3
3
|
import { Opt } from "../function/index.js";
|
|
4
4
|
import { LeyyoErrorLike } from "../error/index.js";
|
|
5
5
|
export declare class ErrorCommon implements ErrorCommonLike {
|
|
6
6
|
private leyyo;
|
|
7
7
|
private _knownPackages;
|
|
8
|
+
private _stats;
|
|
9
|
+
readonly started: Date;
|
|
8
10
|
constructor(leyyo: LeyyoLike);
|
|
9
11
|
/**
|
|
10
12
|
* Transform error as a bare object
|
|
@@ -45,4 +47,10 @@ export declare class ErrorCommon implements ErrorCommonLike {
|
|
|
45
47
|
bareObj(err: Error): ErrorObject;
|
|
46
48
|
/** @inheritDoc */
|
|
47
49
|
text(err: Error, ...parts: Array<string | number>): string;
|
|
50
|
+
/** @inheritDoc */
|
|
51
|
+
addStat(p1: Error | ErrorCtor): number;
|
|
52
|
+
/** @inheritDoc */
|
|
53
|
+
clearStats(): void;
|
|
54
|
+
/** @inheritDoc */
|
|
55
|
+
listStats(): Record<string, number>;
|
|
48
56
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { 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, 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
6
|
// noinspection JSUnusedGlobalSymbols
|
|
7
7
|
export class ErrorCommon {
|
|
8
8
|
leyyo;
|
|
9
9
|
_knownPackages;
|
|
10
|
+
_stats;
|
|
11
|
+
started;
|
|
10
12
|
constructor(leyyo) {
|
|
11
13
|
this.leyyo = leyyo;
|
|
12
14
|
}
|
|
@@ -285,4 +287,58 @@ export class ErrorCommon {
|
|
|
285
287
|
}
|
|
286
288
|
return `${info}[err:${VAL_ERROR_UNKNOWN_NAME}] => ^/${VAL_ERROR_UNKNOWN_MESSAGE}/$`;
|
|
287
289
|
}
|
|
290
|
+
/** @inheritDoc */
|
|
291
|
+
addStat(p1) {
|
|
292
|
+
let num = -1;
|
|
293
|
+
try {
|
|
294
|
+
let clazz;
|
|
295
|
+
if (isObj(p1)) {
|
|
296
|
+
const err = p1;
|
|
297
|
+
if (err[KEY_ERROR_RAISED]) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
err[KEY_ERROR_RAISED] = true;
|
|
301
|
+
clazz = err.constructor;
|
|
302
|
+
}
|
|
303
|
+
else if (typeof p1 === 'function') {
|
|
304
|
+
clazz = p1;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (!this._stats) {
|
|
310
|
+
this._stats = this.leyyo.repoCommon.newMap(`${FQN}.error`);
|
|
311
|
+
}
|
|
312
|
+
num = this._stats.get(clazz);
|
|
313
|
+
if (num === undefined) {
|
|
314
|
+
num = 1;
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
num++;
|
|
318
|
+
}
|
|
319
|
+
this._stats.set(clazz, num);
|
|
320
|
+
}
|
|
321
|
+
catch (e) {
|
|
322
|
+
// nothing
|
|
323
|
+
}
|
|
324
|
+
return num;
|
|
325
|
+
}
|
|
326
|
+
/** @inheritDoc */
|
|
327
|
+
clearStats() {
|
|
328
|
+
if (!this._stats) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
this._stats.clear();
|
|
332
|
+
}
|
|
333
|
+
/** @inheritDoc */
|
|
334
|
+
listStats() {
|
|
335
|
+
if (!this._stats) {
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
const map = {};
|
|
339
|
+
for (const [error, num] of this._stats.entries()) {
|
|
340
|
+
map[getFqn(error)] = num;
|
|
341
|
+
}
|
|
342
|
+
return map;
|
|
343
|
+
}
|
|
288
344
|
}
|
|
@@ -160,6 +160,9 @@ export interface ErrorPoolLike extends InertLike<InertItem<ClassLike>, ClassLike
|
|
|
160
160
|
* Bare omit error without any property
|
|
161
161
|
* */
|
|
162
162
|
export type OmitError = Omit<Error, 'name' | 'message' | 'stack'>;
|
|
163
|
+
export interface ErrorCtor extends Fnc {
|
|
164
|
+
new (...args: Array<unknown>): OmitError;
|
|
165
|
+
}
|
|
163
166
|
export interface ErrorObject {
|
|
164
167
|
name: string;
|
|
165
168
|
message: string;
|
|
@@ -242,6 +245,30 @@ export interface ErrorCommonLike {
|
|
|
242
245
|
* @return {string} - error text
|
|
243
246
|
* */
|
|
244
247
|
text(err: Error, ...parts: Array<string | number>): string;
|
|
248
|
+
/**
|
|
249
|
+
* Add error statistics with instance
|
|
250
|
+
*
|
|
251
|
+
* @param {Error} error
|
|
252
|
+
* @return {number} - total raised count
|
|
253
|
+
* */
|
|
254
|
+
addStat(error: Error): number;
|
|
255
|
+
/**
|
|
256
|
+
* Add error statistics
|
|
257
|
+
*
|
|
258
|
+
* @param {ErrorCtor} clazz
|
|
259
|
+
* @return {number} - total raised count
|
|
260
|
+
* */
|
|
261
|
+
addStat(clazz: ErrorCtor): number;
|
|
262
|
+
/**
|
|
263
|
+
* Clear statistics
|
|
264
|
+
* */
|
|
265
|
+
clearStats(): void;
|
|
266
|
+
/**
|
|
267
|
+
* List statistics
|
|
268
|
+
*
|
|
269
|
+
* @return {Record} - as {[error-name]: number}
|
|
270
|
+
* */
|
|
271
|
+
listStats(): Record<string, number>;
|
|
245
272
|
}
|
|
246
273
|
export type Enum<E extends KeyValue = KeyValue> = {
|
|
247
274
|
[K in E]: KeyValue;
|
package/dist/const/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const VAL_ERROR_UNKNOWN_MESSAGE: string;
|
|
|
17
17
|
export declare const KEY_ERROR_DEFAULT_MESSAGE: unique symbol;
|
|
18
18
|
export declare const KEY_ERROR_I18N: unique symbol;
|
|
19
19
|
export declare const KEY_ERROR_EMIT: unique symbol;
|
|
20
|
+
export declare const KEY_ERROR_RAISED: unique symbol;
|
|
20
21
|
export declare const KEY_ERROR_EMITTED: unique symbol;
|
|
21
22
|
export declare const KEY_ERROR_FLAGS: unique symbol;
|
|
22
23
|
export declare const KEY_ERROR_WHERE: unique symbol;
|
package/dist/const/index.js
CHANGED
|
@@ -18,7 +18,8 @@ export const VAL_ERROR_UNKNOWN_MESSAGE = 'Unknown error';
|
|
|
18
18
|
export const KEY_ERROR_DEFAULT_MESSAGE = Symbol.for('leyyo:error:message');
|
|
19
19
|
export const KEY_ERROR_I18N = Symbol.for('leyyo:error:i18n');
|
|
20
20
|
export const KEY_ERROR_EMIT = Symbol.for('leyyo:error:emit');
|
|
21
|
-
export const
|
|
21
|
+
export const KEY_ERROR_RAISED = Symbol.for('leyyo:error:raised');
|
|
22
|
+
export const KEY_ERROR_EMITTED = Symbol.for('leyyo:error:emitted');
|
|
22
23
|
export const KEY_ERROR_FLAGS = Symbol.for('leyyo:error:flags');
|
|
23
24
|
export const KEY_ERROR_WHERE = Symbol.for('leyyo:error:where');
|
|
24
25
|
export const KEY_LOADER_NAME = Symbol.for('leyyo:loader:name');
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const defLogger: import("./common/index.types.js").Logger;
|
|
2
1
|
export declare const deployCommon: import("./common/index.types.js").DeployCommonLike;
|
|
3
2
|
export declare const enumPool: import("./common/index.types.js").EnumPoolLike;
|
|
4
3
|
export declare const errorCommon: import("./common/index.types.js").ErrorCommonLike;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// noinspection JSUnusedGlobalSymbols
|
|
2
2
|
import { init } from "./init/index.js";
|
|
3
3
|
import { leyyo } from "./base/index.js";
|
|
4
|
+
import { setFqn } from "./function/index.js";
|
|
5
|
+
import { FQN } from "./internal.js";
|
|
6
|
+
import { List } from "./class/index.js";
|
|
7
|
+
import { LoggerInstance } from "./class/logger.instance.js";
|
|
4
8
|
init();
|
|
5
|
-
export const defLogger = leyyo.logger;
|
|
6
9
|
export const deployCommon = leyyo.deployCommon;
|
|
7
10
|
export const enumPool = leyyo.enumPool;
|
|
8
11
|
export const errorCommon = leyyo.errorCommon;
|
|
@@ -12,6 +15,17 @@ export const literalPool = leyyo.literalPool;
|
|
|
12
15
|
export const lifecycleCommon = leyyo.lifecycleCommon;
|
|
13
16
|
export const logCommon = leyyo.logCommon;
|
|
14
17
|
export const repoCommon = leyyo.repoCommon;
|
|
18
|
+
setFqn(deployCommon.constructor, FQN);
|
|
19
|
+
setFqn(enumPool.constructor, FQN);
|
|
20
|
+
setFqn(errorCommon.constructor, FQN);
|
|
21
|
+
setFqn(errorPool.constructor, FQN);
|
|
22
|
+
setFqn(eventCommon.constructor, FQN);
|
|
23
|
+
setFqn(literalPool.constructor, FQN);
|
|
24
|
+
setFqn(lifecycleCommon.constructor, FQN);
|
|
25
|
+
setFqn(logCommon.constructor, FQN);
|
|
26
|
+
setFqn(repoCommon.constructor, FQN);
|
|
27
|
+
setFqn(LoggerInstance, FQN);
|
|
28
|
+
setFqn(List, FQN);
|
|
15
29
|
export * from './base/index.js';
|
|
16
30
|
export * from './class/index.js';
|
|
17
31
|
export * from './common/index.js';
|