@fluojs/validation 1.0.0-beta.4 → 1.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.ko.md +9 -0
- package/README.md +9 -0
- package/dist/mapped-types.d.ts.map +1 -1
- package/dist/mapped-types.js +6 -7
- package/package.json +2 -2
package/README.ko.md
CHANGED
|
@@ -26,6 +26,7 @@ pnpm add @fluojs/validation
|
|
|
26
26
|
- 컨트롤러나 서비스에서 ad hoc parsing 대신 class 기반 검증 규칙을 쓰고 싶을 때
|
|
27
27
|
- `PickType`, `PartialType`, `IntersectionType` 같은 metadata-preserving mapped DTO helper가 필요할 때
|
|
28
28
|
- `@ValidateClass(...)`로 Zod나 Valibot 같은 Standard Schema validator를 붙이고 싶을 때
|
|
29
|
+
- `@fluojs/i18n/validation`으로 명시적으로 localize할 수 있는 안정적인 validation issue code와 path가 필요할 때
|
|
29
30
|
|
|
30
31
|
## 빠른 시작
|
|
31
32
|
|
|
@@ -96,6 +97,8 @@ type ValidationIssue = {
|
|
|
96
97
|
사용합니다. HTTP 바인딩에서 온 규칙은 `source`를 붙이며, standalone validation이나
|
|
97
98
|
Standard Schema 이슈에서는 값이 없을 수 있습니다.
|
|
98
99
|
|
|
100
|
+
`@fluojs/validation`은 항상 기존 human-readable `message` 값을 방출합니다. Localized message가 필요한 애플리케이션은 validation 실패 후 `@fluojs/i18n/validation`에 opt-in할 수 있습니다. 이 통합은 validator 실행을 바꾸거나 이 패키지를 HTTP locale resolution에 결합하지 않고 `source`, `field`, `code`를 translation key로 매핑합니다.
|
|
101
|
+
|
|
99
102
|
### Mapped DTO 헬퍼
|
|
100
103
|
|
|
101
104
|
```ts
|
|
@@ -110,6 +113,11 @@ class EmailOnlyDto extends PickType(UserDto, ['email']) {}
|
|
|
110
113
|
class UpdateUserDto extends PartialType(UserDto) {}
|
|
111
114
|
```
|
|
112
115
|
|
|
116
|
+
Mapped DTO helper는 위와 같은 문서화된 subclassing 패턴에서도 field-level
|
|
117
|
+
validation 및 binding metadata를 보존합니다. `PickType`, `OmitType`,
|
|
118
|
+
`PartialType`은 생략되었거나 optional이 된 필드에 의존할 수 있는 base
|
|
119
|
+
class-level validator를 derived DTO로 전달하지 않습니다.
|
|
120
|
+
|
|
113
121
|
### Standard Schema 지원
|
|
114
122
|
|
|
115
123
|
Standard Schema adapter는 유효하지 않은 입력을 명시적인 issue로 보고해야 합니다. issue가 없는 검증 결과는 성공으로 처리합니다.
|
|
@@ -154,6 +162,7 @@ class RestrictedUserDto {
|
|
|
154
162
|
## 관련 패키지
|
|
155
163
|
|
|
156
164
|
- `@fluojs/http`: request data를 bind한 뒤 이 패키지로 검증합니다.
|
|
165
|
+
- `@fluojs/i18n`: opt-in localized validation issue message를 위한 `@fluojs/i18n/validation`을 제공합니다.
|
|
157
166
|
- `@fluojs/serialization`: response side에서 output DTO를 가공합니다.
|
|
158
167
|
- `@fluojs/core`: validation decorator가 사용하는 metadata primitive를 제공합니다.
|
|
159
168
|
|
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ pnpm add @fluojs/validation
|
|
|
26
26
|
- when you want class-based validation rules instead of ad hoc parsing in controllers and services
|
|
27
27
|
- when you need metadata-preserving mapped DTO helpers such as `PickType`, `PartialType`, and `IntersectionType`
|
|
28
28
|
- when you want to attach Standard Schema validators such as Zod or Valibot through `@ValidateClass(...)`
|
|
29
|
+
- when you want stable validation issue codes and paths that can be localized explicitly through `@fluojs/i18n/validation`
|
|
29
30
|
|
|
30
31
|
## Quick Start
|
|
31
32
|
|
|
@@ -100,6 +101,8 @@ Nested DTOs use dot paths and collection indexes, such as `address.city` or
|
|
|
100
101
|
`items[0].name`. HTTP bindings attach `source` when the rule came from request
|
|
101
102
|
metadata; standalone validation and Standard Schema issues may leave it unset.
|
|
102
103
|
|
|
104
|
+
`@fluojs/validation` always emits its normal human-readable `message` values. Applications that need localized messages can opt into `@fluojs/i18n/validation` after validation fails. That integration maps `source`, `field`, and `code` to translation keys without changing validator execution or coupling this package to HTTP locale resolution.
|
|
105
|
+
|
|
103
106
|
### Mapped DTO helpers
|
|
104
107
|
|
|
105
108
|
```ts
|
|
@@ -114,6 +117,11 @@ class EmailOnlyDto extends PickType(UserDto, ['email']) {}
|
|
|
114
117
|
class UpdateUserDto extends PartialType(UserDto) {}
|
|
115
118
|
```
|
|
116
119
|
|
|
120
|
+
Mapped DTO helpers preserve field-level validation and binding metadata through
|
|
121
|
+
the documented subclassing pattern shown above. `PickType`, `OmitType`, and
|
|
122
|
+
`PartialType` do not carry base class-level validators onto derived DTOs because
|
|
123
|
+
those validators can depend on fields that were omitted or made optional.
|
|
124
|
+
|
|
117
125
|
### Standard Schema support
|
|
118
126
|
|
|
119
127
|
Standard Schema adapters are expected to report invalid input through explicit issues. Validation results without issues are treated as successful.
|
|
@@ -158,6 +166,7 @@ Numeric validators, including `@IsLatitude()` and `@IsLongitude()`, validate num
|
|
|
158
166
|
## Related Packages
|
|
159
167
|
|
|
160
168
|
- `@fluojs/http`: binds request data, then uses this package to validate it
|
|
169
|
+
- `@fluojs/i18n`: exposes `@fluojs/i18n/validation` for opt-in localized validation issue messages
|
|
161
170
|
- `@fluojs/serialization`: shapes output DTOs on the response side
|
|
162
171
|
- `@fluojs/core`: provides the metadata primitives used by validation decorators
|
|
163
172
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapped-types.d.ts","sourceRoot":"","sources":["../src/mapped-types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AAUtB,KAAK,cAAc,CAAC,CAAC,GAAG,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"mapped-types.d.ts","sourceRoot":"","sources":["../src/mapped-types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AAUtB,KAAK,cAAc,CAAC,CAAC,GAAG,MAAM,IAAI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;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,KAAK,SAAS,cAAc,EAAE,OAAO,EAAE,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CA6BtH"}
|
package/dist/mapped-types.js
CHANGED
|
@@ -24,7 +24,7 @@ function collectDtoKeys(dto) {
|
|
|
24
24
|
}
|
|
25
25
|
return [...keys];
|
|
26
26
|
}
|
|
27
|
-
function copyDtoMetadata(source, target, include) {
|
|
27
|
+
function copyDtoMetadata(source, target, include, copyClassRules = false) {
|
|
28
28
|
for (const entry of getDtoBindingSchema(source)) {
|
|
29
29
|
if (!include(entry.propertyKey)) {
|
|
30
30
|
continue;
|
|
@@ -39,8 +39,10 @@ function copyDtoMetadata(source, target, include) {
|
|
|
39
39
|
appendDtoFieldValidationRule(target.prototype, entry.propertyKey, rule);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (copyClassRules) {
|
|
43
|
+
for (const rule of getClassValidationRules(source)) {
|
|
44
|
+
appendClassValidationRule(target, rule);
|
|
45
|
+
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
@@ -150,7 +152,7 @@ export function IntersectionType(...baseDtos) {
|
|
|
150
152
|
}
|
|
151
153
|
});
|
|
152
154
|
for (const BaseDto of baseDtos) {
|
|
153
|
-
copyDtoMetadata(BaseDto, IntersectionDto, () => true);
|
|
155
|
+
copyDtoMetadata(BaseDto, IntersectionDto, () => true, true);
|
|
154
156
|
}
|
|
155
157
|
return IntersectionDto;
|
|
156
158
|
}
|
|
@@ -200,8 +202,5 @@ export function PartialType(BaseDto) {
|
|
|
200
202
|
});
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
|
-
for (const rule of getClassValidationRules(BaseDto)) {
|
|
204
|
-
appendClassValidationRule(PartialDto, rule);
|
|
205
|
-
}
|
|
206
205
|
return PartialDto;
|
|
207
206
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"decorators",
|
|
10
10
|
"schema"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.
|
|
12
|
+
"version": "1.0.1",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@standard-schema/spec": "^1.1.0",
|
|
44
44
|
"validator": "^13.15.26",
|
|
45
|
-
"@fluojs/core": "^1.0.
|
|
45
|
+
"@fluojs/core": "^1.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/validator": "^13.15.10",
|