Oper和Modi的处理对框架的适配
This commit is contained in:
parent
58c4ef5b78
commit
9c498c8a34
164
lib/store.js
164
lib/store.js
|
|
@ -1136,19 +1136,22 @@ var TreeStore = /** @class */ (function (_super) {
|
||||||
TreeStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
TreeStore.prototype.updateAbjointRow = function (entity, operation, context, option) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
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 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 _f, e_10, _g, _h, _j;
|
var _j, _k, _l, _m, _o, e_10, _p, _q, _r;
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return __generator(this, function (_k) {
|
return __generator(this, function (_s) {
|
||||||
switch (_k.label) {
|
switch (_s.label) {
|
||||||
case 0:
|
case 0:
|
||||||
data = operation.data, action = operation.action, operId = operation.id;
|
data = operation.data, action = operation.action, operId = operation.id;
|
||||||
now = Date.now();
|
now = Date.now();
|
||||||
|
if (action.endsWith('-l')) {
|
||||||
|
aciton2 = action.slice(0, action.length - 2);
|
||||||
|
}
|
||||||
_c = action;
|
_c = action;
|
||||||
switch (_c) {
|
switch (_c) {
|
||||||
case 'create': return [3 /*break*/, 1];
|
case 'create': return [3 /*break*/, 1];
|
||||||
}
|
}
|
||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 8];
|
||||||
case 1:
|
case 1:
|
||||||
id = data.id;
|
id = data.id;
|
||||||
// const node = this.store[entity] && (this.store[entity]!)[id as string];
|
// const node = this.store[entity] && (this.store[entity]!)[id as string];
|
||||||
|
|
@ -1209,42 +1212,51 @@ var TreeStore = /** @class */ (function (_super) {
|
||||||
d: data2,
|
d: data2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity))) return [3 /*break*/, 4];
|
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity))) return [3 /*break*/, 7];
|
||||||
_f = {};
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||||
|
(0, assert_1.assert)(operId);
|
||||||
|
_j = {};
|
||||||
return [4 /*yield*/, generateNewId()];
|
return [4 /*yield*/, generateNewId()];
|
||||||
case 2:
|
case 2:
|
||||||
operEntityData = (_f.id = _k.sent(),
|
operEntityData = (_j.id = _s.sent(),
|
||||||
_f.entity = entity,
|
_j.entity = entity,
|
||||||
_f.entityId = id,
|
_j.entityId = id,
|
||||||
_f);
|
_j);
|
||||||
if (!((_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.oper) === null || _b === void 0 ? void 0 : _b.operId)) {
|
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];
|
||||||
Object.assign(operEntityData, {
|
_e = (_d = Object).assign;
|
||||||
oper: {
|
_f = [operEntityData];
|
||||||
id: 'dummy',
|
_k = {};
|
||||||
action: 'create',
|
_l = {
|
||||||
data: {
|
id: 'dummy',
|
||||||
id: operId,
|
action: 'create'
|
||||||
action: action,
|
};
|
||||||
data: data,
|
_m = {
|
||||||
}
|
id: operId,
|
||||||
}
|
action: action,
|
||||||
});
|
data: data
|
||||||
}
|
};
|
||||||
else {
|
return [4 /*yield*/, context.getCurrentUserId()];
|
||||||
Object.assign(operEntityData, {
|
|
||||||
operId: operId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return [4 /*yield*/, this.cascadeUpdate('operEntity', {
|
|
||||||
id: 'dummy',
|
|
||||||
action: 'create',
|
|
||||||
data: operEntityData,
|
|
||||||
}, context)];
|
|
||||||
case 3:
|
case 3:
|
||||||
_k.sent();
|
_e.apply(_d, _f.concat([(_k.oper = (_l.data = (_m.operatorId = _s.sent(),
|
||||||
_k.label = 4;
|
_m),
|
||||||
case 4: return [2 /*return*/, 1];
|
_l),
|
||||||
case 5:
|
_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 = {
|
selection = {
|
||||||
data: {
|
data: {
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
@ -1254,8 +1266,8 @@ var TreeStore = /** @class */ (function (_super) {
|
||||||
count: operation.count,
|
count: operation.count,
|
||||||
};
|
};
|
||||||
return [4 /*yield*/, this.selectAbjointRow(entity, selection, context)];
|
return [4 /*yield*/, this.selectAbjointRow(entity, selection, context)];
|
||||||
case 6:
|
case 9:
|
||||||
rows = _k.sent();
|
rows = _s.sent();
|
||||||
ids = rows.map(function (ele) { return ele.id; });
|
ids = rows.map(function (ele) { return ele.id; });
|
||||||
ids.forEach(function (id) {
|
ids.forEach(function (id) {
|
||||||
var alreadyDirtyNode = false;
|
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];
|
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity'].includes(entity) && rows.length > 0)) return [3 /*break*/, 20];
|
||||||
operData = {
|
_o = {
|
||||||
id: operId,
|
id: operId,
|
||||||
action: action,
|
action: action,
|
||||||
data: data,
|
data: data
|
||||||
operEntity$oper: [],
|
|
||||||
};
|
};
|
||||||
_k.label = 7;
|
return [4 /*yield*/, context.getCurrentUserId()];
|
||||||
case 7:
|
case 10:
|
||||||
_k.trys.push([7, 12, 13, 14]);
|
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();
|
rows_1 = __values(rows), rows_1_1 = rows_1.next();
|
||||||
_k.label = 8;
|
_s.label = 12;
|
||||||
case 8:
|
case 12:
|
||||||
if (!!rows_1_1.done) return [3 /*break*/, 11];
|
if (!!rows_1_1.done) return [3 /*break*/, 15];
|
||||||
row = rows_1_1.value;
|
row = rows_1_1.value;
|
||||||
_e = (_d = operData.operEntity$oper).push;
|
_h = (_g = operData.operEntity$oper).push;
|
||||||
_h = {
|
_q = {
|
||||||
id: 'dummy',
|
id: 'dummy',
|
||||||
action: 'create'
|
action: 'create'
|
||||||
};
|
};
|
||||||
_j = {};
|
_r = {};
|
||||||
return [4 /*yield*/, generateNewId()];
|
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:
|
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 {
|
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; }
|
finally { if (e_10) throw e_10.error; }
|
||||||
return [7 /*endfinally*/];
|
return [7 /*endfinally*/];
|
||||||
case 14: return [4 /*yield*/, this.cascadeUpdate('oper', {
|
case 18: return [4 /*yield*/, this.cascadeUpdate('oper', {
|
||||||
id: 'dummy',
|
id: 'dummy',
|
||||||
action: 'create',
|
action: 'create',
|
||||||
data: operData,
|
data: operData,
|
||||||
}, context)];
|
}, context)];
|
||||||
case 15:
|
case 19:
|
||||||
_k.sent();
|
_s.sent();
|
||||||
_k.label = 16;
|
_s.label = 20;
|
||||||
case 16: return [2 /*return*/, rows.length];
|
case 20: return [2 /*return*/, rows.length];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,15 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"luxon": "^2.3.0",
|
"luxon": "^2.3.0",
|
||||||
"uuid": "^8.3.2",
|
"oak-domain": "file:../oak-domain",
|
||||||
"oak-domain": "file:../oak-domain"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"make:domain": "ts-node test/build-app-domain",
|
"make:domain": "ts-node test/build-app-domain",
|
||||||
"test": "cross-env TS_NODE_PROJECT='tsconfig.mocha.json' mocha",
|
"test": "cross-env TS_NODE_PROJECT='tsconfig.mocha.json' mocha",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"main": "lib/index",
|
"main": "lib/index",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.12.13",
|
"@babel/cli": "^7.12.13",
|
||||||
"@babel/core": "^7.12.13",
|
"@babel/core": "^7.12.13",
|
||||||
|
|
@ -37,6 +37,7 @@
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
"ts-node": "~10.9.1",
|
"ts-node": "~10.9.1",
|
||||||
|
"tslib": "^2.4.0",
|
||||||
"typescript": "~4.7.4"
|
"typescript": "~4.7.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/store.ts
11
src/store.ts
|
|
@ -856,6 +856,12 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict, Cxt exten
|
||||||
const { data, action, id: operId } = operation;
|
const { data, action, id: operId } = operation;
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
if (action.endsWith('-l')) {
|
||||||
|
// 说明是延时动作,此时将之转换成为对Modi对象的插入动作
|
||||||
|
const aciton2 = action.slice(0, action.length -2);
|
||||||
|
|
||||||
|
}
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'create': {
|
case 'create': {
|
||||||
const { id } = data as DeduceCreateOperationData<ED[T]["Schema"]>;
|
const { id } = data as DeduceCreateOperationData<ED[T]["Schema"]>;
|
||||||
|
|
@ -921,12 +927,13 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict, Cxt exten
|
||||||
}
|
}
|
||||||
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity'].includes(entity as string)) {
|
if (!option?.dontCreateOper && !['oper', 'operEntity', 'modiEntity'].includes(entity as string)) {
|
||||||
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
||||||
|
assert(operId);
|
||||||
const operEntityData = {
|
const operEntityData = {
|
||||||
id: await generateNewId(),
|
id: await generateNewId(),
|
||||||
entity,
|
entity,
|
||||||
entityId: id,
|
entityId: id,
|
||||||
};
|
};
|
||||||
if (!this.store?.oper?.operId) {
|
if (!this.store?.oper || !this.store?.oper[operId]) {
|
||||||
Object.assign(operEntityData, {
|
Object.assign(operEntityData, {
|
||||||
oper: {
|
oper: {
|
||||||
id: 'dummy',
|
id: 'dummy',
|
||||||
|
|
@ -935,6 +942,7 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict, Cxt exten
|
||||||
id: operId,
|
id: operId,
|
||||||
action,
|
action,
|
||||||
data,
|
data,
|
||||||
|
operatorId: await context.getCurrentUserId(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1018,6 +1026,7 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict, Cxt exten
|
||||||
id: operId,
|
id: operId,
|
||||||
action,
|
action,
|
||||||
data,
|
data,
|
||||||
|
operatorId: await context.getCurrentUserId(),
|
||||||
operEntity$oper: [],
|
operEntity$oper: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue