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