@byted-apaas/server-sdk-node 1.0.16 → 1.1.0-beta.11

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 (88) hide show
  1. package/README.md +22 -0
  2. package/application/application.d.ts +9 -7
  3. package/application/function/function.d.ts +1 -1
  4. package/application/function/function.js +0 -1
  5. package/application/impl/common.d.ts +1 -1
  6. package/application/impl/common.js +13 -12
  7. package/application/impl/impl.d.ts +8 -6
  8. package/application/impl/impl.js +6 -4
  9. package/common/structs.d.ts +15 -0
  10. package/common/structs.js +21 -0
  11. package/constants/constants.js +4 -4
  12. package/context/context.d.ts +8 -38
  13. package/context/context.js +2 -2
  14. package/context/db/db.d.ts +11 -19
  15. package/context/db/impl/IObject.d.ts +41 -40
  16. package/context/db/impl/db.d.ts +9 -9
  17. package/context/db/impl/db.js +6 -6
  18. package/context/db/impl/object.d.ts +4 -3
  19. package/context/db/impl/object.js +62 -50
  20. package/context/db/impl/oql/oql.d.ts +1 -1
  21. package/context/db/impl/oql/oql.js +1 -1
  22. package/context/db/impl/order.js +1 -1
  23. package/context/db/impl/propertiesStore.js +1 -1
  24. package/context/db/impl/transaction/index.d.ts +1 -1
  25. package/context/db/impl/transaction/index.js +51 -46
  26. package/context/db/impl/transaction.d.ts +0 -5
  27. package/context/integration/IIntegration.d.ts +30 -0
  28. package/context/integration/IIntegration.js +4 -0
  29. package/context/integration/impl/integration.d.ts +16 -0
  30. package/context/integration/impl/integration.js +62 -0
  31. package/context/metadata/components/common.js +3 -3
  32. package/context/metadata/components/components.d.ts +4 -4
  33. package/context/metadata/components/desktop/list.d.ts +3 -3
  34. package/context/metadata/components/desktop/list.js +23 -23
  35. package/context/metadata/components/desktop/recordDetail.d.ts +2 -2
  36. package/context/metadata/components/mobile/list.d.ts +4 -4
  37. package/context/metadata/components/mobile/list.js +1 -1
  38. package/context/metadata/metadata.d.ts +5 -6
  39. package/context/metadata/metadata.js +5 -6
  40. package/context/metadata/objects/fields.d.ts +6 -6
  41. package/context/metadata/objects/fields.js +57 -57
  42. package/context/metadata/objects/fields.util.d.ts +3 -3
  43. package/context/metadata/objects/fields.util.js +21 -21
  44. package/context/metadata/objects/objects.d.ts +1 -1
  45. package/context/metadata/objects/objects.js +1 -1
  46. package/context/metadata/types/components.d.ts +5 -5
  47. package/context/metadata/types/objects.d.ts +88 -88
  48. package/context/msg/msg.d.ts +2 -2
  49. package/context/resources/IResources.d.ts +6 -4
  50. package/context/resources/impl/resources.d.ts +6 -6
  51. package/context/resources/impl/resources.js +5 -5
  52. package/context/tasks/tasks.d.ts +3 -3
  53. package/context/tasks/tasks.js +5 -5
  54. package/data/index.d.ts +2 -2
  55. package/global/application/flow/flow.d.ts +85 -0
  56. package/global/application/flow/flow.js +2 -0
  57. package/global/application/globalVar/globalVar.d.ts +7 -0
  58. package/global/application/globalVar/globalVar.js +2 -0
  59. package/global/global.d.ts +64 -0
  60. package/global/global.js +3 -0
  61. package/hooks/api.d.ts +12 -7
  62. package/hooks/api.js +28 -23
  63. package/hooks/hooks.js +41 -0
  64. package/kunlun/kunlun.d.ts +5 -5
  65. package/kunlun/operator/IOperator.d.ts +16 -16
  66. package/kunlun/operator/impl/expression.d.ts +2 -2
  67. package/kunlun/operator/impl/expression.js +5 -5
  68. package/kunlun/operator/impl/logic.js +48 -31
  69. package/kunlun/operator/impl/logicV2.d.ts +2 -2
  70. package/kunlun/operator/impl/logicV2.js +12 -13
  71. package/kunlun/operator/impl/operator.d.ts +17 -17
  72. package/kunlun/operator/impl/operator.js +38 -38
  73. package/kunlun/operator/impl/operatorV2.d.ts +17 -17
  74. package/kunlun/operator/impl/operatorV2.js +38 -38
  75. package/lib/core.d.ts +3 -3
  76. package/package.json +2 -2
  77. package/request/common.d.ts +1 -1
  78. package/request/common.js +4 -3
  79. package/request/constants.d.ts +1 -1
  80. package/request/constants.js +6 -6
  81. package/request/faasinfra.d.ts +1 -1
  82. package/request/faasinfra.js +41 -253
  83. package/request/innerapi.d.ts +14 -10
  84. package/request/innerapi.js +220 -66
  85. package/request/interface.d.ts +68 -54
  86. package/request/interface.js +8 -9
  87. package/request/openapi.d.ts +15 -11
  88. package/request/openapi.js +266 -158
