forked from labring/laf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstant.ts
124 lines (113 loc) · 2.18 KB
/
constant.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* 常量模块
*
* @author haroldhu
*/
/**
* 错误码
*/
enum ErrorCode {
DocIDError = '文档ID不合法',
CollNameError = '集合名称不合法',
OpStrError = '操作符不合法',
DirectionError = '排序字符不合法',
IntegerError = 'must be integer',
QueryParamTypeError = '查询参数必须为对象',
QueryParamValueError = '查询参数对象值不能均为undefined'
}
/**
* 字段类型
*/
const FieldType = {
String: 'String',
Number: 'Number',
Object: 'Object',
Array: 'Array',
Boolean: 'Boolean',
Null: 'Null',
GeoPoint: 'GeoPoint',
GeoLineString: 'GeoLineString',
GeoPolygon: 'GeoPolygon',
GeoMultiPoint: 'GeoMultiPoint',
GeoMultiLineString: 'GeoMultiLineString',
GeoMultiPolygon: 'GeoMultiPolygon',
Timestamp: 'Date',
Command: 'Command',
ServerDate: 'ServerDate',
BsonDate: 'BsonDate',
ObjectId: 'ObjectId',
Binary: 'Binary'
}
/**
* 排序方向
*/
type OrderByDirection = 'desc' | 'asc'
/**
* 排序方向列表
*/
const OrderDirectionList = ['desc', 'asc']
/**
* 查询条件操作符
*/
type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>'
/**
* 操作符列表
*/
const WhereFilterOpList = ['<', '<=', '==', '>=', '>']
/**
* 操作符别名
*/
enum Operator {
lt = '<',
gt = '>',
lte = '<=',
gte = '>=',
eq = '=='
}
/**
* 操作符映射
* SDK => MongoDB
*/
const OperatorMap = {
[Operator.eq]: '$eq',
[Operator.lt]: '$lt',
[Operator.lte]: '$lte',
[Operator.gt]: '$gt',
[Operator.gte]: '$gte'
}
const UpdateOperatorList = [
'$set',
'$inc',
'$mul',
'$unset',
'$push',
'$pop',
'$unshift',
'$shift',
'$currentDate',
'$each',
'$position'
]
enum ActionType {
add = 'database.addDocument',
query = 'database.queryDocument',
update = 'database.updateDocument',
count = 'database.countDocument',
remove = 'database.deleteDocument',
aggregate = 'database.aggregateDocuments',
createIndex = 'database.createIndex',
dropIndex = "database.dropIndex",
listIndexes = "database.listIndexes",
}
export {
ErrorCode,
FieldType,
WhereFilterOp,
WhereFilterOpList,
Operator,
OperatorMap,
OrderByDirection,
OrderDirectionList,
UpdateOperatorList,
ActionType
}