@byted-apaas/server-sdk-node 0.0.2-beta.1
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.md +0 -0
- package/README.md +1 -0
- package/application/application.d.ts +27 -0
- package/application/application.js +3 -0
- package/application/application.js.map +1 -0
- package/application/application.ts +40 -0
- package/application/function/function.d.ts +14 -0
- package/application/function/function.js +22 -0
- package/application/function/function.js.map +1 -0
- package/application/function/function.ts +37 -0
- package/application/impl/common.d.ts +2 -0
- package/application/impl/common.js +51 -0
- package/application/impl/common.js.map +1 -0
- package/application/impl/common.ts +50 -0
- package/application/impl/impl.d.ts +16 -0
- package/application/impl/impl.js +39 -0
- package/application/impl/impl.js.map +1 -0
- package/application/impl/impl.ts +48 -0
- package/constants/constants.d.ts +10 -0
- package/constants/constants.js +14 -0
- package/constants/constants.js.map +1 -0
- package/constants/constants.ts +12 -0
- package/context/context.d.ts +74 -0
- package/context/context.js +24 -0
- package/context/context.js.map +1 -0
- package/context/context.ts +127 -0
- package/context/db/db.d.ts +73 -0
- package/context/db/db.js +3 -0
- package/context/db/db.js.map +1 -0
- package/context/db/db.ts +77 -0
- package/context/db/impl/IObject.d.ts +251 -0
- package/context/db/impl/IObject.js +4 -0
- package/context/db/impl/IObject.js.map +1 -0
- package/context/db/impl/IObject.ts +244 -0
- package/context/db/impl/db.d.ts +61 -0
- package/context/db/impl/db.js +87 -0
- package/context/db/impl/db.js.map +1 -0
- package/context/db/impl/db.ts +95 -0
- package/context/db/impl/object.d.ts +92 -0
- package/context/db/impl/object.js +523 -0
- package/context/db/impl/object.js.map +1 -0
- package/context/db/impl/object.ts +628 -0
- package/context/db/impl/oql/ioql.d.ts +6 -0
- package/context/db/impl/oql/ioql.js +3 -0
- package/context/db/impl/oql/ioql.js.map +1 -0
- package/context/db/impl/oql/ioql.ts +6 -0
- package/context/db/impl/oql/oql.d.ts +8 -0
- package/context/db/impl/oql/oql.js +20 -0
- package/context/db/impl/oql/oql.js.map +1 -0
- package/context/db/impl/oql/oql.ts +22 -0
- package/context/db/impl/order.d.ts +9 -0
- package/context/db/impl/order.js +14 -0
- package/context/db/impl/order.js.map +1 -0
- package/context/db/impl/order.ts +16 -0
- package/context/db/impl/propertiesStore.d.ts +8 -0
- package/context/db/impl/propertiesStore.js +28 -0
- package/context/db/impl/propertiesStore.js.map +1 -0
- package/context/db/impl/propertiesStore.ts +28 -0
- package/context/db/impl/queryBuilder.d.ts +29 -0
- package/context/db/impl/queryBuilder.js +77 -0
- package/context/db/impl/queryBuilder.js.map +1 -0
- package/context/db/impl/queryBuilder.ts +103 -0
- package/context/db/impl/transaction/index.d.ts +20 -0
- package/context/db/impl/transaction/index.js +276 -0
- package/context/db/impl/transaction/index.js.map +1 -0
- package/context/db/impl/transaction/index.ts +337 -0
- package/context/db/impl/transaction/operation.d.ts +27 -0
- package/context/db/impl/transaction/operation.js +70 -0
- package/context/db/impl/transaction/operation.js.map +1 -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 +3 -0
- package/context/db/impl/transaction.js.map +1 -0
- package/context/db/impl/transaction.ts +76 -0
- package/context/globalConfig/globalConfig.d.ts +7 -0
- package/context/globalConfig/globalConfig.js +15 -0
- package/context/globalConfig/globalConfig.js.map +1 -0
- package/context/globalConfig/globalConfig.ts +11 -0
- package/context/metadata/components/common.d.ts +6 -0
- package/context/metadata/components/common.js +16 -0
- package/context/metadata/components/common.js.map +1 -0
- package/context/metadata/components/common.ts +19 -0
- package/context/metadata/components/components.d.ts +12 -0
- package/context/metadata/components/components.js +18 -0
- package/context/metadata/components/components.js.map +1 -0
- package/context/metadata/components/components.ts +19 -0
- package/context/metadata/components/desktop/list.d.ts +16 -0
- package/context/metadata/components/desktop/list.js +403 -0
- package/context/metadata/components/desktop/list.js.map +1 -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 +52 -0
- package/context/metadata/components/desktop/recordDetail.js.map +1 -0
- package/context/metadata/components/desktop/recordDetail.ts +64 -0
- package/context/metadata/components/mobile/list.d.ts +24 -0
- package/context/metadata/components/mobile/list.js +144 -0
- package/context/metadata/components/mobile/list.js.map +1 -0
- package/context/metadata/components/mobile/list.ts +176 -0
- package/context/metadata/metadata.d.ts +61 -0
- package/context/metadata/metadata.js +102 -0
- package/context/metadata/metadata.js.map +1 -0
- package/context/metadata/metadata.ts +175 -0
- package/context/metadata/objects/fields.d.ts +130 -0
- package/context/metadata/objects/fields.js +333 -0
- package/context/metadata/objects/fields.js.map +1 -0
- package/context/metadata/objects/fields.ts +454 -0
- package/context/metadata/objects/fields.util.d.ts +40 -0
- package/context/metadata/objects/fields.util.js +320 -0
- package/context/metadata/objects/fields.util.js.map +1 -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 +19 -0
- package/context/metadata/objects/objects.js.map +1 -0
- package/context/metadata/objects/objects.ts +27 -0
- package/context/metadata/types/common.d.ts +6 -0
- package/context/metadata/types/common.js +8 -0
- package/context/metadata/types/common.js.map +1 -0
- package/context/metadata/types/common.ts +10 -0
- package/context/metadata/types/components.d.ts +90 -0
- package/context/metadata/types/components.js +3 -0
- package/context/metadata/types/components.js.map +1 -0
- package/context/metadata/types/components.ts +105 -0
- package/context/metadata/types/objects.d.ts +226 -0
- package/context/metadata/types/objects.js +3 -0
- package/context/metadata/types/objects.js.map +1 -0
- package/context/metadata/types/objects.ts +251 -0
- package/context/msg/msg.d.ts +38 -0
- package/context/msg/msg.js +34 -0
- package/context/msg/msg.js.map +1 -0
- package/context/msg/msg.ts +49 -0
- package/context/resources/IResources.d.ts +66 -0
- package/context/resources/IResources.js +3 -0
- package/context/resources/IResources.js.map +1 -0
- package/context/resources/IResources.ts +73 -0
- package/context/resources/impl/resources.d.ts +42 -0
- package/context/resources/impl/resources.js +149 -0
- package/context/resources/impl/resources.js.map +1 -0
- package/context/resources/impl/resources.ts +170 -0
- package/context/tasks/tasks.d.ts +33 -0
- package/context/tasks/tasks.js +140 -0
- package/context/tasks/tasks.js.map +1 -0
- package/context/tasks/tasks.ts +159 -0
- package/data/index.d.ts +27 -0
- package/data/index.js +5 -0
- package/data/index.js.map +1 -0
- package/data/index.ts +30 -0
- package/hooks/api.d.ts +61 -0
- package/hooks/api.js +328 -0
- package/hooks/api.js.map +1 -0
- package/hooks/api.ts +341 -0
- package/hooks/hooks.d.ts +1 -0
- package/hooks/hooks.js +89 -0
- package/hooks/hooks.js.map +1 -0
- package/hooks/hooks.ts +100 -0
- package/kunlun/kunlun.d.ts +55 -0
- package/kunlun/kunlun.js +57 -0
- package/kunlun/kunlun.js.map +1 -0
- package/kunlun/kunlun.ts +69 -0
- package/kunlun/operator/IOperator.d.ts +158 -0
- package/kunlun/operator/IOperator.js +3 -0
- package/kunlun/operator/IOperator.js.map +1 -0
- package/kunlun/operator/IOperator.ts +163 -0
- package/kunlun/operator/impl/expression.d.ts +47 -0
- package/kunlun/operator/impl/expression.js +55 -0
- package/kunlun/operator/impl/expression.js.map +1 -0
- package/kunlun/operator/impl/expression.ts +71 -0
- package/kunlun/operator/impl/logic.d.ts +50 -0
- package/kunlun/operator/impl/logic.js +508 -0
- package/kunlun/operator/impl/logic.js.map +1 -0
- package/kunlun/operator/impl/logic.ts +595 -0
- package/kunlun/operator/impl/logicV2.d.ts +58 -0
- package/kunlun/operator/impl/logicV2.js +201 -0
- package/kunlun/operator/impl/logicV2.js.map +1 -0
- package/kunlun/operator/impl/logicV2.ts +254 -0
- package/kunlun/operator/impl/operator.d.ts +179 -0
- package/kunlun/operator/impl/operator.js +221 -0
- package/kunlun/operator/impl/operator.js.map +1 -0
- package/kunlun/operator/impl/operator.ts +255 -0
- package/kunlun/operator/impl/operatorV2.d.ts +180 -0
- package/kunlun/operator/impl/operatorV2.js +217 -0
- package/kunlun/operator/impl/operatorV2.js.map +1 -0
- package/kunlun/operator/impl/operatorV2.ts +249 -0
- package/lib/core.d.ts +4 -0
- package/lib/core.js +18 -0
- package/lib/core.js.map +1 -0
- package/lib/core.ts +4 -0
- package/package.json +50 -0
- package/request/common.d.ts +13 -0
- package/request/common.js +88 -0
- package/request/common.js.map +1 -0
- package/request/common.ts +91 -0
- package/request/constants.d.ts +10 -0
- package/request/constants.js +26 -0
- package/request/constants.js.map +1 -0
- package/request/constants.ts +25 -0
- package/request/faasinfra.d.ts +8 -0
- package/request/faasinfra.js +359 -0
- package/request/faasinfra.js.map +1 -0
- package/request/faasinfra.ts +393 -0
- package/request/innerapi.d.ts +67 -0
- package/request/innerapi.js +1411 -0
- package/request/innerapi.js.map +1 -0
- package/request/innerapi.ts +1645 -0
- package/request/interface.d.ts +95 -0
- package/request/interface.js +40 -0
- package/request/interface.js.map +1 -0
- package/request/interface.ts +166 -0
- package/request/openapi.d.ts +69 -0
- package/request/openapi.js +1013 -0
- package/request/openapi.js.map +1 -0
- package/request/openapi.ts +1220 -0
- package/types/types.d.ts +79 -0
- package/types/types.js +3 -0
- package/types/types.js.map +1 -0
- package/types/types.ts +105 -0
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
import {Expression, ConstantExpressionField, MetadataExpressionField, UserDataType, PathType} from './expression'
|
|
2
|
+
import {operates} from './operator'
|
|
3
|
+
import {utils, exceptions} from '@byted-apaas/server-common-node'
|
|
4
|
+
import * as Request from '../../../request/interface'
|
|
5
|
+
import * as common from "@byted-apaas/server-common-node";
|
|
6
|
+
import fieldType = common.fieldType
|
|
7
|
+
|
|
8
|
+
const dayjs = require("dayjs");
|
|
9
|
+
|
|
10
|
+
// 条件操作
|
|
11
|
+
export class Condition {
|
|
12
|
+
left: string
|
|
13
|
+
right: Condition | UserDataType
|
|
14
|
+
op: string
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param objectApiName 对象的ApiName
|
|
19
|
+
* @param fieldApiName 字段的ApiName,指左值,即key
|
|
20
|
+
* @param index 条件的排序
|
|
21
|
+
* @returns {Expression}
|
|
22
|
+
*/
|
|
23
|
+
toExpression(objectApiName: string, fieldApiName: string, index: number): Expression {
|
|
24
|
+
this.left = fieldApiName;
|
|
25
|
+
let left: MetadataExpressionField;
|
|
26
|
+
let right: ConstantExpressionField;
|
|
27
|
+
let op: string;
|
|
28
|
+
|
|
29
|
+
if (this.right instanceof Condition) {
|
|
30
|
+
left = new MetadataExpressionField(objectApiName, this.right.left);
|
|
31
|
+
right = new ConstantExpressionField(this.right.right)
|
|
32
|
+
left.settings.fieldPath.unshift(new MetadataExpressionField(objectApiName, fieldApiName).settings.fieldPath[0]);
|
|
33
|
+
op = this.right.op;
|
|
34
|
+
} else {
|
|
35
|
+
left = new MetadataExpressionField(objectApiName, fieldApiName)
|
|
36
|
+
right = new ConstantExpressionField(this.right);
|
|
37
|
+
op = this.op;
|
|
38
|
+
}
|
|
39
|
+
return new Expression(left, op, right, index);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
constructor(left: string, right: Condition | UserDataType, op: string = operates.EQ) {
|
|
43
|
+
this.left = left;
|
|
44
|
+
this.right = right;
|
|
45
|
+
if (op) {
|
|
46
|
+
this.op = op;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// param type should be spercific
|
|
52
|
+
function isKunlunTypeOrSerializedObject(obj: { [index: string]: any }) {
|
|
53
|
+
// instanceof 改动8
|
|
54
|
+
// return !!(obj instanceof fieldType.KunlunFieldType || (obj && obj.toJSON && obj.toJSON instanceof Function));
|
|
55
|
+
return !!(fieldType.isKFieldType(obj) || (obj && obj.toJSON && obj.toJSON instanceof Function));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type Criterion = {
|
|
59
|
+
conditions: Expression[]
|
|
60
|
+
logic: string
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 构造 criterion
|
|
65
|
+
*
|
|
66
|
+
* @param logic
|
|
67
|
+
* @param objectApiName
|
|
68
|
+
* @param maxId 添加 _id>maxId 条件,为 -1 表示不使用该参数
|
|
69
|
+
*/
|
|
70
|
+
export function buildCriterion(logic: Logic, objectApiName: string, maxId: number = -1): Criterion | string {
|
|
71
|
+
let index = 0;
|
|
72
|
+
let logics: string[] = [];
|
|
73
|
+
let expressions: Expression[] = [];
|
|
74
|
+
|
|
75
|
+
// check type of logic
|
|
76
|
+
function f(logic: Logic | { [index: string]: any }, value: string = "and") {
|
|
77
|
+
// 1.如果是逻辑表达式
|
|
78
|
+
if (logic instanceof Logic) {
|
|
79
|
+
logics.push("(");
|
|
80
|
+
for (let i = 0; i < logic.logics.length; i++) {
|
|
81
|
+
let p = logic.logics[i];
|
|
82
|
+
f(p, logic.value);
|
|
83
|
+
if (i < logic.logics.length - 1) {
|
|
84
|
+
logics.push(` ${logic.value} `);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (logic.expressions) {
|
|
89
|
+
f(logic.expressions, logic.value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
logics.push(")");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 2.否则是算法表达式
|
|
97
|
+
let exps = logic;
|
|
98
|
+
let logs = [];
|
|
99
|
+
for (let left of Object.keys(exps)) {
|
|
100
|
+
let right: { [index: string]: any } = logic[left];
|
|
101
|
+
let copy: { [index: string]: any } = right;
|
|
102
|
+
if (utils.isObject(right) && !(right instanceof Condition) && !isKunlunTypeOrSerializedObject(right)) {
|
|
103
|
+
for (let leftInner of Object.keys(right)) {
|
|
104
|
+
index++;
|
|
105
|
+
logs.push(index);
|
|
106
|
+
copy = {};
|
|
107
|
+
copy[leftInner] = right[leftInner];
|
|
108
|
+
expressions.push(buildExpression(objectApiName, left, copy, index));
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
index++;
|
|
112
|
+
logs.push(index);
|
|
113
|
+
expressions.push(buildExpression(objectApiName, left, right, index));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
logics.push(logs.join(` ${value} `));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
f(logic);
|
|
121
|
+
|
|
122
|
+
// 如果未设置filter,默认添加: _isDeleted = false
|
|
123
|
+
if (expressions.length < 1) {
|
|
124
|
+
if(maxId >= 0) {
|
|
125
|
+
return `{"conditions":[{"index":1,"left":{"type":"metadataVariable","settings":{"fieldPath":[{"objectApiName":"${objectApiName}","fieldApiName":"_isDeleted"}]}},"operator":"equals","right":{"type":"constant","settings":{"data":false}}},{"index":2,"left":{"type":"metadataVariable","settings":{"fieldPath":[{"objectApiName":"${objectApiName}","fieldApiName":"_id"}]}},"operator":"greaterThan","right":{"type":"constant","settings":{"data":${maxId}}}}],"logic":"1 and 2"}`;
|
|
126
|
+
} else {
|
|
127
|
+
return `{"conditions":[{"index":1,"left":{"type":"metadataVariable","settings":{"fieldPath":[{"objectApiName":"${objectApiName}","fieldApiName":"_isDeleted"}]}},"operator":"equals","right":{"type":"constant","settings":{"data":false}}}],"logic":"1"}`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let isContainDeleted = false;
|
|
132
|
+
for (let i = 0; i < expressions.length; i++) {
|
|
133
|
+
let expression = expressions[i];
|
|
134
|
+
try {
|
|
135
|
+
if (expression.left.type === "metadataVariable" && expression.left.settings.fieldPath[0].fieldApiName === "_isDeleted") {
|
|
136
|
+
isContainDeleted = true;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
console.error(e);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!isContainDeleted) {
|
|
145
|
+
expressions.push(buildExpression(objectApiName, "_isDeleted", false, expressions.length + 1));
|
|
146
|
+
logics.splice(0, 0, "(");
|
|
147
|
+
logics.push(" and ", `${expressions.length}`, ")");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (maxId >= 0) {
|
|
151
|
+
expressions.push(buildExpression(objectApiName, "_id", new Condition("_id", maxId, operates.GT), expressions.length + 1));
|
|
152
|
+
logics.splice(0, 0, "(");
|
|
153
|
+
logics.push(" and ", `${expressions.length}`, ")");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {conditions: expressions, logic: logics.join("")};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function buildExpression(objectApiName: string, left: string, right: Condition | UserDataType, index = 1): Expression {
|
|
160
|
+
if (!(right instanceof Condition)) {
|
|
161
|
+
right = new Condition(left, right);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (right instanceof Condition) {
|
|
165
|
+
if (utils.isObject(right.right) && !(right.right instanceof Condition) && !isKunlunTypeOrSerializedObject(right.right as object)) {
|
|
166
|
+
let key: string = Object.keys(right.right)[0]
|
|
167
|
+
let rr: {
|
|
168
|
+
[index: string]: any
|
|
169
|
+
} = right.right as object
|
|
170
|
+
if (key === 'id') {
|
|
171
|
+
if (rr[key] instanceof Condition) {
|
|
172
|
+
right.op = rr[key].op;
|
|
173
|
+
right.right = {id: rr[key].right}
|
|
174
|
+
}
|
|
175
|
+
} else if (!(rr[key] instanceof Condition)) {
|
|
176
|
+
right.right = new Condition(key, rr[key], right.op);
|
|
177
|
+
} else {
|
|
178
|
+
rr[key].left = key;
|
|
179
|
+
right.right = rr[key];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return right.toExpression(objectApiName, left, index);
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 逻辑操作:and 和 or
|
|
188
|
+
export class Logic {
|
|
189
|
+
value: string
|
|
190
|
+
expressions: { [index: string]: any }
|
|
191
|
+
logics: Logic[]
|
|
192
|
+
|
|
193
|
+
constructor(expressions: { [index: string]: any } = null, logicValue: string = "and") {
|
|
194
|
+
// 通常情况
|
|
195
|
+
this.value = logicValue;
|
|
196
|
+
this.expressions = expressions;
|
|
197
|
+
this.logics = [];
|
|
198
|
+
|
|
199
|
+
if (!expressions) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// 下钻右值为逻辑表达式 and|or 的情况
|
|
204
|
+
for (let left of Object.keys(expressions)) {
|
|
205
|
+
if (expressions[left] instanceof Object && !(expressions[left] instanceof Array)) {
|
|
206
|
+
let right: {
|
|
207
|
+
[index: string]: any,
|
|
208
|
+
} = expressions[left] as object;
|
|
209
|
+
for (const key of Object.keys(right)) {
|
|
210
|
+
if (right[key] instanceof Logic) {
|
|
211
|
+
this.handleRightLogic(right, left);
|
|
212
|
+
delete expressions[left];
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// 右值为逻辑表达式 and|or 的情况
|
|
220
|
+
for (let left of Object.keys(expressions)) {
|
|
221
|
+
let right = expressions[left];
|
|
222
|
+
if (right instanceof Logic) {
|
|
223
|
+
this.handleRightLogic(expressions);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 处理:右值包含逻辑表达式and|or的情况
|
|
231
|
+
*
|
|
232
|
+
* @param expressions
|
|
233
|
+
* @param lookupField
|
|
234
|
+
*/
|
|
235
|
+
handleRightLogic(expressions: { [index: string]: any }, lookupField: string = null) {
|
|
236
|
+
this.expressions = null;
|
|
237
|
+
for (let left of Object.keys(expressions)) {
|
|
238
|
+
let right = expressions[left];
|
|
239
|
+
|
|
240
|
+
// 1.如果右值为Logic类型
|
|
241
|
+
if (right instanceof Logic) {
|
|
242
|
+
// 1.1 表达式不为空
|
|
243
|
+
if (right.expressions) {
|
|
244
|
+
let exp: { [index: string]: any } = {};
|
|
245
|
+
if (lookupField && right.expressions instanceof Condition) {
|
|
246
|
+
right.expressions.left = lookupField;
|
|
247
|
+
let obj: { [index: string]: any } = {};
|
|
248
|
+
obj[left] = right.expressions.right;
|
|
249
|
+
right.expressions.right = obj
|
|
250
|
+
exp[lookupField] = right.expressions;
|
|
251
|
+
} else {
|
|
252
|
+
exp[left] = right.expressions;
|
|
253
|
+
}
|
|
254
|
+
this.logics.push(new Logic(exp, "and"));
|
|
255
|
+
} else {
|
|
256
|
+
// 1.2 表达式为空
|
|
257
|
+
let log = new Logic(null, right.value);
|
|
258
|
+
for (let logic of right.logics) {
|
|
259
|
+
let exp: { [index: string]: any } = {};
|
|
260
|
+
if (lookupField && logic.expressions instanceof Condition) {
|
|
261
|
+
logic.expressions.left = lookupField;
|
|
262
|
+
let obj: { [index: string]: any } = {};
|
|
263
|
+
obj[left] = logic.expressions.right;
|
|
264
|
+
logic.expressions.right = obj;
|
|
265
|
+
exp[lookupField] = logic.expressions;
|
|
266
|
+
} else {
|
|
267
|
+
if (logic.expressions instanceof Condition) {
|
|
268
|
+
logic.expressions.left = left;
|
|
269
|
+
}
|
|
270
|
+
exp[left] = logic.expressions;
|
|
271
|
+
}
|
|
272
|
+
log.logics.push(new Logic(exp, logic.value));
|
|
273
|
+
}
|
|
274
|
+
this.logics.push(log);
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
let exp: { [index: string]: any } = {};
|
|
278
|
+
exp[left] = right;
|
|
279
|
+
|
|
280
|
+
let log = new Logic(exp, "and");
|
|
281
|
+
this.logics.push(log);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
addLogic(logic: Logic) {
|
|
287
|
+
if (logic instanceof Logic) {
|
|
288
|
+
this.logics.push(logic);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function buildLogic(param: (Logic | object)[], logicValue = "and"): Logic {
|
|
294
|
+
if (param.length === 1) {
|
|
295
|
+
return new Logic(param[0], logicValue)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
let logic = new Logic(null, logicValue);
|
|
299
|
+
param.forEach(p => {
|
|
300
|
+
if (!p) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Check:会走到这里吗?
|
|
305
|
+
if (p instanceof Logic) {
|
|
306
|
+
logic.logics.push(p);
|
|
307
|
+
} else if (p instanceof Object && !(p instanceof Array)) {
|
|
308
|
+
logic.logics.push(new Logic(p, "and"));
|
|
309
|
+
} else {
|
|
310
|
+
throw new exceptions.InvalidParamError(`param (${p}) is invalid`);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return logic;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// where参数的树状结构
|
|
317
|
+
class Filter {
|
|
318
|
+
filters: Filter[]
|
|
319
|
+
logic: string
|
|
320
|
+
expression: Expression
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @param logic: filters之间的逻辑关系
|
|
324
|
+
*/
|
|
325
|
+
constructor(logic: string) {
|
|
326
|
+
if (!logic) {
|
|
327
|
+
this.logic = "and";
|
|
328
|
+
} else {
|
|
329
|
+
this.logic = logic;
|
|
330
|
+
}
|
|
331
|
+
this.expression = null;
|
|
332
|
+
this.filters = [];
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 现在仅考虑一层结构,不考虑嵌套
|
|
336
|
+
toCriterion() {
|
|
337
|
+
let conditions: Expression[] = [];
|
|
338
|
+
let logics: number[] = [];
|
|
339
|
+
|
|
340
|
+
this.filters.forEach((filter, i) => {
|
|
341
|
+
if (!filter.expression) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
conditions.push({
|
|
346
|
+
index: i + 1,
|
|
347
|
+
left: filter.expression.left,
|
|
348
|
+
right: filter.expression.right,
|
|
349
|
+
operator: filter.expression.operator,
|
|
350
|
+
});
|
|
351
|
+
logics.push(i + 1);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
let criterion = {conditions: conditions, logic: logics.join(" and ")};
|
|
355
|
+
return JSON.stringify(criterion);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export async function handleCriterion(criterion: string | Criterion): Promise<string | Criterion> {
|
|
360
|
+
if (typeof criterion === "string") {
|
|
361
|
+
return criterion
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (!criterion || !criterion.conditions || !(criterion.conditions instanceof Array)) {
|
|
365
|
+
return criterion;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
let fieldRes: FieldResType = await handleLookupCondition(criterion.conditions);
|
|
369
|
+
|
|
370
|
+
for (let condition of criterion.conditions) {
|
|
371
|
+
if (fieldRes && fieldRes.lookupMap) {
|
|
372
|
+
let val: LookupField = fieldRes.lookupMap.get(condition.left.settings.fieldPath[0].fieldApiName);
|
|
373
|
+
if (condition.left.settings.fieldPath[1] && val && val.objectApiName) {
|
|
374
|
+
condition.left.settings.fieldPath[1].objectApiName = val.objectApiName;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
await handleCondition(condition, fieldRes);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return JSON.stringify(criterion);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
type FieldResType = {
|
|
384
|
+
isFirstLayer?: boolean
|
|
385
|
+
lookupMap?: Map<string, LookupField>,
|
|
386
|
+
dateSet?: Set<string>
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function handleLookupCondition(conditions: Expression[]): Promise<FieldResType> {
|
|
390
|
+
if (!(conditions && conditions[0] && conditions[0].left && conditions[0].left.settings && conditions[0].left.settings.fieldPath)) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let queryMap = new Map(), fieldName;
|
|
395
|
+
let opList = [operates.LT, operates.LTE, operates.GT, operates.GTE, operates.HAS_ANY_OF, operates.HAS_NONE_OF];
|
|
396
|
+
|
|
397
|
+
for (const condition of conditions) {
|
|
398
|
+
if (condition.left.settings.fieldPath.length > 1 || opList.includes(condition.operator)) {
|
|
399
|
+
fieldName = condition.left.settings.fieldPath[0].fieldApiName;
|
|
400
|
+
queryMap.set(fieldName, {});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (queryMap.size === 0) {
|
|
405
|
+
return {}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let lookupMap = new Map<string, LookupField>(), dateSet = new Set<string>()
|
|
409
|
+
|
|
410
|
+
let firstObjApiName = conditions[0].left.settings.fieldPath[0].objectApiName;
|
|
411
|
+
|
|
412
|
+
let fields = [];
|
|
413
|
+
|
|
414
|
+
if (queryMap.size === 1) {
|
|
415
|
+
fields.push(await Request.GetInstance().getField(firstObjApiName, fieldName));
|
|
416
|
+
} else {
|
|
417
|
+
fields = await Request.GetInstance().getFields(firstObjApiName);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
for (const field of fields) {
|
|
421
|
+
parseFieldInfo(field, lookupMap, dateSet)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
lookupMap: lookupMap,
|
|
426
|
+
dateSet: dateSet,
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
type Field = {
|
|
431
|
+
type: {
|
|
432
|
+
name: string;
|
|
433
|
+
settings: {
|
|
434
|
+
referenced_object_api_name: string;
|
|
435
|
+
is_hierarchy: boolean;
|
|
436
|
+
target_is_hierarchy: boolean;
|
|
437
|
+
return_type: string;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
api_name: string;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
type LookupField = {
|
|
444
|
+
objectApiName: string,
|
|
445
|
+
isHierarchy: boolean,
|
|
446
|
+
targetIsHierarchy: boolean
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function parseFieldInfo(field: Field, lookupMap: Map<string, LookupField>, dateSet: Set<string>) {
|
|
450
|
+
|
|
451
|
+
if (!(field && field.type && field.type.name && field.type.settings)) {
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
switch (field.type.name) {
|
|
456
|
+
case 'lookup':
|
|
457
|
+
lookupMap.set(field.api_name, {
|
|
458
|
+
objectApiName: field.type.settings.referenced_object_api_name,
|
|
459
|
+
isHierarchy: field.type.settings.is_hierarchy,
|
|
460
|
+
targetIsHierarchy: field.type.settings.target_is_hierarchy,
|
|
461
|
+
});
|
|
462
|
+
break;
|
|
463
|
+
case 'date':
|
|
464
|
+
dateSet.add(field.api_name);
|
|
465
|
+
break;
|
|
466
|
+
case 'formula':
|
|
467
|
+
if (field.type.settings.return_type === "date") {
|
|
468
|
+
dateSet.add(field.api_name);
|
|
469
|
+
}
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async function handleCondition(condition: Expression, fieldRes: FieldResType) {
|
|
475
|
+
if (!condition || !condition.left || condition.left.type !== "metadataVariable") {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (!condition.left.settings || !condition.left.settings.fieldPath || !(condition.left.settings.fieldPath instanceof Array)) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
let fieldPathList: PathType[] = condition.left.settings.fieldPath;
|
|
484
|
+
for (let i = 0; i < fieldPathList.length; i++) {
|
|
485
|
+
fieldRes.isFirstLayer = (i === 0);
|
|
486
|
+
if (fieldPathList.length === (i + 1)) { // 最后的查询条件 path 做处理
|
|
487
|
+
switch (condition.operator) {
|
|
488
|
+
case operates.LT:
|
|
489
|
+
// 日期类型的lte,需要转换成isOnOrBefore
|
|
490
|
+
await handleDateAndDatetimeOperator(fieldRes, condition, fieldPathList[i], operates.isOnOrBefore, -1);
|
|
491
|
+
break;
|
|
492
|
+
case operates.LTE:
|
|
493
|
+
// 日期类型的lte,需要转换成isOnOrBefore
|
|
494
|
+
await handleDateAndDatetimeOperator(fieldRes, condition, fieldPathList[i], operates.isOnOrBefore);
|
|
495
|
+
break;
|
|
496
|
+
case operates.GT:
|
|
497
|
+
// 日期类型的gte,需要转换成isOnOrAfter
|
|
498
|
+
await handleDateAndDatetimeOperator(fieldRes, condition, fieldPathList[i], operates.isOnOrAfter, 1);
|
|
499
|
+
break;
|
|
500
|
+
case operates.GTE:
|
|
501
|
+
// 日期类型的gte,需要转换成isOnOrAfter
|
|
502
|
+
await handleDateAndDatetimeOperator(fieldRes, condition, fieldPathList[i], operates.isOnOrAfter);
|
|
503
|
+
break;
|
|
504
|
+
case operates.HAS_ANY_OF:
|
|
505
|
+
case operates.HAS_NONE_OF:
|
|
506
|
+
// hierarchy lookup,需要为extendLogicTags添加all
|
|
507
|
+
// lookup 下钻的话,只在最后一层加 all
|
|
508
|
+
await handleHierarchyFieldPath(fieldRes, fieldPathList[i]);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// 日期类型的lte,需要转换成isOnOrBefore
|
|
517
|
+
// 日期类型的gte,需要转换成isOnOrAfter
|
|
518
|
+
async function handleDateAndDatetimeOperator(fieldRes: FieldResType, condition: Expression, path: PathType, operator: string, addDay: number = 0) {
|
|
519
|
+
if (!condition || !path || !path.objectApiName || !path.fieldApiName) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
let isDateType = false;
|
|
524
|
+
|
|
525
|
+
if (fieldRes && fieldRes.isFirstLayer) {
|
|
526
|
+
if (fieldRes.dateSet && fieldRes.dateSet.has(path.fieldApiName)) {
|
|
527
|
+
isDateType = true;
|
|
528
|
+
}
|
|
529
|
+
} else {
|
|
530
|
+
let field = await Request.GetInstance().getField(path.objectApiName, path.fieldApiName);
|
|
531
|
+
isDateType = isDate(field)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (isDateType) {
|
|
535
|
+
condition.operator = operator;
|
|
536
|
+
if (condition.right && condition.right.settings && condition.right.settings.data) {
|
|
537
|
+
condition.right.settings.data = dateAdd(condition.right.settings.data as Date, addDay);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// hierarchy lookup,需要为extendLogicTags添加all
|
|
543
|
+
async function handleHierarchyFieldPath(fieldRes: FieldResType, path: PathType) {
|
|
544
|
+
if (!path || !path.objectApiName || !path.fieldApiName) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
let isHierarchyType = false;
|
|
549
|
+
|
|
550
|
+
if (fieldRes && fieldRes.isFirstLayer && fieldRes.lookupMap) {
|
|
551
|
+
let val = fieldRes.lookupMap.get(path.fieldApiName);
|
|
552
|
+
if (val && val.targetIsHierarchy) {
|
|
553
|
+
isHierarchyType = true;
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
let field = await Request.GetInstance().getField(path.objectApiName, path.fieldApiName);
|
|
557
|
+
isHierarchyType = targetIsHierarchy(field);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (!isHierarchyType) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (!path.extendLogicTags) {
|
|
565
|
+
path.extendLogicTags = [];
|
|
566
|
+
}
|
|
567
|
+
path.extendLogicTags.push("all");
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function isHierarchy(field: Field) {
|
|
571
|
+
return field && field.type && field.type.name === "lookup" && field.type.settings && field.type.settings.is_hierarchy;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function targetIsHierarchy(field: Field) {
|
|
575
|
+
return field && field.type && field.type.name === "lookup" && field.type.settings && field.type.settings.target_is_hierarchy;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function isDate(field: Field) {
|
|
579
|
+
return field && field.type && ((field.type.name === "date") || (field.type.name === "formula" && field.type.settings && field.type.settings.return_type === "date"));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function dateAdd(date: Date | fieldType.Date | string, num: number) {
|
|
583
|
+
try {
|
|
584
|
+
if (date instanceof Date) {
|
|
585
|
+
return dayjs(date).add(num, "day").format("YYYY-MM-DD");
|
|
586
|
+
// } else if (date instanceof fieldType.Date) { // instanceof 改动9
|
|
587
|
+
} else if (fieldType.isKFieldTypeDate(date)) {
|
|
588
|
+
return dayjs((date as any).toJSON()).add(num, "day").format("YYYY-MM-DD");
|
|
589
|
+
} else if (typeof (date) === "string") {
|
|
590
|
+
return dayjs(date).add(num, "day").format("YYYY-MM-DD");
|
|
591
|
+
}
|
|
592
|
+
} catch (e) {
|
|
593
|
+
return date;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { OrderV2 } from "../../../request/interface";
|
|
2
|
+
import { UserDataType } from "./expression";
|
|
3
|
+
export declare type FieldPath = {
|
|
4
|
+
objectApiName: string;
|
|
5
|
+
fieldApiName: string;
|
|
6
|
+
extendLogicTags: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare type SettingType = {
|
|
9
|
+
data?: any;
|
|
10
|
+
fieldPath?: FieldPath[];
|
|
11
|
+
};
|
|
12
|
+
export declare type Expression = {
|
|
13
|
+
type: string;
|
|
14
|
+
settings: SettingType;
|
|
15
|
+
};
|
|
16
|
+
export declare function NewMetadataExpressionField(objectApiName: string, fieldApiName: string): Expression;
|
|
17
|
+
export declare function NewConstantExpressionField(data: UserDataType): Expression;
|
|
18
|
+
export declare type ExpressionV2 = {
|
|
19
|
+
leftValue: string;
|
|
20
|
+
operator: string;
|
|
21
|
+
rightValue: any;
|
|
22
|
+
};
|
|
23
|
+
export declare class ArithmeticExpression {
|
|
24
|
+
left: Expression;
|
|
25
|
+
operator: string;
|
|
26
|
+
right: Expression;
|
|
27
|
+
expr: ExpressionV2;
|
|
28
|
+
constructor(leftValue: string, op: string, rightValue: any);
|
|
29
|
+
}
|
|
30
|
+
export declare class LogicalExpression {
|
|
31
|
+
type: string;
|
|
32
|
+
arithmeticExpressions: ArithmeticExpression[];
|
|
33
|
+
logicalExpressions: LogicalExpression[];
|
|
34
|
+
constructor(logicType: string, expressions: ArithmeticExpression[], logics: LogicalExpression[]);
|
|
35
|
+
}
|
|
36
|
+
export declare class QueryV2 {
|
|
37
|
+
objectApiName: string;
|
|
38
|
+
_limit: number;
|
|
39
|
+
_offset: number;
|
|
40
|
+
fields: string[];
|
|
41
|
+
_order: OrderV2[];
|
|
42
|
+
filter: LogicalExpression;
|
|
43
|
+
buildCriterion(filter: LogicalExpression): any[];
|
|
44
|
+
where(condition: LogicalExpression | Record<string, ArithmeticExpression>): QueryV2;
|
|
45
|
+
offset(offset: number): QueryV2;
|
|
46
|
+
limit(limit: number): QueryV2;
|
|
47
|
+
orderBy(fieldApiNames: string[]): QueryV2;
|
|
48
|
+
orderByDesc(fieldApiNames: string[]): QueryV2;
|
|
49
|
+
select(fieldApiNames: string[]): QueryV2;
|
|
50
|
+
constructor(objectApiName: string);
|
|
51
|
+
}
|
|
52
|
+
export declare type logicalRet = {
|
|
53
|
+
logicalExps: LogicalExpression[];
|
|
54
|
+
arithmeticExps: ArithmeticExpression[];
|
|
55
|
+
};
|
|
56
|
+
export declare function logical(exps: (LogicalExpression | Record<string, ArithmeticExpression>)[]): logicalRet;
|
|
57
|
+
export declare type CriterionV2 = (Record<string, CriterionV2> | ExpressionV2)[];
|
|
58
|
+
export declare function buildCriterionV2(filter: LogicalExpression): CriterionV2;
|