@fluojs/serialization 1.0.4 → 1.0.5
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.ko.md +17 -4
- package/README.md +17 -4
- package/dist/metadata.js +2 -2
- package/package.json +3 -3
package/README.ko.md
CHANGED
|
@@ -70,6 +70,8 @@ class SecureDto {
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
`ExposeClassOptions`는 `Expose(...)`가 받는 class-level option을 표현하는 export 타입입니다. DTO가 field-level `@Expose()` metadata가 있는 field만 내보내야 할 때 `excludeExtraneous: true`를 사용하세요.
|
|
74
|
+
|
|
73
75
|
### 값 변환
|
|
74
76
|
|
|
75
77
|
```ts
|
|
@@ -86,7 +88,7 @@ class ProductDto {
|
|
|
86
88
|
### HTTP 인터셉터와 함께 사용
|
|
87
89
|
|
|
88
90
|
```ts
|
|
89
|
-
import { Controller, Get, UseInterceptors } from '@fluojs/http';
|
|
91
|
+
import { Controller, Get, type RequestContext, UseInterceptors } from '@fluojs/http';
|
|
90
92
|
import { SerializerInterceptor } from '@fluojs/serialization';
|
|
91
93
|
|
|
92
94
|
@Controller('/users')
|
|
@@ -96,10 +98,21 @@ class UsersController {
|
|
|
96
98
|
findAll() {
|
|
97
99
|
return [new UserEntity()];
|
|
98
100
|
}
|
|
101
|
+
|
|
102
|
+
@Get('/export.csv')
|
|
103
|
+
async exportCsv(_input: undefined, context: RequestContext) {
|
|
104
|
+
context.response.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
|
105
|
+
await context.response.send('id,username\n1,fluo');
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
```
|
|
101
109
|
|
|
102
|
-
|
|
110
|
+
두 route는 서로 다른 응답 소유자를 사용합니다.
|
|
111
|
+
|
|
112
|
+
- **Framework-managed response**: `findAll()`은 `RequestContext.response`가 아직 commit되지 않은 상태에서 반환합니다. `SerializerInterceptor`가 반환된 DTO를 직렬화한 뒤 runtime response writer가 결과를 commit합니다.
|
|
113
|
+
- **Handler-owned response**: `exportCsv()`는 최종 payload를 `RequestContext.response.send(...)`로 직접 씁니다. `send(...)`, `redirect(...)`, 또는 수동 streaming helper가 response를 commit하면 `SerializerInterceptor`는 `serialize(...)`를 건너뛰고 `next.handle()`에서 받은 값을 그대로 반환합니다. 이 보장은 `SerializerInterceptor`에만 해당하며, 다른 interceptor는 chain 결과를 계속 변환할 수 있습니다. 이와 별개로 dispatcher는 commit된 response를 확인하고 두 번째 success-response write를 건너뜁니다.
|
|
114
|
+
|
|
115
|
+
직접 쓰는 payload는 최종 결과로 취급하세요. 필요한 field filtering이나 encoding을 commit 전에 적용해야 합니다. Handler/runtime response ownership이 commit된 뒤에는 serialization이 응답을 후처리할 수 없습니다.
|
|
103
116
|
|
|
104
117
|
### 순환 참조 처리
|
|
105
118
|
|
|
@@ -125,8 +138,8 @@ Decorated metadata가 없는 class instance도 재귀적으로 순회하므로,
|
|
|
125
138
|
|
|
126
139
|
- **데코레이터**: `Expose`, `Exclude`, `Transform`
|
|
127
140
|
- **엔진**: `serialize(value)`는 class instance, 배열, plain object, mixed graph를 재귀적으로 순회하며, 직접 transform하지 않은 opaque built-in 및 non-JSON leaf 값은 보존합니다.
|
|
128
|
-
- **HTTP 통합**: `SerializerInterceptor`는 아직 commit되지 않은 handler 결과를
|
|
129
|
-
- **타입**: `TransformFunction`은 `Transform(...)`에 전달하는 callback 타입으로
|
|
141
|
+
- **HTTP 통합**: `SerializerInterceptor`는 아직 commit되지 않은 handler 결과를 직렬화합니다. Response가 commit된 뒤에는 `next.handle()`에서 받은 값을 그대로 반환하지만, 다른 interceptor는 chain 결과를 계속 변환할 수 있습니다.
|
|
142
|
+
- **타입**: `ExposeClassOptions`는 class-level `Expose(...)` option 타입으로 root entrypoint에서 export되며, `TransformFunction`은 `Transform(...)`에 전달하는 callback 타입으로 export됩니다.
|
|
130
143
|
|
|
131
144
|
`Expose`는 class와 field에 적용할 수 있습니다. `Exclude`와 `Transform`은 field에 적용합니다.
|
|
132
145
|
|
package/README.md
CHANGED
|
@@ -70,6 +70,8 @@ class SecureDto {
|
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
`ExposeClassOptions` is the exported class-level options type accepted by `Expose(...)`. Use `excludeExtraneous: true` when a DTO should emit only fields with field-level `@Expose()` metadata.
|
|
74
|
+
|
|
73
75
|
### Value transforms
|
|
74
76
|
|
|
75
77
|
```ts
|
|
@@ -86,7 +88,7 @@ When the same field is decorated in a base class and a derived class, transforms
|
|
|
86
88
|
### HTTP response shaping with an interceptor
|
|
87
89
|
|
|
88
90
|
```ts
|
|
89
|
-
import { Controller, Get, UseInterceptors } from '@fluojs/http';
|
|
91
|
+
import { Controller, Get, type RequestContext, UseInterceptors } from '@fluojs/http';
|
|
90
92
|
import { SerializerInterceptor } from '@fluojs/serialization';
|
|
91
93
|
|
|
92
94
|
@Controller('/users')
|
|
@@ -96,10 +98,21 @@ class UsersController {
|
|
|
96
98
|
findAll() {
|
|
97
99
|
return [new UserEntity()];
|
|
98
100
|
}
|
|
101
|
+
|
|
102
|
+
@Get('/export.csv')
|
|
103
|
+
async exportCsv(_input: undefined, context: RequestContext) {
|
|
104
|
+
context.response.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
|
105
|
+
await context.response.send('id,username\n1,fluo');
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
```
|
|
101
109
|
|
|
102
|
-
|
|
110
|
+
The two routes use different response owners:
|
|
111
|
+
|
|
112
|
+
- **Framework-managed response**: `findAll()` returns while `RequestContext.response` is still uncommitted. `SerializerInterceptor` serializes the returned DTOs, then the runtime response writer commits the result.
|
|
113
|
+
- **Handler-owned response**: `exportCsv()` writes the final payload through `RequestContext.response.send(...)`. Once `send(...)`, `redirect(...)`, or a manual streaming helper commits the response, `SerializerInterceptor` bypasses `serialize(...)` and returns the value it received from `next.handle()` unchanged. This guarantee is specific to `SerializerInterceptor`; other interceptors may still transform the chain result. Independently, the dispatcher sees the committed response and skips a second success-response write.
|
|
114
|
+
|
|
115
|
+
Treat a directly written payload as final: apply any required field filtering or encoding before the commit. Serialization cannot post-process a response after handler/runtime response ownership has been committed.
|
|
103
116
|
|
|
104
117
|
### Cycle-safe serialization
|
|
105
118
|
|
|
@@ -125,8 +138,8 @@ Undecorated class instances are still traversed recursively, so decorated nested
|
|
|
125
138
|
|
|
126
139
|
- **Decorators**: `Expose`, `Exclude`, `Transform`
|
|
127
140
|
- **Engine**: `serialize(value)` recursively walks class instances, arrays, plain objects, and mixed graphs while preserving opaque built-ins and non-JSON leaf values unless you transform them
|
|
128
|
-
- **HTTP integration**: `SerializerInterceptor` serializes uncommitted handler results
|
|
129
|
-
- **Types**: `
|
|
141
|
+
- **HTTP integration**: `SerializerInterceptor` serializes uncommitted handler results; after the response is committed, it returns the value it received from `next.handle()` unchanged, although other interceptors may still transform the chain result
|
|
142
|
+
- **Types**: `ExposeClassOptions` is exported from the root entrypoint for class-level `Expose(...)` options, and `TransformFunction` is exported for callbacks passed to `Transform(...)`
|
|
130
143
|
|
|
131
144
|
`Expose` can be applied to classes and fields. `Exclude` and `Transform` apply to fields.
|
|
132
145
|
|
package/dist/metadata.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOwnConstructorRequestPipelineMetadataBag } from '@fluojs/core/request-pipeline';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Defines the transform function type.
|
|
@@ -41,7 +41,7 @@ function getClassMetadataObject(metadata) {
|
|
|
41
41
|
return created;
|
|
42
42
|
}
|
|
43
43
|
function getOwnMetadataBagFromConstructor(constructor) {
|
|
44
|
-
return
|
|
44
|
+
return getOwnConstructorRequestPipelineMetadataBag(constructor);
|
|
45
45
|
}
|
|
46
46
|
function getConstructorMetadataBags(constructor) {
|
|
47
47
|
const bags = [];
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"output",
|
|
10
10
|
"transform"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.5",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@fluojs/core": "^1.0
|
|
40
|
-
"@fluojs/http": "^
|
|
39
|
+
"@fluojs/core": "^1.1.0",
|
|
40
|
+
"@fluojs/http": "^2.0.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vitest": "^3.2.4"
|