@tc-libs/constant 3.5.0 → 3.6.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.
Files changed (2) hide show
  1. package/README.md +119 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,124 @@
1
- # constant
1
+ # @tc-libs/constant
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Raccoglie costanti condivise usate dagli altri package del monorepo. Al momento espone enum per:
4
4
 
5
- ## Building
5
+ - ambiente applicativo
6
+ - MIME type di file immagine, audio, video, excel e documenti testuali
7
+ - classificazione logica dei file
8
+ - formati tabellari esportabili
6
9
 
7
- Run `nx build constant` to build the library.
10
+ Questo package non registra moduli NestJS e non ha configurazione runtime: si importa direttamente dove serve.
8
11
 
9
- ## Running unit tests
12
+ ## Export pubblici
10
13
 
11
- Run `nx test constant` to execute the unit tests via [Jest](https://jestjs.io).
14
+ ```ts
15
+ import {
16
+ ENUM_APP_ENVIRONMENT,
17
+ ENUM_FILE_IMAGE_MIME,
18
+ ENUM_FILE_EXCEL_MIME,
19
+ ENUM_FILE_AUDIO_MIME,
20
+ ENUM_FILE_TEXT_MIME,
21
+ ENUM_FILE_VIDEO_MIME,
22
+ ENUM_FILE_TYPE,
23
+ ENUM_TABLE_FILE_TYPE,
24
+ } from '@tc-libs/constant';
25
+ ```
26
+
27
+ ## Cosa contiene
28
+
29
+ ### `ENUM_APP_ENVIRONMENT`
30
+
31
+ Valori standard per distinguere il contesto applicativo:
32
+
33
+ ```ts
34
+ ENUM_APP_ENVIRONMENT.PRODUCTION;
35
+ ENUM_APP_ENVIRONMENT.STAGING;
36
+ ENUM_APP_ENVIRONMENT.DEVELOPMENT;
37
+ ```
38
+
39
+ Utile per confronti espliciti in config, bootstrap e logica condizionale.
40
+
41
+ ### MIME type file
42
+
43
+ Gli enum MIME vengono usati soprattutto dai package `file`, `doc`, `request` e `response` per validazione upload ed export.
44
+
45
+ ```ts
46
+ ENUM_FILE_IMAGE_MIME.PNG;
47
+ ENUM_FILE_EXCEL_MIME.XLSX;
48
+ ENUM_FILE_AUDIO_MIME.MP3;
49
+ ENUM_FILE_VIDEO_MIME.MP4;
50
+ ENUM_FILE_TEXT_MIME.PDF;
51
+ ```
52
+
53
+ `ENUM_FILE_TEXT_MIME` e un oggetto aggregato che unisce plain text, ODT, PDF, DOCX e PowerPoint.
54
+
55
+ ### `ENUM_FILE_TYPE`
56
+
57
+ Categoria logica del file, indipendente dal MIME specifico:
58
+
59
+ ```ts
60
+ ENUM_FILE_TYPE.IMAGE;
61
+ ENUM_FILE_TYPE.AUDIO;
62
+ ENUM_FILE_TYPE.EXCEL;
63
+ ENUM_FILE_TYPE.VIDEO;
64
+ ```
65
+
66
+ Viene usato, ad esempio, per applicare limiti diversi ai file binari o per persistere il tipo in entita database.
67
+
68
+ ### `ENUM_TABLE_FILE_TYPE`
69
+
70
+ Formati tabellari supportati nelle esportazioni:
71
+
72
+ ```ts
73
+ ENUM_TABLE_FILE_TYPE.CSV;
74
+ ENUM_TABLE_FILE_TYPE.XLS;
75
+ ENUM_TABLE_FILE_TYPE.XLSX;
76
+ ```
77
+
78
+ ## Esempi d'uso
79
+
80
+ ### Validare un MIME type in upload
81
+
82
+ ```ts
83
+ import { ENUM_FILE_IMAGE_MIME } from '@tc-libs/constant';
84
+
85
+ const allowed = Object.values(ENUM_FILE_IMAGE_MIME);
86
+
87
+ if (!allowed.includes(file.mimetype as ENUM_FILE_IMAGE_MIME)) {
88
+ throw new Error('Unsupported image format');
89
+ }
90
+ ```
91
+
92
+ ### Gestire comportamenti per ambiente
93
+
94
+ ```ts
95
+ import { ENUM_APP_ENVIRONMENT } from '@tc-libs/constant';
96
+
97
+ const isProd =
98
+ process.env.NODE_ENV === ENUM_APP_ENVIRONMENT.PRODUCTION;
99
+ ```
100
+
101
+ ### Tipizzare un'opzione di export
102
+
103
+ ```ts
104
+ import { ENUM_TABLE_FILE_TYPE } from '@tc-libs/constant';
105
+
106
+ type ExportOptions = {
107
+ fileType: ENUM_TABLE_FILE_TYPE;
108
+ };
109
+ ```
110
+
111
+ ## Quando usarlo
112
+
113
+ Usa questo package quando vuoi:
114
+
115
+ - evitare stringhe duplicate per MIME type e ambienti
116
+ - condividere enum tipizzati tra piu librerie
117
+ - mantenere allineati validation pipe, DTO e modelli persistiti
118
+
119
+ ## Sviluppo
120
+
121
+ ```bash
122
+ nx build constant
123
+ nx test constant
124
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tc-libs/constant",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "dependencies": {
5
5
  "tslib": "^2.8.1"
6
6
  },