Skip to content

Commit 71af5b6

Browse files
author
pedro
committed
fix:移除是否async函数的判断
1 parent bfb16c7 commit 71af5b6

2 files changed

Lines changed: 4 additions & 18 deletions

File tree

lib/lin-validator.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import isAsyncFunction from 'is-async-function';
21
import { get, isArray, unset, cloneDeep } from 'lodash';
32
import { ParametersException, HttpException } from './exception';
43
import { Context } from 'koa';
@@ -165,11 +164,7 @@ export class LinValidator {
165164
// 当rule的optional为false时,进行校验
166165
if (!stoppedFlag && !it.optional) {
167166
let valid: boolean;
168-
if (isAsyncFunction(it.validate)) {
169-
valid = await it.validate(this.data[dataKey][key]);
170-
} else {
171-
valid = it.validate(this.data[dataKey][key]);
172-
}
167+
valid = await it.validate(this.data[dataKey][key]);
173168
if (!valid) {
174169
errs.push(it.message);
175170
// 如果当前key已有错误,则置stoppedFlag为true,后续会直接跳过校验
@@ -187,11 +182,7 @@ export class LinValidator {
187182
const errs: String[] = [];
188183
if (!stoppedFlag && !value.optional) {
189184
let valid: boolean;
190-
if (isAsyncFunction(value.validate)) {
191-
valid = await value.validate(this.data[dataKey][key]);
192-
} else {
193-
valid = value.validate(this.data[dataKey][key]);
194-
}
185+
valid = await value.validate(this.data[dataKey][key]);
195186
if (!valid) {
196187
errs.push(value.message);
197188
// 如果当前key已有错误,则置stoppedFlag为true,后续会直接跳过校验
@@ -220,11 +211,7 @@ export class LinValidator {
220211
// 自定义校验函数,第一个参数是校验是否成功,第二个参数为错误信息
221212
let validRes: boolean;
222213
try {
223-
if (isAsyncFunction(customerValidateFunc)) {
224-
validRes = await customerValidateFunc.call(this, this.data);
225-
} else {
226-
validRes = customerValidateFunc.call(this, this.data);
227-
}
214+
validRes = await customerValidateFunc.call(this, this.data);
228215
if (isArray(validRes) && !validRes[0]) {
229216
let key;
230217
if (validRes[2]) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lin-mizar",
3-
"version": "0.1.0-beta.4",
3+
"version": "0.1.0-beta.5",
44
"description": "The core library of Lin CMS",
55
"main": "lin/index.js",
66
"scripts": {
@@ -21,7 +21,6 @@
2121
"consola": "^2.5.6",
2222
"dayjs": "^1.8.9",
2323
"egg-logger": "^2.4.1",
24-
"is-async-function": "^1.2.3",
2524
"jsonwebtoken": "^8.5.0",
2625
"koa": "^2.7.0",
2726
"koa-router": "^7.4.0",

0 commit comments

Comments
 (0)