From 9c498c8a34b9a3f871f7f7eebfa02fde620df977 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Mon, 22 Aug 2022 17:37:59 +0800 Subject: [PATCH] =?UTF-8?q?Oper=E5=92=8CModi=E7=9A=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=AF=B9=E6=A1=86=E6=9E=B6=E7=9A=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/store.js | 164 ++++++++++++++++++++++++++++----------------------- package.json | 7 ++- src/store.ts | 11 +++- 3 files changed, 104 insertions(+), 78 deletions(-) diff --git a/lib/store.js b/lib/store.js index 5e69a6f..c96c31c 100644 --- a/lib/store.js +++ b/lib/store.js @@ -1136,19 +1136,22 @@ var TreeStore = /** @class */ (function (_super) { TreeStore.prototype.updateAbjointRow = function (entity, operation, context, option) { var _a, _b; return __awaiter(this, void 0, void 0, function () { - var data, action, operId, now, _c, id, node, data2_1, alreadyDirtyNode, data2, node2, operEntityData, selection, rows, ids, operData, rows_1, rows_1_1, row, _d, _e, e_10_1; - var _f, e_10, _g, _h, _j; + var data, action, operId, now, aciton2, _c, id, node, data2_1, alreadyDirtyNode, data2, node2, operEntityData, _d, _e, _f, selection, rows, ids, operData, rows_1, rows_1_1, row, _g, _h, e_10_1; + var _j, _k, _l, _m, _o, e_10, _p, _q, _r; var _this = this; - return __generator(this, function (_k) { - switch (_k.label) { + return __generator(this, function (_s) { + switch (_s.label) { case 0: data = operation.data, action = operation.action, operId = operation.id; now = Date.now(); + if (action.endsWith('-l')) { + aciton2 = action.slice(0, action.length - 2); + } _c = action; switch (_c) { case 'create': return [3 /*break*/, 1]; } - return [3 /*break*/, 5]; + return [3 /*break*/, 8]; case 1: id = data.id; // const node = this.store[entity] && (this.store[entity]!)[id as string]; @@ -1209,42 +1212,51 @@ var TreeStore = /** @class */ (function (_super) { d: data2, }); } - if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity))) return [3 /*break*/, 4]; - _f = {}; + if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity))) return [3 /*break*/, 7]; + // 按照框架要求生成Oper和OperEntity这两个内置的对象 + (0, assert_1.assert)(operId); + _j = {}; return [4 /*yield*/, generateNewId()]; case 2: - operEntityData = (_f.id = _k.sent(), - _f.entity = entity, - _f.entityId = id, - _f); - if (!((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.oper) === null || _b === void 0 ? void 0 : _b.operId)) { - Object.assign(operEntityData, { - oper: { - id: 'dummy', - action: 'create', - data: { - id: operId, - action: action, - data: data, - } - } - }); - } - else { - Object.assign(operEntityData, { - operId: operId, - }); - } - return [4 /*yield*/, this.cascadeUpdate('operEntity', { - id: 'dummy', - action: 'create', - data: operEntityData, - }, context)]; + operEntityData = (_j.id = _s.sent(), + _j.entity = entity, + _j.entityId = id, + _j); + if (!(!((_a = this.store) === null || _a === void 0 ? void 0 : _a.oper) || !((_b = this.store) === null || _b === void 0 ? void 0 : _b.oper[operId]))) return [3 /*break*/, 4]; + _e = (_d = Object).assign; + _f = [operEntityData]; + _k = {}; + _l = { + id: 'dummy', + action: 'create' + }; + _m = { + id: operId, + action: action, + data: data + }; + return [4 /*yield*/, context.getCurrentUserId()]; case 3: - _k.sent(); - _k.label = 4; - case 4: return [2 /*return*/, 1]; - case 5: + _e.apply(_d, _f.concat([(_k.oper = (_l.data = (_m.operatorId = _s.sent(), + _m), + _l), + _k)])); + return [3 /*break*/, 5]; + case 4: + Object.assign(operEntityData, { + operId: operId, + }); + _s.label = 5; + case 5: return [4 /*yield*/, this.cascadeUpdate('operEntity', { + id: 'dummy', + action: 'create', + data: operEntityData, + }, context)]; + case 6: + _s.sent(); + _s.label = 7; + case 7: return [2 /*return*/, 1]; + case 8: selection = { data: { id: 1, @@ -1254,8 +1266,8 @@ var TreeStore = /** @class */ (function (_super) { count: operation.count, }; return [4 /*yield*/, this.selectAbjointRow(entity, selection, context)]; - case 6: - rows = _k.sent(); + case 9: + rows = _s.sent(); ids = rows.map(function (ele) { return ele.id; }); ids.forEach(function (id) { var alreadyDirtyNode = false; @@ -1302,58 +1314,62 @@ var TreeStore = /** @class */ (function (_super) { } } }); - if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity) && rows.length > 0)) return [3 /*break*/, 16]; - operData = { + if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity) && rows.length > 0)) return [3 /*break*/, 20]; + _o = { id: operId, action: action, - data: data, - operEntity$oper: [], + data: data }; - _k.label = 7; - case 7: - _k.trys.push([7, 12, 13, 14]); + return [4 /*yield*/, context.getCurrentUserId()]; + case 10: + operData = (_o.operatorId = _s.sent(), + _o.operEntity$oper = [], + _o); + _s.label = 11; + case 11: + _s.trys.push([11, 16, 17, 18]); rows_1 = __values(rows), rows_1_1 = rows_1.next(); - _k.label = 8; - case 8: - if (!!rows_1_1.done) return [3 /*break*/, 11]; + _s.label = 12; + case 12: + if (!!rows_1_1.done) return [3 /*break*/, 15]; row = rows_1_1.value; - _e = (_d = operData.operEntity$oper).push; - _h = { + _h = (_g = operData.operEntity$oper).push; + _q = { id: 'dummy', action: 'create' }; - _j = {}; + _r = {}; return [4 /*yield*/, generateNewId()]; - case 9: - _e.apply(_d, [(_h.data = (_j.id = _k.sent(), - _j.entity = entity, - _j.entityId = row.id, - _j), - _h)]); - _k.label = 10; - case 10: - rows_1_1 = rows_1.next(); - return [3 /*break*/, 8]; - case 11: return [3 /*break*/, 14]; - case 12: - e_10_1 = _k.sent(); - e_10 = { error: e_10_1 }; - return [3 /*break*/, 14]; case 13: + _h.apply(_g, [(_q.data = (_r.id = _s.sent(), + _r.entity = entity, + _r.entityId = row.id, + _r), + _q)]); + _s.label = 14; + case 14: + rows_1_1 = rows_1.next(); + return [3 /*break*/, 12]; + case 15: return [3 /*break*/, 18]; + case 16: + e_10_1 = _s.sent(); + e_10 = { error: e_10_1 }; + return [3 /*break*/, 18]; + case 17: try { - if (rows_1_1 && !rows_1_1.done && (_g = rows_1.return)) _g.call(rows_1); + if (rows_1_1 && !rows_1_1.done && (_p = rows_1.return)) _p.call(rows_1); } finally { if (e_10) throw e_10.error; } return [7 /*endfinally*/]; - case 14: return [4 /*yield*/, this.cascadeUpdate('oper', { + case 18: return [4 /*yield*/, this.cascadeUpdate('oper', { id: 'dummy', action: 'create', data: operData, }, context)]; - case 15: - _k.sent(); - _k.label = 16; - case 16: return [2 /*return*/, rows.length]; + case 19: + _s.sent(); + _s.label = 20; + case 20: return [2 /*return*/, rows.length]; } }); }); diff --git a/package.json b/package.json index 314631d..d6781dc 100644 --- a/package.json +++ b/package.json @@ -10,15 +10,15 @@ ], "dependencies": { "luxon": "^2.3.0", - "uuid": "^8.3.2", - "oak-domain": "file:../oak-domain" + "oak-domain": "file:../oak-domain", + "uuid": "^8.3.2" }, "scripts": { "make:domain": "ts-node test/build-app-domain", "test": "cross-env TS_NODE_PROJECT='tsconfig.mocha.json' mocha", "build": "tsc" }, - "main": "lib/index", + "main": "lib/index", "devDependencies": { "@babel/cli": "^7.12.13", "@babel/core": "^7.12.13", @@ -37,6 +37,7 @@ "fs-extra": "^10.0.0", "mocha": "^8.2.1", "ts-node": "~10.9.1", + "tslib": "^2.4.0", "typescript": "~4.7.4" } } diff --git a/src/store.ts b/src/store.ts index 8e75dc6..87d318d 100644 --- a/src/store.ts +++ b/src/store.ts @@ -856,6 +856,12 @@ export default class TreeStore; @@ -921,12 +927,13 @@ export default class TreeStore