oak-domain 1.1.14 → 2.0.2

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 (73) hide show
  1. package/lib/base-app-domain/Modi/Schema.d.ts +22 -22
  2. package/lib/base-app-domain/ModiEntity/Schema.d.ts +17 -17
  3. package/lib/base-app-domain/Oper/Schema.d.ts +17 -17
  4. package/lib/base-app-domain/OperEntity/Schema.d.ts +18 -18
  5. package/lib/base-app-domain/User/Schema.d.ts +15 -15
  6. package/lib/checkers/index.d.ts +4 -2
  7. package/lib/compiler/schemalBuilder.js +10 -10
  8. package/lib/store/AsyncRowStore.d.ts +45 -0
  9. package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
  10. package/lib/store/CascadeStore.d.ts +46 -20
  11. package/lib/store/CascadeStore.js +954 -995
  12. package/lib/store/SyncRowStore.d.ts +26 -0
  13. package/lib/store/SyncRowStore.js +45 -0
  14. package/lib/store/TriggerExecutor.d.ts +14 -14
  15. package/lib/store/TriggerExecutor.js +225 -238
  16. package/lib/store/actionDef.d.ts +5 -4
  17. package/lib/store/actionDef.js +44 -134
  18. package/lib/store/checker.d.ts +6 -0
  19. package/lib/store/checker.js +165 -0
  20. package/lib/store/filter.d.ts +30 -0
  21. package/lib/store/filter.js +571 -2
  22. package/lib/store/modi.d.ts +7 -6
  23. package/lib/store/modi.js +35 -46
  24. package/lib/store/relation.d.ts +1 -1
  25. package/lib/triggers/index.d.ts +4 -3
  26. package/lib/triggers/modi.d.ts +2 -2
  27. package/lib/triggers/modi.js +5 -5
  28. package/lib/types/AppLoader.d.ts +3 -3
  29. package/lib/types/Aspect.d.ts +3 -3
  30. package/lib/types/Auth.d.ts +25 -22
  31. package/lib/types/Connector.d.ts +7 -7
  32. package/lib/types/Context.d.ts +4 -14
  33. package/lib/types/Entity.d.ts +20 -15
  34. package/lib/types/Entity.js +9 -2
  35. package/lib/types/Exception.js +11 -11
  36. package/lib/types/RowStore.d.ts +2 -13
  37. package/lib/types/RowStore.js +1 -6
  38. package/lib/types/Trigger.d.ts +32 -48
  39. package/lib/types/Trigger.js +24 -9
  40. package/lib/types/Watcher.d.ts +7 -8
  41. package/lib/utils/SimpleConnector.d.ts +9 -8
  42. package/lib/utils/SimpleConnector.js +4 -5
  43. package/lib/utils/random/random.d.ts +1 -0
  44. package/lib/utils/random/random.js +24 -0
  45. package/lib/utils/random/random.mp.d.ts +1 -0
  46. package/lib/utils/random/random.mp.js +25 -0
  47. package/lib/utils/random/random.web.d.ts +1 -0
  48. package/lib/utils/random/random.web.js +17 -0
  49. package/lib/utils/string.d.ts +20 -0
  50. package/lib/utils/string.js +60 -1
  51. package/lib/utils/uuid.d.ts +10 -0
  52. package/lib/utils/uuid.js +172 -1
  53. package/lib/utils/validator.js +1 -1
  54. package/package.json +7 -4
  55. package/lib/OakError.d.ts +0 -7
  56. package/lib/OakError.js +0 -15
  57. package/lib/compiler/utils.d.ts +0 -2
  58. package/lib/compiler/utils.js +0 -11
  59. package/lib/entities/Action.d.ts +0 -12
  60. package/lib/entities/Action.js +0 -17
  61. package/lib/entities/Ooperation.d.ts +0 -12
  62. package/lib/entities/Ooperation.js +0 -17
  63. package/lib/entities/Update.d.ts +0 -9
  64. package/lib/entities/Update.js +0 -44
  65. package/lib/entities/Uupdate.d.ts +0 -9
  66. package/lib/entities/Uupdate.js +0 -44
  67. package/lib/store/UniversalContext.d.ts +0 -32
  68. package/lib/store/action.d.ts +0 -6
  69. package/lib/store/action.js +0 -14
  70. package/lib/store/projection.d.ts +0 -7
  71. package/lib/store/projection.js +0 -211
  72. package/lib/store/watchers.d.ts +0 -2
  73. package/lib/store/watchers.js +0 -32
@@ -3,81 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CascadeStore = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
+ var Entity_1 = require("../types/Entity");
6
7
  var RowStore_1 = require("../types/RowStore");
7
8
  var filter_1 = require("./filter");
8
9
  var relation_1 = require("./relation");
9
10
  var types_1 = require("../types");
10
11
  var lodash_1 = require("../utils/lodash");
12
+ var filter_2 = require("./filter");
13
+ var uuid_1 = require("../utils/uuid");
11
14
  /**这个用来处理级联的select和update,对不同能力的 */
12
15
  var CascadeStore = /** @class */ (function (_super) {
13
16
  tslib_1.__extends(CascadeStore, _super);
14
17
  function CascadeStore(storageSchema) {
15
18
  return _super.call(this, storageSchema) || this;
16
19
  }
17
- /**
18
- * 将一次查询的结果集加入result
19
- * @param entity
20
- * @param rows
21
- * @param context
22
- */
23
- CascadeStore.prototype.addToResultSelections = function (entity, rows, context) {
24
- var _a;
25
- var opRecords = context.opRecords;
26
- var lastOperation = opRecords[opRecords.length - 1];
27
- if (lastOperation && lastOperation.a === 's') {
28
- var entityBranch_1 = lastOperation.d[entity];
29
- if (entityBranch_1) {
30
- rows.forEach(function (row) {
31
- var _a;
32
- var id = row.id;
33
- if (!entityBranch_1[id]) {
34
- Object.assign(entityBranch_1, (_a = {},
35
- _a[id] = (0, lodash_1.cloneDeep)(row),
36
- _a));
37
- }
38
- else {
39
- Object.assign(entityBranch_1[id], row);
40
- }
41
- });
42
- return;
43
- }
44
- }
45
- else {
46
- lastOperation = {
47
- a: 's',
48
- d: {},
49
- };
50
- opRecords.push(lastOperation);
51
- }
52
- var entityBranch = {};
53
- rows.forEach(function (row) {
54
- var _a;
55
- var id = row.id;
56
- Object.assign(entityBranch, (_a = {},
57
- _a[id] = (0, lodash_1.cloneDeep)(row),
58
- _a));
59
- });
60
- Object.assign(lastOperation.d, (_a = {},
61
- _a[entity] = entityBranch,
62
- _a));
63
- };
64
- CascadeStore.prototype.reduceDescendants = function (entity, rows) {
65
- var _this = this;
66
- return rows.filter(function (ele) { return !!ele; }).map(function (row) {
67
- var _a;
68
- var row2 = {};
69
- for (var attr in row) {
70
- var rel = _this.judgeRelation(entity, attr);
71
- if (typeof rel === 'number' && [0, 1].includes(rel)) {
72
- Object.assign(row2, (_a = {},
73
- _a[attr] = row[attr],
74
- _a));
75
- }
76
- }
77
- return row2;
78
- });
79
- };
80
- CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, option) {
20
+ CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelect, option) {
81
21
  var _this = this;
82
22
  var projection = {};
83
23
  var cascadeSelectionFns = [];
@@ -98,93 +38,84 @@ var CascadeStore = /** @class */ (function (_super) {
98
38
  entityId: 1,
99
39
  });
100
40
  if (supportMtoJoin) {
101
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
102
- return tslib_1.__generator(this, function (_a) {
103
- if (!toModi) {
104
- result.forEach(function (ele) {
105
- if (ele.entity === attr) {
106
- (0, assert_1.default)(ele.entityId);
107
- if (!ele[attr]) {
108
- throw new types_1.OakRowUnexistedException([{
109
- entity: attr,
110
- selection: {
111
- data: projection2[attr],
112
- filter: {
113
- id: ele.entityId,
114
- }
41
+ cascadeSelectionFns.push(function (result) {
42
+ if (!toModi) {
43
+ result.forEach(function (ele) {
44
+ if (ele.entity === attr) {
45
+ (0, assert_1.default)(ele.entityId);
46
+ if (!ele[attr]) {
47
+ throw new types_1.OakRowUnexistedException([{
48
+ entity: attr,
49
+ selection: {
50
+ data: projection2[attr],
51
+ filter: {
52
+ id: ele.entityId,
115
53
  }
116
- }]);
117
- }
54
+ }
55
+ }]);
118
56
  }
119
- });
120
- }
121
- if (!option.dontCollect) {
122
- this.addToResultSelections(attr, this.reduceDescendants(attr, result.map(function (ele) { return ele[attr]; })), context);
123
- }
124
- return [2 /*return*/];
125
- });
126
- }); });
127
- var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
57
+ }
58
+ });
59
+ }
60
+ });
61
+ var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelect, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
128
62
  Object.assign(projection, (_b = {},
129
63
  _b[attr] = subProjection,
130
64
  _b));
131
- subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
132
- return tslib_1.__generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0: return [4 /*yield*/, ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }))];
135
- case 1:
136
- _a.sent();
137
- return [2 /*return*/];
138
- }
139
- });
140
- }); }); });
65
+ subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
66
+ return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
67
+ }); });
141
68
  }
142
69
  else {
143
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
144
- var entityIds, subRows;
145
- return tslib_1.__generator(this, function (_a) {
146
- switch (_a.label) {
147
- case 0:
148
- entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) { return ele.entityId; }));
149
- return [4 /*yield*/, this.cascadeSelect(attr, {
70
+ cascadeSelectionFns.push(function (result) {
71
+ var dealWithSubRows = function (subRows) {
72
+ (0, assert_1.default)(subRows.length <= entityIds.length);
73
+ if (subRows.length < entityIds.length && !toModi) {
74
+ throw new types_1.OakRowUnexistedException([{
75
+ entity: attr,
76
+ selection: {
150
77
  data: projection2[attr],
151
78
  filter: {
152
79
  id: {
153
80
  $in: entityIds
154
81
  },
155
82
  },
156
- }, context, option)];
157
- case 1:
158
- subRows = _a.sent();
159
- (0, assert_1.default)(subRows.length <= entityIds.length);
160
- if (subRows.length < entityIds.length && !toModi) {
161
- throw new types_1.OakRowUnexistedException([{
162
- entity: attr,
163
- selection: {
164
- data: projection2[attr],
165
- filter: {
166
- id: {
167
- $in: entityIds
168
- },
169
- },
170
- },
171
- }]);
172
- }
173
- result.forEach(function (ele) {
174
- var _a;
175
- if (ele.entity === attr) {
176
- var subRow = subRows.find(function (ele2) { return ele2.id === ele.entityId; });
177
- if (subRow) {
178
- Object.assign(ele, (_a = {},
179
- _a[attr] = subRow,
180
- _a));
181
- }
182
- }
183
- });
184
- return [2 /*return*/];
83
+ },
84
+ }]);
185
85
  }
186
- });
187
- }); });
86
+ result.forEach(function (ele) {
87
+ var _a, _b;
88
+ if (ele.entity === attr) {
89
+ var subRow = subRows.find(function (ele2) { return ele2.id === ele.entityId; });
90
+ if (subRow) {
91
+ Object.assign(ele, (_a = {},
92
+ _a[attr] = subRow,
93
+ _a));
94
+ }
95
+ else {
96
+ Object.assign(ele, (_b = {},
97
+ _b[attr] = null,
98
+ _b));
99
+ }
100
+ }
101
+ });
102
+ };
103
+ var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) { return ele.entityId; }));
104
+ var subRows = cascadeSelect.call(_this, attr, {
105
+ data: projection2[attr],
106
+ filter: {
107
+ id: {
108
+ $in: entityIds
109
+ },
110
+ },
111
+ }, context, option);
112
+ if (subRows instanceof Promise) {
113
+ return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
114
+ }
115
+ else {
116
+ dealWithSubRows(subRows);
117
+ }
118
+ });
188
119
  }
189
120
  }
190
121
  else if (typeof relation === 'string') {
@@ -194,91 +125,85 @@ var CascadeStore = /** @class */ (function (_super) {
194
125
  if (supportMtoJoin) {
195
126
  if (!toModi) {
196
127
  // 如果不是modi,要保证外键没有空指针
197
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
198
- return tslib_1.__generator(this, function (_a) {
199
- if (!toModi) {
200
- result.forEach(function (ele) {
201
- if (ele["".concat(attr, "Id")] && !ele[attr]) {
202
- throw new types_1.OakRowUnexistedException([{
203
- entity: relation,
204
- selection: {
205
- data: projection2[attr],
206
- filter: {
207
- id: ele["".concat(attr, "Id")],
208
- }
128
+ cascadeSelectionFns.push(function (result) {
129
+ if (!toModi) {
130
+ result.forEach(function (ele) {
131
+ if (ele["".concat(attr, "Id")] && !ele[attr]) {
132
+ throw new types_1.OakRowUnexistedException([{
133
+ entity: relation,
134
+ selection: {
135
+ data: projection2[attr],
136
+ filter: {
137
+ id: ele["".concat(attr, "Id")],
209
138
  }
210
- }]);
211
- }
212
- });
213
- }
214
- if (!option.dontCollect) {
215
- this.addToResultSelections(relation, this.reduceDescendants(relation, result.map(function (ele) { return ele[attr]; })), context);
216
- }
217
- return [2 /*return*/];
218
- });
219
- }); });
139
+ }
140
+ }]);
141
+ }
142
+ });
143
+ }
144
+ });
220
145
  }
221
- var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
146
+ var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelect, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
222
147
  Object.assign(projection, (_d = {},
223
148
  _d[attr] = subProjection,
224
149
  _d));
225
- subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
226
- return tslib_1.__generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0: return [4 /*yield*/, ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }))];
229
- case 1:
230
- _a.sent();
231
- return [2 /*return*/];
232
- }
233
- });
234
- }); }); });
150
+ subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
151
+ return ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }));
152
+ }); });
235
153
  }
236
154
  else {
237
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
238
- var ids, subRows;
239
- return tslib_1.__generator(this, function (_a) {
240
- switch (_a.label) {
241
- case 0:
242
- ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
243
- return [4 /*yield*/, this.cascadeSelect(relation, {
155
+ cascadeSelectionFns.push(function (result) {
156
+ var dealWithSubRows = function (subRows) {
157
+ (0, assert_1.default)(subRows.length <= ids.length);
158
+ if (subRows.length < ids.length && !toModi) {
159
+ throw new types_1.OakRowUnexistedException([{
160
+ entity: relation,
161
+ selection: {
244
162
  data: projection2[attr],
245
163
  filter: {
246
164
  id: {
247
165
  $in: ids
248
166
  },
249
167
  },
250
- }, context, option)];
251
- case 1:
252
- subRows = _a.sent();
253
- (0, assert_1.default)(subRows.length <= ids.length);
254
- if (subRows.length < ids.length && !toModi) {
255
- throw new types_1.OakRowUnexistedException([{
256
- entity: relation,
257
- selection: {
258
- data: projection2[attr],
259
- filter: {
260
- id: {
261
- $in: ids
262
- },
263
- },
264
- }
265
- }]);
266
- }
267
- result.forEach(function (ele) {
268
- var _a;
269
- if (ele["".concat(attr, "Id")]) {
270
- var subRow = subRows.find(function (ele2) { return ele2.id === ele["".concat(attr, "Id")]; });
271
- if (subRow) {
272
- Object.assign(ele, (_a = {},
273
- _a[attr] = subRow,
274
- _a));
275
- }
276
168
  }
277
- });
278
- return [2 /*return*/];
169
+ }]);
279
170
  }
280
- });
281
- }); });
171
+ result.forEach(function (ele) {
172
+ var _a, _b, _c;
173
+ if (ele["".concat(attr, "Id")]) {
174
+ var subRow = subRows.find(function (ele2) { return ele2.id === ele["".concat(attr, "Id")]; });
175
+ if (subRow) {
176
+ Object.assign(ele, (_a = {},
177
+ _a[attr] = subRow,
178
+ _a));
179
+ }
180
+ else {
181
+ Object.assign(ele, (_b = {},
182
+ _b[attr] = null,
183
+ _b));
184
+ }
185
+ }
186
+ else {
187
+ Object.assign(ele, (_c = {},
188
+ _c[attr] = null,
189
+ _c));
190
+ }
191
+ });
192
+ };
193
+ var ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
194
+ var subRows = cascadeSelect.call(_this, relation, {
195
+ data: projection2[attr],
196
+ filter: {
197
+ id: {
198
+ $in: ids
199
+ },
200
+ },
201
+ }, context, option);
202
+ if (subRows instanceof Promise) {
203
+ return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
204
+ }
205
+ dealWithSubRows(subRows);
206
+ });
282
207
  }
283
208
  }
284
209
  else {
@@ -287,73 +212,67 @@ var CascadeStore = /** @class */ (function (_super) {
287
212
  var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
288
213
  if (foreignKey_1) {
289
214
  // 基于属性的一对多
290
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
291
- var ids, subRows;
215
+ cascadeSelectionFns.push(function (result) {
292
216
  var _a;
293
- return tslib_1.__generator(this, function (_b) {
294
- switch (_b.label) {
295
- case 0:
296
- ids = result.map(function (ele) { return ele.id; });
297
- return [4 /*yield*/, this.cascadeSelect(entity2_1, {
298
- data: subProjection_1,
299
- filter: (0, filter_1.combineFilters)([(_a = {},
300
- _a[foreignKey_1] = {
301
- $in: ids,
302
- },
303
- _a), subFilter_1]),
304
- sorter: subSorter_1,
305
- indexFrom: indexFrom_1,
306
- count: count_1
307
- }, context, option)];
308
- case 1:
309
- subRows = _b.sent();
310
- result.forEach(function (ele) {
311
- var _a;
312
- var subRowss = subRows.filter(function (ele2) { return ele2[foreignKey_1] === ele.id; });
313
- (0, assert_1.default)(subRowss);
314
- Object.assign(ele, (_a = {},
315
- _a[attr] = subRowss,
316
- _a));
317
- });
318
- return [2 /*return*/];
319
- }
320
- });
321
- }); });
217
+ var ids = result.map(function (ele) { return ele.id; });
218
+ var dealWithSubRows = function (subRows) {
219
+ result.forEach(function (ele) {
220
+ var _a;
221
+ var subRowss = subRows.filter(function (ele2) { return ele2[foreignKey_1] === ele.id; });
222
+ (0, assert_1.default)(subRowss);
223
+ Object.assign(ele, (_a = {},
224
+ _a[attr] = subRowss,
225
+ _a));
226
+ });
227
+ };
228
+ var subRows = cascadeSelect.call(_this, entity2_1, {
229
+ data: subProjection_1,
230
+ filter: (0, filter_1.combineFilters)([(_a = {},
231
+ _a[foreignKey_1] = {
232
+ $in: ids,
233
+ },
234
+ _a), subFilter_1]),
235
+ sorter: subSorter_1,
236
+ indexFrom: indexFrom_1,
237
+ count: count_1
238
+ }, context, option);
239
+ if (subRows instanceof Promise) {
240
+ return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
241
+ }
242
+ dealWithSubRows(subRows);
243
+ });
322
244
  }
323
245
  else {
324
246
  // 基于entity的多对一
325
- cascadeSelectionFns.push(function (result) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
326
- var ids, subRows;
327
- return tslib_1.__generator(this, function (_a) {
328
- switch (_a.label) {
329
- case 0:
330
- ids = result.map(function (ele) { return ele.id; });
331
- return [4 /*yield*/, this.cascadeSelect(entity2_1, {
332
- data: subProjection_1,
333
- filter: (0, filter_1.combineFilters)([{
334
- entity: entity,
335
- entityId: {
336
- $in: ids,
337
- }
338
- }, subFilter_1]),
339
- sorter: subSorter_1,
340
- indexFrom: indexFrom_1,
341
- count: count_1
342
- }, context, option)];
343
- case 1:
344
- subRows = _a.sent();
345
- result.forEach(function (ele) {
346
- var _a;
347
- var subRowss = subRows.filter(function (ele2) { return ele2.entityId === ele.id; });
348
- (0, assert_1.default)(subRowss);
349
- Object.assign(ele, (_a = {},
350
- _a[attr] = subRowss,
351
- _a));
352
- });
353
- return [2 /*return*/];
354
- }
355
- });
356
- }); });
247
+ cascadeSelectionFns.push(function (result) {
248
+ var ids = result.map(function (ele) { return ele.id; });
249
+ var dealWithSubRows = function (subRows) {
250
+ result.forEach(function (ele) {
251
+ var _a;
252
+ var subRowss = subRows.filter(function (ele2) { return ele2.entityId === ele.id; });
253
+ (0, assert_1.default)(subRowss);
254
+ Object.assign(ele, (_a = {},
255
+ _a[attr] = subRowss,
256
+ _a));
257
+ });
258
+ };
259
+ var subRows = cascadeSelect.call(_this, entity2_1, {
260
+ data: subProjection_1,
261
+ filter: (0, filter_1.combineFilters)([{
262
+ entity: entity,
263
+ entityId: {
264
+ $in: ids,
265
+ }
266
+ }, subFilter_1]),
267
+ sorter: subSorter_1,
268
+ indexFrom: indexFrom_1,
269
+ count: count_1
270
+ }, context, option);
271
+ if (subRows instanceof Promise) {
272
+ return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
273
+ }
274
+ dealWithSubRows(subRows);
275
+ });
357
276
  }
358
277
  }
359
278
  };
