oak-domain 1.0.0
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/OakError.d.ts +7 -0
- package/lib/OakError.js +29 -0
- package/lib/actions/action.d.ts +6 -0
- package/lib/actions/action.js +12 -0
- package/lib/actions/relation.d.ts +1 -0
- package/lib/actions/relation.js +2 -0
- package/lib/compiler/env.d.ts +10 -0
- package/lib/compiler/env.js +26 -0
- package/lib/compiler/schemalBuilder.d.ts +2 -0
- package/lib/compiler/schemalBuilder.js +2738 -0
- package/lib/compiler/uiBuilder.d.ts +1 -0
- package/lib/compiler/uiBuilder.js +3 -0
- package/lib/compiler/utils.d.ts +2 -0
- package/lib/compiler/utils.js +11 -0
- package/lib/store/CascadeStore.d.ts +38 -0
- package/lib/store/CascadeStore.js +681 -0
- package/lib/store/TriggerExecutor.d.ts +30 -0
- package/lib/store/TriggerExecutor.js +549 -0
- package/lib/store/UniversalContext.d.ts +26 -0
- package/lib/store/UniversalContext.js +208 -0
- package/lib/store/actionDef.d.ts +8 -0
- package/lib/store/actionDef.js +241 -0
- package/lib/store/filter.d.ts +36 -0
- package/lib/store/filter.js +121 -0
- package/lib/store/relation.d.ts +13 -0
- package/lib/store/relation.js +64 -0
- package/lib/store/watchers.d.ts +2 -0
- package/lib/store/watchers.js +32 -0
- package/lib/types/Action.d.ts +14 -0
- package/lib/types/Action.js +2 -0
- package/lib/types/AppLoader.d.ts +11 -0
- package/lib/types/AppLoader.js +10 -0
- package/lib/types/Aspect.d.ts +12 -0
- package/lib/types/Aspect.js +4 -0
- package/lib/types/Auth.d.ts +28 -0
- package/lib/types/Auth.js +2 -0
- package/lib/types/Connector.d.ts +26 -0
- package/lib/types/Connector.js +9 -0
- package/lib/types/Context.d.ts +14 -0
- package/lib/types/Context.js +3 -0
- package/lib/types/DataType.d.ts +17 -0
- package/lib/types/DataType.js +5 -0
- package/lib/types/Demand.d.ts +77 -0
- package/lib/types/Demand.js +9 -0
- package/lib/types/Entity.d.ts +138 -0
- package/lib/types/Entity.js +8 -0
- package/lib/types/Exception.d.ts +48 -0
- package/lib/types/Exception.js +178 -0
- package/lib/types/Expression.d.ts +132 -0
- package/lib/types/Expression.js +378 -0
- package/lib/types/Geo.d.ts +18 -0
- package/lib/types/Geo.js +2 -0
- package/lib/types/Locale.d.ts +24 -0
- package/lib/types/Locale.js +2 -0
- package/lib/types/Logger.d.ts +5 -0
- package/lib/types/Logger.js +3 -0
- package/lib/types/Polyfill.d.ts +23 -0
- package/lib/types/Polyfill.js +2 -0
- package/lib/types/RowStore.d.ts +22 -0
- package/lib/types/RowStore.js +33 -0
- package/lib/types/Storage.d.ts +48 -0
- package/lib/types/Storage.js +2 -0
- package/lib/types/Trigger.d.ts +105 -0
- package/lib/types/Trigger.js +24 -0
- package/lib/types/Txn.d.ts +2 -0
- package/lib/types/Txn.js +3 -0
- package/lib/types/Watcher.d.ts +19 -0
- package/lib/types/Watcher.js +4 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +30 -0
- package/lib/types/schema/DataTypes.d.ts +32 -0
- package/lib/types/schema/DataTypes.js +3 -0
- package/lib/utils/SimpleConnector.d.ts +29 -0
- package/lib/utils/SimpleConnector.js +145 -0
- package/lib/utils/assert.d.ts +5 -0
- package/lib/utils/assert.js +11 -0
- package/lib/utils/concurrent.d.ts +15 -0
- package/lib/utils/concurrent.js +138 -0
- package/lib/utils/geo.d.ts +4 -0
- package/lib/utils/geo.js +24 -0
- package/lib/utils/lodash.d.ts +16 -0
- package/lib/utils/lodash.js +32 -0
- package/lib/utils/string.d.ts +2 -0
- package/lib/utils/string.js +11 -0
- package/lib/utils/uuid.d.ts +2 -0
- package/lib/utils/uuid.js +11 -0
- package/lib/utils/validator.d.ts +23 -0
- package/lib/utils/validator.js +123 -0
- package/package.json +38 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
54
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
55
|
+
if (!m) return o;
|
|
56
|
+
var i = m.call(o), r, ar = [], e;
|
|
57
|
+
try {
|
|
58
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
59
|
+
}
|
|
60
|
+
catch (error) { e = { error: error }; }
|
|
61
|
+
finally {
|
|
62
|
+
try {
|
|
63
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
64
|
+
}
|
|
65
|
+
finally { if (e) throw e.error; }
|
|
66
|
+
}
|
|
67
|
+
return ar;
|
|
68
|
+
};
|
|
69
|
+
var __values = (this && this.__values) || function(o) {
|
|
70
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
71
|
+
if (m) return m.call(o);
|
|
72
|
+
if (o && typeof o.length === "number") return {
|
|
73
|
+
next: function () {
|
|
74
|
+
if (o && i >= o.length) o = void 0;
|
|
75
|
+
return { value: o && o[i++], done: !o };
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
79
|
+
};
|
|
80
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
81
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
82
|
+
};
|
|
83
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
|
+
exports.CascadeStore = void 0;
|
|
85
|
+
var assert_1 = __importDefault(require("assert"));
|
|
86
|
+
var RowStore_1 = require("../types/RowStore");
|
|
87
|
+
var filter_1 = require("./filter");
|
|
88
|
+
var relation_1 = require("./relation");
|
|
89
|
+
/**这个用来处理级联的select和update,对不同能力的 */
|
|
90
|
+
var CascadeStore = /** @class */ (function (_super) {
|
|
91
|
+
__extends(CascadeStore, _super);
|
|
92
|
+
function CascadeStore(storageSchema) {
|
|
93
|
+
return _super.call(this, storageSchema) || this;
|
|
94
|
+
}
|
|
95
|
+
CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var data, projection, oneToMany, oneToManyOnEntity, manyToOne, manyToOneOnEntity, supportMtoJoin, attr, relation, _a, entity2, foreignKey, rows;
|
|
98
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
99
|
+
var _this = this;
|
|
100
|
+
return __generator(this, function (_k) {
|
|
101
|
+
switch (_k.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
data = selection.data;
|
|
104
|
+
projection = {};
|
|
105
|
+
oneToMany = {};
|
|
106
|
+
oneToManyOnEntity = {};
|
|
107
|
+
manyToOne = {};
|
|
108
|
+
manyToOneOnEntity = {};
|
|
109
|
+
supportMtoJoin = this.supportManyToOneJoin();
|
|
110
|
+
for (attr in data) {
|
|
111
|
+
relation = (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
|
|
112
|
+
if (relation === 1 || relation == 0) {
|
|
113
|
+
Object.assign(projection, (_b = {},
|
|
114
|
+
_b[attr] = data[attr],
|
|
115
|
+
_b));
|
|
116
|
+
}
|
|
117
|
+
else if (relation === 2) {
|
|
118
|
+
// 基于entity的多对一
|
|
119
|
+
Object.assign(projection, {
|
|
120
|
+
entity: 1,
|
|
121
|
+
entityId: 1,
|
|
122
|
+
});
|
|
123
|
+
if (supportMtoJoin) {
|
|
124
|
+
Object.assign(projection, (_c = {},
|
|
125
|
+
_c[attr] = data[attr],
|
|
126
|
+
_c));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
Object.assign(manyToOneOnEntity, (_d = {},
|
|
130
|
+
_d[attr] = 1,
|
|
131
|
+
_d));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (typeof relation === 'string') {
|
|
135
|
+
// 基于属性的多对一
|
|
136
|
+
if (supportMtoJoin) {
|
|
137
|
+
Object.assign(projection, (_e = {},
|
|
138
|
+
_e[attr] = data[attr],
|
|
139
|
+
_e));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
Object.assign(projection, (_f = {},
|
|
143
|
+
_f["".concat(attr, "Id")] = 1,
|
|
144
|
+
_f));
|
|
145
|
+
Object.assign(manyToOne, (_g = {},
|
|
146
|
+
_g[attr] = relation,
|
|
147
|
+
_g));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
_a = __read(relation, 2), entity2 = _a[0], foreignKey = _a[1];
|
|
152
|
+
if (foreignKey) {
|
|
153
|
+
// 基于属性的一对多
|
|
154
|
+
Object.assign(oneToMany, (_h = {},
|
|
155
|
+
_h[attr] = {
|
|
156
|
+
entity: entity2,
|
|
157
|
+
foreignKey: foreignKey,
|
|
158
|
+
},
|
|
159
|
+
_h));
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// 基于entity的多对一
|
|
163
|
+
Object.assign(oneToManyOnEntity, (_j = {},
|
|
164
|
+
_j[attr] = entity2,
|
|
165
|
+
_j));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return [4 /*yield*/, this.selectAbjointRow(entity, Object.assign({}, selection, {
|
|
170
|
+
data: projection,
|
|
171
|
+
}), context, option)];
|
|
172
|
+
case 1:
|
|
173
|
+
rows = _k.sent();
|
|
174
|
+
return [4 /*yield*/, Promise.all(
|
|
175
|
+
// manyToOne
|
|
176
|
+
(function () {
|
|
177
|
+
var attrs = Object.keys(manyToOne);
|
|
178
|
+
if (attrs.length > 0) {
|
|
179
|
+
return attrs.map(function (attr) { return __awaiter(_this, void 0, void 0, function () {
|
|
180
|
+
var subRows;
|
|
181
|
+
return __generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0: return [4 /*yield*/, this.cascadeSelect(manyToOne[attr], {
|
|
184
|
+
data: data[attr],
|
|
185
|
+
filter: {
|
|
186
|
+
id: {
|
|
187
|
+
$in: rows.map(function (row) { return row["".concat(attr, "Id")]; })
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
}, context, option)];
|
|
191
|
+
case 1:
|
|
192
|
+
subRows = _a.sent();
|
|
193
|
+
rows.forEach(function (row) {
|
|
194
|
+
var _a;
|
|
195
|
+
var subRow = subRows.find(function (ele) { return ele.id === row["".concat(attr, "Id")]; });
|
|
196
|
+
Object.assign(row, (_a = {},
|
|
197
|
+
_a[attr] = subRow,
|
|
198
|
+
_a));
|
|
199
|
+
});
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); });
|
|
204
|
+
}
|
|
205
|
+
return [];
|
|
206
|
+
})().concat(
|
|
207
|
+
// manyToOneOnEntity
|
|
208
|
+
(function () {
|
|
209
|
+
var attrs = Object.keys(manyToOneOnEntity);
|
|
210
|
+
if (attrs.length > 0) {
|
|
211
|
+
return attrs.map(function (attr) { return __awaiter(_this, void 0, void 0, function () {
|
|
212
|
+
var subRows;
|
|
213
|
+
return __generator(this, function (_a) {
|
|
214
|
+
switch (_a.label) {
|
|
215
|
+
case 0: return [4 /*yield*/, this.cascadeSelect(attr, {
|
|
216
|
+
data: data[attr],
|
|
217
|
+
filter: {
|
|
218
|
+
id: {
|
|
219
|
+
$in: rows.filter(function (row) { return row.entity === attr; }).map(function (row) { return row.entityId; })
|
|
220
|
+
},
|
|
221
|
+
}
|
|
222
|
+
}, context, option)];
|
|
223
|
+
case 1:
|
|
224
|
+
subRows = _a.sent();
|
|
225
|
+
rows.filter(function (row) { return row.entity === attr; }).forEach(function (row) {
|
|
226
|
+
var _a;
|
|
227
|
+
var subRow = subRows.find(function (ele) { return ele.id === row.entityId; });
|
|
228
|
+
Object.assign(row, (_a = {},
|
|
229
|
+
_a[attr] = subRow,
|
|
230
|
+
_a));
|
|
231
|
+
});
|
|
232
|
+
return [2 /*return*/];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}); });
|
|
236
|
+
}
|
|
237
|
+
return [];
|
|
238
|
+
})()).concat((function () {
|
|
239
|
+
var attrs = Object.keys(oneToMany);
|
|
240
|
+
if (attrs.length > 0) {
|
|
241
|
+
// 必须一行一行的查询,否则indexFrom和count无法准确
|
|
242
|
+
return rows.map(function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
243
|
+
var _a, _b, _i, attr, _c, entity2, foreignKey, filter2, rows2;
|
|
244
|
+
var _d, _e;
|
|
245
|
+
return __generator(this, function (_f) {
|
|
246
|
+
switch (_f.label) {
|
|
247
|
+
case 0:
|
|
248
|
+
_a = [];
|
|
249
|
+
for (_b in oneToMany)
|
|
250
|
+
_a.push(_b);
|
|
251
|
+
_i = 0;
|
|
252
|
+
_f.label = 1;
|
|
253
|
+
case 1:
|
|
254
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
255
|
+
attr = _a[_i];
|
|
256
|
+
_c = oneToMany[attr], entity2 = _c.entity, foreignKey = _c.foreignKey;
|
|
257
|
+
filter2 = data[attr];
|
|
258
|
+
return [4 /*yield*/, this.cascadeSelect(entity2, Object.assign({}, filter2, {
|
|
259
|
+
filter: (0, filter_1.addFilterSegment)((_d = {},
|
|
260
|
+
_d[foreignKey] = row.id,
|
|
261
|
+
_d), filter2.filter),
|
|
262
|
+
}), context, option)];
|
|
263
|
+
case 2:
|
|
264
|
+
rows2 = _f.sent();
|
|
265
|
+
Object.assign(row, (_e = {},
|
|
266
|
+
_e[attr] = rows2,
|
|
267
|
+
_e));
|
|
268
|
+
_f.label = 3;
|
|
269
|
+
case 3:
|
|
270
|
+
_i++;
|
|
271
|
+
return [3 /*break*/, 1];
|
|
272
|
+
case 4: return [2 /*return*/];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}); });
|
|
276
|
+
}
|
|
277
|
+
return [];
|
|
278
|
+
})()).concat((function () {
|
|
279
|
+
var attrs = Object.keys(oneToManyOnEntity);
|
|
280
|
+
if (attrs.length > 0) {
|
|
281
|
+
// 必须一行一行的查询,否则indexFrom和count无法准确
|
|
282
|
+
return rows.map(function (row) { return __awaiter(_this, void 0, void 0, function () {
|
|
283
|
+
var _a, _b, _i, attr, filter2, rows2;
|
|
284
|
+
var _c;
|
|
285
|
+
return __generator(this, function (_d) {
|
|
286
|
+
switch (_d.label) {
|
|
287
|
+
case 0:
|
|
288
|
+
_a = [];
|
|
289
|
+
for (_b in oneToManyOnEntity)
|
|
290
|
+
_a.push(_b);
|
|
291
|
+
_i = 0;
|
|
292
|
+
_d.label = 1;
|
|
293
|
+
case 1:
|
|
294
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
295
|
+
attr = _a[_i];
|
|
296
|
+
filter2 = data[attr];
|
|
297
|
+
return [4 /*yield*/, this.cascadeSelect(oneToManyOnEntity[attr], Object.assign({}, filter2, {
|
|
298
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
299
|
+
entityId: row.id,
|
|
300
|
+
entity: entity,
|
|
301
|
+
}, filter2.filter),
|
|
302
|
+
}), context, option)];
|
|
303
|
+
case 2:
|
|
304
|
+
rows2 = _d.sent();
|
|
305
|
+
Object.assign(row, (_c = {},
|
|
306
|
+
_c[attr] = rows2,
|
|
307
|
+
_c));
|
|
308
|
+
_d.label = 3;
|
|
309
|
+
case 3:
|
|
310
|
+
_i++;
|
|
311
|
+
return [3 /*break*/, 1];
|
|
312
|
+
case 4: return [2 /*return*/];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}); });
|
|
316
|
+
}
|
|
317
|
+
return [];
|
|
318
|
+
})()))];
|
|
319
|
+
case 2:
|
|
320
|
+
_k.sent();
|
|
321
|
+
return [2 /*return*/, rows];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* 级联更新
|
|
328
|
+
* A --> B
|
|
329
|
+
多对一:A CREATE/B CREATE,B data的主键赋到A的data上
|
|
330
|
+
A CREATE/B UPDATE,B filter的主键来自A的data
|
|
331
|
+
A UPDATE/B CREATE,B data的主键赋到A的data上
|
|
332
|
+
A UPDATE/B UPDATE,B filter的主键来自A的row
|
|
333
|
+
A UPDATE/B REMOVE,B filter的主键来自A的row
|
|
334
|
+
A REMOVE/B UPDATE,B filter的主键来自A的row
|
|
335
|
+
A REMOVE/B REMOVE,B filter的主键来自A的row
|
|
336
|
+
|
|
337
|
+
一对多:A CREATE/B CREATE,A data上的主键赋到B的data上
|
|
338
|
+
A CREATE/B UPDATE,A data上的主键赋到B的data上
|
|
339
|
+
A UPDATE/B CREATE,A filter上的主键赋到B的data上(一定是带主键的filter)
|
|
340
|
+
A UPDATE/B UPDATE,A filter上的主键赋到B的filter上(一定是带主键的filter)
|
|
341
|
+
A UPDATE/B REMOVE,A filter上的主键赋到B的filter上(一定是带主键的filter)
|
|
342
|
+
A REMOVE/B UPDATE,A filter上的主键赋到B的filter上(且B关于A的外键清空)
|
|
343
|
+
A REMOVE/B REMOVE,A filter上的主键赋到B的filter上
|
|
344
|
+
* @param entity
|
|
345
|
+
* @param operation
|
|
346
|
+
* @param context
|
|
347
|
+
* @param option
|
|
348
|
+
*/
|
|
349
|
+
CascadeStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
|
|
350
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
351
|
+
var action, data, filter, opData, result, multipleCreate, data_1, data_1_1, dataEle, result2, e_1_1, data2, _loop_1, this_1, _a, _b, _i, attr, operation2, count;
|
|
352
|
+
var e_1, _c, _d, _e;
|
|
353
|
+
var _this = this;
|
|
354
|
+
return __generator(this, function (_f) {
|
|
355
|
+
switch (_f.label) {
|
|
356
|
+
case 0:
|
|
357
|
+
action = operation.action, data = operation.data, filter = operation.filter;
|
|
358
|
+
opData = {};
|
|
359
|
+
result = {};
|
|
360
|
+
if (!(action === 'create' && data instanceof Array)) return [3 /*break*/, 9];
|
|
361
|
+
multipleCreate = this.supportMultipleCreate();
|
|
362
|
+
_f.label = 1;
|
|
363
|
+
case 1:
|
|
364
|
+
_f.trys.push([1, 6, 7, 8]);
|
|
365
|
+
data_1 = __values(data), data_1_1 = data_1.next();
|
|
366
|
+
_f.label = 2;
|
|
367
|
+
case 2:
|
|
368
|
+
if (!!data_1_1.done) return [3 /*break*/, 5];
|
|
369
|
+
dataEle = data_1_1.value;
|
|
370
|
+
return [4 /*yield*/, this.cascadeUpdate(entity, {
|
|
371
|
+
action: action,
|
|
372
|
+
data: dataEle,
|
|
373
|
+
}, context, option)];
|
|
374
|
+
case 3:
|
|
375
|
+
result2 = _f.sent();
|
|
376
|
+
this.mergeOperationResult(result, result2);
|
|
377
|
+
_f.label = 4;
|
|
378
|
+
case 4:
|
|
379
|
+
data_1_1 = data_1.next();
|
|
380
|
+
return [3 /*break*/, 2];
|
|
381
|
+
case 5: return [3 /*break*/, 8];
|
|
382
|
+
case 6:
|
|
383
|
+
e_1_1 = _f.sent();
|
|
384
|
+
e_1 = { error: e_1_1 };
|
|
385
|
+
return [3 /*break*/, 8];
|
|
386
|
+
case 7:
|
|
387
|
+
try {
|
|
388
|
+
if (data_1_1 && !data_1_1.done && (_c = data_1.return)) _c.call(data_1);
|
|
389
|
+
}
|
|
390
|
+
finally { if (e_1) throw e_1.error; }
|
|
391
|
+
return [7 /*endfinally*/];
|
|
392
|
+
case 8: return [2 /*return*/, result];
|
|
393
|
+
case 9:
|
|
394
|
+
data2 = data;
|
|
395
|
+
_loop_1 = function (attr) {
|
|
396
|
+
var relation, operationMto, actionMto, dataMto, filterMto, fkId, entity_1, result2, operationMto, actionMto, dataMto, filterMto, _g, _h, fkId, result2, _j, entityOtm_1, foreignKey_1, otmOperations, dealWithOneToMany, otmOperations_1, otmOperations_1_1, oper, e_2_1;
|
|
397
|
+
var _k, _l, _m, e_2, _o;
|
|
398
|
+
return __generator(this, function (_p) {
|
|
399
|
+
switch (_p.label) {
|
|
400
|
+
case 0:
|
|
401
|
+
relation = (0, relation_1.judgeRelation)(this_1.storageSchema, entity, attr);
|
|
402
|
+
if (!(relation === 1)) return [3 /*break*/, 1];
|
|
403
|
+
Object.assign(opData, (_k = {},
|
|
404
|
+
_k[attr] = data2[attr],
|
|
405
|
+
_k));
|
|
406
|
+
return [3 /*break*/, 16];
|
|
407
|
+
case 1:
|
|
408
|
+
if (!(relation === 2)) return [3 /*break*/, 3];
|
|
409
|
+
operationMto = data2[attr];
|
|
410
|
+
actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
|
|
411
|
+
if (actionMto === 'create') {
|
|
412
|
+
Object.assign(opData, {
|
|
413
|
+
entityId: dataMto.id,
|
|
414
|
+
entity: attr,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
else if (action === 'create') {
|
|
418
|
+
fkId = data2.entityId, entity_1 = data2.entity;
|
|
419
|
+
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr); // A中data的entityId作为B中filter的主键
|
|
420
|
+
Object.assign(operationMto, {
|
|
421
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
422
|
+
id: fkId,
|
|
423
|
+
}),
|
|
424
|
+
filterMto: filterMto,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
|
429
|
+
(0, assert_1.default)(!data2.hasOwnProperty('entityId') && !data2.hasOwnProperty('entity'));
|
|
430
|
+
Object.assign(operationMto, {
|
|
431
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
432
|
+
id: {
|
|
433
|
+
$in: {
|
|
434
|
+
entity: entity,
|
|
435
|
+
data: {
|
|
436
|
+
entityId: 1,
|
|
437
|
+
},
|
|
438
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
439
|
+
entity: attr,
|
|
440
|
+
}, filter),
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
}, filterMto),
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
return [4 /*yield*/, this_1.cascadeUpdate(attr, operationMto, context, option)];
|
|
447
|
+
case 2:
|
|
448
|
+
result2 = _p.sent();
|
|
449
|
+
this_1.mergeOperationResult(result, result2);
|
|
450
|
+
return [3 /*break*/, 16];
|
|
451
|
+
case 3:
|
|
452
|
+
if (!(typeof relation === 'string')) return [3 /*break*/, 5];
|
|
453
|
+
operationMto = data2[attr];
|
|
454
|
+
actionMto = operationMto.action, dataMto = operationMto.data, filterMto = operationMto.filter;
|
|
455
|
+
if (actionMto === 'create') {
|
|
456
|
+
Object.assign(opData, (_l = {},
|
|
457
|
+
_l["".concat(attr, "Id")] = dataMto.id,
|
|
458
|
+
_l));
|
|
459
|
+
}
|
|
460
|
+
else if (action === 'create') {
|
|
461
|
+
_g = data2, _h = "".concat(attr, "Id"), fkId = _g[_h];
|
|
462
|
+
(0, assert_1.default)(typeof fkId === 'string');
|
|
463
|
+
Object.assign(operationMto, {
|
|
464
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
465
|
+
id: fkId,
|
|
466
|
+
}),
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
(0, assert_1.default)(!data2.hasOwnProperty("".concat(attr, "Id")));
|
|
471
|
+
Object.assign(operationMto, {
|
|
472
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
473
|
+
id: {
|
|
474
|
+
$in: {
|
|
475
|
+
entity: entity,
|
|
476
|
+
data: (_m = {},
|
|
477
|
+
_m["".concat(attr, "Id")] = 1,
|
|
478
|
+
_m),
|
|
479
|
+
filter: filter,
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
}),
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
return [4 /*yield*/, this_1.cascadeUpdate(relation, operationMto, context, option)];
|
|
486
|
+
case 4:
|
|
487
|
+
result2 = _p.sent();
|
|
488
|
+
this_1.mergeOperationResult(result, result2);
|
|
489
|
+
return [3 /*break*/, 16];
|
|
490
|
+
case 5:
|
|
491
|
+
(0, assert_1.default)(relation instanceof Array);
|
|
492
|
+
_j = __read(relation, 2), entityOtm_1 = _j[0], foreignKey_1 = _j[1];
|
|
493
|
+
otmOperations = data2[attr];
|
|
494
|
+
dealWithOneToMany = function (otm) { return __awaiter(_this, void 0, void 0, function () {
|
|
495
|
+
var actionOtm, dataOtm, filterOtm, id_1, id_2, id, id_3, id_4, id, result2;
|
|
496
|
+
var _a, _b, _c, _d;
|
|
497
|
+
return __generator(this, function (_e) {
|
|
498
|
+
switch (_e.label) {
|
|
499
|
+
case 0:
|
|
500
|
+
actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
|
|
501
|
+
if (!foreignKey_1) {
|
|
502
|
+
// 基于entity/entityId的one-to-many
|
|
503
|
+
if (action === 'create') {
|
|
504
|
+
id_1 = data2.id;
|
|
505
|
+
if (dataOtm instanceof Array) {
|
|
506
|
+
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
507
|
+
entity: entity,
|
|
508
|
+
entityId: id_1,
|
|
509
|
+
}); });
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
Object.assign(dataOtm, {
|
|
513
|
+
entity: entity,
|
|
514
|
+
entityId: id_1,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
else if (actionOtm === 'create') {
|
|
519
|
+
id_2 = filter.id;
|
|
520
|
+
(0, assert_1.default)(typeof id_2 === 'string');
|
|
521
|
+
if (dataOtm instanceof Array) {
|
|
522
|
+
dataOtm.forEach(function (ele) { return Object.assign(ele, {
|
|
523
|
+
entity: entity,
|
|
524
|
+
entityId: id_2,
|
|
525
|
+
}); });
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
Object.assign(dataOtm, {
|
|
529
|
+
entity: entity,
|
|
530
|
+
entityId: id_2,
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
id = filter.id;
|
|
536
|
+
Object.assign(otm, {
|
|
537
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
538
|
+
entity: entity,
|
|
539
|
+
entityId: id,
|
|
540
|
+
}, filterOtm),
|
|
541
|
+
});
|
|
542
|
+
if (action === 'remove' && actionOtm === 'update') {
|
|
543
|
+
Object.assign(dataOtm, {
|
|
544
|
+
entity: null,
|
|
545
|
+
entityId: null,
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
// 基于foreignKey的one-to-many
|
|
552
|
+
if (action === 'create') {
|
|
553
|
+
id_3 = data2.id;
|
|
554
|
+
if (dataOtm instanceof Array) {
|
|
555
|
+
dataOtm.forEach(function (ele) {
|
|
556
|
+
var _a;
|
|
557
|
+
return Object.assign(ele, (_a = {},
|
|
558
|
+
_a[foreignKey_1] = id_3,
|
|
559
|
+
_a));
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
Object.assign(dataOtm, (_a = {},
|
|
564
|
+
_a[foreignKey_1] = id_3,
|
|
565
|
+
_a));
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
else if (actionOtm === 'create') {
|
|
569
|
+
id_4 = filter.id;
|
|
570
|
+
(0, assert_1.default)(typeof id_4 === 'string');
|
|
571
|
+
if (dataOtm instanceof Array) {
|
|
572
|
+
dataOtm.forEach(function (ele) {
|
|
573
|
+
var _a;
|
|
574
|
+
return Object.assign(ele, (_a = {},
|
|
575
|
+
_a[foreignKey_1] = id_4,
|
|
576
|
+
_a));
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
Object.assign(dataOtm, (_b = {},
|
|
581
|
+
_b[foreignKey_1] = id_4,
|
|
582
|
+
_b));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
id = filter.id;
|
|
587
|
+
Object.assign(otm, {
|
|
588
|
+
filter: (0, filter_1.addFilterSegment)((_c = {},
|
|
589
|
+
_c[foreignKey_1] = id,
|
|
590
|
+
_c), filterOtm),
|
|
591
|
+
});
|
|
592
|
+
if (action === 'remove' && actionOtm === 'update') {
|
|
593
|
+
Object.assign(dataOtm, (_d = {},
|
|
594
|
+
_d[foreignKey_1] = null,
|
|
595
|
+
_d));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return [4 /*yield*/, this.cascadeUpdate(entityOtm_1, otm, context, option)];
|
|
600
|
+
case 1:
|
|
601
|
+
result2 = _e.sent();
|
|
602
|
+
this.mergeOperationResult(result, result2);
|
|
603
|
+
return [2 /*return*/];
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}); };
|
|
607
|
+
if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
|
|
608
|
+
_p.label = 6;
|
|
609
|
+
case 6:
|
|
610
|
+
_p.trys.push([6, 11, 12, 13]);
|
|
611
|
+
otmOperations_1 = (e_2 = void 0, __values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
|
|
612
|
+
_p.label = 7;
|
|
613
|
+
case 7:
|
|
614
|
+
if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
|
|
615
|
+
oper = otmOperations_1_1.value;
|
|
616
|
+
return [4 /*yield*/, dealWithOneToMany(oper)];
|
|
617
|
+
case 8:
|
|
618
|
+
_p.sent();
|
|
619
|
+
_p.label = 9;
|
|
620
|
+
case 9:
|
|
621
|
+
otmOperations_1_1 = otmOperations_1.next();
|
|
622
|
+
return [3 /*break*/, 7];
|
|
623
|
+
case 10: return [3 /*break*/, 13];
|
|
624
|
+
case 11:
|
|
625
|
+
e_2_1 = _p.sent();
|
|
626
|
+
e_2 = { error: e_2_1 };
|
|
627
|
+
return [3 /*break*/, 13];
|
|
628
|
+
case 12:
|
|
629
|
+
try {
|
|
630
|
+
if (otmOperations_1_1 && !otmOperations_1_1.done && (_o = otmOperations_1.return)) _o.call(otmOperations_1);
|
|
631
|
+
}
|
|
632
|
+
finally { if (e_2) throw e_2.error; }
|
|
633
|
+
return [7 /*endfinally*/];
|
|
634
|
+
case 13: return [3 /*break*/, 16];
|
|
635
|
+
case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
|
|
636
|
+
case 15:
|
|
637
|
+
_p.sent();
|
|
638
|
+
_p.label = 16;
|
|
639
|
+
case 16: return [2 /*return*/];
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
this_1 = this;
|
|
644
|
+
_a = [];
|
|
645
|
+
for (_b in data2)
|
|
646
|
+
_a.push(_b);
|
|
647
|
+
_i = 0;
|
|
648
|
+
_f.label = 10;
|
|
649
|
+
case 10:
|
|
650
|
+
if (!(_i < _a.length)) return [3 /*break*/, 13];
|
|
651
|
+
attr = _a[_i];
|
|
652
|
+
return [5 /*yield**/, _loop_1(attr)];
|
|
653
|
+
case 11:
|
|
654
|
+
_f.sent();
|
|
655
|
+
_f.label = 12;
|
|
656
|
+
case 12:
|
|
657
|
+
_i++;
|
|
658
|
+
return [3 /*break*/, 10];
|
|
659
|
+
case 13:
|
|
660
|
+
operation2 = Object.assign({}, operation, {
|
|
661
|
+
data: opData,
|
|
662
|
+
});
|
|
663
|
+
return [4 /*yield*/, this.updateAbjointRow(entity, operation2, context, option)];
|
|
664
|
+
case 14:
|
|
665
|
+
count = _f.sent();
|
|
666
|
+
this.mergeOperationResult(result, (_d = {},
|
|
667
|
+
_d[entity] = (_e = {},
|
|
668
|
+
_e[operation2.action] = count,
|
|
669
|
+
_e),
|
|
670
|
+
_d));
|
|
671
|
+
return [2 /*return*/, result];
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
};
|
|
676
|
+
CascadeStore.prototype.judgeRelation = function (entity, attr) {
|
|
677
|
+
return (0, relation_1.judgeRelation)(this.storageSchema, entity, attr);
|
|
678
|
+
};
|
|
679
|
+
return CascadeStore;
|
|
680
|
+
}(RowStore_1.RowStore));
|
|
681
|
+
exports.CascadeStore = CascadeStore;
|