uni-manager 0.0.1
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/README.md +63 -0
- package/fesm2022/uni-manager.mjs +70 -0
- package/fesm2022/uni-manager.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/error/index.d.ts +2 -0
- package/lib/error/manager.d.ts +25 -0
- package/lib/error/model.d.ts +4 -0
- package/package.json +23 -0
- package/public-api.d.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# UniManager
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.1.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build uni-manager
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/uni-manager
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
class ErrorManager {
|
|
4
|
+
constructor() {
|
|
5
|
+
// Store privato (Subject)
|
|
6
|
+
this.store = new BehaviorSubject(new Map());
|
|
7
|
+
// Store pubblico (Observable) - Svelte userà questo con la sintassi $
|
|
8
|
+
this.store$ = this.store.asObservable();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable
|
|
12
|
+
*/
|
|
13
|
+
get currentErrors() {
|
|
14
|
+
return this.store.getValue();
|
|
15
|
+
}
|
|
16
|
+
/* ------------------------------ Methods ------------------------------ */
|
|
17
|
+
/**
|
|
18
|
+
* Aggiunge o aggiorna un errore (HTTP o FE) nello store.
|
|
19
|
+
* Se l'errore esiste già (stesso ID), incrementa il contatore.
|
|
20
|
+
*/
|
|
21
|
+
addError(error) {
|
|
22
|
+
// Determina l'ID univoco in base al tipo di errore
|
|
23
|
+
const id = error.type === 'fe'
|
|
24
|
+
? `FE: ${error.exception.functionName ?? 'unknown'}`
|
|
25
|
+
: `${error.status} - ${error.url}`;
|
|
26
|
+
// Recupera lo stato attuale (la "foto" istantanea)
|
|
27
|
+
const map = this.currentErrors;
|
|
28
|
+
const oldError = map.get(id);
|
|
29
|
+
// Crea il nuovo oggetto errore con il conteggio aggiornato
|
|
30
|
+
const newError = {
|
|
31
|
+
...error,
|
|
32
|
+
count: oldError ? oldError.count + 1 : 1,
|
|
33
|
+
};
|
|
34
|
+
// Aggiorna store
|
|
35
|
+
const newMap = new Map(map);
|
|
36
|
+
newMap.set(id, newError);
|
|
37
|
+
this.store.next(newMap);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Rimuove un errore specifico tramite ID
|
|
41
|
+
*/
|
|
42
|
+
removeError(id) {
|
|
43
|
+
const map = this.currentErrors;
|
|
44
|
+
if (!map.has(id))
|
|
45
|
+
return;
|
|
46
|
+
// Aggiorna store
|
|
47
|
+
const newMap = new Map(map);
|
|
48
|
+
newMap.delete(id);
|
|
49
|
+
this.store.next(newMap);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Svuota completamente la lista degli errori
|
|
53
|
+
*/
|
|
54
|
+
clearAll() {
|
|
55
|
+
this.store.next(new Map());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Esporta un'istanza singola (Singleton)
|
|
59
|
+
const errorManager = new ErrorManager();
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* Public API Surface of uni-manager
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generated bundle index. Do not edit.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export { ErrorManager, errorManager };
|
|
70
|
+
//# sourceMappingURL=uni-manager.mjs.map
|
|
@@ -0,0 +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) - Svelte userà questo con la sintassi $\r\n public store$: Observable<Map<string, AppError>> = this.store.asObservable();\r\n\r\n /**\r\n * Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable\r\n */\r\n public get currentErrors(): Map<string, AppError> {\r\n return this.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 addError(error: IUniHttpError | IUniFeError): void {\r\n // Determina l'ID univoco in base al tipo di errore\r\n const id =\r\n error.type === 'fe'\r\n ? `FE: ${error.exception.functionName ?? 'unknown'}`\r\n : `${error.status} - ${error.url}`;\r\n\r\n // Recupera lo stato attuale (la \"foto\" istantanea)\r\n const map = this.currentErrors;\r\n const oldError = map.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(map);\r\n newMap.set(id, newError);\r\n this.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Rimuove un errore specifico tramite ID\r\n */\r\n public removeError(id: string): void {\r\n const map = this.currentErrors;\r\n if (!map.has(id)) return;\r\n\r\n // Aggiorna store\r\n const newMap = new Map(map);\r\n newMap.delete(id);\r\n this.store.next(newMap);\r\n }\r\n\r\n /**\r\n * Svuota completamente la lista degli errori\r\n */\r\n public clearAll(): void {\r\n this.store.next(new Map());\r\n }\r\n}\r\n\r\n// Esporta un'istanza singola (Singleton)\r\nexport const errorManager = new ErrorManager();\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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B,QAAA,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AACjB,QAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;;AAGzB;;AAEG;IACI,QAAQ,GAAA;QACb,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;;AAE7B;AAED;AACa,MAAA,YAAY,GAAG,IAAI,YAAY;;ACrE5C;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { IUniFeError, IUniHttpError } from 'uni-error';
|
|
3
|
+
import { AppError } from './model';
|
|
4
|
+
export declare class ErrorManager {
|
|
5
|
+
private store;
|
|
6
|
+
store$: Observable<Map<string, AppError>>;
|
|
7
|
+
/**
|
|
8
|
+
* Ottiene lo stato attuale della Map senza dover sottoscrivere l'observable
|
|
9
|
+
*/
|
|
10
|
+
get currentErrors(): Map<string, AppError>;
|
|
11
|
+
/**
|
|
12
|
+
* Aggiunge o aggiorna un errore (HTTP o FE) nello store.
|
|
13
|
+
* Se l'errore esiste già (stesso ID), incrementa il contatore.
|
|
14
|
+
*/
|
|
15
|
+
addError(error: IUniHttpError | IUniFeError): void;
|
|
16
|
+
/**
|
|
17
|
+
* Rimuove un errore specifico tramite ID
|
|
18
|
+
*/
|
|
19
|
+
removeError(id: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Svuota completamente la lista degli errori
|
|
22
|
+
*/
|
|
23
|
+
clearAll(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare const errorManager: ErrorManager;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uni-manager",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^19.1.0",
|
|
6
|
+
"@angular/core": "^19.1.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"tslib": "^2.3.0"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"module": "fesm2022/uni-manager.mjs",
|
|
13
|
+
"typings": "index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": {
|
|
16
|
+
"default": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"default": "./fesm2022/uni-manager.mjs"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/public-api.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/error';
|