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