oak-domain 1.1.13 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base-app-domain/Modi/Schema.d.ts +29 -32
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +24 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +24 -27
- package/lib/base-app-domain/OperEntity/Schema.d.ts +25 -28
- package/lib/base-app-domain/User/Schema.d.ts +22 -25
- package/lib/checkers/index.d.ts +4 -2
- package/lib/compiler/schemalBuilder.js +22 -24
- package/lib/store/AsyncRowStore.d.ts +45 -0
- package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
- package/lib/store/CascadeStore.d.ts +46 -20
- package/lib/store/CascadeStore.js +960 -996
- package/lib/store/SyncRowStore.d.ts +26 -0
- package/lib/store/SyncRowStore.js +45 -0
- package/lib/store/TriggerExecutor.d.ts +14 -14
- package/lib/store/TriggerExecutor.js +225 -238
- package/lib/store/actionDef.d.ts +5 -4
- package/lib/store/actionDef.js +44 -133
- package/lib/store/checker.d.ts +6 -0
- package/lib/store/checker.js +165 -0
- package/lib/store/filter.d.ts +5 -0
- package/lib/store/filter.js +395 -3
- package/lib/store/modi.d.ts +7 -6
- package/lib/store/modi.js +35 -46
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/selection.js +1 -0
- package/lib/triggers/index.d.ts +4 -3
- package/lib/triggers/modi.d.ts +2 -2
- package/lib/triggers/modi.js +5 -5
- package/lib/types/AppLoader.d.ts +3 -3
- package/lib/types/Aspect.d.ts +3 -3
- package/lib/types/Auth.d.ts +25 -22
- package/lib/types/Connector.d.ts +7 -7
- package/lib/types/Context.d.ts +4 -14
- package/lib/types/DataType.d.ts +1 -0
- package/lib/types/Entity.d.ts +26 -18
- package/lib/types/Entity.js +9 -2
- package/lib/types/Exception.d.ts +6 -1
- package/lib/types/Exception.js +30 -13
- package/lib/types/RowStore.d.ts +2 -13
- package/lib/types/RowStore.js +1 -6
- package/lib/types/Storage.d.ts +1 -0
- package/lib/types/Trigger.d.ts +32 -48
- package/lib/types/Trigger.js +24 -9
- package/lib/types/Watcher.d.ts +7 -8
- package/lib/types/schema/DataTypes.d.ts +1 -1
- package/lib/utils/SimpleConnector.d.ts +9 -8
- package/lib/utils/SimpleConnector.js +4 -5
- package/lib/utils/random/random.d.ts +1 -0
- package/lib/utils/random/random.js +24 -0
- package/lib/utils/random/random.mp.d.ts +1 -0
- package/lib/utils/random/random.mp.js +25 -0
- package/lib/utils/random/random.web.d.ts +1 -0
- package/lib/utils/random/random.web.js +17 -0
- package/lib/utils/string.d.ts +20 -0
- package/lib/utils/string.js +60 -1
- package/lib/utils/uuid.d.ts +10 -0
- package/lib/utils/uuid.js +172 -1
- package/lib/utils/validator.d.ts +2 -2
- package/lib/utils/validator.js +5 -5
- package/package.json +5 -3
- package/lib/OakError.d.ts +0 -7
- package/lib/OakError.js +0 -15
- package/lib/compiler/utils.d.ts +0 -2
- package/lib/compiler/utils.js +0 -11
- package/lib/entities/Action.d.ts +0 -12
- package/lib/entities/Action.js +0 -17
- package/lib/entities/Ooperation.d.ts +0 -12
- package/lib/entities/Ooperation.js +0 -17
- package/lib/entities/Update.d.ts +0 -9
- package/lib/entities/Update.js +0 -44
- package/lib/entities/Uupdate.d.ts +0 -9
- package/lib/entities/Uupdate.js +0 -44
- package/lib/store/UniversalContext.d.ts +0 -32
- package/lib/store/action.d.ts +0 -6
- package/lib/store/action.js +0 -14
- package/lib/store/projection.d.ts +0 -7
- package/lib/store/projection.js +0 -211
- package/lib/store/watchers.d.ts +0 -2
- package/lib/store/watchers.js +0 -32
|
@@ -3,78 +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
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
lastOperation = {
|
|
44
|
-
a: 's',
|
|
45
|
-
d: {},
|
|
46
|
-
};
|
|
47
|
-
opRecords.push(lastOperation);
|
|
48
|
-
}
|
|
49
|
-
var entityBranch = {};
|
|
50
|
-
rows.forEach(function (row) {
|
|
51
|
-
var _a;
|
|
52
|
-
var id = row.id;
|
|
53
|
-
Object.assign(entityBranch, (_a = {},
|
|
54
|
-
_a[id] = (0, lodash_1.cloneDeep)(row),
|
|
55
|
-
_a));
|
|
56
|
-
});
|
|
57
|
-
Object.assign(lastOperation.d, (_a = {},
|
|
58
|
-
_a[entity] = entityBranch,
|
|
59
|
-
_a));
|
|
60
|
-
};
|
|
61
|
-
CascadeStore.prototype.reduceDescendants = function (entity, rows) {
|
|
62
|
-
var _this = this;
|
|
63
|
-
return rows.filter(function (ele) { return !!ele; }).map(function (row) {
|
|
64
|
-
var _a;
|
|
65
|
-
var row2 = {};
|
|
66
|
-
for (var attr in row) {
|
|
67
|
-
var rel = _this.judgeRelation(entity, attr);
|
|
68
|
-
if (typeof rel === 'number' && [0, 1].includes(rel)) {
|
|
69
|
-
Object.assign(row2, (_a = {},
|
|
70
|
-
_a[attr] = row[attr],
|
|
71
|
-
_a));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return row2;
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, option) {
|
|
20
|
+
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelect, option) {
|
|
78
21
|
var _this = this;
|
|
79
22
|
var projection = {};
|
|
80
23
|
var cascadeSelectionFns = [];
|
|
@@ -95,93 +38,84 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
95
38
|
entityId: 1,
|
|
96
39
|
});
|
|
97
40
|
if (supportMtoJoin) {
|
|
98
|
-
cascadeSelectionFns.push(function (result) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
id: ele.entityId,
|
|
111
|
-
}
|
|
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,
|
|
112
53
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
54
|
+
}
|
|
55
|
+
}]);
|
|
115
56
|
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
}); });
|
|
124
|
-
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;
|
|
125
62
|
Object.assign(projection, (_b = {},
|
|
126
63
|
_b[attr] = subProjection,
|
|
127
64
|
_b));
|
|
128
|
-
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
case 0: return [4 /*yield*/, ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }))];
|
|
132
|
-
case 1:
|
|
133
|
-
_a.sent();
|
|
134
|
-
return [2 /*return*/];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}); }); });
|
|
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
|
+
}); });
|
|
138
68
|
}
|
|
139
69
|
else {
|
|
140
|
-
cascadeSelectionFns.push(function (result) {
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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: {
|
|
147
77
|
data: projection2[attr],
|
|
148
78
|
filter: {
|
|
149
79
|
id: {
|
|
150
80
|
$in: entityIds
|
|
151
81
|
},
|
|
152
82
|
},
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
subRows = _a.sent();
|
|
156
|
-
(0, assert_1.default)(subRows.length <= entityIds.length);
|
|
157
|
-
if (subRows.length < entityIds.length && !toModi) {
|
|
158
|
-
throw new types_1.OakRowUnexistedException([{
|
|
159
|
-
entity: attr,
|
|
160
|
-
selection: {
|
|
161
|
-
data: projection2[attr],
|
|
162
|
-
filter: {
|
|
163
|
-
id: {
|
|
164
|
-
$in: entityIds
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
}]);
|
|
169
|
-
}
|
|
170
|
-
result.forEach(function (ele) {
|
|
171
|
-
var _a;
|
|
172
|
-
if (ele.entity === attr) {
|
|
173
|
-
var subRow = subRows.find(function (ele2) { return ele2.id === ele.entityId; });
|
|
174
|
-
if (subRow) {
|
|
175
|
-
Object.assign(ele, (_a = {},
|
|
176
|
-
_a[attr] = subRow,
|
|
177
|
-
_a));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
return [2 /*return*/];
|
|
83
|
+
},
|
|
84
|
+
}]);
|
|
182
85
|
}
|
|
183
|
-
|
|
184
|
-
|
|
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
|
+
});
|
|
185
119
|
}
|
|
186
120
|
}
|
|
187
121
|
else if (typeof relation === 'string') {
|
|
@@ -191,91 +125,85 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
191
125
|
if (supportMtoJoin) {
|
|
192
126
|
if (!toModi) {
|
|
193
127
|
// 如果不是modi,要保证外键没有空指针
|
|
194
|
-
cascadeSelectionFns.push(function (result) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
id: ele["".concat(attr, "Id")],
|
|
205
|
-
}
|
|
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")],
|
|
206
138
|
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
return [2 /*return*/];
|
|
215
|
-
});
|
|
216
|
-
}); });
|
|
139
|
+
}
|
|
140
|
+
}]);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
217
145
|
}
|
|
218
|
-
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;
|
|
219
147
|
Object.assign(projection, (_d = {},
|
|
220
148
|
_d[attr] = subProjection,
|
|
221
149
|
_d));
|
|
222
|
-
subCascadeSelectionFns.forEach(function (ele) { return cascadeSelectionFns.push(function (result) {
|
|
223
|
-
return
|
|
224
|
-
|
|
225
|
-
case 0: return [4 /*yield*/, ele(result.map(function (ele2) { return ele2[attr]; }).filter(function (ele2) { return !!ele2; }))];
|
|
226
|
-
case 1:
|
|
227
|
-
_a.sent();
|
|
228
|
-
return [2 /*return*/];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}); }); });
|
|
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
|
+
}); });
|
|
232
153
|
}
|
|
233
154
|
else {
|
|
234
|
-
cascadeSelectionFns.push(function (result) {
|
|
235
|
-
var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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: {
|
|
241
162
|
data: projection2[attr],
|
|
242
163
|
filter: {
|
|
243
164
|
id: {
|
|
244
165
|
$in: ids
|
|
245
166
|
},
|
|
246
167
|
},
|
|
247
|
-
}, context, option)];
|
|
248
|
-
case 1:
|
|
249
|
-
subRows = _a.sent();
|
|
250
|
-
(0, assert_1.default)(subRows.length <= ids.length);
|
|
251
|
-
if (subRows.length < ids.length && !toModi) {
|
|
252
|
-
throw new types_1.OakRowUnexistedException([{
|
|
253
|
-
entity: relation,
|
|
254
|
-
selection: {
|
|
255
|
-
data: projection2[attr],
|
|
256
|
-
filter: {
|
|
257
|
-
id: {
|
|
258
|
-
$in: ids
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
}
|
|
262
|
-
}]);
|
|
263
|
-
}
|
|
264
|
-
result.forEach(function (ele) {
|
|
265
|
-
var _a;
|
|
266
|
-
if (ele["".concat(attr, "Id")]) {
|
|
267
|
-
var subRow = subRows.find(function (ele2) { return ele2.id === ele["".concat(attr, "Id")]; });
|
|
268
|
-
if (subRow) {
|
|
269
|
-
Object.assign(ele, (_a = {},
|
|
270
|
-
_a[attr] = subRow,
|
|
271
|
-
_a));
|
|
272
|
-
}
|
|
273
168
|
}
|
|
274
|
-
});
|
|
275
|
-
return [2 /*return*/];
|
|
169
|
+
}]);
|
|
276
170
|
}
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
});
|
|
279
207
|
}
|
|
280
208
|
}
|
|
281
209
|
else {
|
|
@@ -284,73 +212,67 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
284
212
|
var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
|
|
285
213
|
if (foreignKey_1) {
|
|
286
214
|
// 基于属性的一对多
|
|
287
|
-
cascadeSelectionFns.push(function (result) {
|
|
288
|
-
var ids, subRows;
|
|
215
|
+
cascadeSelectionFns.push(function (result) {
|
|
289
216
|
var _a;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
});
|
|
318
|
-
}); });
|
|
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
|
+
});
|
|
319
244
|
}
|
|
320
245
|
else {
|
|
321
246
|
// 基于entity的多对一
|
|
322
|
-
cascadeSelectionFns.push(function (result) {
|
|
323
|
-
var ids
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
}); });
|
|
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
|
+
});
|
|
354
276
|
}
|
|
355
277
|
}
|
|
356
278
|
};
|
|
@@ -363,620 +285,6 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
363
285
|
cascadeSelectionFns: cascadeSelectionFns,
|
|
364
286
|
};
|
|
365
287
|
};
|
|
366
|
-
CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
|
|
367
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
368
|
-
var data, filter, indexFrom, count, sorter, _a, projection, cascadeSelectionFns, rows, ruException_1;
|
|
369
|
-
var _this = this;
|
|
370
|
-
return tslib_1.__generator(this, function (_b) {
|
|
371
|
-
switch (_b.label) {
|
|
372
|
-
case 0:
|
|
373
|
-
data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
|
|
374
|
-
return [4 /*yield*/, this.destructCascadeSelect(entity, data, context, option)];
|
|
375
|
-
case 1:
|
|
376
|
-
_a = _b.sent(), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
377
|
-
return [4 /*yield*/, this.selectAbjointRow(entity, {
|
|
378
|
-
data: projection,
|
|
379
|
-
filter: filter,
|
|
380
|
-
indexFrom: indexFrom,
|
|
381
|
-
count: count,
|
|
382
|
-
sorter: sorter
|
|
383
|
-
}, context, option)];
|
|
384
|
-
case 2:
|
|
385
|
-
rows = _b.sent();
|
|
386
|
-
if (!option.dontCollect) {
|
|
387
|
-
this.addToResultSelections(entity, this.supportMultipleCreate() ? this.reduceDescendants(entity, rows) : rows, context);
|
|
388
|
-
}
|
|
389
|
-
if (!(cascadeSelectionFns.length > 0)) return [3 /*break*/, 4];
|
|
390
|
-
ruException_1 = [];
|
|
391
|
-
return [4 /*yield*/, Promise.all(cascadeSelectionFns.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
392
|
-
var e_1, rows_1;
|
|
393
|
-
return tslib_1.__generator(this, function (_a) {
|
|
394
|
-
switch (_a.label) {
|
|
395
|
-
case 0:
|
|
396
|
-
_a.trys.push([0, 2, , 3]);
|
|
397
|
-
return [4 /*yield*/, ele(rows)];
|
|
398
|
-
case 1:
|
|
399
|
-
_a.sent();
|
|
400
|
-
return [3 /*break*/, 3];
|
|
401
|
-
case 2:
|
|
402
|
-
e_1 = _a.sent();
|
|
403
|
-
if (e_1 instanceof types_1.OakRowUnexistedException) {
|
|
404
|
-
rows_1 = e_1.getRows();
|
|
405
|
-
ruException_1.push.apply(ruException_1, tslib_1.__spreadArray([], tslib_1.__read(rows_1), false));
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
throw e_1;
|
|
409
|
-
}
|
|
410
|
-
return [3 /*break*/, 3];
|
|
411
|
-
case 3: return [2 /*return*/];
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
}); }))];
|
|
415
|
-
case 3:
|
|
416
|
-
_b.sent();
|
|
417
|
-
if (ruException_1.length > 0) {
|
|
418
|
-
throw new types_1.OakRowUnexistedException(ruException_1);
|
|
419
|
-
}
|
|
420
|
-
_b.label = 4;
|
|
421
|
-
case 4: return [2 /*return*/, rows];
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
};
|
|
426
|
-
CascadeStore.prototype.cascadeSelect2 = function (entity, selection, context, option) {
|
|
427
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
428
|
-
var data, filter, projection, oneToMany, oneToManyOnEntity, manyToOne, manyToOneOnEntity, supportMtoJoin, attr, relation, _a, entity2, foreignKey, rows;
|
|
429
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
430
|
-
var _this = this;
|
|
431
|
-
return tslib_1.__generator(this, function (_k) {
|
|
432
|
-
switch (_k.label) {
|
|
433
|
-
case 0:
|
|
434
|
-
data = selection.data, filter = selection.filter;
|
|
435
|
-
projection = {};
|
|
436
|
-
oneToMany = {};
|
|
437
|
-
oneToManyOnEntity = {};
|
|
438
|
-
manyToOne = {};
|
|
439
|
-
manyToOneOnEntity = {};
|
|
440
|
-
supportMtoJoin = this.supportManyToOneJoin();
|
|
441
|
-
for (attr in data) {
|
|
442
|
-
relation = (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
|
|
443
|
-
if (relation === 1 || relation == 0) {
|
|
444
|
-
Object.assign(projection, (_b = {},
|
|
445
|
-
_b[attr] = data[attr],
|
|
446
|
-
_b));
|
|
447
|
-
}
|
|
448
|
-
else if (relation === 2) {
|
|
449
|
-
// 基于entity的多对一
|
|
450
|
-
Object.assign(projection, {
|
|
451
|
-
entity: 1,
|
|
452
|
-
entityId: 1,
|
|
453
|
-
});
|
|
454
|
-
if (supportMtoJoin) {
|
|
455
|
-
Object.assign(projection, (_c = {},
|
|
456
|
-
_c[attr] = data[attr],
|
|
457
|
-
_c));
|
|
458
|
-
}
|
|
459
|
-
else {
|
|
460
|
-
Object.assign(manyToOneOnEntity, (_d = {},
|
|
461
|
-
_d[attr] = 1,
|
|
462
|
-
_d));
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
else if (typeof relation === 'string') {
|
|
466
|
-
// 基于属性的多对一
|
|
467
|
-
if (supportMtoJoin) {
|
|
468
|
-
Object.assign(projection, (_e = {},
|
|
469
|
-
_e[attr] = data[attr],
|
|
470
|
-
_e));
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
Object.assign(projection, (_f = {},
|
|
474
|
-
_f["".concat(attr, "Id")] = 1,
|
|
475
|
-
_f));
|
|
476
|
-
Object.assign(manyToOne, (_g = {},
|
|
477
|
-
_g[attr] = relation,
|
|
478
|
-
_g));
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
_a = tslib_1.__read(relation, 2), entity2 = _a[0], foreignKey = _a[1];
|
|
483
|
-
if (foreignKey) {
|
|
484
|
-
// 基于属性的一对多
|
|
485
|
-
Object.assign(oneToMany, (_h = {},
|
|
486
|
-
_h[attr] = {
|
|
487
|
-
entity: entity2,
|
|
488
|
-
foreignKey: foreignKey,
|
|
489
|
-
},
|
|
490
|
-
_h));
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
// 基于entity的多对一
|
|
494
|
-
Object.assign(oneToManyOnEntity, (_j = {},
|
|
495
|
-
_j[attr] = entity2,
|
|
496
|
-
_j));
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return [4 /*yield*/, this.selectAbjointRow(entity, Object.assign({}, selection, {
|
|
501
|
-
data: projection,
|
|
502
|
-
}), context, option)];
|
|
503
|
-
case 1:
|
|
504
|
-
rows = _k.sent();
|
|
505
|
-
if (!option.dontCollect) {
|
|
506
|
-
this.addToResultSelections(entity, rows, context);
|
|
507
|
-
}
|
|
508
|
-
return [4 /*yield*/, Promise.all(
|
|
509
|
-
// manyToOne
|
|
510
|
-
(function () {
|
|
511
|
-
var attrs = Object.keys(manyToOne);
|
|
512
|
-
if (attrs.length > 0) {
|
|
513
|
-
return attrs.map(function (attr) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
514
|
-
var subRows;
|
|
515
|
-
return tslib_1.__generator(this, function (_a) {
|
|
516
|
-
switch (_a.label) {
|
|
517
|
-
case 0: return [4 /*yield*/, this.cascadeSelect(manyToOne[attr], {
|
|
518
|
-
data: data[attr],
|
|
519
|
-
filter: {
|
|
520
|
-
id: {
|
|
521
|
-
$in: rows.map(function (row) { return row["".concat(attr, "Id")]; })
|
|
522
|
-
},
|
|
523
|
-
}
|
|
524
|
-
}, context, option)];
|
|
525
|
-
case 1:
|
|
526
|
-
subRows = _a.sent();
|
|
527
|
-
rows.forEach(function (row) {
|
|
528
|
-
var _a;
|
|
529
|
-
var subRow = subRows.find(function (ele) { return ele.id === row["".concat(attr, "Id")]; });
|
|
530
|
-
Object.assign(row, (_a = {},
|
|
531
|
-
_a[attr] = subRow,
|
|
532
|
-
_a));
|
|
533
|
-
});
|
|
534
|
-
return [2 /*return*/];
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
}); });
|
|
538
|
-
}
|
|
539
|
-
return [];
|
|
540
|
-
})().concat(
|
|
541
|
-
// manyToOneOnEntity
|
|
542
|
-
(function () {
|
|
543
|
-
var attrs = Object.keys(manyToOneOnEntity);
|
|
544
|
-
if (attrs.length > 0) {
|
|
545
|
-
return attrs.map(function (attr) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
546
|
-
var subRows;
|
|
547
|
-
return tslib_1.__generator(this, function (_a) {
|
|
548
|
-
switch (_a.label) {
|
|
549
|
-
case 0: return [4 /*yield*/, this.cascadeSelect(attr, {
|
|
550
|
-
data: data[attr],
|
|
551
|
-
filter: {
|
|
552
|
-
id: {
|
|
553
|
-
$in: rows.filter(function (row) { return row.entity === attr; }).map(function (row) { return row.entityId; })
|
|
554
|
-
},
|
|
555
|
-
}
|
|
556
|
-
}, context, option)];
|
|
557
|
-
case 1:
|
|
558
|
-
subRows = _a.sent();
|
|
559
|
-
rows.filter(function (row) { return row.entity === attr; }).forEach(function (row) {
|
|
560
|
-
var _a;
|
|
561
|
-
var subRow = subRows.find(function (ele) { return ele.id === row.entityId; });
|
|
562
|
-
Object.assign(row, (_a = {},
|
|
563
|
-
_a[attr] = subRow,
|
|
564
|
-
_a));
|
|
565
|
-
});
|
|
566
|
-
return [2 /*return*/];
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
}); });
|
|
570
|
-
}
|
|
571
|
-
return [];
|
|
572
|
-
})()).concat((function () {
|
|
573
|
-
var attrs = Object.keys(oneToMany);
|
|
574
|
-
if (attrs.length > 0) {
|
|
575
|
-
// 必须一行一行的查询,否则indexFrom和count无法准确
|
|
576
|
-
return rows.map(function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
577
|
-
var _a, _b, _i, attr, _c, entity2, foreignKey, filter2, rows2;
|
|
578
|
-
var _d, _e;
|
|
579
|
-
return tslib_1.__generator(this, function (_f) {
|
|
580
|
-
switch (_f.label) {
|
|
581
|
-
case 0:
|
|
582
|
-
_a = [];
|
|
583
|
-
for (_b in oneToMany)
|
|
584
|
-
_a.push(_b);
|
|
585
|
-
_i = 0;
|
|
586
|
-
_f.label = 1;
|
|
587
|
-
case 1:
|
|
588
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
589
|
-
attr = _a[_i];
|
|
590
|
-
_c = oneToMany[attr], entity2 = _c.entity, foreignKey = _c.foreignKey;
|
|
591
|
-
filter2 = data[attr];
|
|
592
|
-
return [4 /*yield*/, this.cascadeSelect(entity2, Object.assign({}, filter2, {
|
|
593
|
-
filter: (0, filter_1.addFilterSegment)((_d = {},
|
|
594
|
-
_d[foreignKey] = row.id,
|
|
595
|
-
_d), filter2.filter),
|
|
596
|
-
}), context, option)];
|
|
597
|
-
case 2:
|
|
598
|
-
rows2 = _f.sent();
|
|
599
|
-
Object.assign(row, (_e = {},
|
|
600
|
-
_e[attr] = rows2,
|
|
601
|
-
_e));
|
|
602
|
-
_f.label = 3;
|
|
603
|
-
case 3:
|
|
604
|
-
_i++;
|
|
605
|
-
return [3 /*break*/, 1];
|
|
606
|
-
case 4: return [2 /*return*/];
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
}); });
|
|
610
|
-
}
|
|
611
|
-
return [];
|
|
612
|
-
})()).concat((function () {
|
|
613
|
-
var attrs = Object.keys(oneToManyOnEntity);
|
|
614
|
-
if (attrs.length > 0) {
|
|
615
|
-
// 必须一行一行的查询,否则indexFrom和count无法准确
|
|
616
|
-
return rows.map(function (row) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
617
|
-
var _a, _b, _i, attr, filter2, rows2;
|
|
618
|
-
var _c;
|
|
619
|
-
return tslib_1.__generator(this, function (_d) {
|
|
620
|
-
switch (_d.label) {
|
|
621
|
-
case 0:
|
|
622
|
-
_a = [];
|
|
623
|
-
for (_b in oneToManyOnEntity)
|
|
624
|
-
_a.push(_b);
|
|
625
|
-
_i = 0;
|
|
626
|
-
_d.label = 1;
|
|
627
|
-
case 1:
|
|
628
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
629
|
-
attr = _a[_i];
|
|
630
|
-
filter2 = data[attr];
|
|
631
|
-
return [4 /*yield*/, this.cascadeSelect(oneToManyOnEntity[attr], Object.assign({}, filter2, {
|
|
632
|
-
filter: (0, filter_1.addFilterSegment)({
|
|
633
|
-
entityId: row.id,
|
|
634
|
-
entity: entity,
|
|
635
|
-
}, filter2.filter),
|
|
636
|
-
}), context, option)];
|
|
637
|
-
case 2:
|
|
638
|
-
rows2 = _d.sent();
|
|
639
|
-
Object.assign(row, (_c = {},
|
|
640
|
-
_c[attr] = rows2,
|
|
641
|
-
_c));
|
|
642
|
-
_d.label = 3;
|
|
643
|
-
case 3:
|
|
644
|
-
_i++;
|
|
645
|
-
return [3 /*break*/, 1];
|
|
646
|
-
case 4: return [2 /*return*/];
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
}); });
|
|
650
|
-
}
|
|
651
|
-
return [];
|
|
652
|
-
})()))];
|
|
653
|
-
case 2:
|
|
654
|
-
_k.sent();
|
|
655
|
-
return [2 /*return*/, rows];
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
});
|
|
659
|
-
};
|
|
660
|
-
CascadeStore.prototype.destructCascadeUpdate = function (entity, action, data, context, option, result, filter) {
|
|
661
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
662
|
-
var modiAttr, option2, opData, _loop_2, this_2, _a, _b, _i, attr;
|
|
663
|
-
var _this = this;
|
|
664
|
-
return tslib_1.__generator(this, function (_c) {
|
|
665
|
-
switch (_c.label) {
|
|
666
|
-
case 0:
|
|
667
|
-
modiAttr = this.getSchema()[entity].toModi;
|
|
668
|
-
option2 = Object.assign({}, option);
|
|
669
|
-
opData = {};
|
|
670
|
-
if (modiAttr && action !== 'remove') {
|
|
671
|
-
// create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
|
|
672
|
-
// delete此对象,所有的modi子对象应该通过触发器作废,这个通过系统的trigger来搞
|
|
673
|
-
(0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
|
|
674
|
-
if (action === 'create') {
|
|
675
|
-
option2.modiParentId = data.id;
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
(0, assert_1.default)((filter === null || filter === void 0 ? void 0 : filter.id) && typeof filter.id === 'string');
|
|
679
|
-
option2.modiParentId = filter.id;
|
|
680
|
-
}
|
|
681
|
-
option2.modiParentEntity = entity;
|
|
682
|
-
}
|
|
683
|
-
_loop_2 = function (attr) {
|
|
684
|
-
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;
|
|
685
|
-
var _g, _h, _j, e_2, _k;
|
|
686
|
-
return tslib_1.__generator(this, function (_l) {
|
|
687
|
-
switch (_l.label) {
|
|
688
|
-
case 0:
|
|
689
|
-
relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
|
|
690
|
-
if (!(relation === 1)) return [3 /*break*/, 1];
|
|
691
|
-
Object.assign(opData, (_g = {},
|
|
692
|
-
_g[attr] = data[attr],
|
|
693
|
-
_g));
|
|
694
|
-
return [3 /*break*/, 16];
|
|
695
|
-
case 1:
|
|
696
|
-
if (!(relation === 2)) return [3 /*break*/, 3];
|
|
697
|
-
operationMto = data[attr];
|
|
698
|
-
actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
|
|
699
|
-
if (actionMto === 'create') {
|
|
700
|
-
Object.assign(opData, {
|
|
701
|
-
entityId: dataMto.id,
|
|
702
|
-
entity: attr,
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
else if (action === 'create') {
|
|
706
|
-
fkId = data.entityId, entity_1 = data.entity;
|
|
707
|
-
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
|
|
708
|
-
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
709
|
-
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
710
|
-
(0, assert_1.default)(filterMto.id === fkId);
|
|
711
|
-
}
|
|
712
|
-
else {
|
|
713
|
-
// A中data的entityId作为B中filter的主键
|
|
714
|
-
Object.assign(operationMto, {
|
|
715
|
-
filter: (0, filter_1.addFilterSegment)({
|
|
716
|
-
id: fkId,
|
|
717
|
-
}),
|
|
718
|
-
filterMto: filterMto,
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
|
724
|
-
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
|
725
|
-
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
726
|
-
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
727
|
-
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
// A中data的entityId作为B中filter的主键
|
|
731
|
-
Object.assign(operationMto, {
|
|
732
|
-
filter: (0, filter_1.addFilterSegment)({
|
|
733
|
-
id: {
|
|
734
|
-
$in: {
|
|
735
|
-
entity: entity,
|
|
736
|
-
data: {
|
|
737
|
-
entityId: 1,
|
|
738
|
-
},
|
|
739
|
-
filter: (0, filter_1.addFilterSegment)({
|
|
740
|
-
entity: attr,
|
|
741
|
-
}, filter),
|
|
742
|
-
}
|
|
743
|
-
},
|
|
744
|
-
}, filterMto),
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
|
|
749
|
-
case 2:
|
|
750
|
-
result2 = _l.sent();
|
|
751
|
-
this_2.mergeOperationResult(result, result2);
|
|
752
|
-
return [3 /*break*/, 16];
|
|
753
|
-
case 3:
|
|
754
|
-
if (!(typeof relation === 'string')) return [3 /*break*/, 5];
|
|
755
|
-
operationMto = data[attr];
|
|
756
|
-
actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
|
|
757
|
-
if (actionMto === 'create') {
|
|
758
|
-
Object.assign(opData, (_h = {},
|
|
759
|
-
_h["".concat(attr, "Id")] = dataMto.id,
|
|
760
|
-
_h));
|
|
761
|
-
}
|
|
762
|
-
else if (action === 'create') {
|
|
763
|
-
_d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
|
|
764
|
-
(0, assert_1.default)(typeof fkId === 'string');
|
|
765
|
-
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
766
|
-
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
767
|
-
(0, assert_1.default)(filterMto.id === fkId);
|
|
768
|
-
}
|
|
769
|
-
else {
|
|
770
|
-
// A中data的entityId作为B中filter的主键
|
|
771
|
-
Object.assign(operationMto, {
|
|
772
|
-
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
773
|
-
id: fkId,
|
|
774
|
-
}),
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
(0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
|
|
780
|
-
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
781
|
-
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
782
|
-
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
783
|
-
}
|
|
784
|
-
else {
|
|
785
|
-
// A中data的entityId作为B中filter的主键
|
|
786
|
-
Object.assign(operationMto, {
|
|
787
|
-
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
788
|
-
id: {
|
|
789
|
-
$in: {
|
|
790
|
-
entity: entity,
|
|
791
|
-
data: (_j = {},
|
|
792
|
-
_j["".concat(attr, "Id")] = 1,
|
|
793
|
-
_j),
|
|
794
|
-
filter: filter,
|
|
795
|
-
}
|
|
796
|
-
},
|
|
797
|
-
}),
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
|
|
802
|
-
case 4:
|
|
803
|
-
result2 = _l.sent();
|
|
804
|
-
this_2.mergeOperationResult(result, result2);
|
|
805
|
-
return [3 /*break*/, 16];
|
|
806
|
-
case 5:
|
|
807
|
-
(0, assert_1.default)(relation instanceof Array);
|
|
808
|
-
_f = tslib_1.__read(relation, 2), entityOtm_1 = _f[0], foreignKey_2 = _f[1];
|
|
809
|
-
otmOperations = data[attr];
|
|
810
|
-
dealWithOneToMany = function (otm) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
811
|
-
var actionOtm, dataOtm, filterOtm, id_1, id_2, id, id_3, id_4, id, result2;
|
|
812
|
-
var _a, _b, _c, _d;
|
|
813
|
-
return tslib_1.__generator(this, function (_e) {
|
|
814
|
-
switch (_e.label) {
|
|
815
|
-
case 0:
|
|
816
|
-
actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
|
|
817
|
-
if (!foreignKey_2) {
|
|
818
|
-
// 基于entity/entityId的one-to-many
|
|
819
|
-
if (action === 'create') {
|
|
820
|
-
id_1 = data.id;
|
|
821
|
-
if (dataOtm instanceof Array) {
|
|
822
|
-
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
823
|
-
entity: entity,
|
|
824
|
-
entityId: id_1,
|
|
825
|
-
}); });
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
Object.assign(dataOtm, {
|
|
829
|
-
entity: entity,
|
|
830
|
-
entityId: id_1,
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
else if (actionOtm === 'create') {
|
|
835
|
-
id_2 = filter.id;
|
|
836
|
-
(0, assert_1.default)(typeof id_2 === 'string');
|
|
837
|
-
if (dataOtm instanceof Array) {
|
|
838
|
-
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
839
|
-
entity: entity,
|
|
840
|
-
entityId: id_2,
|
|
841
|
-
}); });
|
|
842
|
-
}
|
|
843
|
-
else {
|
|
844
|
-
Object.assign(dataOtm, {
|
|
845
|
-
entity: entity,
|
|
846
|
-
entityId: id_2,
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
else {
|
|
851
|
-
id = filter.id;
|
|
852
|
-
Object.assign(otm, {
|
|
853
|
-
filter: (0, filter_1.addFilterSegment)({
|
|
854
|
-
entity: entity,
|
|
855
|
-
entityId: id,
|
|
856
|
-
}, filterOtm),
|
|
857
|
-
});
|
|
858
|
-
if (action === 'remove' && actionOtm === 'update') {
|
|
859
|
-
Object.assign(dataOtm, {
|
|
860
|
-
entity: null,
|
|
861
|
-
entityId: null,
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
else {
|
|
867
|
-
// 基于foreignKey的one-to-many
|
|
868
|
-
if (action === 'create') {
|
|
869
|
-
id_3 = data.id;
|
|
870
|
-
if (dataOtm instanceof Array) {
|
|
871
|
-
dataOtm.forEach(function (ele) {
|
|
872
|
-
var _a;
|
|
873
|
-
return Object.assign(ele, (_a = {},
|
|
874
|
-
_a[foreignKey_2] = id_3,
|
|
875
|
-
_a));
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
else {
|
|
879
|
-
Object.assign(dataOtm, (_a = {},
|
|
880
|
-
_a[foreignKey_2] = id_3,
|
|
881
|
-
_a));
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
else if (actionOtm === 'create') {
|
|
885
|
-
id_4 = filter.id;
|
|
886
|
-
(0, assert_1.default)(typeof id_4 === 'string');
|
|
887
|
-
if (dataOtm instanceof Array) {
|
|
888
|
-
dataOtm.forEach(function (ele) {
|
|
889
|
-
var _a;
|
|
890
|
-
return Object.assign(ele, (_a = {},
|
|
891
|
-
_a[foreignKey_2] = id_4,
|
|
892
|
-
_a));
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
Object.assign(dataOtm, (_b = {},
|
|
897
|
-
_b[foreignKey_2] = id_4,
|
|
898
|
-
_b));
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
else {
|
|
902
|
-
id = filter.id;
|
|
903
|
-
Object.assign(otm, {
|
|
904
|
-
filter: (0, filter_1.addFilterSegment)((_c = {},
|
|
905
|
-
_c[foreignKey_2] = id,
|
|
906
|
-
_c), filterOtm),
|
|
907
|
-
});
|
|
908
|
-
if (action === 'remove' && actionOtm === 'update') {
|
|
909
|
-
Object.assign(dataOtm, (_d = {},
|
|
910
|
-
_d[foreignKey_2] = null,
|
|
911
|
-
_d));
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
return [4 /*yield*/, this.cascadeUpdate(entityOtm_1, otm, context, option2)];
|
|
916
|
-
case 1:
|
|
917
|
-
result2 = _e.sent();
|
|
918
|
-
this.mergeOperationResult(result, result2);
|
|
919
|
-
return [2 /*return*/];
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
}); };
|
|
923
|
-
if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
|
|
924
|
-
_l.label = 6;
|
|
925
|
-
case 6:
|
|
926
|
-
_l.trys.push([6, 11, 12, 13]);
|
|
927
|
-
otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
|
|
928
|
-
_l.label = 7;
|
|
929
|
-
case 7:
|
|
930
|
-
if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
|
|
931
|
-
oper = otmOperations_1_1.value;
|
|
932
|
-
return [4 /*yield*/, dealWithOneToMany(oper)];
|
|
933
|
-
case 8:
|
|
934
|
-
_l.sent();
|
|
935
|
-
_l.label = 9;
|
|
936
|
-
case 9:
|
|
937
|
-
otmOperations_1_1 = otmOperations_1.next();
|
|
938
|
-
return [3 /*break*/, 7];
|
|
939
|
-
case 10: return [3 /*break*/, 13];
|
|
940
|
-
case 11:
|
|
941
|
-
e_2_1 = _l.sent();
|
|
942
|
-
e_2 = { error: e_2_1 };
|
|
943
|
-
return [3 /*break*/, 13];
|
|
944
|
-
case 12:
|
|
945
|
-
try {
|
|
946
|
-
if (otmOperations_1_1 && !otmOperations_1_1.done && (_k = otmOperations_1.return)) _k.call(otmOperations_1);
|
|
947
|
-
}
|
|
948
|
-
finally { if (e_2) throw e_2.error; }
|
|
949
|
-
return [7 /*endfinally*/];
|
|
950
|
-
case 13: return [3 /*break*/, 16];
|
|
951
|
-
case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
|
|
952
|
-
case 15:
|
|
953
|
-
_l.sent();
|
|
954
|
-
_l.label = 16;
|
|
955
|
-
case 16: return [2 /*return*/];
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
};
|
|
959
|
-
this_2 = this;
|
|
960
|
-
_a = [];
|
|
961
|
-
for (_b in data)
|
|
962
|
-
_a.push(_b);
|
|
963
|
-
_i = 0;
|
|
964
|
-
_c.label = 1;
|
|
965
|
-
case 1:
|
|
966
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
967
|
-
attr = _a[_i];
|
|
968
|
-
return [5 /*yield**/, _loop_2(attr)];
|
|
969
|
-
case 2:
|
|
970
|
-
_c.sent();
|
|
971
|
-
_c.label = 3;
|
|
972
|
-
case 3:
|
|
973
|
-
_i++;
|
|
974
|
-
return [3 /*break*/, 1];
|
|
975
|
-
case 4: return [2 /*return*/, opData];
|
|
976
|
-
}
|
|
977
|
-
});
|
|
978
|
-
});
|
|
979
|
-
};
|
|
980
288
|
/**
|
|
981
289
|
* 级联更新
|
|
982
290
|
* A --> B
|
|
@@ -1001,69 +309,320 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1001
309
|
* 两者必须通过entity/entityId关联
|
|
1002
310
|
* 此时需要把对B的更新记录成一条新插入的Modi对象,并将A上的entity/entityId指向该对象(新生成的Modi对象的id与此operation的id保持一致)
|
|
1003
311
|
* @param entity
|
|
1004
|
-
* @param
|
|
312
|
+
* @param action
|
|
313
|
+
* @param data
|
|
1005
314
|
* @param context
|
|
1006
315
|
* @param option
|
|
316
|
+
* @param result
|
|
317
|
+
* @param filter
|
|
318
|
+
* @returns
|
|
1007
319
|
*/
|
|
1008
|
-
CascadeStore.prototype.
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
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 {
|
|
1041
573
|
try {
|
|
1042
|
-
if (
|
|
574
|
+
if (otmOperations_1_1 && !otmOperations_1_1.done && (_d = otmOperations_1.return)) _d.call(otmOperations_1);
|
|
1043
575
|
}
|
|
1044
|
-
finally { if (
|
|
1045
|
-
|
|
1046
|
-
case 8: return [3 /*break*/, 11];
|
|
1047
|
-
case 9: return [4 /*yield*/, this.destructCascadeUpdate(entity, action, data, context, option, result, filter)];
|
|
1048
|
-
case 10:
|
|
1049
|
-
opData = _d.sent();
|
|
1050
|
-
_d.label = 11;
|
|
1051
|
-
case 11:
|
|
1052
|
-
operation2 = Object.assign({}, operation, {
|
|
1053
|
-
data: opData,
|
|
1054
|
-
});
|
|
1055
|
-
return [4 /*yield*/, this.doUpdateSingleRow(entity, operation2, context, option)];
|
|
1056
|
-
case 12:
|
|
1057
|
-
count = _d.sent();
|
|
1058
|
-
this.mergeOperationResult(result, (_b = {},
|
|
1059
|
-
_b[entity] = (_c = {},
|
|
1060
|
-
_c[operation2.action] = count,
|
|
1061
|
-
_c),
|
|
1062
|
-
_b));
|
|
1063
|
-
return [2 /*return*/, result];
|
|
576
|
+
finally { if (e_1) throw e_1.error; }
|
|
577
|
+
}
|
|
1064
578
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
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);
|
|
1067
626
|
};
|
|
1068
627
|
/**
|
|
1069
628
|
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
|
@@ -1072,10 +631,10 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1072
631
|
* @param context
|
|
1073
632
|
* @param option
|
|
1074
633
|
*/
|
|
1075
|
-
CascadeStore.prototype.
|
|
634
|
+
CascadeStore.prototype.doUpdateSingleRowAsync = function (entity, operation, context, option) {
|
|
1076
635
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1077
|
-
var data, action, operId, filter, now, _a, modiCreate,
|
|
1078
|
-
var
|
|
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;
|
|
1079
638
|
var _this = this;
|
|
1080
639
|
return tslib_1.__generator(this, function (_o) {
|
|
1081
640
|
switch (_o.label) {
|
|
@@ -1088,6 +647,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1088
647
|
}
|
|
1089
648
|
return [3 /*break*/, 23];
|
|
1090
649
|
case 1:
|
|
650
|
+
this.preProcessDataCreated(entity, data);
|
|
1091
651
|
if (!(option.modiParentEntity && !['modi', 'modiEntity', 'oper', 'operEntity'].includes(entity))) return [3 /*break*/, 3];
|
|
1092
652
|
modiCreate = {
|
|
1093
653
|
id: 'dummy',
|
|
@@ -1107,35 +667,25 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1107
667
|
iState: 'active',
|
|
1108
668
|
},
|
|
1109
669
|
};
|
|
1110
|
-
return [4 /*yield*/, this.
|
|
670
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiCreate, context, option)];
|
|
1111
671
|
case 2:
|
|
1112
672
|
_o.sent();
|
|
1113
673
|
return [2 /*return*/, 1];
|
|
1114
674
|
case 3:
|
|
1115
|
-
|
|
1116
|
-
Object.assign(data2, {
|
|
1117
|
-
$$createAt$$: now,
|
|
1118
|
-
$$updateAt$$: now,
|
|
1119
|
-
});
|
|
1120
|
-
};
|
|
1121
|
-
if (data instanceof Array) {
|
|
1122
|
-
data.forEach(function (ele) { return addTimestamp_1(ele); });
|
|
1123
|
-
}
|
|
1124
|
-
else {
|
|
1125
|
-
addTimestamp_1(data);
|
|
1126
|
-
}
|
|
675
|
+
result_1 = 0;
|
|
1127
676
|
createInner = function (operation2) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1128
|
-
var
|
|
1129
|
-
return tslib_1.__generator(this, function (
|
|
1130
|
-
switch (
|
|
677
|
+
var _a, e_3;
|
|
678
|
+
return tslib_1.__generator(this, function (_b) {
|
|
679
|
+
switch (_b.label) {
|
|
1131
680
|
case 0:
|
|
1132
|
-
|
|
1133
|
-
|
|
681
|
+
_b.trys.push([0, 2, , 3]);
|
|
682
|
+
_a = result_1;
|
|
683
|
+
return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation2, context, option)];
|
|
1134
684
|
case 1:
|
|
1135
|
-
result_1 = _a.sent();
|
|
685
|
+
result_1 = _a + _b.sent();
|
|
1136
686
|
return [3 /*break*/, 3];
|
|
1137
687
|
case 2:
|
|
1138
|
-
|
|
688
|
+
e_3 = _b.sent();
|
|
1139
689
|
/* 这段代码是处理插入时有重复的行,现在看有问题,等实际需求出现再写
|
|
1140
690
|
if (e instanceof OakCongruentRowExists) {
|
|
1141
691
|
if (option.allowExists) {
|
|
@@ -1199,7 +749,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1199
749
|
}
|
|
1200
750
|
}
|
|
1201
751
|
} */
|
|
1202
|
-
throw
|
|
752
|
+
throw e_3;
|
|
1203
753
|
case 3: return [2 /*return*/];
|
|
1204
754
|
}
|
|
1205
755
|
});
|
|
@@ -1213,11 +763,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1213
763
|
return [3 /*break*/, 12];
|
|
1214
764
|
case 5:
|
|
1215
765
|
_o.trys.push([5, 10, 11, 12]);
|
|
1216
|
-
|
|
766
|
+
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
|
|
1217
767
|
_o.label = 6;
|
|
1218
768
|
case 6:
|
|
1219
|
-
if (!!
|
|
1220
|
-
d =
|
|
769
|
+
if (!!data_1_1.done) return [3 /*break*/, 9];
|
|
770
|
+
d = data_1_1.value;
|
|
1221
771
|
createSingleOper = {
|
|
1222
772
|
id: 'any',
|
|
1223
773
|
action: 'create',
|
|
@@ -1228,18 +778,18 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1228
778
|
_o.sent();
|
|
1229
779
|
_o.label = 8;
|
|
1230
780
|
case 8:
|
|
1231
|
-
|
|
781
|
+
data_1_1 = data_1.next();
|
|
1232
782
|
return [3 /*break*/, 6];
|
|
1233
783
|
case 9: return [3 /*break*/, 12];
|
|
1234
784
|
case 10:
|
|
1235
|
-
|
|
1236
|
-
|
|
785
|
+
e_2_1 = _o.sent();
|
|
786
|
+
e_2 = { error: e_2_1 };
|
|
1237
787
|
return [3 /*break*/, 12];
|
|
1238
788
|
case 11:
|
|
1239
789
|
try {
|
|
1240
|
-
if (
|
|
790
|
+
if (data_1_1 && !data_1_1.done && (_d = data_1.return)) _d.call(data_1);
|
|
1241
791
|
}
|
|
1242
|
-
finally { if (
|
|
792
|
+
finally { if (e_2) throw e_2.error; }
|
|
1243
793
|
return [7 /*endfinally*/];
|
|
1244
794
|
case 12: return [3 /*break*/, 15];
|
|
1245
795
|
case 13: return [4 /*yield*/, createInner(operation)];
|
|
@@ -1257,6 +807,10 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1257
807
|
if (!(!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity))) return [3 /*break*/, 22];
|
|
1258
808
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1259
809
|
(0, assert_1.default)(operId);
|
|
810
|
+
return [4 /*yield*/, context.getCurrentUserId(true)];
|
|
811
|
+
case 16:
|
|
812
|
+
operatorId = _o.sent();
|
|
813
|
+
if (!operatorId) return [3 /*break*/, 22];
|
|
1260
814
|
_e = {
|
|
1261
815
|
id: 'dummy',
|
|
1262
816
|
action: 'create'
|
|
@@ -1264,11 +818,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1264
818
|
_f = {
|
|
1265
819
|
id: operId,
|
|
1266
820
|
action: action,
|
|
1267
|
-
data: data
|
|
821
|
+
data: data,
|
|
822
|
+
operatorId: operatorId
|
|
1268
823
|
};
|
|
1269
|
-
return [4 /*yield*/, context.getCurrentUserId()];
|
|
1270
|
-
case 16:
|
|
1271
|
-
_f.operatorId = _o.sent();
|
|
1272
824
|
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
|
1273
825
|
_g = {
|
|
1274
826
|
id: 'dummy',
|
|
@@ -1280,7 +832,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1280
832
|
switch (_b.label) {
|
|
1281
833
|
case 0:
|
|
1282
834
|
_a = {};
|
|
1283
|
-
return [4 /*yield*/,
|
|
835
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1284
836
|
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1285
837
|
_a.entity = entity,
|
|
1286
838
|
_a.entityId = ele.id,
|
|
@@ -1298,7 +850,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1298
850
|
action: 'create'
|
|
1299
851
|
};
|
|
1300
852
|
_j = {};
|
|
1301
|
-
return [4 /*yield*/,
|
|
853
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1302
854
|
case 19:
|
|
1303
855
|
_b = [(_h.data = (_j.id = _o.sent(),
|
|
1304
856
|
_j.entity = entity,
|
|
@@ -1310,7 +862,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1310
862
|
createOper = (_e.data = (_f.operEntity$oper = _b,
|
|
1311
863
|
_f),
|
|
1312
864
|
_e);
|
|
1313
|
-
return [4 /*yield*/, this.
|
|
865
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper, context, {
|
|
1314
866
|
dontCollect: true,
|
|
1315
867
|
dontCreateOper: true,
|
|
1316
868
|
})];
|
|
@@ -1319,7 +871,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1319
871
|
_o.label = 22;
|
|
1320
872
|
case 22: return [2 /*return*/, result_1];
|
|
1321
873
|
case 23:
|
|
1322
|
-
ids_1 = (0,
|
|
874
|
+
ids_1 = (0, filter_2.getRelevantIds)(filter);
|
|
1323
875
|
if (!(ids_1.length === 0)) return [3 /*break*/, 25];
|
|
1324
876
|
selection = {
|
|
1325
877
|
data: {
|
|
@@ -1329,7 +881,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1329
881
|
indexFrom: operation.indexFrom,
|
|
1330
882
|
count: operation.count,
|
|
1331
883
|
};
|
|
1332
|
-
return [4 /*yield*/, this.
|
|
884
|
+
return [4 /*yield*/, this.selectAbjointRowAsync(entity, selection, context, {
|
|
1333
885
|
dontCollect: true,
|
|
1334
886
|
})];
|
|
1335
887
|
case 24:
|
|
@@ -1337,10 +889,13 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1337
889
|
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
|
1338
890
|
_o.label = 25;
|
|
1339
891
|
case 25:
|
|
892
|
+
if (data) {
|
|
893
|
+
this.preProcessDataUpdated(data);
|
|
894
|
+
}
|
|
1340
895
|
if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/, 31];
|
|
1341
896
|
modiUpsert = void 0;
|
|
1342
897
|
if (!(action !== 'remove')) return [3 /*break*/, 27];
|
|
1343
|
-
return [4 /*yield*/, this.
|
|
898
|
+
return [4 /*yield*/, this.selectAbjointRowAsync('modi', {
|
|
1344
899
|
data: {
|
|
1345
900
|
id: 1,
|
|
1346
901
|
data: 1,
|
|
@@ -1351,11 +906,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1351
906
|
$in: ['create', 'update'],
|
|
1352
907
|
},
|
|
1353
908
|
iState: 'active',
|
|
1354
|
-
filter: {
|
|
909
|
+
filter: ids_1.length > 0 ? {
|
|
1355
910
|
id: {
|
|
1356
911
|
$in: ids_1,
|
|
1357
912
|
},
|
|
1358
|
-
}
|
|
913
|
+
} : filter,
|
|
1359
914
|
},
|
|
1360
915
|
sorter: [
|
|
1361
916
|
{
|
|
@@ -1398,11 +953,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1398
953
|
action: action,
|
|
1399
954
|
data: data,
|
|
1400
955
|
iState: 'active',
|
|
1401
|
-
filter:
|
|
1402
|
-
id: {
|
|
1403
|
-
$in: ids_1,
|
|
1404
|
-
},
|
|
1405
|
-
}
|
|
956
|
+
filter: filter
|
|
1406
957
|
};
|
|
1407
958
|
_m = {
|
|
1408
959
|
id: 'dummy',
|
|
@@ -1414,7 +965,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1414
965
|
switch (_b.label) {
|
|
1415
966
|
case 0:
|
|
1416
967
|
_a = {};
|
|
1417
|
-
return [4 /*yield*/,
|
|
968
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1418
969
|
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1419
970
|
_a.entity = entity,
|
|
1420
971
|
_a.entityId = id,
|
|
@@ -1428,7 +979,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1428
979
|
_l),
|
|
1429
980
|
_k);
|
|
1430
981
|
_o.label = 29;
|
|
1431
|
-
case 29: return [4 /*yield*/, this.
|
|
982
|
+
case 29: return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiUpsert, context, option)];
|
|
1432
983
|
case 30:
|
|
1433
984
|
_o.sent();
|
|
1434
985
|
return [2 /*return*/, 1];
|
|
@@ -1462,7 +1013,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1462
1013
|
switch (_b.label) {
|
|
1463
1014
|
case 0:
|
|
1464
1015
|
_a = {};
|
|
1465
|
-
return [4 /*yield*/,
|
|
1016
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
1466
1017
|
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1467
1018
|
_a.entity = entity,
|
|
1468
1019
|
_a.entityId = ele,
|
|
@@ -1475,7 +1026,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1475
1026
|
_c),
|
|
1476
1027
|
_b),
|
|
1477
1028
|
_a);
|
|
1478
|
-
return [4 /*yield*/, this.
|
|
1029
|
+
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper_1, context, {
|
|
1479
1030
|
dontCollect: true,
|
|
1480
1031
|
dontCreateOper: true,
|
|
1481
1032
|
})];
|
|
@@ -1528,19 +1079,432 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1528
1079
|
_o.sent();
|
|
1529
1080
|
return [2 /*return*/, 0];
|
|
1530
1081
|
case 35: return [2 /*return*/, 0];
|
|
1531
|
-
case 36: return [4 /*yield*/, this.
|
|
1082
|
+
case 36: return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation, context, option)];
|
|
1532
1083
|
case 37:
|
|
1533
|
-
|
|
1084
|
+
result = _o.sent();
|
|
1534
1085
|
return [4 /*yield*/, createOper()];
|
|
1535
1086
|
case 38:
|
|
1536
1087
|
_o.sent();
|
|
1537
|
-
return [2 /*return*/,
|
|
1088
|
+
return [2 /*return*/, result];
|
|
1538
1089
|
}
|
|
1539
1090
|
});
|
|
1540
1091
|
});
|
|
1541
1092
|
};
|
|
1542
|
-
CascadeStore.prototype.
|
|
1543
|
-
|
|
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]; }), context);
|
|
1383
|
+
}
|
|
1384
|
+
else if (typeof rel === 'string') {
|
|
1385
|
+
this_3.addToResultSelections(rel, rows.map(function (ele) { return ele[attr]; }), 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
|
+
});
|
|
1544
1508
|
};
|
|
1545
1509
|
return CascadeStore;
|
|
1546
1510
|
}(RowStore_1.RowStore));
|