"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constant_1 = require("./constant");
const util_1 = require("./util");
class Validate {
static isGeopoint(point, degree) {
Iif (util_1.Util.whichType(degree) !== constant_1.FieldType.Number) {
throw new Error("Geo Point must be number type");
}
const degreeAbs = Math.abs(degree);
Iif (point === "latitude" && degreeAbs > 90) {
throw new Error("latitude should be a number ranges from -90 to 90");
}
else Iif (point === "longitude" && degreeAbs > 180) {
throw new Error("longitude should be a number ranges from -180 to 180");
}
return true;
}
static isInteger(param, num) {
Iif (!Number.isInteger(num)) {
throw new Error(param + constant_1.ErrorCode.IntergerError);
}
return true;
}
static isFieldOrder(direction) {
Iif (constant_1.OrderDirectionList.indexOf(direction) === -1) {
throw new Error(constant_1.ErrorCode.DirectionError);
}
return true;
}
static isFieldPath(path) {
Iif (!/^[a-zA-Z0-9-_\.]/.test(path)) {
throw new Error();
}
return true;
}
static isOperator(op) {
if (constant_1.WhereFilterOpList.indexOf(op) === -1) {
throw new Error(constant_1.ErrorCode.OpStrError);
}
return true;
}
static isCollName(name) {
if (!/^[a-zA-Z0-9]([a-zA-Z0-9-_]){1,32}$/.test(name)) {
throw new Error(constant_1.ErrorCode.CollNameError);
}
return true;
}
static isDocID(docId) {
if (!/^([a-fA-F0-9]){24}$/.test(docId)) {
throw new Error(constant_1.ErrorCode.DocIDError);
}
return true;
}
}
exports.Validate = Validate;
|