@byted-apaas/server-sdk-node 1.1.23-beta.9 → 1.1.23

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 (131) hide show
  1. package/package.json +2 -2
  2. package/application/application.d.ts +0 -33
  3. package/application/application.js +0 -2
  4. package/application/function/function.d.ts +0 -14
  5. package/application/function/function.js +0 -20
  6. package/application/impl/common.d.ts +0 -2
  7. package/application/impl/common.js +0 -52
  8. package/application/impl/impl.d.ts +0 -19
  9. package/application/impl/impl.js +0 -45
  10. package/common/structs.d.ts +0 -15
  11. package/common/structs.js +0 -21
  12. package/constants/constants.d.ts +0 -13
  13. package/constants/constants.js +0 -18
  14. package/context/context.d.ts +0 -44
  15. package/context/context.js +0 -25
  16. package/context/db/db.d.ts +0 -110
  17. package/context/db/db.js +0 -2
  18. package/context/db/impl/IObject.d.ts +0 -303
  19. package/context/db/impl/IObject.js +0 -5
  20. package/context/db/impl/IObjectV3.d.ts +0 -239
  21. package/context/db/impl/IObjectV3.js +0 -5
  22. package/context/db/impl/db.d.ts +0 -62
  23. package/context/db/impl/db.js +0 -84
  24. package/context/db/impl/dbV3.d.ts +0 -35
  25. package/context/db/impl/dbV3.js +0 -50
  26. package/context/db/impl/object.d.ts +0 -123
  27. package/context/db/impl/object.js +0 -1008
  28. package/context/db/impl/oql/ioql.d.ts +0 -14
  29. package/context/db/impl/oql/ioql.js +0 -4
  30. package/context/db/impl/oql/oql.d.ts +0 -14
  31. package/context/db/impl/oql/oql.js +0 -39
  32. package/context/db/impl/order.d.ts +0 -9
  33. package/context/db/impl/order.js +0 -15
  34. package/context/db/impl/propertiesStore.d.ts +0 -8
  35. package/context/db/impl/propertiesStore.js +0 -29
  36. package/context/db/impl/queryBuilder.d.ts +0 -33
  37. package/context/db/impl/queryBuilder.js +0 -72
  38. package/context/db/impl/transaction/index.d.ts +0 -25
  39. package/context/db/impl/transaction/index.js +0 -300
  40. package/context/db/impl/transaction/operation.d.ts +0 -27
  41. package/context/db/impl/transaction/operation.js +0 -69
  42. package/context/db/impl/transaction.d.ts +0 -70
  43. package/context/db/impl/transaction.js +0 -4
  44. package/context/globalConfig/globalConfig.d.ts +0 -7
  45. package/context/globalConfig/globalConfig.js +0 -16
  46. package/context/integration/IIntegration.d.ts +0 -30
  47. package/context/integration/IIntegration.js +0 -4
  48. package/context/integration/impl/integration.d.ts +0 -16
  49. package/context/integration/impl/integration.js +0 -62
  50. package/context/metadata/components/common.d.ts +0 -6
  51. package/context/metadata/components/common.js +0 -17
  52. package/context/metadata/components/components.d.ts +0 -12
  53. package/context/metadata/components/components.js +0 -19
  54. package/context/metadata/components/desktop/list.d.ts +0 -16
  55. package/context/metadata/components/desktop/list.js +0 -402
  56. package/context/metadata/components/desktop/recordDetail.d.ts +0 -11
  57. package/context/metadata/components/desktop/recordDetail.js +0 -53
  58. package/context/metadata/components/mobile/list.d.ts +0 -24
  59. package/context/metadata/components/mobile/list.js +0 -145
  60. package/context/metadata/metadata.d.ts +0 -63
  61. package/context/metadata/metadata.js +0 -125
  62. package/context/metadata/objects/fields.d.ts +0 -158
  63. package/context/metadata/objects/fields.js +0 -369
  64. package/context/metadata/objects/fields.util.d.ts +0 -52
  65. package/context/metadata/objects/fields.util.js +0 -420
  66. package/context/metadata/objects/fieldsV3.d.ts +0 -159
  67. package/context/metadata/objects/fieldsV3.js +0 -369
  68. package/context/metadata/objects/objects.d.ts +0 -11
  69. package/context/metadata/objects/objects.js +0 -20
  70. package/context/metadata/types/common.d.ts +0 -11
  71. package/context/metadata/types/common.js +0 -33
  72. package/context/metadata/types/components.d.ts +0 -90
  73. package/context/metadata/types/components.js +0 -4
  74. package/context/metadata/types/objects.d.ts +0 -246
  75. package/context/metadata/types/objects.js +0 -4
  76. package/context/metadata/types/objectsV3.d.ts +0 -128
  77. package/context/metadata/types/objectsV3.js +0 -4
  78. package/context/msg/msg.d.ts +0 -38
  79. package/context/msg/msg.js +0 -35
  80. package/context/resources/IResources.d.ts +0 -68
  81. package/context/resources/IResources.js +0 -2
  82. package/context/resources/impl/resources.d.ts +0 -42
  83. package/context/resources/impl/resources.js +0 -161
  84. package/context/tasks/tasks.d.ts +0 -33
  85. package/context/tasks/tasks.js +0 -139
  86. package/data/index.d.ts +0 -27
  87. package/data/index.js +0 -4
  88. package/global/application/flow/flow.d.ts +0 -99
  89. package/global/application/flow/flow.js +0 -8
  90. package/global/application/flow/impl/flow.d.ts +0 -20
  91. package/global/application/flow/impl/flow.js +0 -56
  92. package/global/application/globalVar/globalVar.d.ts +0 -7
  93. package/global/application/globalVar/globalVar.js +0 -2
  94. package/global/global.d.ts +0 -70
  95. package/global/global.js +0 -3
  96. package/hooks/api.d.ts +0 -65
  97. package/hooks/api.js +0 -347
  98. package/hooks/hooks.d.ts +0 -1
  99. package/hooks/hooks.js +0 -107
  100. package/kunlun/kunlun.d.ts +0 -55
  101. package/kunlun/kunlun.js +0 -58
  102. package/kunlun/operator/IOperator.d.ts +0 -158
  103. package/kunlun/operator/IOperator.js +0 -4
  104. package/kunlun/operator/impl/expression.d.ts +0 -75
  105. package/kunlun/operator/impl/expression.js +0 -96
  106. package/kunlun/operator/impl/logic.d.ts +0 -68
  107. package/kunlun/operator/impl/logic.js +0 -573
  108. package/kunlun/operator/impl/logicV2.d.ts +0 -59
  109. package/kunlun/operator/impl/logicV2.js +0 -197
  110. package/kunlun/operator/impl/operator.d.ts +0 -179
  111. package/kunlun/operator/impl/operator.js +0 -222
  112. package/kunlun/operator/impl/operatorV2.d.ts +0 -180
  113. package/kunlun/operator/impl/operatorV2.js +0 -216
  114. package/lib/core.d.ts +0 -4
  115. package/lib/core.js +0 -19
  116. package/request/common.d.ts +0 -13
  117. package/request/common.js +0 -88
  118. package/request/constants.d.ts +0 -12
  119. package/request/constants.js +0 -29
  120. package/request/faasinfra.d.ts +0 -8
  121. package/request/faasinfra.js +0 -146
  122. package/request/interface.d.ts +0 -121
  123. package/request/interface.js +0 -30
  124. package/request/openapi.d.ts +0 -84
  125. package/request/openapi.js +0 -1529
  126. package/request/structs.d.ts +0 -99
  127. package/request/structs.js +0 -15
  128. package/types/types.d.ts +0 -79
  129. package/types/types.js +0 -4
  130. package/version/version.d.ts +0 -2
  131. package/version/version.js +0 -8
