database-proxy
Version:
Through a set of access control rules configuration database access to realize the client directly access the database via HTTP.
55 lines • 1.89 kB
TypeScript
import { HandlerContext } from '../processor';
export declare enum ConstraintTypes {
REQUIRED = "required",
IN = "in",
DEFAULT = "default",
LENGTH = "length",
NUMBER = "number",
UNIQUE = "unique",
MATCH = "match",
EXISTS = "exists",
CONDITION = "condition",
COND = "cond",
NOT_EXISTS = "notExists"
}
export declare class Constraint {
static readonly ALLOWED_CONSTRAINTS: ConstraintTypes[];
readonly context: HandlerContext;
data: any;
ignoreConstraints: string[];
constructor(context: HandlerContext, data: any, ignoreConstraints?: string[]);
/**
* 验证请求 query 中的一个字段
* 1. 如果请求 query 中缺省了该字段,除进行 required 和 default 检查外,则不进行额外约束,直接通过
* 2. 如果请求 query 中存在该字段,则对该字段进行所有约束检查,任意一条检查未通过则返回检查失败
* @param field 要验证的字段名
* @param constrains 此字段的约束配置
* @param context 请求上下文
* @returns
*/
constraintField(field: string, constrains: any): Promise<any>;
/**
* 对字段进行约束性检查
* @param constraintName 约束名
* @param constraintOption 约束配置
* @param fieldKey query 字段名
* @param context 请求上下文
* @returns error or null
*/
checkConstraint(constraintName: ConstraintTypes, constraintOption: any, fieldKey: string): Promise<any>;
/**
* 约束未被忽略
* @param constraintName 约束名
* @returns
*/
private ignored;
private performCondition;
private performIn;
private performLength;
private performNumber;
private performMatch;
private performExists;
private performNotExists;
private performUnique;
}
//# sourceMappingURL=constraint.d.ts.map