@tc-libs/response 3.6.0 → 3.8.0

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 +80 -6
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,11 +1,85 @@
1
- # response
1
+ # @tc-libs/response
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ Layer di risposta HTTP uniforme per il monorepo.
4
4
 
5
- ## Building
5
+ Fornisce:
6
6
 
7
- Run `nx build response` to build the library.
7
+ - `ResponseModule`
8
+ - decorator `Response()` e `ResponsePaging()`
9
+ - interceptor per wrapping standard delle risposte
10
+ - serializzazioni Swagger-friendly
8
11
 
9
- ## Running unit tests
12
+ ## Come si usa
10
13
 
11
- Run `nx test response` to execute the unit tests via [Jest](https://jestjs.io).
14
+ ### Risposta standard
15
+
16
+ ```ts
17
+ @Get(':id')
18
+ @Response('user.get', {
19
+ serialization: UserGetSerialization,
20
+ })
21
+ async getOne() {
22
+ return {
23
+ data: user,
24
+ };
25
+ }
26
+ ```
27
+
28
+ ### Risposta paginata
29
+
30
+ ```ts
31
+ @Get()
32
+ @ResponsePaging('user.list', {
33
+ serialization: UserListSerialization,
34
+ })
35
+ async list() {
36
+ return {
37
+ _pagination: { total: 100, totalPages: 5 },
38
+ data: rows,
39
+ };
40
+ }
41
+ ```
42
+
43
+ ## Cosa fanno gli interceptor
44
+
45
+ `ResponseDefaultInterceptor` e `ResponsePagingInterceptor`:
46
+
47
+ - leggono `messagePath` e serializzazione dai metadata del decorator
48
+ - serializzano `data` con `plainToInstance`
49
+ - costruiscono `_metadata` con request id, version, timezone, lingue, repoVersion
50
+ - nel caso paginato aggiungono metadata pagination e link cursor
51
+ - risolvono il messaggio tramite `MessageService`
52
+
53
+ ## Shape attesa del return
54
+
55
+ Standard:
56
+
57
+ ```ts
58
+ { data }
59
+ ```
60
+
61
+ Paginato:
62
+
63
+ ```ts
64
+ {
65
+ _pagination: { total, totalPages },
66
+ data
67
+ }
68
+ ```
69
+
70
+ E' supportato anche `_metadata.customProperty` per override di `statusCode`, `message` e `messageProperties`.
71
+
72
+ ## Export utili
73
+
74
+ - `Response`
75
+ - `ResponsePaging`
76
+ - `ResponseSerializationOptions`
77
+ - `ResponseDefaultSerialization`
78
+ - `ResponsePagingSerialization`
79
+
80
+ ## Sviluppo
81
+
82
+ ```bash
83
+ nx build response
84
+ nx test response
85
+ ```
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tc-libs/response",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "dependencies": {
5
- "@tc-libs/request": "3.6.0",
6
- "@tc-libs/message": "3.6.0",
7
- "@tc-libs/constant": "3.6.0",
8
- "@tc-libs/pagination": "3.6.0",
5
+ "@tc-libs/request": "3.8.0",
6
+ "@tc-libs/message": "3.8.0",
7
+ "@tc-libs/constant": "3.8.0",
8
+ "@tc-libs/pagination": "3.8.0",
9
9
  "@nestjs/common": "^11.0.12",
10
10
  "rxjs": "^7.8.2",
11
11
  "express": "5.0.1",