@@ -1,1008 +0,0 @@
1
- "use strict";
2
- // nolint: cognitive_complexity
3
- // Copyright 2022 ByteDance Ltd. and/or its affiliates
4
- // SPDX-License-Identifier: MIT
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._KApplicationObject = exports._KObject = void 0;
7
- const queryBuilder_1 = require("./queryBuilder");
8
- const order_1 = require("./order");
9
- const Request = require("../../../request/interface");
10
- const logic_1 = require("../../../kunlun/operator/impl/logic");
11
- const server_common_node_1 = require("@byted-apaas/server-common-node");
12
- const propertiesStore_1 = require("./propertiesStore");
13
- const common_1 = require("../../../application/impl/common");
14
- const logicV2_1 = require("../../../kunlun/operator/impl/logicV2");
15
- const operator_1 = require("../../../kunlun/operator/impl/operator");
16
- const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
17
- const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
18
- const structs_1 = require("../../../common/structs");
19
- const queryPropertiesStore = new propertiesStore_1.default();
20
- // _KObject will be Mixin with [_KObjectSync, _KObjectAsync, _KObjectQuery]
21
- class _KObject {
22
- constructor(objectApiName, appCtx) {
23
- this.apiName = '';
24
- if (!objectApiName) {
25
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
26
- }
27
- this.apiName = objectApiName;
28
- this.appCtx = appCtx;
29
- }
30
- }
31
- exports._KObject = _KObject;
32
- class _KApplicationObject {
33
- constructor(objectApiName, appCtx) {
34
- this.apiName = '';
35
- this.appCtx = null;
36
- this.apiName = objectApiName;
37
- this.appCtx = appCtx;
38
- }
39
- }
40
- exports._KApplicationObject = _KApplicationObject;
41
- class _KObjectSync {
42
- constructor() {
43
- this.apiName = '';
44
- this.appCtx = null;
45
- }
46
- // create, update, delete
47
- async create(recordMap) {
48
- if (!recordMap) {
49
- throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
50
- }
51
- if (server_common_node_1.checkUtils.isNotObject(recordMap)) {
52
- throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
53
- }
54
- recordMap = permissionUtils.delUnauthField(recordMap).newRecord;
55
- if (this.appCtx && this.appCtx.mode == 'openSDK') {
56
- // request from OpenSDK
57
- return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
58
- return await Request.GetInstance().openSDKCreateRecordBySync(this.apiName, recordMap);
59
- });
60
- }
61
- else if (this.appCtx && this.appCtx.dataVersion === 'v3') {
62
- return await Request.GetInstance().createRecordBySyncV3(this.apiName, recordMap, this.authType);
63
- }
64
- return await Request.GetInstance().createRecordBySync(this.apiName, recordMap, this.authType);
65
- }
66
- ;
67
- async delete(recordOrRecordID) {
68
- if (this.appCtx && this.appCtx.dataVersion === 'v3') {
69
- return this.deleteV3(recordOrRecordID);
70
- }
71
- // v1 v2 接口只支持 number 类型
72
- if (typeof recordOrRecordID === 'string') {
73
- throw new server_common_node_1.exceptions.InvalidParamError('_id must be number');
74
- }
75
- let recordID;
76
- // 用户直接传入 record id 来进行删除的情况
77
- if (typeof recordOrRecordID === 'number') {
78
- recordID = recordOrRecordID;
79
- }
80
- else {
81
- // 用户传入 object 结构来进行删除的情况
82
- let record = recordOrRecordID;
83
- if (server_common_node_1.checkUtils.isObject(record)) {
84
- // 如果用户没有传入包含 id 的 record,则报错
85
- if (!record._id) {
86
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
87
- }
88
- if (typeof record._id === 'number') {
89
- recordID = record._id;
90
- }
91
- else if (typeof record._id === 'string') {
92
- recordID = parseInt(record._id);
93
- }
94
- }
95
- }
96
- if (recordID > 0) {
97
- if (this.appCtx && this.appCtx.mode == 'openSDK') {
98
- // request from OpenSDK
99
- return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
100
- return await Request.GetInstance().openSDKDeleteRecordBySync(this.apiName, recordID);
101
- });
102
- }
103
- return await Request.GetInstance().deleteRecordBySync(this.apiName, recordID, this.authType);
104
- }
105
- throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
106
- }
107
- ;
108
- async deleteV3(recordOrRecordID) {
109
- let recordIDStr;
110
- if (typeof recordOrRecordID === 'number') {
111
- recordIDStr = recordOrRecordID.toString();
112
- }
113
- else if (typeof recordOrRecordID === 'string') {
114
- recordIDStr = recordOrRecordID;
115
- }
116
- else {
117
- let record = recordOrRecordID;
118
- if (server_common_node_1.checkUtils.isObject(record)) {
119
- // 如果用户没有传入包含 id 的 record,则报错
120
- if (!record._id) {
121
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
122
- }
123
- if (typeof record._id === 'number') {
124
- recordIDStr = record._id.toString();
125
- }
126
- else if (typeof record._id === 'string') {
127
- recordIDStr = record._id;
128
- }
129
- }
130
- }
131
- if (recordIDStr.length <= 0) {
132
- throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
133
- }
134
- return await Request.GetInstance().deleteRecordBySyncV3(this.apiName, recordIDStr, this.authType);
135
- }
136
- async update(_idOrRecordMap, recordMap) {
137
- if (this.appCtx && this.appCtx.dataVersion === 'v3') {
138
- return this.updateV3(_idOrRecordMap, recordMap);
139
- }
140
- // v1 v2 接口只支持 number 类型
141
- if (typeof _idOrRecordMap === 'string') {
142
- throw new server_common_node_1.exceptions.InvalidParamError('_id must be number');
143
- }
144
- // record 必须包含 _id
145
- let record;
146
- // 用户显式传入 id 的情况
147
- if (recordMap && typeof _idOrRecordMap === 'number') {
148
- record = recordMap;
149
- record['_id'] = _idOrRecordMap;
150
- }
151
- else {
152
- // 用户隐式传入 id 的情况
153
- record = _idOrRecordMap;
154
- if (!record._id) {
155
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
156
- }
157
- if (typeof record._id !== 'number') {
158
- throw new server_common_node_1.exceptions.InvalidParamError('the type of record._id is not number');
159
- }
160
- }
161
- if (!record) {
162
- throw new server_common_node_1.exceptions.InvalidParamError('param is empty');
163
- }
164
- record = permissionUtils.delUnauthField(record).newRecord;
165
- let recordID = record['_id'];
166
- if (recordID <= 0) {
167
- throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
168
- }
169
- if (this.appCtx && this.appCtx.mode == 'openSDK') {
170
- // request from OpenSDK
171
- return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
172
- return await Request.GetInstance().openSDKUpdateRecordBySync(this.apiName, recordID, record);
173
- });
174
- }
175
- return await Request.GetInstance().updateRecordBySync(this.apiName, recordID, record, this.authType);
176
- }
177
- ;
178
- async updateV3(_idOrRecordMap, recordMap) {
179
- // record 必须包含 _id
180
- let record;
181
- // 用户显式传入 id 的情况
182
- if (recordMap && (typeof _idOrRecordMap === 'string' || typeof _idOrRecordMap === 'number')) {
183
- record = recordMap;
184
- if (typeof _idOrRecordMap === 'number')
185
- record._id = _idOrRecordMap.toString();
186
- else if (typeof _idOrRecordMap === 'string')
187
- record._id = _idOrRecordMap;
188
- }
189
- else {
190
- // 用户隐式传入 id 的情况
191
- record = _idOrRecordMap;
192
- if (!record._id) {
193
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
194
- }
195
- if (typeof record._id === 'number') {
196
- record._id = record._id.toString();
197
- }
198
- }
199
- if (!record) {
200
- throw new server_common_node_1.exceptions.InvalidParamError('param is empty');
201
- }
202
- record = permissionUtils.delUnauthField(record).newRecord;
203
- let recordIDStr = record._id;
204
- if (recordIDStr.length <= 0) {
205
- throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
206
- }
207
- return await Request.GetInstance().updateRecordBySyncV3(this.apiName, recordIDStr, record, this.authType);
208
- }
209
- // batch sync
210
- async batchCreate(recordMapList) {
211
- // 参数校验
212
- if (!this.apiName) {
213
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
214
- }
215
- if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
216
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
217
- }
218
- for (let record of recordMapList) {
219
- if (server_common_node_1.checkUtils.isNotObject(record)) {
220
- throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
221
- }
222
- }
223
- recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
224
- if (this.appCtx && this.appCtx.dataVersion === 'v3') {
225
- return await this.batchCreateV3(recordMapList);
226
- }
227
- let data = (this.appCtx && this.appCtx.mode == 'openSDK') ?
228
- await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => await Request.GetInstance().openSDKCreateRecordsBySync(this.apiName, recordMapList))
229
- : await Request.GetInstance().createRecordsBySync(this.apiName, recordMapList, this.authType);
230
- // todo: 确定函数返回值
231
- if (!(data instanceof Array) && data.record_ids) {
232
- return data.record_ids;
233
- }
234
- return data;
235
- }
236
- ;
237
- async batchCreateV3(recordMapList) {
238
- const dataV3 = await Request.GetInstance().createRecordsBySyncV3(this.apiName, recordMapList, this.authType);
239
- const ids = (dataV3.items || []).map((item) => item?._id);
240
- return ids;
241
- }
242
- async batchDelete(idOrRecordList) {
243
- // 参数校验、组装
244
- if (!this.apiName) {
245
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
246
- }
247
- if (!(idOrRecordList instanceof Array) || idOrRecordList.length === 0) {
248
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
249
- }
250
- if (this.appCtx && this.appCtx.dataVersion === 'v3') {
251
- return this.batchDeleteV3(idOrRecordList);
252
- }
253
- let recordIDs = [];
254
- for (let record of idOrRecordList) {
255
- if (typeof (record) === 'number') {
256
- recordIDs.push(record);
257
- }
258
- else if (server_common_node_1.checkUtils.isObject(record) && record._id && typeof (record._id) === 'number') {
259
- recordIDs.push(record._id);
260
- }
261
- else {
262
- throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
263
- }
264
- }
265
- if (this.appCtx && this.appCtx.mode == 'openSDK') {
266
- // request from OpenSDK
267
- return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
268
- return await Request.GetInstance().openSDKDeleteRecordsBySync(this.apiName, recordIDs);
269
- });
270
- }
271
- const errMap = await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs, this.authType);
272
- return (0, structs_1.NewBatchResult)(recordIDs, errMap);
273
- }
274
- async batchDeleteV3(idOrRecordList) {
275
- let recordIDs = [];
276
- for (let record of idOrRecordList) {
277
- if (typeof (record) === 'string') {
278
- recordIDs.push(record);
279
- }
280
- else if (typeof (record) === 'number') {
281
- recordIDs.push(record.toString());
282
- }
283
- else if (server_common_node_1.checkUtils.isObject(record) && record._id && typeof (record._id) === 'string') {
284
- recordIDs.push(record._id);
285
- }
286
- else {
287
- throw new server_common_node_1.exceptions.InvalidParamError('record must be string or number or object');
288
- }
289
- }
290
- const errMap = await Request.GetInstance().deleteRecordsBySyncV3(this.apiName, recordIDs, this.authType);
291
- return (0, structs_1.NewBatchResult)(recordIDs, errMap);
292
- }
293
- async batchUpdate(recordMapList) {
294
- // 参数校验、组装
295
- if (!this.apiName) {
296
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
297
- }
298
- if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
299
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
300
- }
301
- recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
302
- if (this.appCtx && this.appCtx.dataVersion === 'v3') {
303
- return await this.batchUpdateV3(recordMapList);
304
- }
305
- const recordIDs = [];
306
- let recordMap = {};
307
- for (let record of recordMapList) {
308
- let recordID;
309
- if (typeof record._id === 'number') {
310
- recordID = record._id;
311
- }
312
- else if (typeof record._id === 'string') {
313
- recordID = parseInt(record._id);
314
- }
315
- if ((typeof recordID !== 'number') || recordID <= 0) {
316
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
317
- }
318
- recordMap[recordID] = record;
319
- recordIDs.push(recordID);
320
- }
321
- if (this.appCtx && this.appCtx.mode == 'openSDK') {
322
- // request from OpenSDK
323
- return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
324
- return await Request.GetInstance().openSDKUpdateRecordsBySync(this.apiName, recordMapList);
325
- });
326
- }
327
- const errMap = await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap, this.authType);
328
- return (0, structs_1.NewBatchResult)(recordIDs, errMap);
329
- }
330
- ;
331
- async batchUpdateV3(recordMapList) {
332
- const recordIDs = [];
333
- let recordMap = {};
334
- for (let record of recordMapList) {
335
- let recordID;
336
- if (typeof record._id === 'number') {
337
- recordID = record._id.toString();
338
- }
339
- else if (typeof record._id === 'string') {
340
- recordID = record._id;
341
- }
342
- if ((typeof recordID !== 'string') || recordID === '') {
343
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
344
- }
345
- recordIDs.push(recordID);
346
- }
347
- const errMap = await Request.GetInstance().updateRecordsBySyncV3(this.apiName, recordMapList, this.authType);
348
- return (0, structs_1.NewBatchResult)(recordIDs, errMap);
349
- }
350
- useUserAuth() {
351
- this.authType = constants_1.AuthTypeUser;
352
- return this;
353
- }
354
- useSystemAuth() {
355
- this.authType = constants_1.AuthTypeSystem;
356
- return this;
357
- }
358
- }
359
- class _KObjectAsync {
360
- constructor() {
361
- this.apiName = '';
362
- }
363
- // batch async
364
- async batchCreateAsync(recordMapList) {
365
- // 参数校验
366
- if (!this.apiName) {
367
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
368
- }
369
- if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
370
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
371
- }
372
- if (recordMapList.length > 1000) {
373
- throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
374
- }
375
- for (let record of recordMapList) {
376
- if (server_common_node_1.checkUtils.isNotObject(record)) {
377
- throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
378
- }
379
- }
380
- if (server_common_node_1.utils.stringify(recordMapList).length > 50 * 1024 * 1024) {
381
- throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
382
- }
383
- recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
384
- return await Request.GetInstance().createRecordsByAsync(this.apiName, recordMapList, this.authType);
385
- }
386
- ;
387
- async batchDeleteAsync(recordOrIDList) {
388
- // 参数校验、组装
389
- if (!this.apiName) {
390
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
391
- }
392
- if (!(recordOrIDList instanceof Array) || recordOrIDList.length === 0) {
393
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
394
- }
395
- if (recordOrIDList.length > 1000) {
396
- throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
397
- }
398
- let recordIDs = [];
399
- for (let record of recordOrIDList) {
400
- if (typeof (record) === 'number') {
401
- recordIDs.push(record);
402
- }
403
- else if (server_common_node_1.checkUtils.isObject(record) && record._id && typeof (record._id) === 'number') {
404
- recordIDs.push(record._id);
405
- }
406
- else {
407
- throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
408
- }
409
- }
410
- if (server_common_node_1.utils.stringify(recordIDs).length > 50 * 1024 * 1024) {
411
- throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
412
- }
413
- return await Request.GetInstance().deleteRecordsByAsync(this.apiName, recordIDs, this.authType);
414
- }
415
- async batchUpdateAsync(recordMapList) {
416
- // 参数校验、组装
417
- if (!this.apiName) {
418
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
419
- }
420
- if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
421
- throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
422
- }
423
- if (recordMapList.length > 1000) {
424
- throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
425
- }
426
- recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
427
- let recordMap = {};
428
- for (let record of recordMapList) {
429
- let recordID;
430
- if (typeof record._id === 'number') {
431
- recordID = record._id;
432
- }
433
- else if (typeof record._id === 'string') {
434
- recordID = parseInt(record._id);
435
- }
436
- if (recordID === undefined || recordID === null) {
437
- throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
438
- }
439
- if (typeof recordID !== 'number') {
440
- throw new server_common_node_1.exceptions.InvalidParamError('the type of record._id is not number');
441
- }
442
- if (recordID <= 0) {
443
- throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
444
- }
445
- recordMap[recordID] = record;
446
- }
447
- if (server_common_node_1.utils.stringify(recordMap).length > 50 * 1024 * 1024) {
448
- throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
449
- }
450
- return await Request.GetInstance().updateRecordsByAsync(this.apiName, recordMap, this.authType);
451
- }
452
- ;
453
- useUserAuth() {
454
- this.authType = constants_1.AuthTypeUser;
455
- return this;
456
- }
457
- useSystemAuth() {
458
- this.authType = constants_1.AuthTypeSystem;
459
- return this;
460
- }
461
- }
462
- class _KObjectQuery {
463
- constructor() {
464
- this.appCtx = null;
465
- }
466
- // find, findOne
467
- async find() {
468
- return new _KQuery(this.apiName, this.appCtx, this.authType).find();
469
- }
470
- ;
471
- async findOne() {
472
- return new _KQuery(this.apiName, this.appCtx, this.authType).findOne();
473
- }
474
- ;
475
- async findAll() {
476
- return new _KQuery(this.apiName, this.appCtx, this.authType).findAll();
477
- }
478
- ;
479
- async findStream(handler) {
480
- return new _KQuery(this.apiName, this.appCtx, this.authType).findStream(handler);
481
- }
482
- orderBy(fieldApiNames, ...restFieldApiNames) {
483
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
484
- return new _KQuery(this.apiName, this.appCtx, this.authType).orderBy(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
485
- }
486
- orderByDesc(fieldApiNames, ...restFieldApiNames) {
487
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
488
- return new _KQuery(this.apiName, this.appCtx, this.authType).orderByDesc(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
489
- }
490
- select(fieldApiNames, ...restFieldApiNames) {
491
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
492
- return new _KQuery(this.apiName, this.appCtx, this.authType).select(server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames));
493
- }
494
- where(conditionMap) {
495
- if (!conditionMap) {
496
- return new _KQuery(this.apiName, this.appCtx, this.authType).where();
497
- }
498
- return new _KQuery(this.apiName, this.appCtx, this.authType).where(conditionMap);
499
- }
500
- fuzzySearch(keyword, fieldAPINames) {
501
- return new _KQuery(this.apiName, this.appCtx, this.authType).fuzzySearch(keyword, fieldAPINames);
502
- }
503
- // limit, offset, count
504
- limit(limit) {
505
- return new _KQuery(this.apiName, this.appCtx, this.authType).limit(limit);
506
- }
507
- ;
508
- offset(offset) {
509
- return new _KQuery(this.apiName, this.appCtx, this.authType).offset(offset);
510
- }
511
- ;
512
- async count() {
513
- return new _KQuery(this.apiName, this.appCtx, this.authType).count();
514
- }
515
- ;
516
- useSystemAuth() {
517
- this.authType = constants_1.AuthTypeSystem;
518
- return this;
519
- }
520
- useUserAuth() {
521
- this.authType = constants_1.AuthTypeUser;
522
- return this;
523
- }
524
- }
525
- /**
526
- * _KQuery is kunlun query implement, implements ORM operations.
527
- */
528
- class _KQuery {
529
- constructor(objectApiName, appCtx = null, authType = null) {
530
- if (authType) {
531
- this.authType = authType;
532
- }
533
- if (!objectApiName) {
534
- throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
535
- }
536
- queryPropertiesStore.set(this, {
537
- apiName: objectApiName,
538
- appCtx: appCtx,
539
- queryBuilder: new queryBuilder_1.QueryBuilder(objectApiName),
540
- queryV2: appCtx && appCtx.mode === 'openSDK' ? new logicV2_1.QueryV2(objectApiName) : null, // QueryV2 是提供给 openSDK 使用的
541
- });
542
- }
543
- async find() {
544
- this.findPreCheck();
545
- const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
546
- if (appCtx && appCtx.dataVersion === 'v3') {
547
- return await this.findV3(false);
548
- }
549
- if (queryV2) {
550
- const param = {
551
- limit: queryV2._limit,
552
- offset: queryV2._offset,
553
- sort: queryV2._order,
554
- fields: queryV2.fields,
555
- count: false,
556
- filter: (0, logicV2_1.buildCriterionV2)(queryV2.filter),
557
- };
558
- return await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
559
- return await Request.GetInstance().openSDKGetRecords(apiName, param);
560
- });
561
- }
562
- else {
563
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
564
- if (queryBuilder.getLogic().logics.length > 0) {
565
- criterion = await (0, logic_1.handleCriterion)(criterion);
566
- }
567
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), false, this.authType);
568
- }
569
- }
570
- ;
571
- async findOne() {
572
- // 限制 limit 为 1
573
- this.limit(1);
574
- const records = await this.find();
575
- return records instanceof Array ? (records.length > 0 ? records[0] : null) : null;
576
- }
577
- ;
578
- /**
579
- * @Deprecated Use FindStream instead.
580
- */
581
- async findAll() {
582
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
583
- if (queryBuilder.getOrder().length > 0) {
584
- throw new server_common_node_1.exceptions.InvalidParamError('findAll does not support orderBy and orderByDesc');
585
- }
586
- if (queryV2 && queryV2._order.length > 0) {
587
- throw new server_common_node_1.exceptions.InvalidParamError('findAll does not support orderBy and orderByDesc');
588
- }
589
- return await this.getRecordsByPage();
590
- }
591
- ;
592
- async findStream(handler, pageLimit = 200) {
593
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
594
- let offset = 0, orders = [];
595
- if (queryV2) {
596
- offset = queryV2._offset;
597
- orders = queryV2._order;
598
- }
599
- else {
600
- offset = queryBuilder.getOffset();
601
- orders = queryBuilder.getOrder();
602
- }
603
- if (pageLimit === 0) {
604
- pageLimit = queryBuilder_1.defaultLimit;
605
- }
606
- if (orders.length === 0 && offset === 0) {
607
- // 走主键翻页
608
- return await this.walkRecordsByID(handler, pageLimit);
609
- }
610
- // 走 limit offset 翻页
611
- return await this.walkRecordsByLimitOffset(handler, pageLimit);
612
- }
613
- async walkRecordsByID(handler, pageLimit) {
614
- const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
615
- let limit = 0, selectFields = [];
616
- if (queryV2) {
617
- if (queryV2.isSetLimit) {
618
- limit = queryV2._limit;
619
- }
620
- selectFields = queryV2.fields;
621
- }
622
- else {
623
- if (queryBuilder.isSetLimit) {
624
- limit = queryBuilder.getLimit();
625
- }
626
- selectFields = queryBuilder.getSelect();
627
- }
628
- let maxId = 0, queryCount = 0;
629
- let criterionV2;
630
- let criterion;
631
- if (queryV2) {
632
- criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
633
- criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
634
- }
635
- else {
636
- criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
637
- if (queryBuilder.getLogic().logics.length > 0) { // 有自定义搜索条件时,需要获取 fields
638
- criterion = await (0, logic_1.handleCriterion)(criterion);
639
- }
640
- // 在最后,添加 _id>maxId 条件
641
- criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
642
- }
643
- while (true) {
644
- let newLimit = pageLimit;
645
- if (limit > 0 && limit - queryCount < pageLimit) {
646
- newLimit = limit - queryCount;
647
- }
648
- if (newLimit <= 0) {
649
- break;
650
- }
651
- let rs;
652
- if (queryV2) {
653
- criterionV2[criterionV2.length - 1].rightValue = maxId;
654
- const param = {
655
- limit: newLimit,
656
- offset: 0,
657
- sort: [{ field: '_id', direction: 'asc', type: '' }],
658
- fields: selectFields,
659
- count: false,
660
- filter: criterionV2,
661
- };
662
- rs = await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
663
- return await Request.GetInstance().openSDKGetRecords(apiName, param);
664
- });
665
- }
666
- else if (appCtx && appCtx.dataVersion === 'v3') {
667
- // 更新 maxId
668
- criterion.conditions[criterion.conditions.length - 1].right.settings.data = maxId;
669
- // 转换成 V3 的 criterion
670
- const criterionV3 = (0, logic_1.convertCriterionToCriterionV3)(criterion);
671
- rs = await Request.GetInstance().getRecordsV3OrCounByCriterion(apiName, criterionV3, queryBuilder.quickQuery, queryBuilder.quickQueryFields, [new order_1.Order('_id', 'asc')], queryBuilder.getSelect(), 0, newLimit, false, this.authType);
672
- }
673
- else {
674
- // 更新 maxId
675
- criterion.conditions[criterion.conditions.length - 1].right.settings.data = maxId;
676
- // 发起请求
677
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
678
- }
679
- queryCount += rs.length;
680
- rs.forEach((r) => {
681
- maxId = r._id > maxId ? r._id : maxId;
682
- });
683
- try {
684
- if (rs.length > 0) {
685
- await handler(rs);
686
- }
687
- }
688
- catch (err) {
689
- throw err;
690
- }
691
- if (rs.length < pageLimit) {
692
- break;
693
- }
694
- }
695
- }
696
- async walkRecordsByLimitOffset(handler, pageLimit) {
697
- const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
698
- let limit = 0, offset = 0, selectFields = [], orders = [];
699
- if (queryV2) {
700
- if (queryV2.isSetLimit) {
701
- limit = queryV2._limit;
702
- }
703
- offset = queryV2._offset;
704
- selectFields = queryV2.fields;
705
- orders = queryV2._order;
706
- }
707
- else {
708
- if (queryBuilder.isSetLimit) {
709
- limit = queryBuilder.getLimit();
710
- }
711
- offset = queryBuilder.getOffset();
712
- selectFields = queryBuilder.getSelect();
713
- orders = queryBuilder.getOrder();
714
- }
715
- // 当用户未设置排序字段时,强制指定为主键增序,避免数据重复
716
- if (!orders || orders.length === 0) {
717
- orders = [{ field: '_id', direction: 'asc', type: '' }];
718
- }
719
- let maxId = 0, queryCount = 0;
720
- let criterionV2;
721
- let criterion;
722
- if (queryV2) {
723
- criterionV2 = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
724
- criterionV2.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
725
- }
726
- else {
727
- criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
728
- if (queryBuilder.getLogic().logics.length > 0) { // 有自定义搜索条件时,需要获取 fields
729
- criterion = await (0, logic_1.handleCriterion)(criterion);
730
- }
731
- // 在最后,添加 _id>maxId 条件
732
- criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
733
- }
734
- let curOffset = offset;
735
- while (true) {
736
- let newLimit = function () {
737
- if (limit == 0) {
738
- return pageLimit;
739
- }
740
- if (offset + limit - curOffset < pageLimit) {
741
- return offset + limit - curOffset;
742
- }
743
- return pageLimit;
744
- }();
745
- if (newLimit <= 0) {
746
- break;
747
- }
748
- let rs;
749
- if (queryV2) {
750
- criterionV2[criterionV2.length - 1].rightValue = maxId;
751
- const param = {
752
- limit: newLimit,
753
- offset: curOffset,
754
- sort: orders,
755
- fields: selectFields,
756
- count: false,
757
- filter: criterionV2,
758
- };
759
- rs = await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
760
- return await Request.GetInstance().openSDKGetRecords(apiName, param);
761
- });
762
- }
763
- else if (appCtx && appCtx.dataVersion === 'v3') {
764
- // 更新 maxId
765
- criterion.conditions[criterion.conditions.length - 1].right.settings.data = maxId;
766
- // 转换成 V3 的 criterion
767
- const criterionV3 = (0, logic_1.convertCriterionToCriterionV3)(criterion);
768
- rs = await Request.GetInstance().getRecordsV3OrCounByCriterion(apiName, criterionV3, queryBuilder.quickQuery, queryBuilder.quickQueryFields, orders, selectFields, curOffset, newLimit, false, this.authType);
769
- }
770
- else {
771
- // 更新 maxId
772
- criterion.conditions[criterion.conditions.length - 1].right.settings.data = maxId;
773
- // 发起请求
774
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, orders, false, selectFields, curOffset, newLimit, false, this.authType);
775
- }
776
- queryCount += rs.length;
777
- try {
778
- if (rs.length > 0) {
779
- await handler(rs);
780
- }
781
- }
782
- catch (err) {
783
- throw err;
784
- }
785
- if (rs.length < pageLimit) {
786
- break;
787
- }
788
- curOffset += pageLimit;
789
- }
790
- }
791
- async getRecordsByPage() {
792
- const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
793
- let maxId = 0, records = [];
794
- while (true) {
795
- let rs;
796
- if (queryV2) {
797
- let criterion = (0, logicV2_1.buildCriterionV2)(queryV2.filter);
798
- criterion.push({ leftValue: '_id', operator: operator_1.operates.GT, rightValue: maxId });
799
- const param = {
800
- limit: 200,
801
- offset: 0,
802
- sort: [{ field: '_id', direction: 'asc', type: '' }],
803
- fields: queryV2.fields,
804
- count: false,
805
- filter: criterion,
806
- };
807
- rs = await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
808
- return await Request.GetInstance().openSDKGetRecords(apiName, param);
809
- });
810
- }
811
- else {
812
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
813
- if (queryBuilder.getLogic().logics.length > 0) {
814
- criterion = await (0, logic_1.handleCriterion)(criterion);
815
- }
816
- criterion = (0, logic_1.addIDCriterion)(criterion, apiName, maxId);
817
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, null, // FindAll 不再迭代
818
- [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
819
- }
820
- rs.forEach((r) => {
821
- maxId = r._id > maxId ? r._id : maxId;
822
- });
823
- records.push(...rs);
824
- if (rs.length < queryBuilder_1.defaultLimit) {
825
- break;
826
- }
827
- }
828
- return records;
829
- }
830
- orderBy(fieldApiNames, ...restFieldApiNames) {
831
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
832
- let fields = server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames);
833
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
834
- if (queryV2) {
835
- queryV2.orderBy(fields);
836
- }
837
- else {
838
- queryBuilder.addOrders(fields, order_1.ASC);
839
- }
840
- return this;
841
- }
842
- orderByDesc(fieldApiNames, ...restFieldApiNames) {
843
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
844
- let fields = server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames);
845
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
846
- if (queryV2) {
847
- queryV2.orderByDesc(fields);
848
- }
849
- else {
850
- queryBuilder.addOrders(fields, order_1.DESC);
851
- }
852
- return this;
853
- }
854
- select(fieldApiNames, ...restFieldApiNames) {
855
- const { appCtx } = queryPropertiesStore.get(this);
856
- fieldApiNames = !fieldApiNames ? [] : fieldApiNames;
857
- let fields = server_common_node_1.utils.argsToList(fieldApiNames, restFieldApiNames);
858
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
859
- if (queryV2) {
860
- queryV2.select(fields);
861
- }
862
- else {
863
- queryBuilder.addSelects(fields);
864
- }
865
- return this;
866
- }
867
- where(conditionMap) {
868
- // 如果 where 内是空,直接返回
869
- if (!conditionMap || Object.keys(conditionMap).length === 0) {
870
- return this;
871
- }
872
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
873
- if (queryV2) {
874
- queryV2.where(conditionMap);
875
- }
876
- else {
877
- let logic;
878
- // 如果 conditionMap 不是 Logic,需要构建为 Logic
879
- if (!(conditionMap instanceof logic_1.Logic)) {
880
- logic = (0, logic_1.buildLogic)([conditionMap]);
881
- }
882
- else {
883
- logic = conditionMap;
884
- }
885
- queryBuilder.addLogic(logic);
886
- }
887
- return this;
888
- }
889
- fuzzySearch(keyword, fieldAPINames) {
890
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
891
- if (queryV2) {
892
- throw new server_common_node_1.exceptions.InvalidParamError(`OpenSDK does not implement FuzzySearch`);
893
- }
894
- if (queryBuilder.fuzzySearch) {
895
- throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch can only be called once`);
896
- }
897
- if (!keyword) {
898
- throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's keyword can not be empty`);
899
- }
900
- if (!fieldAPINames || fieldAPINames.length === 0) {
901
- throw new server_common_node_1.exceptions.InvalidParamError(`FuzzySearch's fieldAPINames can not be empty`);
902
- }
903
- queryBuilder.fuzzySearch = {
904
- keyword: keyword,
905
- fieldAPINames: fieldAPINames,
906
- };
907
- queryBuilder.quickQuery = keyword;
908
- queryBuilder.quickQueryFields = fieldAPINames;
909
- return this;
910
- }
911
- limit(limit) {
912
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
913
- limit = Number(limit);
914
- if (queryV2) {
915
- queryV2.limit(limit);
916
- }
917
- else {
918
- queryBuilder.setLimit(limit);
919
- }
920
- return this;
921
- }
922
- ;
923
- offset(offset) {
924
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
925
- offset = Number(offset);
926
- if (queryV2) {
927
- queryV2.offset(offset);
928
- }
929
- else {
930
- queryBuilder.setOffset(offset);
931
- }
932
- return this;
933
- }
934
- ;
935
- async count() {
936
- const { apiName, appCtx, queryBuilder, queryV2 } = queryPropertiesStore.get(this);
937
- if (appCtx && appCtx.dataVersion === 'v3') {
938
- return await this.findV3(true);
939
- }
940
- if (queryV2) {
941
- const param = {
942
- limit: 1,
943
- offset: queryV2._offset,
944
- fields: queryV2.fields,
945
- sort: queryV2._order,
946
- count: true,
947
- filter: (0, logicV2_1.buildCriterionV2)(queryV2.filter),
948
- };
949
- param.count = true;
950
- return await (0, common_1.runCtxForOpenSDK)(appCtx, async () => {
951
- return await Request.GetInstance().openSDKGetRecords(apiName, param);
952
- });
953
- }
954
- else {
955
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
956
- if (queryBuilder.getLogic().logics.length > 0) {
957
- criterion = await (0, logic_1.handleCriterion)(criterion);
958
- }
959
- return await Request.GetInstance().getRecordsOrCountByCriterion(apiName, criterion, queryBuilder.fuzzySearch, queryBuilder.getOrder(), false, queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), true, this.authType);
960
- }
961
- }
962
- ;
963
- async findV3(needCount) {
964
- const { apiName, queryBuilder } = queryPropertiesStore.get(this);
965
- let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName);
966
- if (queryBuilder.getLogic().logics.length > 0) {
967
- criterion = await (0, logic_1.handleCriterion)(criterion);
968
- }
969
- const criterionV3 = (0, logic_1.convertCriterionToCriterionV3)(criterion);
970
- const res = await Request.GetInstance().getRecordsV3OrCounByCriterion(apiName, criterionV3, queryBuilder.quickQuery, queryBuilder.quickQueryFields, queryBuilder.getOrder(), queryBuilder.getSelect(), queryBuilder.getOffset(), queryBuilder.getLimit(), needCount, this.authType);
971
- if (needCount) {
972
- return res;
973
- }
974
- return res;
975
- }
976
- findPreCheck() {
977
- const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
978
- let limit = queryBuilder_1.defaultLimit;
979
- if (queryV2) {
980
- limit = queryV2._limit;
981
- }
982
- else {
983
- limit = queryBuilder.limit;
984
- }
985
- if (limit < 1) {
986
- // need import exceptions
987
- throw new server_common_node_1.exceptions.InvalidParamError(`limit(${limit}) < 1`);
988
- }
989
- }
990
- useSystemAuth() {
991
- this.authType = constants_1.AuthTypeSystem;
992
- return this;
993
- }
994
- useUserAuth() {
995
- this.authType = constants_1.AuthTypeUser;
996
- return this;
997
- }
998
- }
999
- function applyMixins(derivedCtor, constructors) {
1000
- constructors.forEach((baseCtor) => {
1001
- Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
1002
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) ||
1003
- Object.create(null));
1004
- });
1005
- });
1006
- }
1007
- applyMixins(_KObject, [_KObjectSync, _KObjectAsync, _KObjectQuery]);
1008
- applyMixins(_KApplicationObject, [_KObjectSync, _KObjectQuery]); // @ts-ignore