@@ -13,13 +13,15 @@ const common_1 = require("../../../application/impl/common");
13
13
  const logicV2_1 = require("../../../kunlun/operator/impl/logicV2");
14
14
  const operator_1 = require("../../../kunlun/operator/impl/operator");
15
15
  const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
16
+ const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
17
+ const structs_1 = require("../../../common/structs");
16
18
  const queryPropertiesStore = new propertiesStore_1.default();
17
19
  // _KObject will be Mixin with [_KObjectSync, _KObjectAsync, _KObjectQuery]
18
20
  class _KObject {
19
21
  constructor(objectApiName) {
20
22
  this.apiName = '';
21
23
  if (!objectApiName) {
22
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
24
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
23
25
  }
24
26
  this.apiName = objectApiName;
25
27
  }
@@ -42,11 +44,12 @@ class _KObjectSync {
42
44
  // create, update, delete
43
45
  async create(recordMap) {
44
46
  if (!recordMap) {
45
- throw new server_common_node_1.exceptions.InvalidParamError("record is empty");
47
+ throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
46
48
  }
47
49
  if (server_common_node_1.checkUtils.isNotObject(recordMap)) {
48
- throw new server_common_node_1.exceptions.InvalidParamError("record is not object");
50
+ throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
49
51
  }
52
+ recordMap = permissionUtils.delUnauthField(recordMap).newRecord;
50
53
  if (this.appCtx && this.appCtx.mode == 'openSDK') {
51
54
  // request from OpenSDK
52
55
  return await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
@@ -59,7 +62,7 @@ class _KObjectSync {
59
62
  async delete(recordOrRecordID) {
60
63
  let recordID = 0;
61
64
  // 用户直接传入 record id 来进行删除的情况
62
- if (typeof recordOrRecordID === "number") {
65
+ if (typeof recordOrRecordID === 'number') {
63
66
  recordID = recordOrRecordID;
64
67
  }
65
68
  else {
@@ -68,7 +71,7 @@ class _KObjectSync {
68
71
  if (server_common_node_1.checkUtils.isObject(record)) {
69
72
  // 如果用户没有传入包含 id 的 record,则报错
70
73
  if (!record._id) {
71
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
74
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
72
75
  }
73
76
  recordID = record._id;
74
77
  }
@@ -82,14 +85,14 @@ class _KObjectSync {
82
85
  }
83
86
  return await Request.GetInstance().deleteRecordBySync(this.apiName, recordID, this.authType);
84
87
  }
85
- throw new server_common_node_1.exceptions.InvalidParamError("record must be number or object");
88
+ throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
86
89
  }
87
90
  ;
88
91
  async update(_idOrRecordMap, recordMap) {
89
92
  // record 必须包含 _id
90
93
  let record;
91
94
  // 用户显式传入 id 的情况
92
- if (recordMap && typeof _idOrRecordMap === "number") {
95
+ if (recordMap && typeof _idOrRecordMap === 'number') {
93
96
  record = recordMap;
94
97
  record['_id'] = _idOrRecordMap;
95
98
  }
@@ -97,18 +100,19 @@ class _KObjectSync {
97
100
  // 用户隐式传入 id 的情况
98
101
  record = _idOrRecordMap;
99
102
  if (!record._id) {
100
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
103
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
101
104
  }
102
- if (typeof record._id !== "number") {
103
- throw new server_common_node_1.exceptions.InvalidParamError("the type of record._id is not number");
105
+ if (typeof record._id !== 'number') {
106
+ throw new server_common_node_1.exceptions.InvalidParamError('the type of record._id is not number');
104
107
  }
105
108
  }
106
109
  if (!record) {
107
- throw new server_common_node_1.exceptions.InvalidParamError("param is empty");
110
+ throw new server_common_node_1.exceptions.InvalidParamError('param is empty');
108
111
  }
112
+ record = permissionUtils.delUnauthField(record).newRecord;
109
113
  let recordID = record['_id'];
110
114
  if (recordID <= 0) {
111
- throw new server_common_node_1.exceptions.InvalidParamError("record._id must greater than 0");
115
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
112
116
  }
113
117
  if (this.appCtx && this.appCtx.mode == 'openSDK') {
114
118
  // request from OpenSDK
@@ -123,23 +127,24 @@ class _KObjectSync {
123
127
  async batchCreate(recordMapList) {
124
128
  // 参数校验
125
129
  if (!this.apiName) {
126
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
130
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
127
131
  }
128
132
  if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
129
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
133
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
130
134
  }
131
135
  for (let record of recordMapList) {
132
136
  if (server_common_node_1.checkUtils.isNotObject(record)) {
133
- throw new server_common_node_1.exceptions.InvalidParamError("record is not object");
137
+ throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
134
138
  }
135
139
  }
140
+ recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
136
141
  let data = (this.appCtx && this.appCtx.mode == 'openSDK') ?
137
142
  await (0, common_1.runCtxForOpenSDK)(this.appCtx, async () => {
138
143
  return await Request.GetInstance().openSDKCreateRecordsBySync(this.apiName, recordMapList);
139
144
  }) : await Request.GetInstance().createRecordsBySync(this.apiName, recordMapList, this.authType);
140
145
  // todo: 确定函数返回值
141
- if (!(data instanceof Array) && data["record_ids"]) {
142
- return data["record_ids"];
146
+ if (!(data instanceof Array) && data.record_ids) {
147
+ return data.record_ids;
143
148
  }
144
149
  return data;
145
150
  }
@@ -147,10 +152,10 @@ class _KObjectSync {
147
152
  async batchDelete(idOrRecordList) {
148
153
  // 参数校验、组装
149
154
  if (!this.apiName) {
150
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
155
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
151
156
  }
152
157
  if (!(idOrRecordList instanceof Array) || idOrRecordList.length === 0) {
153
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
158
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
154
159
  }
155
160
  let recordIDs = [];
156
161
  for (let record of idOrRecordList) {
@@ -161,7 +166,7 @@ class _KObjectSync {
161
166
  recordIDs.push(record._id);
162
167
  }
163
168
  else {
164
- throw new server_common_node_1.exceptions.InvalidParamError("record must be number or object");
169
+ throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
165
170
  }
166
171
  }
167
172
  if (this.appCtx && this.appCtx.mode == 'openSDK') {
@@ -170,23 +175,27 @@ class _KObjectSync {
170
175
  return await Request.GetInstance().openSDKDeleteRecordsBySync(this.apiName, recordIDs);
171
176
  });
172
177
  }
173
- return await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs, this.authType);
178
+ const errMap = await Request.GetInstance().deleteRecordsBySync(this.apiName, recordIDs, this.authType);
179
+ return (0, structs_1.NewBatchResult)(recordIDs, errMap);
174
180
  }
175
181
  async batchUpdate(recordMapList) {
176
182
  // 参数校验、组装
177
183
  if (!this.apiName) {
178
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
184
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
179
185
  }
180
186
  if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
181
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
187
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
182
188
  }
189
+ recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
190
+ const recordIDs = [];
183
191
  let recordMap = {};
184
192
  for (let record of recordMapList) {
185
193
  let recordID = record['_id'];
186
- if ((typeof recordID !== "number") || recordID <= 0) {
187
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
194
+ if ((typeof recordID !== 'number') || recordID <= 0) {
195
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
188
196
  }
189
197
  recordMap[recordID] = record;
198
+ recordIDs.push(recordID);
190
199
  }
191
200
  if (this.appCtx && this.appCtx.mode == 'openSDK') {
192
201
  // request from OpenSDK
@@ -194,7 +203,8 @@ class _KObjectSync {
194
203
  return await Request.GetInstance().openSDKUpdateRecordsBySync(this.apiName, recordMapList);
195
204
  });
196
205
  }
197
- return await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap, this.authType);
206
+ const errMap = await Request.GetInstance().updateRecordsBySync(this.apiName, recordMap, this.authType);
207
+ return (0, structs_1.NewBatchResult)(recordIDs, errMap);
198
208
  }
199
209
  ;
200
210
  useUserAuth() {
@@ -214,35 +224,36 @@ class _KObjectAsync {
214
224
  async batchCreateAsync(recordMapList) {
215
225
  // 参数校验
216
226
  if (!this.apiName) {
217
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
227
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
218
228
  }
219
229
  if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
220
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
230
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
221
231
  }
222
232
  if (recordMapList.length > 1000) {
223
- throw new server_common_node_1.exceptions.InvalidParamError("more than 1000 records in one operation");
233
+ throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
224
234
  }
225
235
  for (let record of recordMapList) {
226
236
  if (server_common_node_1.checkUtils.isNotObject(record)) {
227
- throw new server_common_node_1.exceptions.InvalidParamError("record is not object");
237
+ throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
228
238
  }
229
239
  }
230
240
  if (server_common_node_1.utils.stringify(recordMapList).length > 50 * 1024 * 1024) {
231
- throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
241
+ throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
232
242
  }
243
+ recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
233
244
  return await Request.GetInstance().createRecordsByAsync(this.apiName, recordMapList, this.authType);
234
245
  }
235
246
  ;
236
247
  async batchDeleteAsync(recordOrIDList) {
237
248
  // 参数校验、组装
238
249
  if (!this.apiName) {
239
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
250
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
240
251
  }
241
252
  if (!(recordOrIDList instanceof Array) || recordOrIDList.length === 0) {
242
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
253
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
243
254
  }
244
255
  if (recordOrIDList.length > 1000) {
245
- throw new server_common_node_1.exceptions.InvalidParamError("more than 1000 records in one operation");
256
+ throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
246
257
  }
247
258
  let recordIDs = [];
248
259
  for (let record of recordOrIDList) {
@@ -253,41 +264,42 @@ class _KObjectAsync {
253
264
  recordIDs.push(record._id);
254
265
  }
255
266
  else {
256
- throw new server_common_node_1.exceptions.InvalidParamError("record must be number or object");
267
+ throw new server_common_node_1.exceptions.InvalidParamError('record must be number or object');
257
268
  }
258
269
  }
259
270
  if (server_common_node_1.utils.stringify(recordIDs).length > 50 * 1024 * 1024) {
260
- throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
271
+ throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
261
272
  }
262
273
  return await Request.GetInstance().deleteRecordsByAsync(this.apiName, recordIDs, this.authType);
263
274
  }
264
275
  async batchUpdateAsync(recordMapList) {
265
276
  // 参数校验、组装
266
277
  if (!this.apiName) {
267
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
278
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
268
279
  }
269
280
  if (!(recordMapList instanceof Array) || recordMapList.length === 0) {
270
- throw new server_common_node_1.exceptions.InvalidParamError("param records is not an array or an empty array");
281
+ throw new server_common_node_1.exceptions.InvalidParamError('param records is not an array or an empty array');
271
282
  }
272
283
  if (recordMapList.length > 1000) {
273
- throw new server_common_node_1.exceptions.InvalidParamError("more than 1000 records in one operation");
284
+ throw new server_common_node_1.exceptions.InvalidParamError('more than 1000 records in one operation');
274
285
  }
286
+ recordMapList = permissionUtils.batchDelUnauthField(recordMapList).newRecords;
275
287
  let recordMap = {};
276
288
  for (let record of recordMapList) {
277
289
  let recordID = record['_id'];
278
290
  if (recordID === undefined || recordID === null) {
279
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
291
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
280
292
  }
281
- if (typeof recordID !== "number") {
282
- throw new server_common_node_1.exceptions.InvalidParamError("the type of record._id is not number");
293
+ if (typeof recordID !== 'number') {
294
+ throw new server_common_node_1.exceptions.InvalidParamError('the type of record._id is not number');
283
295
  }
284
296
  if (recordID <= 0) {
285
- throw new server_common_node_1.exceptions.InvalidParamError("record._id must greater than 0");
297
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id must greater than 0');
286
298
  }
287
299
  recordMap[recordID] = record;
288
300
  }
289
301
  if (server_common_node_1.utils.stringify(recordMap).length > 50 * 1024 * 1024) {
290
- throw new server_common_node_1.exceptions.InvalidParamError("parameter records size exceeds 50MB");
302
+ throw new server_common_node_1.exceptions.InvalidParamError('parameter records size exceeds 50MB');
291
303
  }
292
304
  return await Request.GetInstance().updateRecordsByAsync(this.apiName, recordMap, this.authType);
293
305
  }
@@ -373,7 +385,7 @@ class _KQuery {
373
385
  this.authType = authType;
374
386
  }
375
387
  if (!objectApiName) {
376
- throw new server_common_node_1.exceptions.InvalidParamError("objectApiName is empty");
388
+ throw new server_common_node_1.exceptions.InvalidParamError('objectApiName is empty');
377
389
  }
378
390
  queryPropertiesStore.set(this, {
379
391
  apiName: objectApiName,
@@ -417,10 +429,10 @@ class _KQuery {
417
429
  async findAll() {
418
430
  const { queryBuilder, queryV2 } = queryPropertiesStore.get(this);
419
431
  if (queryBuilder.getOrder().length > 0) {
420
- throw new server_common_node_1.exceptions.InvalidParamError("findAll does not support orderBy and orderByDesc");
432
+ throw new server_common_node_1.exceptions.InvalidParamError('findAll does not support orderBy and orderByDesc');
421
433
  }
422
434
  if (queryV2 && queryV2._order.length > 0) {
423
- throw new server_common_node_1.exceptions.InvalidParamError("findAll does not support orderBy and orderByDesc");
435
+ throw new server_common_node_1.exceptions.InvalidParamError('findAll does not support orderBy and orderByDesc');
424
436
  }
425
437
  return await this.getRecordsByPage();
426
438
  }
@@ -485,7 +497,7 @@ class _KQuery {
485
497
  }
486
498
  else {
487
499
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
488
- rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
500
+ rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), queryBuilder.fuzzySearch, [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, newLimit, false, this.authType);
489
501
  }
490
502
  queryCount += rs.length;
491
503
  rs.forEach((r) => {
@@ -594,7 +606,7 @@ class _KQuery {
594
606
  else {
595
607
  let criterion = (0, logic_1.buildCriterion)(queryBuilder.getLogic(), apiName, maxId);
596
608
  rs = await Request.GetInstance().getRecordsOrCountByCriterion(apiName, await (0, logic_1.handleCriterion)(criterion), null, // FindAll 不再迭代
597
- [new order_1.Order("_id", "asc")], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
609
+ [new order_1.Order('_id', 'asc')], false, queryBuilder.getSelect(), 0, queryBuilder_1.defaultLimit, false, this.authType);
598
610
  }
599
611
  rs.forEach((r) => {
600
612
  maxId = r._id > maxId ? r._id : maxId;
@@ -762,4 +774,4 @@ function applyMixins(derivedCtor, constructors) {
762
774
  });
763
775
  }
764
776
  applyMixins(_KObject, [_KObjectSync, _KObjectAsync, _KObjectQuery]);
765
- applyMixins(_KApplicationObject, [_KObjectSync, _KObjectQuery]);
777
+ applyMixins(_KApplicationObject, [_KObjectSync, _KObjectQuery]); // @ts-ignore
@@ -1,4 +1,4 @@
1
- import { IOql } from "./ioql";
1
+ import { IOql } from './ioql';
2
2
  export declare class Oql implements IOql {
3
3
  oql: string;
4
4
  params: any[];
@@ -27,7 +27,7 @@ class Oql {
27
27
  return this;
28
28
  }
29
29
  useUserAuth() {
30
- this.authType = constants_1.AuthTypeUser;
30
+ this.authType = constants_1.AuthTypeMixUserSystem;
31
31
  return this;
32
32
  }
33
33
  }
@@ -8,7 +8,7 @@ exports.DESC = 'desc';
8
8
  class Order {
9
9
  constructor(fieldApiName, direction) {
10
10
  this.field = fieldApiName;
11
- this.type = "";
11
+ this.type = '';
12
12
  this.direction = direction;
13
13
  }
14
14
  }
@@ -9,7 +9,7 @@ class PropertiesStore {
9
9
  properties(obj) {
10
10
  const properties = this.get(obj);
11
11
  if (!properties) {
12
- throw Error("Properties store error. ");
12
+ throw Error('Properties store error. ');
13
13
  }
14
14
  return properties;
15
15
  }
@@ -1,4 +1,4 @@
1
- import { ITransaction, ITransactionWithCurrentObject, TransactionObject } from "../transaction";
1
+ import { ITransaction, ITransactionWithCurrentObject, TransactionObject } from '../transaction';
2
2
  import { TransactionOperation } from './operation';
3
3
  import { currentObjApiName } from '../../../../data';
4
4
  type uuidOrRecordIDResult = {
@@ -7,8 +7,10 @@ const server_common_node_1 = require("@byted-apaas/server-common-node");
7
7
  const Request = require("../../../../request/interface");
8
8
  const operation_1 = require("./operation");
9
9
  const constants_1 = require("@byted-apaas/server-common-node/constants/constants");
10
+ const permissionUtils = require("@byted-apaas/server-common-node/utils/permissionUtils");
10
11
  const assert = require('assert');
11
- const { v4: uuidv4 } = require("uuid");
12
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
13
+ const { v4: uuidv4 } = require('uuid'); //nolint:byted_s_ts_no_require_imports
12
14
  class Transaction {
13
15
  constructor(objectApiName) {
14
16
  this.objectApiName = objectApiName;
@@ -35,15 +37,15 @@ class Transaction {
35
37
  // SDK 生成的 uuid 只是为了 Mock 住 ID 这个字段,在事务执行后并不会落库。
36
38
  registerCreate: (oldRecord) => {
37
39
  if (this.isCommit) {
38
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
40
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
39
41
  }
40
42
  if (!oldRecord) {
41
- throw new server_common_node_1.exceptions.InvalidParamError("record is empty");
43
+ throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
42
44
  }
43
45
  if (server_common_node_1.checkUtils.isNotObject(oldRecord)) {
44
- throw new server_common_node_1.exceptions.InvalidParamError("record is not object");
46
+ throw new server_common_node_1.exceptions.InvalidParamError('record is not object');
45
47
  }
46
- let record = { ...oldRecord };
48
+ let record = permissionUtils.delUnauthField(oldRecord).newRecord;
47
49
  let uuid = uuidv4();
48
50
  let result = { _id: uuid };
49
51
  record._id = uuid;
@@ -57,21 +59,22 @@ class Transaction {
57
59
  registerUpdate: (idOrRecord, record) => {
58
60
  let recordMap;
59
61
  if (this.isCommit) {
60
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
62
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
61
63
  }
62
- if (typeof idOrRecord === "number" || typeof idOrRecord === "string") {
64
+ if (typeof idOrRecord === 'number' || typeof idOrRecord === 'string') {
63
65
  recordMap = record;
64
- recordMap["_id"] = idOrRecord;
66
+ recordMap._id = idOrRecord;
65
67
  }
66
68
  else {
67
69
  recordMap = idOrRecord;
68
70
  }
69
71
  if (!recordMap) {
70
- throw new server_common_node_1.exceptions.InvalidParamError("record is empty");
72
+ throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
71
73
  }
72
- let recordID = recordMap['_id'];
74
+ recordMap = permissionUtils.delUnauthField(recordMap).newRecord;
75
+ const recordID = recordMap._id;
73
76
  if (!recordID) {
74
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
77
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
75
78
  }
76
79
  this.operations.push(new operation_1.UpdateOperation(objectApiName, recordMap));
77
80
  },
@@ -79,24 +82,24 @@ class Transaction {
79
82
  // 注册删除和注册更新一样,ID 有可能是事务中创建的 Record,也有可能是现存的 Record,因此 ID 的类型是 string | number
80
83
  registerDelete: (idOrRecord) => {
81
84
  if (this.isCommit) {
82
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
85
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
83
86
  }
84
87
  if (!idOrRecord) {
85
- throw new server_common_node_1.exceptions.InvalidParamError("record is empty");
88
+ throw new server_common_node_1.exceptions.InvalidParamError('record is empty');
86
89
  }
87
90
  let recordId = null;
88
- if (typeof idOrRecord === "number" || typeof idOrRecord === "string") {
91
+ if (typeof idOrRecord === 'number' || typeof idOrRecord === 'string') {
89
92
  recordId = idOrRecord;
90
93
  }
91
94
  else {
92
95
  if (server_common_node_1.checkUtils.isObject(idOrRecord)) {
93
96
  if (!idOrRecord._id) {
94
- throw new server_common_node_1.exceptions.InvalidParamError("record._id is empty");
97
+ throw new server_common_node_1.exceptions.InvalidParamError('record._id is empty');
95
98
  }
96
99
  recordId = idOrRecord._id;
97
100
  }
98
101
  else {
99
- throw new server_common_node_1.exceptions.InvalidParamError("param type should be number | string | Object. ");
102
+ throw new server_common_node_1.exceptions.InvalidParamError('param type should be number | string | Object. ');
100
103
  }
101
104
  }
102
105
  this.operations.push(new operation_1.DeleteOperation(objectApiName, { _id: recordId }));
@@ -104,24 +107,25 @@ class Transaction {
104
107
  // 注册批量创建
105
108
  registerBatchCreate: (recordMaps) => {
106
109
  if (this.isCommit) {
107
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
110
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
108
111
  }
109
112
  if (!recordMaps) {
110
- throw new server_common_node_1.exceptions.InvalidParamError("recordMaps is empty");
113
+ throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is empty');
111
114
  }
112
115
  if (!Array.isArray(recordMaps)) {
113
- throw new server_common_node_1.exceptions.InvalidParamError("recordMaps is not Array");
116
+ throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is not Array');
114
117
  }
115
118
  if (recordMaps.length < 1) {
116
119
  return [];
117
120
  }
121
+ recordMaps = permissionUtils.batchDelUnauthField(recordMaps).newRecords;
118
122
  let result = [];
119
123
  let records = [];
120
124
  for (let oldRecord of recordMaps) {
121
125
  let record = { ...oldRecord };
122
126
  let uuid = uuidv4();
123
127
  this.placeholders[uuid] = 0;
124
- record['_id'] = uuid;
128
+ record._id = uuid;
125
129
  result.push(uuid);
126
130
  records.push(record);
127
131
  }
@@ -131,29 +135,30 @@ class Transaction {
131
135
  },
132
136
  registerBatchUpdate: (recordMaps) => {
133
137
  if (this.isCommit) {
134
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
138
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
135
139
  }
136
140
  if (!recordMaps) {
137
- throw new server_common_node_1.exceptions.InvalidParamError("recordMaps is empty");
141
+ throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is empty');
138
142
  }
139
143
  if (!Array.isArray(recordMaps)) {
140
- throw new server_common_node_1.exceptions.InvalidParamError("recordMaps is not Array");
144
+ throw new server_common_node_1.exceptions.InvalidParamError('recordMaps is not Array');
141
145
  }
142
146
  if (recordMaps.length < 1) {
143
147
  return;
144
148
  }
149
+ recordMaps = permissionUtils.batchDelUnauthField(recordMaps).newRecords;
145
150
  // 判断同字段同值更新标志
146
151
  let isSameValue = true;
147
152
  let ids = [];
148
153
  let flag = recordMaps[0];
149
154
  for (let record of recordMaps) {
150
155
  if (server_common_node_1.checkUtils.isNotObject(record)) {
151
- throw new server_common_node_1.exceptions.InvalidParamError("one record of recordMaps is not object");
156
+ throw new server_common_node_1.exceptions.InvalidParamError('one record of recordMaps is not object');
152
157
  }
153
- if (!record["_id"]) {
158
+ if (!record._id) {
154
159
  throw new server_common_node_1.exceptions.InvalidParamError(`one record of recordMaps has no _id ${JSON.stringify(record)}`);
155
160
  }
156
- ids.push(record["_id"]);
161
+ ids.push(record._id);
157
162
  if (!deepEqualExceptID(flag, record)) {
158
163
  isSameValue = false;
159
164
  break;
@@ -167,7 +172,7 @@ class Transaction {
167
172
  }
168
173
  else {
169
174
  for (const i in ids) {
170
- recordMaps[i]["_id"] = ids[i];
175
+ recordMaps[i]._id = ids[i];
171
176
  }
172
177
  this.operations.push(new operation_1.BatchUpdateOperation(objectApiName, recordMaps));
173
178
  }
@@ -175,13 +180,13 @@ class Transaction {
175
180
  // 注册批量删除
176
181
  registerBatchDelete: (idOrRecords) => {
177
182
  if (this.isCommit) {
178
- throw new server_common_node_1.exceptions.InvalidParamError("Committed transaction cannot register operations");
183
+ throw new server_common_node_1.exceptions.InvalidParamError('Committed transaction cannot register operations');
179
184
  }
180
185
  if (!idOrRecords) {
181
- throw new server_common_node_1.exceptions.InvalidParamError("idOrRecords is empty");
186
+ throw new server_common_node_1.exceptions.InvalidParamError('idOrRecords is empty');
182
187
  }
183
188
  if (!Array.isArray(idOrRecords)) {
184
- throw new server_common_node_1.exceptions.InvalidParamError("idOrRecords is not Array");
189
+ throw new server_common_node_1.exceptions.InvalidParamError('idOrRecords is not Array');
185
190
  }
186
191
  if (idOrRecords.length < 1) {
187
192
  return;
@@ -189,20 +194,20 @@ class Transaction {
189
194
  let ids = [];
190
195
  for (const idOrRecord of idOrRecords) {
191
196
  switch (typeof idOrRecord) {
192
- case "string":
193
- case "number":
197
+ case 'string':
198
+ case 'number':
194
199
  ids.push(idOrRecord);
195
200
  break;
196
- case "object":
197
- if (!idOrRecord['_id']) {
198
- throw new server_common_node_1.exceptions.InvalidParamError("_id of one record is empty");
201
+ case 'object':
202
+ if (!idOrRecord._id) {
203
+ throw new server_common_node_1.exceptions.InvalidParamError('_id of one record is empty');
199
204
  }
200
205
  else {
201
- ids.push(idOrRecord['_id']);
206
+ ids.push(idOrRecord._id);
202
207
  }
203
208
  break;
204
209
  default:
205
- throw new server_common_node_1.exceptions.InvalidParamError("type of one param is not string | number | object");
210
+ throw new server_common_node_1.exceptions.InvalidParamError('type of one param is not string | number | object');
206
211
  }
207
212
  }
208
213
  this.operations.push(new operation_1.BatchDeleteOperation(objectApiName, { 'ids': ids }));
@@ -211,7 +216,7 @@ class Transaction {
211
216
  }
212
217
  async commit() {
213
218
  if (this.isCommit) {
214
- throw new server_common_node_1.exceptions.InvalidParamError("The transaction cannot be committed repeatedly");
219
+ throw new server_common_node_1.exceptions.InvalidParamError('The transaction cannot be committed repeatedly');
215
220
  }
216
221
  this.isCommit = true;
217
222
  if (!this.operations || this.operations.length === 0) {
@@ -219,7 +224,7 @@ class Transaction {
219
224
  }
220
225
  let uuid2recordId = await Request.GetInstance().modifyRecordsWithTransaction(this.placeholders, this.operations, this.authType);
221
226
  if (!uuid2recordId) {
222
- throw new server_common_node_1.exceptions.InternalError("uuid2recordId is empty");
227
+ throw new server_common_node_1.exceptions.InternalError('uuid2recordId is empty');
223
228
  }
224
229
  // 单个注册结果映射
225
230
  for (let uuid of Object.keys(this.uuid2result)) {
@@ -228,7 +233,7 @@ class Transaction {
228
233
  if (!recordId) {
229
234
  throw new server_common_node_1.exceptions.InternalError(`uuid (${uuid}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
230
235
  }
231
- if (typeof (recordId) !== "number") {
236
+ if (typeof (recordId) !== 'number') {
232
237
  throw new server_common_node_1.exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
233
238
  }
234
239
  preResult._id = recordId;
@@ -249,7 +254,7 @@ class Transaction {
249
254
  if (!recordId) {
250
255
  throw new server_common_node_1.exceptions.InternalError(`uuid (${this.batchResults[i][j]}) is not in uuid2recordId (${JSON.stringify(uuid2recordId)})`);
251
256
  }
252
- if (typeof (recordId) !== "number") {
257
+ if (typeof (recordId) !== 'number') {
253
258
  throw new server_common_node_1.exceptions.InternalError(`the type (${typeof (recordId)}) of recordId (${recordId}) must be number`);
254
259
  }
255
260
  this.batchResults[i][j] = recordId;
@@ -267,12 +272,12 @@ class Transaction {
267
272
  }
268
273
  exports.Transaction = Transaction;
269
274
  function deepEqualExceptID(left, right) {
270
- let leftID = left["_id"], rightID = right["_id"];
271
- delete left["_id"];
272
- delete right["_id"];
275
+ const leftID = left._id, rightID = right._id;
276
+ delete left._id;
277
+ delete right._id;
273
278
  let result = deepEqual(left, right);
274
- left["_id"] = leftID;
275
- right["_id"] = rightID;
279
+ left._id = leftID;
280
+ right._id = rightID;
276
281
  return result;
277
282
  }
278
283
  function deepEqual(left, right) {