uni-manager 0.0.1 → 0.0.3
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/fesm2022/uni-manager.mjs
CHANGED
|
@@ -1,62 +1,55 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
|
|
3
3
|
class ErrorManager {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
this.store$ = this.store.asObservable();
|
|
9
|
-
}
|
|
4
|
+
// Store privato (Subject)
|
|
5
|
+
static { this.store = new BehaviorSubject(new Map()); }
|
|
6
|
+
// Store pubblico (Observable)
|
|
7
|
+
static { this.store$ = ErrorManager.store.asObservable(); }
|
|
10
8
|
/**
|
|
11
9
|
* Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable
|
|
12
10
|
*/
|
|
13
|
-
get currentErrors() {
|
|
14
|
-
return
|
|
11
|
+
static get currentErrors() {
|
|
12
|
+
return ErrorManager.store.getValue();
|
|
15
13
|
}
|
|
16
14
|
/* ------------------------------ Methods ------------------------------ */
|
|
17
15
|
/**
|
|
18
16
|
* Aggiunge o aggiorna un errore (HTTP o FE) nello store.
|
|
19
17
|
* Se l'errore esiste già (stesso ID), incrementa il contatore.
|
|
20
18
|
*/
|
|
21
|
-
addError(error) {
|
|
22
|
-
|
|
23
|
-
const id = error.type === 'fe'
|
|
24
|
-
? `FE: ${error.exception.functionName ?? 'unknown'}`
|
|
25
|
-
: `${error.status} - ${error.url}`;
|
|
19
|
+
static addError(error) {
|
|
20
|
+
const id = error.ref;
|
|
26
21
|
// Recupera lo stato attuale (la "foto" istantanea)
|
|
27
|
-
const
|
|
28
|
-
const oldError =
|
|
22
|
+
const oldMap = ErrorManager.currentErrors;
|
|
23
|
+
const oldError = oldMap.get(id);
|
|
29
24
|
// Crea il nuovo oggetto errore con il conteggio aggiornato
|
|
30
25
|
const newError = {
|
|
31
26
|
...error,
|
|
32
27
|
count: oldError ? oldError.count + 1 : 1,
|
|
33
28
|
};
|
|
34
29
|
// Aggiorna store
|
|
35
|
-
const newMap = new Map(
|
|
30
|
+
const newMap = new Map(oldMap);
|
|
36
31
|
newMap.set(id, newError);
|
|
37
|
-
|
|
32
|
+
ErrorManager.store.next(newMap);
|
|
38
33
|
}
|
|
39
34
|
/**
|
|
40
|
-
* Rimuove un errore
|
|
35
|
+
* Rimuove un errore tramite ID
|
|
41
36
|
*/
|
|
42
|
-
removeError(id) {
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
37
|
+
static removeError(id) {
|
|
38
|
+
const oldMap = ErrorManager.currentErrors;
|
|
39
|
+
if (!oldMap.has(id))
|
|
45
40
|
return;
|
|
46
41
|
// Aggiorna store
|
|
47
|
-
const newMap = new Map(
|
|
42
|
+
const newMap = new Map(oldMap);
|
|
48
43
|
newMap.delete(id);
|
|
49
|
-
|
|
44
|
+
ErrorManager.store.next(newMap);
|
|
50
45
|
}
|
|
51
46
|
/**
|
|
52
47
|
* Svuota completamente la lista degli errori
|
|
53
48
|
*/
|
|
54
|
-
clearAll() {
|
|
55
|
-
|
|
49
|
+
static clearAll() {
|
|
50
|
+
ErrorManager.store.next(new Map());
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
|
-
// Esporta un'istanza singola (Singleton)
|
|
59
|
-
const errorManager = new ErrorManager();
|
|
60
53
|
|
|
61
54
|
/*
|
|
62
55
|
* Public API Surface of uni-manager
|
|
@@ -66,5 +59,5 @@ const errorManager = new ErrorManager();
|
|
|
66
59
|
* Generated bundle index. Do not edit.
|
|
67
60
|
*/
|
|
68
61
|
|
|
69
|
-
export { ErrorManager
|
|
62
|
+
export { ErrorManager };
|
|
70
63
|
//# sourceMappingURL=uni-manager.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uni-manager.mjs","sources":["../../../projects/uni-manager/src/lib/error/manager.ts","../../../projects/uni-manager/src/public-api.ts","../../../projects/uni-manager/src/uni-manager.ts"],"sourcesContent":["import { BehaviorSubject, Observable } from 'rxjs';\r\nimport { IUniFeError, IUniHttpError } from 'uni-error';\r\n\r\nimport { AppError } from './model';\r\n\r\nexport class ErrorManager {\r\n // Store privato (Subject)\r\n private store = new BehaviorSubject<Map<string, AppError>>(new Map());\r\n\r\n // Store pubblico (Observable)
|
|
1
|
+
{"version":3,"file":"uni-manager.mjs","sources":["../../../projects/uni-manager/src/lib/error/manager.ts","../../../projects/uni-manager/src/public-api.ts","../../../projects/uni-manager/src/uni-manager.ts"],"sourcesContent":["import { BehaviorSubject, Observable } from 'rxjs';\r\nimport { IUniFeError, IUniHttpError } from 'uni-error';\r\n\r\nimport { AppError } from './model';\r\n\r\nexport class ErrorManager {\r\n // Store privato (Subject)\r\n private static store = new BehaviorSubject<Map<string, AppError>>(new Map());\r\n\r\n // Store pubblico (Observable)\r\n public static store$: Observable<Map<string, AppError>> = ErrorManager.store.asObservable();\r\n\r\n /**\r\n * Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable\r\n */\r\n public static get currentErrors(): Map<string, AppError> {\r\n return ErrorManager.store.getValue();\r\n }\r\n\r\n /* ------------------------------ Methods ------------------------------ */\r\n /**\r\n * Aggiunge o aggiorna un errore (HTTP o FE) nello store.\r\n * Se l'errore esiste già (stesso ID), incrementa il contatore.\r\n */\r\n public static addError(error: IUniHttpError | IUniFeError): void {\r\n const id = error.ref;\r\n\r\n // Recupera lo stato attuale (la \"foto\" istantanea)\r\n const oldMap = ErrorManager.currentErrors;\r\n const oldError = oldMap.get(id);\r\n\r\n // Crea il nuovo oggetto errore con il conteggio aggiornato\r\n const newError: AppError = {\r\n ...error,\r\n count: oldError ? oldError.count + 1 : 1,\r\n } as AppError;\r\n\r\n // Aggiorna store\r\n const newMap = new Map(oldMap);\r\n newMap.set(id, newError);\r\n ErrorManager.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Rimuove un errore tramite ID\r\n */\r\n public static removeError(id: string): void {\r\n const oldMap = ErrorManager.currentErrors;\r\n if (!oldMap.has(id)) return;\r\n\r\n // Aggiorna store\r\n const newMap = new Map(oldMap);\r\n newMap.delete(id);\r\n ErrorManager.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Svuota completamente la lista degli errori\r\n */\r\n public static clearAll(): void {\r\n ErrorManager.store.next(new Map());\r\n }\r\n}\r\n","/*\r\n * Public API Surface of uni-manager\r\n */\r\n\r\nexport * from './lib/error';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;MAKa,YAAY,CAAA;;aAER,IAAK,CAAA,KAAA,GAAG,IAAI,eAAe,CAAwB,IAAI,GAAG,EAAE,CAAC,CAAC;;AAG/D,IAAA,SAAA,IAAA,CAAA,MAAM,GAAsC,YAAY,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;AAE5F;;AAEG;AACI,IAAA,WAAW,aAAa,GAAA;AAC7B,QAAA,OAAO,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE;;;AAItC;;;AAGG;IACI,OAAO,QAAQ,CAAC,KAAkC,EAAA;AACvD,QAAA,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG;;AAGpB,QAAA,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa;QACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;;AAG/B,QAAA,MAAM,QAAQ,GAAa;AACzB,YAAA,GAAG,KAAK;AACR,YAAA,KAAK,EAAE,QAAQ,GAAG,QAAQ,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC;SAC7B;;AAGb,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC9B,QAAA,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC;AACxB,QAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;;AAGjC;;AAEG;IACI,OAAO,WAAW,CAAC,EAAU,EAAA;AAClC,QAAA,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa;AACzC,QAAA,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE;;AAGrB,QAAA,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC;AAC9B,QAAA,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AACjB,QAAA,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;;AAGjC;;AAEG;AACI,IAAA,OAAO,QAAQ,GAAA;QACpB,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;;;;AC5DtC;;AAEG;;ACFH;;AAEG;;;;"}
|
package/lib/error/manager.d.ts
CHANGED
|
@@ -2,24 +2,23 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import { IUniFeError, IUniHttpError } from 'uni-error';
|
|
3
3
|
import { AppError } from './model';
|
|
4
4
|
export declare class ErrorManager {
|
|
5
|
-
private store;
|
|
6
|
-
store$: Observable<Map<string, AppError>>;
|
|
5
|
+
private static store;
|
|
6
|
+
static store$: Observable<Map<string, AppError>>;
|
|
7
7
|
/**
|
|
8
8
|
* Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable
|
|
9
9
|
*/
|
|
10
|
-
get currentErrors(): Map<string, AppError>;
|
|
10
|
+
static get currentErrors(): Map<string, AppError>;
|
|
11
11
|
/**
|
|
12
12
|
* Aggiunge o aggiorna un errore (HTTP o FE) nello store.
|
|
13
13
|
* Se l'errore esiste già (stesso ID), incrementa il contatore.
|
|
14
14
|
*/
|
|
15
|
-
addError(error: IUniHttpError | IUniFeError): void;
|
|
15
|
+
static addError(error: IUniHttpError | IUniFeError): void;
|
|
16
16
|
/**
|
|
17
|
-
* Rimuove un errore
|
|
17
|
+
* Rimuove un errore tramite ID
|
|
18
18
|
*/
|
|
19
|
-
removeError(id: string): void;
|
|
19
|
+
static removeError(id: string): void;
|
|
20
20
|
/**
|
|
21
21
|
* Svuota completamente la lista degli errori
|
|
22
22
|
*/
|
|
23
|
-
clearAll(): void;
|
|
23
|
+
static clearAll(): void;
|
|
24
24
|
}
|
|
25
|
-
export declare const errorManager: ErrorManager;
|