@byted-apaas/server-sdk-node 0.0.1-beta.3
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/LICENSE +7 -0
- package/NOTICE +3 -0
- package/README.md +1 -0
- package/application/application.d.ts +27 -0
- package/application/application.js +2 -0
- package/application/application.ts +40 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +21 -0
- package/application/function/function.ts +37 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +50 -0
- package/application/impl/common.ts +50 -0
- package/application/impl/impl.d.ts +16 -0
- package/application/impl/impl.js +38 -0
- package/application/impl/impl.ts +48 -0
- package/constants/constants.d.ts +10 -0
- package/constants/constants.js +15 -0
- package/constants/constants.ts +15 -0
- package/context/context.d.ts +74 -0
- package/context/context.js +25 -0
- package/context/context.ts +130 -0
- package/context/db/db.d.ts +73 -0
- package/context/db/db.js +4 -0
- package/context/db/db.ts +80 -0
- package/context/db/impl/IObject.d.ts +251 -0
- package/context/db/impl/IObject.js +5 -0
- package/context/db/impl/IObject.ts +247 -0
- package/context/db/impl/db.d.ts +61 -0
- package/context/db/impl/db.js +86 -0
- package/context/db/impl/db.ts +95 -0
- package/context/db/impl/object.d.ts +92 -0
- package/context/db/impl/object.js +524 -0
- package/context/db/impl/object.ts +631 -0
- package/context/db/impl/oql/ioql.d.ts +6 -0
- package/context/db/impl/oql/ioql.js +4 -0
- package/context/db/impl/oql/ioql.ts +9 -0
- package/context/db/impl/oql/oql.d.ts +8 -0
- package/context/db/impl/oql/oql.js +21 -0
- package/context/db/impl/oql/oql.ts +25 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +15 -0
- package/context/db/impl/order.ts +19 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +29 -0
- package/context/db/impl/propertiesStore.ts +31 -0
- package/context/db/impl/queryBuilder.d.ts +29 -0
- package/context/db/impl/queryBuilder.js +78 -0
- package/context/db/impl/queryBuilder.ts +106 -0
- package/context/db/impl/transaction/index.d.ts +20 -0
- package/context/db/impl/transaction/index.js +277 -0
- package/context/db/impl/transaction/index.ts +340 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +69 -0
- package/context/db/impl/transaction/operation.ts +72 -0
- package/context/db/impl/transaction.d.ts +67 -0
- package/context/db/impl/transaction.js +4 -0
- package/context/db/impl/transaction.ts +79 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +16 -0
- package/context/globalConfig/globalConfig.ts +14 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +17 -0
- package/context/metadata/components/common.ts +22 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +19 -0
- package/context/metadata/components/components.ts +22 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +402 -0
- package/context/metadata/components/desktop/list.ts +457 -0
- package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
- package/context/metadata/components/desktop/recordDetail.js +53 -0
- package/context/metadata/components/desktop/recordDetail.ts +67 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +145 -0
- package/context/metadata/components/mobile/list.ts +179 -0
- package/context/metadata/metadata.d.ts +61 -0
- package/context/metadata/metadata.js +103 -0
- package/context/metadata/metadata.ts +178 -0
- package/context/metadata/objects/fields.d.ts +130 -0
- package/context/metadata/objects/fields.js +334 -0
- package/context/metadata/objects/fields.ts +457 -0
- package/context/metadata/objects/fields.util.d.ts +40 -0
- package/context/metadata/objects/fields.util.js +319 -0
- package/context/metadata/objects/fields.util.ts +360 -0
- package/context/metadata/objects/objects.d.ts +11 -0
- package/context/metadata/objects/objects.js +20 -0
- package/context/metadata/objects/objects.ts +30 -0
- package/context/metadata/types/common.d.ts +6 -0
- package/context/metadata/types/common.js +9 -0
- package/context/metadata/types/common.ts +13 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +4 -0
- package/context/metadata/types/components.ts +108 -0
- package/context/metadata/types/objects.d.ts +226 -0
- package/context/metadata/types/objects.js +4 -0
- package/context/metadata/types/objects.ts +254 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +35 -0
- package/context/msg/msg.ts +52 -0
- package/context/resources/IResources.d.ts +66 -0
- package/context/resources/IResources.js +2 -0
- package/context/resources/IResources.ts +73 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +150 -0
- package/context/resources/impl/resources.ts +173 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +139 -0
- package/context/tasks/tasks.ts +159 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +4 -0
- package/data/index.ts +30 -0
- package/hooks/api.d.ts +61 -0
- package/hooks/api.js +327 -0
- package/hooks/api.ts +341 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +88 -0
- package/hooks/hooks.ts +100 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +58 -0
- package/kunlun/kunlun.ts +72 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +4 -0
- package/kunlun/operator/IOperator.ts +166 -0
- package/kunlun/operator/impl/expression.d.ts +47 -0
- package/kunlun/operator/impl/expression.js +56 -0
- package/kunlun/operator/impl/expression.ts +74 -0
- package/kunlun/operator/impl/logic.d.ts +50 -0
- package/kunlun/operator/impl/logic.js +509 -0
- package/kunlun/operator/impl/logic.ts +598 -0
- package/kunlun/operator/impl/logicV2.d.ts +58 -0
- package/kunlun/operator/impl/logicV2.js +200 -0
- package/kunlun/operator/impl/logicV2.ts +254 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +222 -0
- package/kunlun/operator/impl/operator.ts +258 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +216 -0
- package/kunlun/operator/impl/operatorV2.ts +249 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +19 -0
- package/lib/core.ts +7 -0
- package/package.json +50 -0
- package/request/common.d.ts +13 -0
- package/request/common.js +87 -0
- package/request/common.ts +91 -0
- package/request/constants.d.ts +10 -0
- package/request/constants.js +25 -0
- package/request/constants.ts +25 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +358 -0
- package/request/faasinfra.ts +393 -0
- package/request/innerapi.d.ts +67 -0
- package/request/innerapi.js +1412 -0
- package/request/innerapi.ts +1648 -0
- package/request/interface.d.ts +95 -0
- package/request/interface.js +41 -0
- package/request/interface.ts +169 -0
- package/request/openapi.d.ts +69 -0
- package/request/openapi.js +1014 -0
- package/request/openapi.ts +1223 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +4 -0
- package/types/types.ts +108 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCriterionV2 = exports.logical = exports.QueryV2 = exports.LogicalExpression = exports.ArithmeticExpression = exports.NewConstantExpressionField = exports.NewMetadataExpressionField = void 0;
|
|
4
|
+
const operator_1 = require("./operator");
|
|
5
|
+
function NewMetadataExpressionField(objectApiName, fieldApiName) {
|
|
6
|
+
return {
|
|
7
|
+
type: "metadataVariable",
|
|
8
|
+
settings: {
|
|
9
|
+
fieldPath: [{
|
|
10
|
+
objectApiName: objectApiName,
|
|
11
|
+
fieldApiName: fieldApiName,
|
|
12
|
+
extendLogicTags: []
|
|
13
|
+
}]
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.NewMetadataExpressionField = NewMetadataExpressionField;
|
|
18
|
+
function NewConstantExpressionField(data) {
|
|
19
|
+
return {
|
|
20
|
+
type: "constant",
|
|
21
|
+
settings: {
|
|
22
|
+
data: data
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.NewConstantExpressionField = NewConstantExpressionField;
|
|
27
|
+
class ArithmeticExpression {
|
|
28
|
+
constructor(leftValue, op, rightValue) {
|
|
29
|
+
let fieldPaths = [];
|
|
30
|
+
leftValue.split('.').forEach((fieldApiName) => {
|
|
31
|
+
fieldPaths.push({
|
|
32
|
+
fieldApiName: fieldApiName,
|
|
33
|
+
objectApiName: "",
|
|
34
|
+
extendLogicTags: []
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const left = {
|
|
38
|
+
type: "metadataVariable",
|
|
39
|
+
settings: {
|
|
40
|
+
fieldPath: fieldPaths,
|
|
41
|
+
data: null
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
let right = {
|
|
45
|
+
type: "constant",
|
|
46
|
+
settings: {
|
|
47
|
+
fieldPath: [],
|
|
48
|
+
data: rightValue
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
if (op == "isEmpty" || op == "isNotEmpty") {
|
|
52
|
+
right = null;
|
|
53
|
+
}
|
|
54
|
+
this.operator = op;
|
|
55
|
+
this.left = left;
|
|
56
|
+
this.right = right;
|
|
57
|
+
this.expr = {
|
|
58
|
+
leftValue: leftValue,
|
|
59
|
+
operator: op,
|
|
60
|
+
rightValue: rightValue
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ArithmeticExpression = ArithmeticExpression;
|
|
65
|
+
;
|
|
66
|
+
class LogicalExpression {
|
|
67
|
+
constructor(logicType, expressions, logics) {
|
|
68
|
+
this.type = logicType;
|
|
69
|
+
this.arithmeticExpressions = expressions;
|
|
70
|
+
this.logicalExpressions = logics;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.LogicalExpression = LogicalExpression;
|
|
74
|
+
class QueryV2 {
|
|
75
|
+
constructor(objectApiName) {
|
|
76
|
+
this.objectApiName = objectApiName;
|
|
77
|
+
this._limit = 200;
|
|
78
|
+
this._offset = 0;
|
|
79
|
+
this.fields = [];
|
|
80
|
+
this._order = [];
|
|
81
|
+
this.filter = {
|
|
82
|
+
type: "and",
|
|
83
|
+
arithmeticExpressions: null,
|
|
84
|
+
logicalExpressions: null,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
buildCriterion(filter) {
|
|
88
|
+
if (!filter || filter.arithmeticExpressions.length == 0 && filter.logicalExpressions.length == 0) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
var conditions = [];
|
|
92
|
+
filter.logicalExpressions.forEach((logicalExpression) => {
|
|
93
|
+
conditions.push({
|
|
94
|
+
[logicalExpression.type]: this.buildCriterion(logicalExpression),
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
filter.arithmeticExpressions.forEach((arithmeticExpression) => {
|
|
98
|
+
conditions.push(arithmeticExpression.expr);
|
|
99
|
+
});
|
|
100
|
+
return conditions;
|
|
101
|
+
}
|
|
102
|
+
where(condition) {
|
|
103
|
+
if (!condition) {
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
const { logicalExps, arithmeticExps } = logical([condition]);
|
|
107
|
+
logicalExps.forEach((logicalExpression) => {
|
|
108
|
+
if (this.filter) {
|
|
109
|
+
this.filter.logicalExpressions.push(logicalExpression);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const logicalExpBuiltByArithmeticExps = new LogicalExpression(operator_1.operates.AND, arithmeticExps, []);
|
|
113
|
+
this.filter.logicalExpressions.push(logicalExpBuiltByArithmeticExps);
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
offset(offset) {
|
|
117
|
+
if (offset < 0) {
|
|
118
|
+
throw new Error("offset must be greater than or equal to 0");
|
|
119
|
+
}
|
|
120
|
+
this._offset = offset;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
limit(limit) {
|
|
124
|
+
if (limit <= 0 || limit > 200) {
|
|
125
|
+
throw new Error("limit must be greater than 0 and less than or equal to 200");
|
|
126
|
+
}
|
|
127
|
+
this._limit = limit;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
orderBy(fieldApiNames) {
|
|
131
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
132
|
+
this._order.push({
|
|
133
|
+
field: fieldApiName,
|
|
134
|
+
direction: "asc",
|
|
135
|
+
type: "",
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
orderByDesc(fieldApiNames) {
|
|
141
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
142
|
+
this._order.push({
|
|
143
|
+
field: fieldApiName,
|
|
144
|
+
direction: "desc",
|
|
145
|
+
type: "",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
select(fieldApiNames) {
|
|
151
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
152
|
+
this.fields.push(fieldApiName);
|
|
153
|
+
});
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.QueryV2 = QueryV2;
|
|
158
|
+
function logical(exps) {
|
|
159
|
+
if (!exps || exps.length == 0) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
var logicalExps = [];
|
|
163
|
+
var arithmeticExps = [];
|
|
164
|
+
exps.forEach((exp) => {
|
|
165
|
+
if (!exp) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (exp instanceof LogicalExpression) {
|
|
169
|
+
logicalExps.push(exp);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
for (var key in exp) {
|
|
173
|
+
if (exp[key]) {
|
|
174
|
+
arithmeticExps.push(new ArithmeticExpression(key, exp[key].operator, exp[key].right));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
logicalExps: logicalExps,
|
|
181
|
+
arithmeticExps: arithmeticExps,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
exports.logical = logical;
|
|
185
|
+
function buildCriterionV2(filter) {
|
|
186
|
+
if (!filter || filter.logicalExpressions.length == 0 && filter.arithmeticExpressions.length == 0) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
var conditions = [];
|
|
190
|
+
filter.logicalExpressions.forEach((logicalExp) => {
|
|
191
|
+
conditions.push({
|
|
192
|
+
[logicalExp.type]: buildCriterionV2(logicalExp),
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
filter.arithmeticExpressions.forEach((arithmeticExp) => {
|
|
196
|
+
conditions.push(arithmeticExp.expr);
|
|
197
|
+
});
|
|
198
|
+
return conditions;
|
|
199
|
+
}
|
|
200
|
+
exports.buildCriterionV2 = buildCriterionV2;
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { OrderV2 } from "../../../request/interface";
|
|
2
|
+
import { UserDataType } from "./expression";
|
|
3
|
+
import { operates } from "./operator";
|
|
4
|
+
|
|
5
|
+
export type FieldPath = {
|
|
6
|
+
objectApiName: string;
|
|
7
|
+
fieldApiName: string;
|
|
8
|
+
extendLogicTags: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SettingType = {
|
|
12
|
+
data?: any;
|
|
13
|
+
fieldPath?: FieldPath[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type Expression = {
|
|
17
|
+
type: string;
|
|
18
|
+
settings: SettingType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function NewMetadataExpressionField(objectApiName: string, fieldApiName: string): Expression {
|
|
22
|
+
return {
|
|
23
|
+
type: "metadataVariable",
|
|
24
|
+
settings: {
|
|
25
|
+
fieldPath: [{
|
|
26
|
+
objectApiName: objectApiName,
|
|
27
|
+
fieldApiName: fieldApiName,
|
|
28
|
+
extendLogicTags: []
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function NewConstantExpressionField(data: UserDataType): Expression {
|
|
35
|
+
return {
|
|
36
|
+
type: "constant",
|
|
37
|
+
settings: {
|
|
38
|
+
data: data
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ExpressionV2 = {
|
|
44
|
+
leftValue: string;
|
|
45
|
+
operator: string;
|
|
46
|
+
rightValue: any;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ArithmeticExpression {
|
|
50
|
+
left: Expression;
|
|
51
|
+
operator: string;
|
|
52
|
+
right: Expression;
|
|
53
|
+
expr: ExpressionV2;
|
|
54
|
+
|
|
55
|
+
constructor(leftValue: string, op: string, rightValue: any) {
|
|
56
|
+
let fieldPaths: FieldPath[] = [];
|
|
57
|
+
leftValue.split('.').forEach((fieldApiName) => {
|
|
58
|
+
fieldPaths.push({
|
|
59
|
+
fieldApiName: fieldApiName,
|
|
60
|
+
objectApiName: "",
|
|
61
|
+
extendLogicTags: []
|
|
62
|
+
});
|
|
63
|
+
})
|
|
64
|
+
const left: Expression = {
|
|
65
|
+
type: "metadataVariable",
|
|
66
|
+
settings: {
|
|
67
|
+
fieldPath: fieldPaths,
|
|
68
|
+
data: null
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
let right: Expression = {
|
|
72
|
+
type: "constant",
|
|
73
|
+
settings: {
|
|
74
|
+
fieldPath: [],
|
|
75
|
+
data: rightValue
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (op == "isEmpty" || op == "isNotEmpty") {
|
|
79
|
+
right = null;
|
|
80
|
+
}
|
|
81
|
+
this.operator = op;
|
|
82
|
+
this.left = left;
|
|
83
|
+
this.right = right;
|
|
84
|
+
this.expr = {
|
|
85
|
+
leftValue: leftValue,
|
|
86
|
+
operator: op,
|
|
87
|
+
rightValue: rightValue
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
export class LogicalExpression {
|
|
94
|
+
type: string;
|
|
95
|
+
arithmeticExpressions: ArithmeticExpression[];
|
|
96
|
+
logicalExpressions: LogicalExpression[];
|
|
97
|
+
|
|
98
|
+
constructor(logicType: string, expressions: ArithmeticExpression[], logics: LogicalExpression[]) {
|
|
99
|
+
this.type = logicType;
|
|
100
|
+
this.arithmeticExpressions = expressions;
|
|
101
|
+
this.logicalExpressions = logics;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class QueryV2 {
|
|
106
|
+
objectApiName: string;
|
|
107
|
+
_limit: number;
|
|
108
|
+
_offset: number;
|
|
109
|
+
fields: string[];
|
|
110
|
+
_order: OrderV2[];
|
|
111
|
+
filter: LogicalExpression;
|
|
112
|
+
|
|
113
|
+
buildCriterion(filter: LogicalExpression): any[] {
|
|
114
|
+
if (!filter || filter.arithmeticExpressions.length == 0 && filter.logicalExpressions.length == 0) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
var conditions: any[] = [];
|
|
118
|
+
|
|
119
|
+
filter.logicalExpressions.forEach((logicalExpression) => {
|
|
120
|
+
conditions.push({
|
|
121
|
+
[logicalExpression.type]: this.buildCriterion(logicalExpression),
|
|
122
|
+
});
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
filter.arithmeticExpressions.forEach((arithmeticExpression) => {
|
|
126
|
+
conditions.push(arithmeticExpression.expr);
|
|
127
|
+
});
|
|
128
|
+
return conditions;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
where(condition: LogicalExpression | Record<string, ArithmeticExpression>): QueryV2 {
|
|
132
|
+
if (!condition) {
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const { logicalExps, arithmeticExps } = logical([condition]);
|
|
137
|
+
logicalExps.forEach((logicalExpression) => {
|
|
138
|
+
if (this.filter) {
|
|
139
|
+
this.filter.logicalExpressions.push(logicalExpression);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const logicalExpBuiltByArithmeticExps = new LogicalExpression(operates.AND, arithmeticExps, []);
|
|
143
|
+
this.filter.logicalExpressions.push(logicalExpBuiltByArithmeticExps);
|
|
144
|
+
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
offset(offset: number): QueryV2 {
|
|
149
|
+
if (offset < 0) {
|
|
150
|
+
throw new Error("offset must be greater than or equal to 0");
|
|
151
|
+
}
|
|
152
|
+
this._offset = offset;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
limit(limit: number): QueryV2 {
|
|
157
|
+
if (limit <= 0 || limit > 200) {
|
|
158
|
+
throw new Error("limit must be greater than 0 and less than or equal to 200");
|
|
159
|
+
}
|
|
160
|
+
this._limit = limit;
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
orderBy(fieldApiNames: string[]): QueryV2 {
|
|
165
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
166
|
+
this._order.push({
|
|
167
|
+
field: fieldApiName,
|
|
168
|
+
direction: "asc",
|
|
169
|
+
type: "",
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
orderByDesc(fieldApiNames: string[]): QueryV2 {
|
|
176
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
177
|
+
this._order.push({
|
|
178
|
+
field: fieldApiName,
|
|
179
|
+
direction: "desc",
|
|
180
|
+
type: "",
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
select(fieldApiNames: string[]): QueryV2 {
|
|
187
|
+
fieldApiNames.forEach((fieldApiName) => {
|
|
188
|
+
this.fields.push(fieldApiName);
|
|
189
|
+
});
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
constructor(objectApiName: string) {
|
|
194
|
+
this.objectApiName = objectApiName;
|
|
195
|
+
this._limit = 200;
|
|
196
|
+
this._offset = 0;
|
|
197
|
+
this.fields = [];
|
|
198
|
+
this._order = [];
|
|
199
|
+
this.filter = {
|
|
200
|
+
type: "and",
|
|
201
|
+
arithmeticExpressions: null,
|
|
202
|
+
logicalExpressions: null,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type logicalRet = {
|
|
208
|
+
logicalExps: LogicalExpression[];
|
|
209
|
+
arithmeticExps: ArithmeticExpression[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function logical(exps: (LogicalExpression | Record<string, ArithmeticExpression>)[]): logicalRet {
|
|
213
|
+
if (!exps || exps.length == 0) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
var logicalExps: LogicalExpression[] = [];
|
|
217
|
+
var arithmeticExps: ArithmeticExpression[] = [];
|
|
218
|
+
exps.forEach((exp) => {
|
|
219
|
+
if (!exp) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (exp instanceof LogicalExpression) {
|
|
223
|
+
logicalExps.push(exp);
|
|
224
|
+
} else {
|
|
225
|
+
for (var key in exp) {
|
|
226
|
+
if (exp[key]) {
|
|
227
|
+
arithmeticExps.push(new ArithmeticExpression(key, exp[key].operator, exp[key].right));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
logicalExps: logicalExps,
|
|
234
|
+
arithmeticExps: arithmeticExps,
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export type CriterionV2 = (Record<string, CriterionV2> | ExpressionV2)[];
|
|
239
|
+
|
|
240
|
+
export function buildCriterionV2(filter: LogicalExpression): CriterionV2 {
|
|
241
|
+
if (!filter || filter.logicalExpressions.length == 0 && filter.arithmeticExpressions.length == 0) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
var conditions: any[] = [];
|
|
245
|
+
filter.logicalExpressions.forEach((logicalExp) => {
|
|
246
|
+
conditions.push({
|
|
247
|
+
[logicalExp.type]: buildCriterionV2(logicalExp),
|
|
248
|
+
})
|
|
249
|
+
});
|
|
250
|
+
filter.arithmeticExpressions.forEach((arithmeticExp) => {
|
|
251
|
+
conditions.push(arithmeticExp.expr);
|
|
252
|
+
});
|
|
253
|
+
return conditions;
|
|
254
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { _Cond, _BooleanCond, _LogicalCond } from '../../../types/types';
|
|
2
|
+
import { IOperator } from "../IOperator";
|
|
3
|
+
import { UserDataType } from './expression';
|
|
4
|
+
export declare const operates: {
|
|
5
|
+
AND: string;
|
|
6
|
+
OR: string;
|
|
7
|
+
EMTPY: string;
|
|
8
|
+
NOT_EMTPY: string;
|
|
9
|
+
EQ: string;
|
|
10
|
+
NEQ: string;
|
|
11
|
+
LT: string;
|
|
12
|
+
LTE: string;
|
|
13
|
+
GT: string;
|
|
14
|
+
GTE: string;
|
|
15
|
+
CONTAIN: string;
|
|
16
|
+
NOT_CONTAIN: string;
|
|
17
|
+
IN: string;
|
|
18
|
+
NIN: string;
|
|
19
|
+
HAS_ANY_OF: string;
|
|
20
|
+
HAS_NONE_OF: string;
|
|
21
|
+
isOnOrBefore: string;
|
|
22
|
+
isOnOrAfter: string;
|
|
23
|
+
};
|
|
24
|
+
export declare class Operator<T> implements IOperator {
|
|
25
|
+
/**
|
|
26
|
+
* 逻辑且
|
|
27
|
+
* @param conditions 多个条件,用逗号分隔
|
|
28
|
+
* @example
|
|
29
|
+
* ```
|
|
30
|
+
* context.db.object("_user").where(kunlun.operator.and({
|
|
31
|
+
* age: "22"
|
|
32
|
+
* },{
|
|
33
|
+
* gender: "male"
|
|
34
|
+
* }))
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
and<T>(...conditions: (_Cond<T> | _BooleanCond<T>)[]): _LogicalCond<T>;
|
|
38
|
+
/**
|
|
39
|
+
* 逻辑或
|
|
40
|
+
* @param conditions 多个条件,用逗号分隔
|
|
41
|
+
* @example
|
|
42
|
+
* ```
|
|
43
|
+
* context.db.object("_user").where(kunlun.operator.or({
|
|
44
|
+
* age: "22"
|
|
45
|
+
* },{
|
|
46
|
+
* age: "25"
|
|
47
|
+
* }))
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
or<T>(...conditions: (_Cond<T> | _BooleanCond<T>)[]): _LogicalCond<T>;
|
|
51
|
+
/**
|
|
52
|
+
* 包含
|
|
53
|
+
* @param value 判定是否包含的文本值
|
|
54
|
+
* @example
|
|
55
|
+
* ```
|
|
56
|
+
* context.db.object("_user").where({_name: kunlun.operator.contain("a")})
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
contain<T>(value: UserDataType): _BooleanCond<T>;
|
|
60
|
+
/**
|
|
61
|
+
* 不包含
|
|
62
|
+
* @param value 判定是否不包含的文本值
|
|
63
|
+
* @example
|
|
64
|
+
* ```
|
|
65
|
+
* context.db.object("_user").where({_name: kunlun.operator.notContain("a")})
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
notContain<T>(value: UserDataType): _BooleanCond<T>;
|
|
69
|
+
/**
|
|
70
|
+
* 无需入参,判断是否为空
|
|
71
|
+
* @example
|
|
72
|
+
* ```
|
|
73
|
+
* context.db.object("_user").where({employeeType: kunlun.operator.empty()})
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
empty(): _BooleanCond<undefined>;
|
|
77
|
+
/**
|
|
78
|
+
* 无需入参,判断是否为空
|
|
79
|
+
* @example
|
|
80
|
+
* ```
|
|
81
|
+
* context.db.object("_user").where({employeeType: kunlun.operator.notEmpty()})
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
notEmpty(): _BooleanCond<undefined>;
|
|
85
|
+
/**
|
|
86
|
+
* 等于
|
|
87
|
+
* @param value 判定是否相等的值
|
|
88
|
+
* @example
|
|
89
|
+
* ```
|
|
90
|
+
* context.db.object("_user").where({age: kunlun.operator.eq(20)})
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
eq<T>(value: UserDataType): _BooleanCond<T>;
|
|
94
|
+
/**
|
|
95
|
+
* 不等于
|
|
96
|
+
* @param value 判定是否不相等的值
|
|
97
|
+
* @example
|
|
98
|
+
* ```
|
|
99
|
+
* context.db.object("_user").where({age: kunlun.operator.neq(20)})
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
neq<T>(value: UserDataType): _BooleanCond<T>;
|
|
103
|
+
/**
|
|
104
|
+
* 大于或晚于
|
|
105
|
+
* @param value 判定是否大于或晚于的值
|
|
106
|
+
* @example
|
|
107
|
+
* ```
|
|
108
|
+
* kunlun.operator.gt(new Date("2020-11-26").getTime())
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
gt<T>(value: number | Date): _BooleanCond<T>;
|
|
112
|
+
/**
|
|
113
|
+
* 大于等于或晚于等于
|
|
114
|
+
* @param value 判定是否大于等于或晚于等于的值
|
|
115
|
+
* @example
|
|
116
|
+
* ```
|
|
117
|
+
* kunlun.operator.gte(new Date("2020-11-26").getTime())
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
gte<T>(value: number | Date): _BooleanCond<T>;
|
|
121
|
+
/**
|
|
122
|
+
* 小于或早于
|
|
123
|
+
* @param value 判定是否小于或早于的值
|
|
124
|
+
* @example
|
|
125
|
+
* ```
|
|
126
|
+
* kunlun.operator.lt(new Date("2020-11-26").getTime())
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
lt<T>(value: number | Date): _BooleanCond<T>;
|
|
130
|
+
/**
|
|
131
|
+
* 小于等于或早于等于
|
|
132
|
+
* @param value 判定是否小于等于或早于等于的值
|
|
133
|
+
* @example
|
|
134
|
+
* ```
|
|
135
|
+
* kunlun.operator.lte(new Date("2020-11-26").getTime())
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
lte<T>(value: number | Date): _BooleanCond<T>;
|
|
139
|
+
/**
|
|
140
|
+
* 存在于给定的数组内
|
|
141
|
+
* @param values 判定是否存在于的一组值,用数组传递
|
|
142
|
+
*/
|
|
143
|
+
in<T>(values: T[]): _BooleanCond<T>;
|
|
144
|
+
/**
|
|
145
|
+
* 存在于给定的数组内
|
|
146
|
+
* @param values 判定是否存在于的一组值,用逗号分隔
|
|
147
|
+
*/
|
|
148
|
+
in<T>(...values: T[]): _BooleanCond<T>;
|
|
149
|
+
/**
|
|
150
|
+
* 不存在于给定的数组内
|
|
151
|
+
* @param values 判定是否不存在于的一组值,用数组传递
|
|
152
|
+
*/
|
|
153
|
+
notIn<T>(values: T[]): _BooleanCond<T>;
|
|
154
|
+
/**
|
|
155
|
+
* 不存在于给定的数组内
|
|
156
|
+
* @param values 判定是否不存在于的一组值,用逗号分隔
|
|
157
|
+
*/
|
|
158
|
+
notIn<T>(...values: T[]): _BooleanCond<T>;
|
|
159
|
+
/**
|
|
160
|
+
* 存在给定的多个值中的任何一个值
|
|
161
|
+
* @param values 判定是否不存在于的一组值,用逗号分隔
|
|
162
|
+
*/
|
|
163
|
+
hasAnyOf<T>(values: number[] | string[]): _BooleanCond<T>;
|
|
164
|
+
/**
|
|
165
|
+
* 存在给定的多个值中的任何一个值
|
|
166
|
+
* @param values 判定是否不存在于的一组值,用逗号分隔
|
|
167
|
+
*/
|
|
168
|
+
hasAnyOf<T>(...values: (number | string)[]): _BooleanCond<T>;
|
|
169
|
+
/**
|
|
170
|
+
* 不存在给定的多个值中的任何值
|
|
171
|
+
* @param values 判定是否不存在于的一组值,用逗号分隔
|
|
172
|
+
*/
|
|
173
|
+
hasNoneOf<T>(values: number[] | string[]): _BooleanCond<T>;
|
|
174
|
+
/**
|
|
175
|
+
* 不存在给定的多个值中的任何值
|
|
176
|
+
* @param values 判定是否不存在于的一组值,用逗号分隔
|
|
177
|
+
*/
|
|
178
|
+
hasNoneOf<T>(...values: (number | string)[]): _BooleanCond<T>;
|
|
179
|
+
}
|