@@ -366,620 +285,6 @@ var CascadeStore = /** @class */ (function (_super) {
366
285
  cascadeSelectionFns: cascadeSelectionFns,
367
286
  };
368
287
  };
369
- CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
370
- return tslib_1.__awaiter(this, void 0, void 0, function () {
371
- var data, filter, indexFrom, count, sorter, _a, projection, cascadeSelectionFns, rows, ruException_1;
372
- var _this = this;
373
- return tslib_1.__generator(this, function (_b) {
374
- switch (_b.label) {
375
- case 0:
376
- data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
377
- return [4 /*yield*/, this.destructCascadeSelect(entity, data, context, option)];
378
- case 1:
379
- _a = _b.sent(), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
380
- return [4 /*yield*/, this.selectAbjointRow(entity, {
381
- data: projection,
382
- filter: filter,
383
- indexFrom: indexFrom,
384
- count: count,
385
- sorter: sorter
386
- }, context, option)];
387
- case 2:
388
- rows = _b.sent();
389
- if (!option.dontCollect) {
390
- this.addToResultSelections(entity, this.supportMultipleCreate() ? this.reduceDescendants(entity, rows) : rows, context);
391
- }
392
- if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 4];
393
- ruException_1 = [];
394
- return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
395
- var e_1, rows_1;
396
- return tslib_1.__generator(this, function (_a) {
397
- switch (_a.label) {
398
- case 0:
399
- _a.trys.push([0, 2, , 3]);
400
- return [4 /*yield*/, ele(rows)];
401
- case 1:
402
- _a.sent();
403
- return [3 /*break*/, 3];
404
- case 2:
405
- e_1 = _a.sent();
406
- if (e_1 instanceof types_1.OakRowUnexistedException) {
407
- rows_1 = e_1.getRows();
408
- ruException_1.push.apply(ruException_1, tslib_1.__spreadArray([], tslib_1.__read(rows_1), false));
409
- }
410
- else {
411
- throw e_1;
412
- }
413
- return [3 /*break*/, 3];
414
- case 3: return [2 /*return*/];
415
- }
416
- });
417
- }); }))];
418
- case 3:
419
- _b.sent();
420
- if (ruException_1.length > 0) {
421
- throw new types_1.OakRowUnexistedException(ruException_1);
422
- }
423
- _b.label = 4;
424
- case 4: return [2 /*return*/, rows];
425
- }
426
- });
427
- });
428
- };
429
- CascadeStore.prototype.cascadeSelect2 = function (entity, selection, context, option) {
430
- return tslib_1.__awaiter(this, void 0, void 0, function () {
431
- var data, filter, projection, oneToMany, oneToManyOnEntity, manyToOne, manyToOneOnEntity, supportMtoJoin, attr, relation, _a, entity2, foreignKey, rows;
432
- var _b, _c, _d, _e, _f, _g, _h, _j;
433
- var _this = this;
434
- return tslib_1.__generator(this, function (_k) {
435
- switch (_k.label) {
436
- case 0:
437
- data = selection.data, filter = selection.filter;
438
- projection = {};
439
- oneToMany = {};
440
- oneToManyOnEntity = {};
441
- manyToOne = {};
442
- manyToOneOnEntity = {};
443
- supportMtoJoin = this.supportManyToOneJoin();
444
- for (attr in data) {
445
- relation = (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
446
- if (relation === 1 || relation == 0) {
447
- Object.assign(projection, (_b = {},
448
- _b[attr] = data[attr],
449
- _b));
450
- }
451
- else if (relation === 2) {
452
- // 基于entity的多对一
453
- Object.assign(projection, {
454
- entity: 1,
455
- entityId: 1,
456
- });
457
- if (supportMtoJoin) {
458
- Object.assign(projection, (_c = {},
459
- _c[attr] = data[attr],
460
- _c));
461
- }
462
- else {
463
- Object.assign(manyToOneOnEntity, (_d = {},
464
- _d[attr] = 1,
465
- _d));
466
- }
467
- }
468
- else if (typeof relation === 'string') {
469
- // 基于属性的多对一
470
- if (supportMtoJoin) {
471
- Object.assign(projection, (_e = {},
472
- _e[attr] = data[attr],
473
- _e));
474
- }
475
- else {
476
- Object.assign(projection, (_f = {},
477
- _f["".concat(attr, "Id")] = 1,
478
- _f));
479
- Object.assign(manyToOne, (_g = {},
480
- _g[attr] = relation,
481
- _g));
482
- }
483
- }
484
- else {
485
- _a = tslib_1.__read(relation, 2), entity2 = _a[0], foreignKey = _a[1];
486
- if (foreignKey) {
487
- // 基于属性的一对多
488
- Object.assign(oneToMany, (_h = {},
489
- _h[attr] = {
490
- entity: entity2,
491
- foreignKey: foreignKey,
492
- },
493
- _h));
494
- }
495
- else {
496
- // 基于entity的多对一
497
- Object.assign(oneToManyOnEntity, (_j = {},
498
- _j[attr] = entity2,
499
- _j));
500
- }
501
- }
502
- }
503
- return [4 /*yield*/, this.selectAbjointRow(entity, Object.assign({}, selection, {
504
- data: projection,
505
- }), context, option)];
506
- case 1:
507
- rows = _k.sent();
508
- if (!option.dontCollect) {
509
- this.addToResultSelections(entity, rows, context);
510
- }
511
- return [4 /*yield*/, Promise.all(
512
- // manyToOne
513
- (function () {
514
- var attrs = Object.keys(manyToOne);
515
- if (attrs.length > 0) {
516
- return attrs.map(function (attr) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
517
- var subRows;
518
- return tslib_1.__generator(this, function (_a) {
519
- switch (_a.label) {
520
- case 0: return [4 /*yield*/, this.cascadeSelect(manyToOne[attr], {
521
- data: data[attr],
522
- filter: {
523
- id: {
524
- $in: rows.map(function (row) { return row["".concat(attr, "Id")]; })
525
- },
526
- }
527
- }, context, option)];
528
- case 1:
529
- subRows = _a.sent();
530
- rows.forEach(function (row) {
531
- var _a;
532
- var subRow = subRows.find(function (ele) { return ele.id === row["".concat(attr, "Id")]; });
533
- Object.assign(row, (_a = {},
534
- _a[attr] = subRow,
535
- _a));
536
- });
537
- return [2 /*return*/];
538
- }
539
- });
540
- }); });
541
- }
542
- return [];
543
- })().concat(
544
- // manyToOneOnEntity
545
- (function () {
546
- var attrs = Object.keys(manyToOneOnEntity);
547
- if (attrs.length > 0) {
548
- return attrs.map(function (attr) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
549
- var subRows;
550
- return tslib_1.__generator(this, function (_a) {
551
- switch (_a.label) {
552
- case 0: return [4 /*yield*/, this.cascadeSelect(attr, {
553
- data: data[attr],
554
- filter: {
555
- id: {
556
- $in: rows.filter(function (row) { return row.entity === attr; }).map(function (row) { return row.entityId; })
557
- },
558
- }
559
- }, context, option)];
560
- case 1:
561
- subRows = _a.sent();
562
- rows.filter(function (row) { return row.entity === attr; }).forEach(function (row) {
563
- var _a;
564
- var subRow = subRows.find(function (ele) { return ele.id === row.entityId; });
565
- Object.assign(row, (_a = {},
566
- _a[attr] = subRow,
567
- _a));
568
- });
569
- return [2 /*return*/];
570
- }
571
- });
572
- }); });
573
- }
574
- return [];
575
- })()).concat((function () {
576
- var attrs = Object.keys(oneToMany);
577
- if (attrs.length > 0) {
578
- // 必须一行一行的查询,否则indexFrom和count无法准确
579
- return rows.map(function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
580
- var _a, _b, _i, attr, _c, entity2, foreignKey, filter2, rows2;
581
- var _d, _e;
582
- return tslib_1.__generator(this, function (_f) {
583
- switch (_f.label) {
584
- case 0:
585
- _a = [];
586
- for (_b in oneToMany)
587
- _a.push(_b);
588
- _i = 0;
589
- _f.label = 1;
590
- case 1:
591
- if (!(_i < _a.length)) return [3 /*break*/, 4];
592
- attr = _a[_i];
593
- _c = oneToMany[attr], entity2 = _c.entity, foreignKey = _c.foreignKey;
594
- filter2 = data[attr];
595
- return [4 /*yield*/, this.cascadeSelect(entity2, Object.assign({}, filter2, {
596
- filter: (0, filter_1.addFilterSegment)((_d = {},
597
- _d[foreignKey] = row.id,
598
- _d), filter2.filter),
599
- }), context, option)];
600
- case 2:
601
- rows2 = _f.sent();
602
- Object.assign(row, (_e = {},
603
- _e[attr] = rows2,
604
- _e));
605
- _f.label = 3;
606
- case 3:
607
- _i++;
608
- return [3 /*break*/, 1];
609
- case 4: return [2 /*return*/];
610
- }
611
- });
612
- }); });
613
- }
614
- return [];
615
- })()).concat((function () {
616
- var attrs = Object.keys(oneToManyOnEntity);
617
- if (attrs.length > 0) {
618
- // 必须一行一行的查询,否则indexFrom和count无法准确
619
- return rows.map(function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
620
- var _a, _b, _i, attr, filter2, rows2;
621
- var _c;
622
- return tslib_1.__generator(this, function (_d) {
623
- switch (_d.label) {
624
- case 0:
625
- _a = [];
626
- for (_b in oneToManyOnEntity)
627
- _a.push(_b);
628
- _i = 0;
629
- _d.label = 1;
630
- case 1:
631
- if (!(_i < _a.length)) return [3 /*break*/, 4];
632
- attr = _a[_i];
633
- filter2 = data[attr];
634
- return [4 /*yield*/, this.cascadeSelect(oneToManyOnEntity[attr], Object.assign({}, filter2, {
635
- filter: (0, filter_1.addFilterSegment)({
636
- entityId: row.id,
637
- entity: entity,
638
- }, filter2.filter),
639
- }), context, option)];
640
- case 2:
641
- rows2 = _d.sent();
642
- Object.assign(row, (_c = {},
643
- _c[attr] = rows2,
644
- _c));
645
- _d.label = 3;
646
- case 3:
647
- _i++;
648
- return [3 /*break*/, 1];
649
- case 4: return [2 /*return*/];
650
- }
651
- });
652
- }); });
653
- }
654
- return [];
655
- })()))];
656
- case 2:
657
- _k.sent();
658
- return [2 /*return*/, rows];
659
- }
660
- });
661
- });
662
- };
663
- CascadeStore.prototype.destructCascadeUpdate = function (entity, action, data, context, option, result, filter) {
664
- return tslib_1.__awaiter(this, void 0, void 0, function () {
665
- var modiAttr, option2, opData, _loop_2, this_2, _a, _b, _i, attr;
666
- var _this = this;
667
- return tslib_1.__generator(this, function (_c) {
668
- switch (_c.label) {
669
- case 0:
670
- modiAttr = this.getSchema()[entity].toModi;
671
- option2 = Object.assign({}, option);
672
- opData = {};
673
- if (modiAttr && action !== 'remove' && !option.dontCreateModi) {
674
- // create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
675
- // delete此对象,所有的modi子对象应该通过触发器作废,这个通过系统的trigger来搞
676
- (0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
677
- if (action === 'create') {
678
- option2.modiParentId = data.id;
679
- }
680
- else {
681
- (0, assert_1.default)((filter === null || filter === void 0 ? void 0 : filter.id) && typeof filter.id === 'string');
682
- option2.modiParentId = filter.id;
683
- }
684
- option2.modiParentEntity = entity;
685
- }
686
- _loop_2 = function (attr) {
687
- var relation, operationMto, actionMto, dataMto, filterMto, fkId, entity_1, result2, operationMto, actionMto, dataMto, filterMto, _d, _e, fkId, result2, _f, entityOtm_1, foreignKey_2, otmOperations, dealWithOneToMany, otmOperations_1, otmOperations_1_1, oper, e_2_1;
688
- var _g, _h, _j, e_2, _k;
689
- return tslib_1.__generator(this, function (_l) {
690
- switch (_l.label) {
691
- case 0:
692
- relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
693
- if (!(relation === 1)) return [3 /*break*/, 1];
694
- Object.assign(opData, (_g = {},
695
- _g[attr] = data[attr],
696
- _g));
697
- return [3 /*break*/, 16];
698
- case 1:
699
- if (!(relation === 2)) return [3 /*break*/, 3];
700
- operationMto = data[attr];
701
- actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
702
- if (actionMto === 'create') {
703
- Object.assign(opData, {
704
- entityId: dataMto.id,
705
- entity: attr,
706
- });
707
- }
708
- else if (action === 'create') {
709
- fkId = data.entityId, entity_1 = data.entity;
710
- (0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
711
- if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
712
- // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
713
- (0, assert_1.default)(filterMto.id === fkId);
714
- }
715
- else {
716
- // A中data的entityId作为B中filter的主键
717
- Object.assign(operationMto, {
718
- filter: (0, filter_1.addFilterSegment)({
719
- id: fkId,
720
- }),
721
- filterMto: filterMto,
722
- });
723
- }
724
- }
725
- else {
726
- // 剩下三种情况都是B中的filter的id来自A中row的entityId
727
- (0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
728
- if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
729
- // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
730
- (0, assert_1.default)(typeof filterMto.id === 'string');
731
- }
732
- else {
733
- // A中data的entityId作为B中filter的主键
734
- Object.assign(operationMto, {
735
- filter: (0, filter_1.addFilterSegment)({
736
- id: {
737
- $in: {
738
- entity: entity,
739
- data: {
740
- entityId: 1,
741
- },
742
- filter: (0, filter_1.addFilterSegment)({
743
- entity: attr,
744
- }, filter),
745
- }
746
- },
747
- }, filterMto),
748
- });
749
- }
750
- }
751
- return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
752
- case 2:
753
- result2 = _l.sent();
754
- this_2.mergeOperationResult(result, result2);
755
- return [3 /*break*/, 16];
756
- case 3:
757
- if (!(typeof relation === 'string')) return [3 /*break*/, 5];
758
- operationMto = data[attr];
759
- actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
760
- if (actionMto === 'create') {
761
- Object.assign(opData, (_h = {},
762
- _h["".concat(attr, "Id")] = dataMto.id,
763
- _h));
764
- }
765
- else if (action === 'create') {
766
- _d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
767
- (0, assert_1.default)(typeof fkId === 'string');
768
- if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
769
- // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
770
- (0, assert_1.default)(filterMto.id === fkId);
771
- }
772
- else {
773
- // A中data的entityId作为B中filter的主键
774
- Object.assign(operationMto, {
775
- filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
776
- id: fkId,
777
- }),
778
- });
779
- }
780
- }
781
- else {
782
- (0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
783
- if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
784
- // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
785
- (0, assert_1.default)(typeof filterMto.id === 'string');
786
- }
787
- else {
788
- // A中data的entityId作为B中filter的主键
789
- Object.assign(operationMto, {
790
- filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
791
- id: {
792
- $in: {
793
- entity: entity,
794
- data: (_j = {},
795
- _j["".concat(attr, "Id")] = 1,
796
- _j),
797
- filter: filter,
798
- }
799
- },
800
- }),
801
- });
802
- }
803
- }
804
- return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
805
- case 4:
806
- result2 = _l.sent();
807
- this_2.mergeOperationResult(result, result2);
808
- return [3 /*break*/, 16];
809
- case 5:
810
- (0, assert_1.default)(relation instanceof Array);
811
- _f = tslib_1.__read(relation, 2), entityOtm_1 = _f[0], foreignKey_2 = _f[1];
812
- otmOperations = data[attr];
813
- dealWithOneToMany = function (otm) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
814
- var actionOtm, dataOtm, filterOtm, id_1, id_2, id, id_3, id_4, id, result2;
815
- var _a, _b, _c, _d;
816
- return tslib_1.__generator(this, function (_e) {
817
- switch (_e.label) {
818
- case 0:
819
- actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
820
- if (!foreignKey_2) {
821
- // 基于entity/entityId的one-to-many
822
- if (action === 'create') {
823
- id_1 = data.id;
824
- if (dataOtm instanceof Array) {
825
- dataOtm.forEach(function (ele) { return Object.assign(ele, {
826
- entity: entity,
827
- entityId: id_1,
828
- }); });
829
- }
830
- else {
831
- Object.assign(dataOtm, {
832
- entity: entity,
833
- entityId: id_1,
834
- });
835
- }
836
- }
837
- else if (actionOtm === 'create') {
838
- id_2 = filter.id;
839
- (0, assert_1.default)(typeof id_2 === 'string');
840
- if (dataOtm instanceof Array) {
841
- dataOtm.forEach(function (ele) { return Object.assign(ele, {
842
- entity: entity,
843
- entityId: id_2,
844
- }); });
845
- }
846
- else {
847
- Object.assign(dataOtm, {
848
- entity: entity,
849
- entityId: id_2,
850
- });
851
- }
852
- }
853
- else {
854
- id = filter.id;
855
- Object.assign(otm, {
856
- filter: (0, filter_1.addFilterSegment)({
857
- entity: entity,
858
- entityId: id,
859
- }, filterOtm),
860
- });
861
- if (action === 'remove' && actionOtm === 'update') {
862
- Object.assign(dataOtm, {
863
- entity: null,
864
- entityId: null,
865
- });
866
- }
867
- }
868
- }
869
- else {
870
- // 基于foreignKey的one-to-many
871
- if (action === 'create') {
872
- id_3 = data.id;
873
- if (dataOtm instanceof Array) {
874
- dataOtm.forEach(function (ele) {
875
- var _a;
876
- return Object.assign(ele, (_a = {},
877
- _a[foreignKey_2] = id_3,
878
- _a));
879
- });
880
- }
881
- else {
882
- Object.assign(dataOtm, (_a = {},
883
- _a[foreignKey_2] = id_3,
884
- _a));
885
- }
886
- }
887
- else if (actionOtm === 'create') {
888
- id_4 = filter.id;
889
- (0, assert_1.default)(typeof id_4 === 'string');
890
- if (dataOtm instanceof Array) {
891
- dataOtm.forEach(function (ele) {
892
- var _a;
893
- return Object.assign(ele, (_a = {},
894
- _a[foreignKey_2] = id_4,
895
- _a));
896
- });
897
- }
898
- else {
899
- Object.assign(dataOtm, (_b = {},
900
- _b[foreignKey_2] = id_4,
901
- _b));
902
- }
903
- }
904
- else {
905
- id = filter.id;
906
- Object.assign(otm, {
907
- filter: (0, filter_1.addFilterSegment)((_c = {},
908
- _c[foreignKey_2] = id,
909
- _c), filterOtm),
910
- });
911
- if (action === 'remove' && actionOtm === 'update') {
912
- Object.assign(dataOtm, (_d = {},
913
- _d[foreignKey_2] = null,
914
- _d));
915
- }
916
- }
917
- }
918
- return [4 /*yield*/, this.cascadeUpdate(entityOtm_1, otm, context, option2)];
919
- case 1:
920
- result2 = _e.sent();
921
- this.mergeOperationResult(result, result2);
922
- return [2 /*return*/];
923
- }
924
- });
925
- }); };
926
- if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
927
- _l.label = 6;
928
- case 6:
929
- _l.trys.push([6, 11, 12, 13]);
930
- otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
931
- _l.label = 7;
932
- case 7:
933
- if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
934
- oper = otmOperations_1_1.value;
935
- return [4 /*yield*/, dealWithOneToMany(oper)];
936
- case 8:
937
- _l.sent();
938
- _l.label = 9;
939
- case 9:
940
- otmOperations_1_1 = otmOperations_1.next();
941
- return [3 /*break*/, 7];
942
- case 10: return [3 /*break*/, 13];
943
- case 11:
944
- e_2_1 = _l.sent();
945
- e_2 = { error: e_2_1 };
946
- return [3 /*break*/, 13];
947
- case 12:
948
- try {
949
- if (otmOperations_1_1 && !otmOperations_1_1.done && (_k = otmOperations_1.return)) _k.call(otmOperations_1);
950
- }
951
- finally { if (e_2) throw e_2.error; }
952
- return [7 /*endfinally*/];
953
- case 13: return [3 /*break*/, 16];
954
- case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
955
- case 15:
956
- _l.sent();
957
- _l.label = 16;
958
- case 16: return [2 /*return*/];
959
- }
960
- });
961
- };
962
- this_2 = this;
963
- _a = [];
964
- for (_b in data)
965
- _a.push(_b);
966
- _i = 0;
967
- _c.label = 1;
968
- case 1:
969
- if (!(_i < _a.length)) return [3 /*break*/, 4];
970
- attr = _a[_i];
971
- return [5 /*yield**/, _loop_2(attr)];
972
- case 2:
973
- _c.sent();
974
- _c.label = 3;
975
- case 3:
976
- _i++;
977
- return [3 /*break*/, 1];
978
- case 4: return [2 /*return*/, opData];
979
- }
980
- });
981
- });
982
- };
983
288
  /**
984
289
  * 级联更新
985
290
  * A --> B
@@ -1004,69 +309,320 @@ var CascadeStore = /** @class */ (function (_super) {
1004
309
  * 两者必须通过entity/entityId关联
1005
310
  * 此时需要把对B的更新记录成一条新插入的Modi对象,并将A上的entity/entityId指向该对象(新生成的Modi对象的id与此operation的id保持一致)
1006
311
  * @param entity
1007
- * @param operation
312
+ * @param action
313
+ * @param data
1008
314
  * @param context
1009
315
  * @param option
316
+ * @param result
317
+ * @param filter
318
+ * @returns
1010
319
  */
1011
- CascadeStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
1012
- return tslib_1.__awaiter(this, void 0, void 0, function () {
1013
- var action, data, filter, id, opData, result, data_1, data_1_1, d, od, e_3_1, operation2, count;
1014
- var e_3, _a, _b, _c;
1015
- return tslib_1.__generator(this, function (_d) {
1016
- switch (_d.label) {
1017
- case 0:
1018
- action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
1019
- result = {};
1020
- if (!(['create', 'create-l'].includes(action) && data instanceof Array)) return [3 /*break*/, 9];
1021
- opData = [];
1022
- _d.label = 1;
1023
- case 1:
1024
- _d.trys.push([1, 6, 7, 8]);
1025
- data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
1026
- _d.label = 2;
1027
- case 2:
1028
- if (!!data_1_1.done) return [3 /*break*/, 5];
1029
- d = data_1_1.value;
1030
- return [4 /*yield*/, this.destructCascadeUpdate(entity, action, d, context, option, result)];
1031
- case 3:
1032
- od = _d.sent();
1033
- opData.push(od);
1034
- _d.label = 4;
1035
- case 4:
1036
- data_1_1 = data_1.next();
1037
- return [3 /*break*/, 2];
1038
- case 5: return [3 /*break*/, 8];
1039
- case 6:
1040
- e_3_1 = _d.sent();
1041
- e_3 = { error: e_3_1 };
1042
- return [3 /*break*/, 8];
1043
- case 7:
320
+ CascadeStore.prototype.destructCascadeUpdate = function (entity, action, data, context, option, cascadeUpdate, filter) {
321
+ var _this = this;
322
+ var modiAttr = this.getSchema()[entity].toModi;
323
+ var option2 = Object.assign({}, option);
324
+ var opData = {};
325
+ var beforeFns = [];
326
+ var afterFns = [];
327
+ if (modiAttr && action !== 'remove' && !option.dontCreateModi) {
328
+ // create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
329
+ // delete此对象,所有的modi子对象应该通过触发器作废,这个目前先通过系统的trigger来实现
330
+ (0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
331
+ if (action === 'create') {
332
+ option2.modiParentId = data.id;
333
+ }
334
+ else {
335
+ (0, assert_1.default)((filter === null || filter === void 0 ? void 0 : filter.id) && typeof filter.id === 'string');
336
+ option2.modiParentId = filter.id;
337
+ }
338
+ option2.modiParentEntity = entity;
339
+ }
340
+ var _loop_2 = function (attr) {
341
+ var _a, _b, _c, e_1, _d;
342
+ var relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
343
+ if (relation === 1) {
344
+ Object.assign(opData, (_a = {},
345
+ _a[attr] = data[attr],
346
+ _a));
347
+ }
348
+ else if (relation === 2) {
349
+ // 基于entity/entityId的many-to-one
350
+ var operationMto_1 = data[attr];
351
+ var actionMto = operationMto_1.action, dataMto = operationMto_1.data, filterMto = operationMto_1.filter;
352
+ if (actionMto === 'create') {
353
+ Object.assign(opData, {
354
+ entityId: dataMto.id,
355
+ entity: attr,
356
+ });
357
+ }
358
+ else if (action === 'create') {
359
+ var fkId = data.entityId, entity_1 = data.entity;
360
+ (0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
361
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
362
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
363
+ (0, assert_1.default)(filterMto.id === fkId);
364
+ }
365
+ else {
366
+ // A中data的entityId作为B中filter的主键
367
+ Object.assign(operationMto_1, {
368
+ filter: (0, filter_1.addFilterSegment)({
369
+ id: fkId,
370
+ }),
371
+ filterMto: filterMto,
372
+ });
373
+ }
374
+ }
375
+ else {
376
+ // 剩下三种情况都是B中的filter的id来自A中row的entityId
377
+ (0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
378
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
379
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
380
+ (0, assert_1.default)(typeof filterMto.id === 'string');
381
+ }
382
+ else {
383
+ // A中data的entityId作为B中filter的主键
384
+ Object.assign(operationMto_1, {
385
+ filter: (0, filter_1.addFilterSegment)({
386
+ id: {
387
+ $in: {
388
+ entity: entity,
389
+ data: {
390
+ entityId: 1,
391
+ },
392
+ filter: (0, filter_1.addFilterSegment)({
393
+ entity: attr,
394
+ }, filter),
395
+ }
396
+ },
397
+ }, filterMto),
398
+ });
399
+ }
400
+ }
401
+ beforeFns.push(function () { return cascadeUpdate.call(_this, attr, operationMto_1, context, option2); });
402
+ }
403
+ else if (typeof relation === 'string') {
404
+ // 基于attr的外键的many-to-one
405
+ var operationMto_2 = data[attr];
406
+ var actionMto = operationMto_2.action, dataMto = operationMto_2.data, filterMto = operationMto_2.filter;
407
+ if (actionMto === 'create') {
408
+ Object.assign(opData, (_b = {},
409
+ _b["".concat(attr, "Id")] = dataMto.id,
410
+ _b));
411
+ }
412
+ else if (action === 'create') {
413
+ var _e = data, _f = "".concat(attr, "Id"), fkId = _e[_f];
414
+ (0, assert_1.default)(typeof fkId === 'string');
415
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
416
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
417
+ (0, assert_1.default)(filterMto.id === fkId);
418
+ }
419
+ else {
420
+ // A中data的entityId作为B中filter的主键
421
+ Object.assign(operationMto_2, {
422
+ filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
423
+ id: fkId,
424
+ }),
425
+ });
426
+ }
427
+ }
428
+ else {
429
+ (0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
430
+ if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
431
+ // 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
432
+ (0, assert_1.default)(typeof filterMto.id === 'string');
433
+ }
434
+ else {
435
+ // A中data的entityId作为B中filter的主键
436
+ Object.assign(operationMto_2, {
437
+ filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
438
+ id: {
439
+ $in: {
440
+ entity: entity,
441
+ data: (_c = {},
442
+ _c["".concat(attr, "Id")] = 1,
443
+ _c),
444
+ filter: filter,
445
+ }
446
+ },
447
+ }),
448
+ });
449
+ }
450
+ }
451
+ beforeFns.push(function () { return cascadeUpdate.call(_this, relation, operationMto_2, context, option2); });
452
+ }
453
+ else {
454
+ (0, assert_1.default)(relation instanceof Array);
455
+ var _g = tslib_1.__read(relation, 2), entityOtm_1 = _g[0], foreignKey_2 = _g[1];
456
+ var otmOperations = data[attr];
457
+ var dealWithOneToMany = function (otm) {
458
+ var _a, _b, _c, _d;
459
+ var actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
460
+ if (!foreignKey_2) {
461
+ // 基于entity/entityId的one-to-many
462
+ if (action === 'create') {
463
+ var id_1 = data.id;
464
+ if (dataOtm instanceof Array) {
465
+ dataOtm.forEach(function (ele) { return Object.assign(ele, {
466
+ entity: entity,
467
+ entityId: id_1,
468
+ }); });
469
+ }
470
+ else {
471
+ Object.assign(dataOtm, {
472
+ entity: entity,
473
+ entityId: id_1,
474
+ });
475
+ }
476
+ }
477
+ else if (actionOtm === 'create') {
478
+ // 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
479
+ var id_2 = filter.id;
480
+ (0, assert_1.default)(typeof id_2 === 'string');
481
+ if (dataOtm instanceof Array) {
482
+ dataOtm.forEach(function (ele) { return Object.assign(ele, {
483
+ entity: entity,
484
+ entityId: id_2,
485
+ }); });
486
+ }
487
+ else {
488
+ Object.assign(dataOtm, {
489
+ entity: entity,
490
+ entityId: id_2,
491
+ });
492
+ }
493
+ }
494
+ else {
495
+ // 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
496
+ var id = filter.id;
497
+ Object.assign(otm, {
498
+ filter: (0, filter_1.addFilterSegment)({
499
+ entity: entity,
500
+ entityId: id,
501
+ }, filterOtm),
502
+ });
503
+ if (action === 'remove' && actionOtm === 'update') {
504
+ Object.assign(dataOtm, {
505
+ entity: null,
506
+ entityId: null,
507
+ });
508
+ }
509
+ }
510
+ }
511
+ else {
512
+ // 基于foreignKey的one-to-many
513
+ if (action === 'create') {
514
+ var id_3 = data.id;
515
+ if (dataOtm instanceof Array) {
516
+ dataOtm.forEach(function (ele) {
517
+ var _a;
518
+ return Object.assign(ele, (_a = {},
519
+ _a[foreignKey_2] = id_3,
520
+ _a));
521
+ });
522
+ }
523
+ else {
524
+ Object.assign(dataOtm, (_a = {},
525
+ _a[foreignKey_2] = id_3,
526
+ _a));
527
+ }
528
+ }
529
+ else if (actionOtm === 'create') {
530
+ // 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
531
+ var id_4 = filter.id;
532
+ (0, assert_1.default)(typeof id_4 === 'string');
533
+ if (dataOtm instanceof Array) {
534
+ dataOtm.forEach(function (ele) {
535
+ var _a;
536
+ return Object.assign(ele, (_a = {},
537
+ _a[foreignKey_2] = id_4,
538
+ _a));
539
+ });
540
+ }
541
+ else {
542
+ Object.assign(dataOtm, (_b = {},
543
+ _b[foreignKey_2] = id_4,
544
+ _b));
545
+ }
546
+ }
547
+ else {
548
+ // 这里先假设A(必是update)的filter上一定有id,否则用户界面上应该设计不出来这样的操作
549
+ var id = filter.id;
550
+ Object.assign(otm, {
551
+ filter: (0, filter_1.addFilterSegment)((_c = {},
552
+ _c[foreignKey_2] = id,
553
+ _c), filterOtm),
554
+ });
555
+ if (action === 'remove' && actionOtm === 'update') {
556
+ Object.assign(dataOtm, (_d = {},
557
+ _d[foreignKey_2] = null,
558
+ _d));
559
+ }
560
+ }
561
+ }
562
+ afterFns.push(function () { return cascadeUpdate.call(_this, entityOtm_1, otm, context, option2); });
563
+ };
564
+ if (otmOperations instanceof Array) {
565
+ try {
566
+ for (var otmOperations_1 = (e_1 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next(); !otmOperations_1_1.done; otmOperations_1_1 = otmOperations_1.next()) {
567
+ var oper = otmOperations_1_1.value;
568
+ dealWithOneToMany(oper);
569
+ }
570
+ }
571
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
572
+ finally {
1044
573
  try {
1045
- if (data_1_1 && !data_1_1.done && (_a = data_1.return)) _a.call(data_1);
574
+ if (otmOperations_1_1 && !otmOperations_1_1.done && (_d = otmOperations_1.return)) _d.call(otmOperations_1);
1046
575
  }
1047
- finally { if (e_3) throw e_3.error; }
1048
- return [7 /*endfinally*/];
1049
- case 8: return [3 /*break*/, 11];
1050
- case 9: return [4 /*yield*/, this.destructCascadeUpdate(entity, action, data, context, option, result, filter)];
1051
- case 10:
1052
- opData = _d.sent();
1053
- _d.label = 11;
1054
- case 11:
1055
- operation2 = Object.assign({}, operation, {
1056
- data: opData,
1057
- });
1058
- return [4 /*yield*/, this.doUpdateSingleRow(entity, operation2, context, option)];
1059
- case 12:
1060
- count = _d.sent();
1061
- this.mergeOperationResult(result, (_b = {},
1062
- _b[entity] = (_c = {},
1063
- _c[operation2.action] = count,
1064
- _c),
1065
- _b));
1066
- return [2 /*return*/, result];
576
+ finally { if (e_1) throw e_1.error; }
577
+ }
1067
578
  }
1068
- });
1069
- });
579
+ else {
580
+ dealWithOneToMany(otmOperations);
581
+ }
582
+ }
583
+ };
584
+ var this_2 = this;
585
+ for (var attr in data) {
586
+ _loop_2(attr);
587
+ }
588
+ return {
589
+ data: opData,
590
+ beforeFns: beforeFns,
591
+ afterFns: afterFns,
592
+ };
593
+ };
594
+ // 对插入的数据,没有初始值的属性置null
595
+ CascadeStore.prototype.preProcessDataCreated = function (entity, data) {
596
+ var now = Date.now();
597
+ var attributes = this.getSchema()[entity].attributes;
598
+ var processSingle = function (data2) {
599
+ var _a, _b;
600
+ for (var key in attributes) {
601
+ if (data2[key] === undefined) {
602
+ Object.assign(data2, (_a = {},
603
+ _a[key] = null,
604
+ _a));
605
+ }
606
+ }
607
+ Object.assign(data2, (_b = {},
608
+ _b[Entity_1.CreateAtAttribute] = now,
609
+ _b[Entity_1.UpdateAtAttribute] = now,
610
+ _b));
611
+ };
612
+ if (data instanceof Array) {
613
+ data.forEach(function (ele) { return processSingle(ele); });
614
+ }
615
+ else {
616
+ processSingle(data);
617
+ }
618
+ };
619
+ // 对更新的数据,去掉所有的undefined属性
620
+ CascadeStore.prototype.preProcessDataUpdated = function (data) {
621
+ var undefinedKeys = Object.keys(data).filter(function (ele) { return data[ele] === undefined; });
622
+ undefinedKeys.forEach(function (ele) { return (0, lodash_1.unset)(data, ele); });
623
+ };
624
+ CascadeStore.prototype.judgeRelation = function (entity, attr) {
625
+ return (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
1070
626
  };
1071
627
  /**
1072
628
  * 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
@@ -1075,10 +631,10 @@ var CascadeStore = /** @class */ (function (_super) {
1075
631
  * @param context
1076
632
  * @param option
1077
633
  */
1078
- CascadeStore.prototype.doUpdateSingleRow = function (entity, operation, context, option) {
634
+ CascadeStore.prototype.doUpdateSingleRowAsync = function (entity, operation, context, option) {
1079
635
  return tslib_1.__awaiter(this, void 0, void 0, function () {
1080
- var data, action, operId, filter, now, _a, modiCreate, addTimestamp_1, result_1, createInner, multipleCreate, data_2, data_2_1, d, createSingleOper, e_4_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, createOper, updateAttrCount, result_2;
1081
- var e_4, _d, _e, _f, _g, _h, _j, _k, _l, _m;
636
+ var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, createOper, updateAttrCount, result;
637
+ var e_2, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1082
638
  var _this = this;
1083
639
  return tslib_1.__generator(this, function (_o) {
1084
640
  switch (_o.label) {
@@ -1091,6 +647,7 @@ var CascadeStore = /** @class */ (function (_super) {
1091
647
  }
1092
648
  return [3 /*break*/, 23];
1093
649
  case 1:
650
+ this.preProcessDataCreated(entity, data);
1094
651
  if (!(option.modiParentEntity && !['modi', 'modiEntity', 'oper', 'operEntity'].includes(entity))) return [3 /*break*/, 3];
1095
652
  modiCreate = {
1096
653
  id: 'dummy',
@@ -1110,35 +667,25 @@ var CascadeStore = /** @class */ (function (_super) {
1110
667
  iState: 'active',
1111
668
  },
1112
669
  };
1113
- return [4 /*yield*/, this.cascadeUpdate('modi', modiCreate, context, option)];
670
+ return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiCreate, context, option)];
1114
671
  case 2:
1115
672
  _o.sent();
1116
673
  return [2 /*return*/, 1];
1117
674
  case 3:
1118
- addTimestamp_1 = function (data2) {
1119
- Object.assign(data2, {
1120
- $$createAt$$: now,
1121
- $$updateAt$$: now,
1122
- });
1123
- };
1124
- if (data instanceof Array) {
1125
- data.forEach(function (ele) { return addTimestamp_1(ele); });
1126
- }
1127
- else {
1128
- addTimestamp_1(data);
1129
- }
675
+ result_1 = 0;
1130
676
  createInner = function (operation2) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1131
- var e_5;
1132
- return tslib_1.__generator(this, function (_a) {
1133
- switch (_a.label) {
677
+ var _a, e_3;
678
+ return tslib_1.__generator(this, function (_b) {
679
+ switch (_b.label) {
1134
680
  case 0:
1135
- _a.trys.push([0, 2, , 3]);
1136
- return [4 /*yield*/, this.updateAbjointRow(entity, operation2, context, option)];
681
+ _b.trys.push([0, 2, , 3]);
682
+ _a = result_1;
683
+ return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation2, context, option)];
1137
684
  case 1:
1138
- result_1 = _a.sent();
685
+ result_1 = _a + _b.sent();
1139
686
  return [3 /*break*/, 3];
1140
687
  case 2:
1141
- e_5 = _a.sent();
688
+ e_3 = _b.sent();
1142
689
  /* 这段代码是处理插入时有重复的行,现在看有问题,等实际需求出现再写
1143
690
  if (e instanceof OakCongruentRowExists) {
1144
691
  if (option.allowExists) {
@@ -1202,7 +749,7 @@ var CascadeStore = /** @class */ (function (_super) {
1202
749
  }
1203
750
  }
1204
751
  } */
1205
- throw e_5;
752
+ throw e_3;
1206
753
  case 3: return [2 /*return*/];
1207
754
  }
1208
755
  });
@@ -1216,11 +763,11 @@ var CascadeStore = /** @class */ (function (_super) {
1216
763
  return [3 /*break*/, 12];
1217
764
  case 5:
1218
765
  _o.trys.push([5, 10, 11, 12]);
1219
- data_2 = tslib_1.__values(data), data_2_1 = data_2.next();
766
+ data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
1220
767
  _o.label = 6;
1221
768
  case 6:
1222
- if (!!data_2_1.done) return [3 /*break*/, 9];
1223
- d = data_2_1.value;
769
+ if (!!data_1_1.done) return [3 /*break*/, 9];
770
+ d = data_1_1.value;
1224
771
  createSingleOper = {
1225
772
  id: 'any',
1226
773
  action: 'create',
@@ -1231,18 +778,18 @@ var CascadeStore = /** @class */ (function (_super) {
1231
778
  _o.sent();
1232
779
  _o.label = 8;
1233
780
  case 8:
1234
- data_2_1 = data_2.next();
781
+ data_1_1 = data_1.next();
1235
782
  return [3 /*break*/, 6];
1236
783
  case 9: return [3 /*break*/, 12];
1237
784
  case 10:
1238
- e_4_1 = _o.sent();
1239
- e_4 = { error: e_4_1 };
785
+ e_2_1 = _o.sent();
786
+ e_2 = { error: e_2_1 };
1240
787
  return [3 /*break*/, 12];
1241
788
  case 11:
1242
789
  try {
1243
- if (data_2_1 && !data_2_1.done && (_d = data_2.return)) _d.call(data_2);
790
+ if (data_1_1 && !data_1_1.done && (_d = data_1.return)) _d.call(data_1);
1244
791
  }
1245
- finally { if (e_4) throw e_4.error; }
792
+ finally { if (e_2) throw e_2.error; }
1246
793
  return [7 /*endfinally*/];
1247
794
  case 12: return [3 /*break*/, 15];
1248
795
  case 13: return [4 /*yield*/, createInner(operation)];
@@ -1285,7 +832,7 @@ var CascadeStore = /** @class */ (function (_super) {
1285
832
  switch (_b.label) {
1286
833
  case 0:
1287
834
  _a = {};
1288
- return [4 /*yield*/, generateNewId()];
835
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
1289
836
  case 1: return [2 /*return*/, (_a.id = _b.sent(),
1290
837
  _a.entity = entity,
1291
838
  _a.entityId = ele.id,
@@ -1303,7 +850,7 @@ var CascadeStore = /** @class */ (function (_super) {
1303
850
  action: 'create'
1304
851
  };
1305
852
  _j = {};
1306
- return [4 /*yield*/, generateNewId()];
853
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
1307
854
  case 19:
1308
855
  _b = [(_h.data = (_j.id = _o.sent(),
1309
856
  _j.entity = entity,
@@ -1315,7 +862,7 @@ var CascadeStore = /** @class */ (function (_super) {
1315
862
  createOper = (_e.data = (_f.operEntity$oper = _b,
1316
863
  _f),
1317
864
  _e);
1318
- return [4 /*yield*/, this.cascadeUpdate('oper', createOper, context, {
865
+ return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper, context, {
1319
866
  dontCollect: true,
1320
867
  dontCreateOper: true,
1321
868
  })];
@@ -1324,7 +871,7 @@ var CascadeStore = /** @class */ (function (_super) {
1324
871
  _o.label = 22;
1325
872
  case 22: return [2 /*return*/, result_1];
1326
873
  case 23:
1327
- ids_1 = (0, filter_1.getRelevantIds)(filter);
874
+ ids_1 = (0, filter_2.getRelevantIds)(filter);
1328
875
  if (!(ids_1.length === 0)) return [3 /*break*/, 25];
1329
876
  selection = {
1330
877
  data: {
@@ -1334,7 +881,7 @@ var CascadeStore = /** @class */ (function (_super) {
1334
881
  indexFrom: operation.indexFrom,
1335
882
  count: operation.count,
1336
883
  };
1337
- return [4 /*yield*/, this.selectAbjointRow(entity, selection, context, {
884
+ return [4 /*yield*/, this.selectAbjointRowAsync(entity, selection, context, {
1338
885
  dontCollect: true,
1339
886
  })];
1340
887
  case 24:
@@ -1342,10 +889,13 @@ var CascadeStore = /** @class */ (function (_super) {
1342
889
  ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
1343
890
  _o.label = 25;
1344
891
  case 25:
892
+ if (data) {
893
+ this.preProcessDataUpdated(data);
894
+ }
1345
895
  if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/, 31];
1346
896
  modiUpsert = void 0;
1347
897
  if (!(action !== 'remove')) return [3 /*break*/, 27];
1348
- return [4 /*yield*/, this.selectAbjointRow('modi', {
898
+ return [4 /*yield*/, this.selectAbjointRowAsync('modi', {
1349
899
  data: {
1350
900
  id: 1,
1351
901
  data: 1,
@@ -1356,11 +906,11 @@ var CascadeStore = /** @class */ (function (_super) {
1356
906
  $in: ['create', 'update'],
1357
907
  },
1358
908
  iState: 'active',
1359
- filter: {
909
+ filter: ids_1.length > 0 ? {
1360
910
  id: {
1361
911
  $in: ids_1,
1362
912
  },
1363
- }
913
+ } : filter,
1364
914
  },
1365
915
  sorter: [
1366
916
  {
@@ -1403,11 +953,7 @@ var CascadeStore = /** @class */ (function (_super) {
1403
953
  action: action,
1404
954
  data: data,
1405
955
  iState: 'active',
1406
- filter: {
1407
- id: {
1408
- $in: ids_1,
1409
- },
1410
- }
956
+ filter: filter
1411
957
  };
1412
958
  _m = {
1413
959
  id: 'dummy',
@@ -1419,7 +965,7 @@ var CascadeStore = /** @class */ (function (_super) {
1419
965
  switch (_b.label) {
1420
966
  case 0:
1421
967
  _a = {};
1422
- return [4 /*yield*/, generateNewId()];
968
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
1423
969
  case 1: return [2 /*return*/, (_a.id = _b.sent(),
1424
970
  _a.entity = entity,
1425
971
  _a.entityId = id,
@@ -1433,7 +979,7 @@ var CascadeStore = /** @class */ (function (_super) {
1433
979
  _l),
1434
980
  _k);
1435
981
  _o.label = 29;
1436
- case 29: return [4 /*yield*/, this.cascadeUpdate('modi', modiUpsert, context, option)];
982
+ case 29: return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiUpsert, context, option)];
1437
983
  case 30:
1438
984
  _o.sent();
1439
985
  return [2 /*return*/, 1];
@@ -1467,7 +1013,7 @@ var CascadeStore = /** @class */ (function (_super) {
1467
1013
  switch (_b.label) {
1468
1014
  case 0:
1469
1015
  _a = {};
1470
- return [4 /*yield*/, generateNewId()];
1016
+ return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
1471
1017
  case 1: return [2 /*return*/, (_a.id = _b.sent(),
1472
1018
  _a.entity = entity,
1473
1019
  _a.entityId = ele,
@@ -1480,7 +1026,7 @@ var CascadeStore = /** @class */ (function (_super) {
1480
1026
  _c),
1481
1027
  _b),
1482
1028
  _a);
1483
- return [4 /*yield*/, this.cascadeUpdate('oper', createOper_1, context, {
1029
+ return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper_1, context, {
1484
1030
  dontCollect: true,
1485
1031
  dontCreateOper: true,
1486
1032
  })];
@@ -1533,19 +1079,432 @@ var CascadeStore = /** @class */ (function (_super) {
1533
1079
  _o.sent();
1534
1080
  return [2 /*return*/, 0];
1535
1081
  case 35: return [2 /*return*/, 0];
1536
- case 36: return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
1082
+ case 36: return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation, context, option)];
1537
1083
  case 37:
1538
- result_2 = _o.sent();
1084
+ result = _o.sent();
1539
1085
  return [4 /*yield*/, createOper()];
1540
1086
  case 38:
1541
1087
  _o.sent();
1542
- return [2 /*return*/, result_2];
1088
+ return [2 /*return*/, result];
1543
1089
  }
1544
1090
  });
1545
1091
  });
1546
1092
  };
1547
- CascadeStore.prototype.judgeRelation = function (entity, attr) {
1548
- return (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
1093
+ CascadeStore.prototype.doUpdateSingleRow = function (entity, operation, context, option) {
1094
+ var e_4, _a;
1095
+ var _this = this;
1096
+ var data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
1097
+ var now = Date.now();
1098
+ switch (action) {
1099
+ case 'create': {
1100
+ this.preProcessDataCreated(entity, data);
1101
+ var result_2 = 0;
1102
+ var createInner = function (operation2) {
1103
+ try {
1104
+ result_2 += _this.updateAbjointRow(entity, operation2, context, option);
1105
+ }
1106
+ catch (e) {
1107
+ throw e;
1108
+ }
1109
+ };
1110
+ if (data instanceof Array) {
1111
+ var multipleCreate = this.supportMultipleCreate();
1112
+ if (multipleCreate) {
1113
+ createInner(operation);
1114
+ }
1115
+ else {
1116
+ try {
1117
+ for (var data_2 = tslib_1.__values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
1118
+ var d = data_2_1.value;
1119
+ var createSingleOper = {
1120
+ id: 'any',
1121
+ action: 'create',
1122
+ data: d,
1123
+ };
1124
+ createInner(createSingleOper);
1125
+ }
1126
+ }
1127
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1128
+ finally {
1129
+ try {
1130
+ if (data_2_1 && !data_2_1.done && (_a = data_2.return)) _a.call(data_2);
1131
+ }
1132
+ finally { if (e_4) throw e_4.error; }
1133
+ }
1134
+ }
1135
+ }
1136
+ else {
1137
+ createInner(operation);
1138
+ }
1139
+ return result_2;
1140
+ }
1141
+ default: {
1142
+ if (action === 'remove') {
1143
+ }
1144
+ else {
1145
+ var updateAttrCount = Object.keys(data).length;
1146
+ if (updateAttrCount > 0) {
1147
+ // 优化一下,如果不更新任何属性,则不实际执行
1148
+ Object.assign(data, {
1149
+ $$updateAt$$: now,
1150
+ });
1151
+ this.preProcessDataUpdated(data);
1152
+ }
1153
+ else {
1154
+ return 0;
1155
+ }
1156
+ }
1157
+ return this.updateAbjointRow(entity, operation, context, option);
1158
+ }
1159
+ }
1160
+ };
1161
+ CascadeStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
1162
+ var e_5, _a, e_6, _b, e_7, _c;
1163
+ var action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
1164
+ var opData;
1165
+ var wholeBeforeFns = [];
1166
+ var wholeAfterFns = [];
1167
+ var result = {};
1168
+ if (['create', 'create-l'].includes(action) && data instanceof Array) {
1169
+ opData = [];
1170
+ try {
1171
+ for (var data_3 = tslib_1.__values(data), data_3_1 = data_3.next(); !data_3_1.done; data_3_1 = data_3.next()) {
1172
+ var d = data_3_1.value;
1173
+ var _d = this.destructCascadeUpdate(entity, action, d, context, option, this.cascadeUpdate), od = _d.data, beforeFns = _d.beforeFns, afterFns = _d.afterFns;
1174
+ opData.push(od);
1175
+ wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
1176
+ wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
1177
+ }
1178
+ }
1179
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1180
+ finally {
1181
+ try {
1182
+ if (data_3_1 && !data_3_1.done && (_a = data_3.return)) _a.call(data_3);
1183
+ }
1184
+ finally { if (e_5) throw e_5.error; }
1185
+ }
1186
+ }
1187
+ else {
1188
+ var _e = this.destructCascadeUpdate(entity, action, data, context, option, this.cascadeUpdate, filter), od = _e.data, beforeFns = _e.beforeFns, afterFns = _e.afterFns;
1189
+ opData = od;
1190
+ wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
1191
+ wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
1192
+ }
1193
+ var operation2 = Object.assign({}, operation, {
1194
+ data: opData,
1195
+ });
1196
+ try {
1197
+ for (var wholeBeforeFns_1 = tslib_1.__values(wholeBeforeFns), wholeBeforeFns_1_1 = wholeBeforeFns_1.next(); !wholeBeforeFns_1_1.done; wholeBeforeFns_1_1 = wholeBeforeFns_1.next()) {
1198
+ var before_1 = wholeBeforeFns_1_1.value;
1199
+ before_1();
1200
+ }
1201
+ }
1202
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
1203
+ finally {
1204
+ try {
1205
+ if (wholeBeforeFns_1_1 && !wholeBeforeFns_1_1.done && (_b = wholeBeforeFns_1.return)) _b.call(wholeBeforeFns_1);
1206
+ }
1207
+ finally { if (e_6) throw e_6.error; }
1208
+ }
1209
+ var count = this.doUpdateSingleRow(entity, operation2, context, option);
1210
+ try {
1211
+ for (var wholeAfterFns_1 = tslib_1.__values(wholeAfterFns), wholeAfterFns_1_1 = wholeAfterFns_1.next(); !wholeAfterFns_1_1.done; wholeAfterFns_1_1 = wholeAfterFns_1.next()) {
1212
+ var after_1 = wholeAfterFns_1_1.value;
1213
+ after_1();
1214
+ }
1215
+ }
1216
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
1217
+ finally {
1218
+ try {
1219
+ if (wholeAfterFns_1_1 && !wholeAfterFns_1_1.done && (_c = wholeAfterFns_1.return)) _c.call(wholeAfterFns_1);
1220
+ }
1221
+ finally { if (e_7) throw e_7.error; }
1222
+ }
1223
+ return result;
1224
+ };
1225
+ /**
1226
+ *
1227
+ * @param entity
1228
+ * @param operation
1229
+ * @param context
1230
+ * @param option
1231
+ */
1232
+ CascadeStore.prototype.cascadeUpdateAsync = function (entity, operation, context, option) {
1233
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1234
+ var action, data, filter, id, opData, wholeBeforeFns, wholeAfterFns, result, data_4, data_4_1, d, _a, od, beforeFns, afterFns, _b, od, beforeFns, afterFns, operation2, wholeBeforeFns_2, wholeBeforeFns_2_1, before_2, e_8_1, count, wholeAfterFns_2, wholeAfterFns_2_1, after_2, e_9_1;
1235
+ var e_10, _c, e_8, _d, _e, _f, e_9, _g;
1236
+ return tslib_1.__generator(this, function (_h) {
1237
+ switch (_h.label) {
1238
+ case 0:
1239
+ action = operation.action, data = operation.data, filter = operation.filter, id = operation.id;
1240
+ wholeBeforeFns = [];
1241
+ wholeAfterFns = [];
1242
+ result = {};
1243
+ if (['create', 'create-l'].includes(action) && data instanceof Array) {
1244
+ opData = [];
1245
+ try {
1246
+ for (data_4 = tslib_1.__values(data), data_4_1 = data_4.next(); !data_4_1.done; data_4_1 = data_4.next()) {
1247
+ d = data_4_1.value;
1248
+ _a = this.destructCascadeUpdate(entity, action, d, context, option, this.cascadeUpdateAsync), od = _a.data, beforeFns = _a.beforeFns, afterFns = _a.afterFns;
1249
+ opData.push(od);
1250
+ wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
1251
+ wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
1252
+ }
1253
+ }
1254
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
1255
+ finally {
1256
+ try {
1257
+ if (data_4_1 && !data_4_1.done && (_c = data_4.return)) _c.call(data_4);
1258
+ }
1259
+ finally { if (e_10) throw e_10.error; }
1260
+ }
1261
+ }
1262
+ else {
1263
+ _b = this.destructCascadeUpdate(entity, action, data, context, option, this.cascadeUpdateAsync, filter), od = _b.data, beforeFns = _b.beforeFns, afterFns = _b.afterFns;
1264
+ opData = od;
1265
+ wholeBeforeFns.push.apply(wholeBeforeFns, tslib_1.__spreadArray([], tslib_1.__read(beforeFns), false));
1266
+ wholeAfterFns.push.apply(wholeAfterFns, tslib_1.__spreadArray([], tslib_1.__read(afterFns), false));
1267
+ }
1268
+ operation2 = Object.assign({}, operation, {
1269
+ data: opData,
1270
+ });
1271
+ _h.label = 1;
1272
+ case 1:
1273
+ _h.trys.push([1, 6, 7, 8]);
1274
+ wholeBeforeFns_2 = tslib_1.__values(wholeBeforeFns), wholeBeforeFns_2_1 = wholeBeforeFns_2.next();
1275
+ _h.label = 2;
1276
+ case 2:
1277
+ if (!!wholeBeforeFns_2_1.done) return [3 /*break*/, 5];
1278
+ before_2 = wholeBeforeFns_2_1.value;
1279
+ return [4 /*yield*/, before_2()];
1280
+ case 3:
1281
+ _h.sent();
1282
+ _h.label = 4;
1283
+ case 4:
1284
+ wholeBeforeFns_2_1 = wholeBeforeFns_2.next();
1285
+ return [3 /*break*/, 2];
1286
+ case 5: return [3 /*break*/, 8];
1287
+ case 6:
1288
+ e_8_1 = _h.sent();
1289
+ e_8 = { error: e_8_1 };
1290
+ return [3 /*break*/, 8];
1291
+ case 7:
1292
+ try {
1293
+ if (wholeBeforeFns_2_1 && !wholeBeforeFns_2_1.done && (_d = wholeBeforeFns_2.return)) _d.call(wholeBeforeFns_2);
1294
+ }
1295
+ finally { if (e_8) throw e_8.error; }
1296
+ return [7 /*endfinally*/];
1297
+ case 8: return [4 /*yield*/, this.doUpdateSingleRowAsync(entity, operation2, context, option)];
1298
+ case 9:
1299
+ count = _h.sent();
1300
+ this.mergeOperationResult(result, (_e = {},
1301
+ _e[entity] = (_f = {},
1302
+ _f[operation2.action] = count,
1303
+ _f),
1304
+ _e));
1305
+ _h.label = 10;
1306
+ case 10:
1307
+ _h.trys.push([10, 15, 16, 17]);
1308
+ wholeAfterFns_2 = tslib_1.__values(wholeAfterFns), wholeAfterFns_2_1 = wholeAfterFns_2.next();
1309
+ _h.label = 11;
1310
+ case 11:
1311
+ if (!!wholeAfterFns_2_1.done) return [3 /*break*/, 14];
1312
+ after_2 = wholeAfterFns_2_1.value;
1313
+ return [4 /*yield*/, after_2()];
1314
+ case 12:
1315
+ _h.sent();
1316
+ _h.label = 13;
1317
+ case 13:
1318
+ wholeAfterFns_2_1 = wholeAfterFns_2.next();
1319
+ return [3 /*break*/, 11];
1320
+ case 14: return [3 /*break*/, 17];
1321
+ case 15:
1322
+ e_9_1 = _h.sent();
1323
+ e_9 = { error: e_9_1 };
1324
+ return [3 /*break*/, 17];
1325
+ case 16:
1326
+ try {
1327
+ if (wholeAfterFns_2_1 && !wholeAfterFns_2_1.done && (_g = wholeAfterFns_2.return)) _g.call(wholeAfterFns_2);
1328
+ }
1329
+ finally { if (e_9) throw e_9.error; }
1330
+ return [7 /*endfinally*/];
1331
+ case 17: return [2 /*return*/, result];
1332
+ }
1333
+ });
1334
+ });
1335
+ };
1336
+ CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
1337
+ var data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
1338
+ var _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelect, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
1339
+ var rows = this.selectAbjointRow(entity, {
1340
+ data: projection,
1341
+ filter: filter,
1342
+ indexFrom: indexFrom,
1343
+ count: count,
1344
+ sorter: sorter
1345
+ }, context, option);
1346
+ if (cascadeSelectionFns.length > 0) {
1347
+ var ruException_1 = [];
1348
+ cascadeSelectionFns.forEach(function (ele) {
1349
+ try {
1350
+ ele(rows);
1351
+ }
1352
+ catch (e) {
1353
+ if (e instanceof types_1.OakRowUnexistedException) {
1354
+ var rows_1 = e.getRows();
1355
+ ruException_1.push.apply(ruException_1, tslib_1.__spreadArray([], tslib_1.__read(rows_1), false));
1356
+ }
1357
+ else {
1358
+ throw e;
1359
+ }
1360
+ }
1361
+ });
1362
+ if (ruException_1.length > 0) {
1363
+ throw new types_1.OakRowUnexistedException(ruException_1);
1364
+ }
1365
+ }
1366
+ return rows;
1367
+ };
1368
+ /**
1369
+ * 将一次查询的结果集加入result
1370
+ * todo 如果是supportMtoOJoin,这里还要解构(未充分测试)
1371
+ * @param entity
1372
+ * @param rows
1373
+ * @param context
1374
+ */
1375
+ CascadeStore.prototype.addToResultSelections = function (entity, rows, context) {
1376
+ if (this.supportManyToOneJoin()) {
1377
+ var attrsToPick_1 = [];
1378
+ var _loop_3 = function (attr) {
1379
+ var data = {};
1380
+ var rel = this_3.judgeRelation(entity, attr);
1381
+ if (rel === 2) {
1382
+ this_3.addToResultSelections(attr, rows.map(function (ele) { return ele[attr]; }).filter(function (ele) { return !!ele; }), context);
1383
+ }
1384
+ else if (typeof rel === 'string') {
1385
+ this_3.addToResultSelections(rel, rows.map(function (ele) { return ele[attr]; }).filter(function (ele) { return !!ele; }), context);
1386
+ }
1387
+ else if (rel instanceof Array) {
1388
+ this_3.addToResultSelections(rel[0], rows.map(function (ele) { return ele[attr]; }).reduce(function (prev, current) { return prev.concat(current); }, []), context);
1389
+ }
1390
+ else {
1391
+ attrsToPick_1.push(attr);
1392
+ }
1393
+ };
1394
+ var this_3 = this;
1395
+ for (var attr in rows[0]) {
1396
+ _loop_3(attr);
1397
+ }
1398
+ var originRows = rows.map(function (ele) { return (0, lodash_1.pick)(ele, attrsToPick_1); });
1399
+ this.addSingleRowToResultSelections(entity, originRows, context);
1400
+ }
1401
+ else {
1402
+ this.addSingleRowToResultSelections(entity, rows, context);
1403
+ }
1404
+ };
1405
+ CascadeStore.prototype.addSingleRowToResultSelections = function (entity, rows, context) {
1406
+ var _a;
1407
+ var opRecords = context.opRecords;
1408
+ var lastOperation = opRecords[opRecords.length - 1];
1409
+ if (lastOperation && lastOperation.a === 's') {
1410
+ var entityBranch_1 = lastOperation.d[entity];
1411
+ if (entityBranch_1) {
1412
+ rows.forEach(function (row) {
1413
+ var _a;
1414
+ if (row) {
1415
+ (0, assert_1.default)(row.id);
1416
+ var id = row.id;
1417
+ if (!entityBranch_1[id]) {
1418
+ Object.assign(entityBranch_1, (_a = {},
1419
+ _a[id] = row,
1420
+ _a));
1421
+ }
1422
+ else {
1423
+ Object.assign(entityBranch_1[id], row);
1424
+ }
1425
+ }
1426
+ });
1427
+ return;
1428
+ }
1429
+ }
1430
+ else {
1431
+ lastOperation = {
1432
+ a: 's',
1433
+ d: {},
1434
+ };
1435
+ opRecords.push(lastOperation);
1436
+ }
1437
+ var entityBranch = {};
1438
+ rows.forEach(function (row) {
1439
+ var _a;
1440
+ if (row) {
1441
+ var id = row.id;
1442
+ Object.assign(entityBranch, (_a = {},
1443
+ _a[id] = row,
1444
+ _a));
1445
+ }
1446
+ });
1447
+ Object.assign(lastOperation.d, (_a = {},
1448
+ _a[entity] = entityBranch,
1449
+ _a));
1450
+ };
1451
+ CascadeStore.prototype.cascadeSelectAsync = function (entity, selection, context, option) {
1452
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
1453
+ var data, filter, indexFrom, count, sorter, _a, projection, cascadeSelectionFns, rows, ruException_2;
1454
+ var _this = this;
1455
+ return tslib_1.__generator(this, function (_b) {
1456
+ switch (_b.label) {
1457
+ case 0:
1458
+ data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
1459
+ _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelectAsync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
1460
+ return [4 /*yield*/, this.selectAbjointRowAsync(entity, {
1461
+ data: projection,
1462
+ filter: filter,
1463
+ indexFrom: indexFrom,
1464
+ count: count,
1465
+ sorter: sorter
1466
+ }, context, option)];
1467
+ case 1:
1468
+ rows = _b.sent();
1469
+ if (!option.dontCollect) {
1470
+ this.addToResultSelections(entity, rows, context);
1471
+ }
1472
+ if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 3];
1473
+ ruException_2 = [];
1474
+ return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
1475
+ var e_11, rows_2;
1476
+ return tslib_1.__generator(this, function (_a) {
1477
+ switch (_a.label) {
1478
+ case 0:
1479
+ _a.trys.push([0, 2, , 3]);
1480
+ return [4 /*yield*/, ele(rows)];
1481
+ case 1:
1482
+ _a.sent();
1483
+ return [3 /*break*/, 3];
1484
+ case 2:
1485
+ e_11 = _a.sent();
1486
+ if (e_11 instanceof types_1.OakRowUnexistedException) {
1487
+ rows_2 = e_11.getRows();
1488
+ ruException_2.push.apply(ruException_2, tslib_1.__spreadArray([], tslib_1.__read(rows_2), false));
1489
+ }
1490
+ else {
1491
+ throw e_11;
1492
+ }
1493
+ return [3 /*break*/, 3];
1494
+ case 3: return [2 /*return*/];
1495
+ }
1496
+ });
1497
+ }); }))];
1498
+ case 2:
1499
+ _b.sent();
1500
+ if (ruException_2.length > 0) {
1501
+ throw new types_1.OakRowUnexistedException(ruException_2);
1502
+ }
1503
+ _b.label = 3;
1504
+ case 3: return [2 /*return*/, rows];
1505
+ }
1506
+ });
1507
+ });
1549
1508
  };
1550
1509
  return CascadeStore;
1551
1510
  }(RowStore_1.RowStore));