@celljs/validation 4.6.1 → 4.7.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.
- package/README.zh-cn.md +32 -0
- package/package.json +3 -3
package/README.zh-cn.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Cell - 校验组件
|
|
2
|
+
|
|
3
|
+
将 `@celljs/validation` 添加到依赖项以检查请求数据:类型为类的控制器或 RPC 参数会变成它的实例([class-transformer](https://github.com/typestack/class-transformer))并用其 [class-validator](https://github.com/typestack/class-validator) 装饰器验证。失败时返回 `400` 和 JSON 格式的错误。
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { IsInt, IsString, Min } from 'class-validator';
|
|
7
|
+
|
|
8
|
+
export class CreateUser {
|
|
9
|
+
@IsString()
|
|
10
|
+
name: string;
|
|
11
|
+
|
|
12
|
+
@IsInt()
|
|
13
|
+
@Min(0)
|
|
14
|
+
age: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Controller('users')
|
|
18
|
+
export class UserController {
|
|
19
|
+
@Post()
|
|
20
|
+
create(@Body() user: CreateUser) { ... }
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
没有这个包时 `@celljs/web` 把这样的参数作为原始请求数据传递,仍然转换 `String`、`Number`、`Boolean` 和 `Date` 参数(`TypeConversionPipe`)。
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
validation:
|
|
28
|
+
detailedOutputDisabled: false # true:返回 400,不带错误
|
|
29
|
+
transformEnabled: true # false:把请求数据而非实例传给方法
|
|
30
|
+
transformOptions: {} # plainToInstance 的选项
|
|
31
|
+
validatorOptions: {} # validate 的选项,例如 whitelist: true
|
|
32
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/validation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Validates request data of Cell controllers and RPC services with class-validator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@celljs/core": "4.
|
|
37
|
-
"@celljs/web": "4.
|
|
36
|
+
"@celljs/core": "4.7.0",
|
|
37
|
+
"@celljs/web": "4.7.0",
|
|
38
38
|
"class-transformer": "^0.5.1",
|
|
39
39
|
"class-validator": "^0.14.4"
|
|
40
40
|
},
|