debugStore中的cascadeSelect下降到根select去处理trigger,runningTree在composeOperation时尽可能把主键构造出来
This commit is contained in:
parent
2938e847fa
commit
fe4429a440
|
|
@ -16,7 +16,6 @@ export declare class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt exte
|
||||||
commit(txnId: string): Promise<void>;
|
commit(txnId: string): Promise<void>;
|
||||||
rollback(txnId: string): Promise<void>;
|
rollback(txnId: string): Promise<void>;
|
||||||
protected cascadeUpdateAsync<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
protected cascadeUpdateAsync<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||||
protected cascadeSelectAsync<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
|
||||||
operate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
operate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||||
select<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
select<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
||||||
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number>;
|
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number>;
|
||||||
|
|
|
||||||
|
|
@ -47,33 +47,6 @@ var DebugStore = /** @class */ (function (_super) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
DebugStore.prototype.cascadeSelectAsync = function (entity, selection, context, option) {
|
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
||||||
var selection2, result;
|
|
||||||
return tslib_1.__generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0:
|
|
||||||
selection2 = Object.assign({
|
|
||||||
action: 'select',
|
|
||||||
}, selection);
|
|
||||||
if (!!option.blockTrigger) return [3 /*break*/, 2];
|
|
||||||
return [4 /*yield*/, this.executor.preOperation(entity, selection2, context, option)];
|
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
_a.label = 2;
|
|
||||||
case 2: return [4 /*yield*/, _super.prototype.cascadeSelectAsync.call(this, entity, selection2, context, option)];
|
|
||||||
case 3:
|
|
||||||
result = _a.sent();
|
|
||||||
if (!!option.blockTrigger) return [3 /*break*/, 5];
|
|
||||||
return [4 /*yield*/, this.executor.postOperation(entity, selection2, context, option, result)];
|
|
||||||
case 4:
|
|
||||||
_a.sent();
|
|
||||||
_a.label = 5;
|
|
||||||
case 5: return [2 /*return*/, result];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
DebugStore.prototype.operate = function (entity, operation, context, option) {
|
DebugStore.prototype.operate = function (entity, operation, context, option) {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
return tslib_1.__generator(this, function (_a) {
|
return tslib_1.__generator(this, function (_a) {
|
||||||
|
|
@ -84,9 +57,29 @@ var DebugStore = /** @class */ (function (_super) {
|
||||||
};
|
};
|
||||||
DebugStore.prototype.select = function (entity, selection, context, option) {
|
DebugStore.prototype.select = function (entity, selection, context, option) {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
|
var selection2, result;
|
||||||
return tslib_1.__generator(this, function (_a) {
|
return tslib_1.__generator(this, function (_a) {
|
||||||
(0, assert_1.default)(context.getCurrentTxnId());
|
switch (_a.label) {
|
||||||
return [2 /*return*/, _super.prototype.selectAsync.call(this, entity, selection, context, option)];
|
case 0:
|
||||||
|
(0, assert_1.default)(context.getCurrentTxnId());
|
||||||
|
selection2 = Object.assign({
|
||||||
|
action: 'select',
|
||||||
|
}, selection);
|
||||||
|
if (!!option.blockTrigger) return [3 /*break*/, 2];
|
||||||
|
return [4 /*yield*/, this.executor.preOperation(entity, selection2, context, option)];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
_a.label = 2;
|
||||||
|
case 2: return [4 /*yield*/, _super.prototype.selectAsync.call(this, entity, selection, context, option)];
|
||||||
|
case 3:
|
||||||
|
result = _a.sent();
|
||||||
|
if (!!option.blockTrigger) return [3 /*break*/, 5];
|
||||||
|
return [4 /*yield*/, this.executor.postOperation(entity, selection2, context, option, result)];
|
||||||
|
case 4:
|
||||||
|
_a.sent();
|
||||||
|
_a.label = 5;
|
||||||
|
case 5: return [2 /*return*/, result];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -128,86 +128,89 @@ function initializeWatchers(store, contextBuilder, watchers) {
|
||||||
var count = 0;
|
var count = 0;
|
||||||
function doWatchers() {
|
function doWatchers() {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
var start, context, watchers_1, watchers_1_1, w, _a, entity, action, filter, actionData, filter2, _b, data, _c, result, _d, entity, projection, fn, filter, filter2, _e, projection2, _f, rows, result, err_1, e_1_1, duration;
|
var start, context, watchers_1, watchers_1_1, w, _a, entity, action, filter, actionData, filter2, _b, data, _c, result, _d, _e, _f, _g, entity, projection, fn, filter, filter2, _h, projection2, _j, rows, result, err_1, e_1_1, duration;
|
||||||
var e_1, _g;
|
var e_1, _k, _l;
|
||||||
return tslib_1.__generator(this, function (_h) {
|
return tslib_1.__generator(this, function (_m) {
|
||||||
switch (_h.label) {
|
switch (_m.label) {
|
||||||
case 0:
|
case 0:
|
||||||
count++;
|
count++;
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
return [4 /*yield*/, contextBuilder()(store)];
|
return [4 /*yield*/, contextBuilder()(store)];
|
||||||
case 1:
|
case 1:
|
||||||
context = _h.sent();
|
context = _m.sent();
|
||||||
_h.label = 2;
|
_m.label = 2;
|
||||||
case 2:
|
case 2:
|
||||||
_h.trys.push([2, 28, 29, 30]);
|
_m.trys.push([2, 29, 30, 31]);
|
||||||
watchers_1 = tslib_1.__values(watchers), watchers_1_1 = watchers_1.next();
|
watchers_1 = tslib_1.__values(watchers), watchers_1_1 = watchers_1.next();
|
||||||
_h.label = 3;
|
_m.label = 3;
|
||||||
case 3:
|
case 3:
|
||||||
if (!!watchers_1_1.done) return [3 /*break*/, 27];
|
if (!!watchers_1_1.done) return [3 /*break*/, 28];
|
||||||
w = watchers_1_1.value;
|
w = watchers_1_1.value;
|
||||||
return [4 /*yield*/, context.begin()];
|
return [4 /*yield*/, context.begin()];
|
||||||
case 4:
|
case 4:
|
||||||
_h.sent();
|
_m.sent();
|
||||||
_h.label = 5;
|
_m.label = 5;
|
||||||
case 5:
|
case 5:
|
||||||
_h.trys.push([5, 24, , 26]);
|
_m.trys.push([5, 25, , 27]);
|
||||||
if (!w.hasOwnProperty('actionData')) return [3 /*break*/, 13];
|
if (!w.hasOwnProperty('actionData')) return [3 /*break*/, 14];
|
||||||
_a = w, entity = _a.entity, action = _a.action, filter = _a.filter, actionData = _a.actionData;
|
_a = w, entity = _a.entity, action = _a.action, filter = _a.filter, actionData = _a.actionData;
|
||||||
if (!(typeof filter === 'function')) return [3 /*break*/, 7];
|
if (!(typeof filter === 'function')) return [3 /*break*/, 7];
|
||||||
return [4 /*yield*/, filter()];
|
return [4 /*yield*/, filter()];
|
||||||
case 6:
|
case 6:
|
||||||
_b = _h.sent();
|
_b = _m.sent();
|
||||||
return [3 /*break*/, 8];
|
return [3 /*break*/, 8];
|
||||||
case 7:
|
case 7:
|
||||||
_b = filter;
|
_b = filter;
|
||||||
_h.label = 8;
|
_m.label = 8;
|
||||||
case 8:
|
case 8:
|
||||||
filter2 = _b;
|
filter2 = _b;
|
||||||
if (!(typeof actionData === 'function')) return [3 /*break*/, 10];
|
if (!(typeof actionData === 'function')) return [3 /*break*/, 10];
|
||||||
return [4 /*yield*/, actionData()];
|
return [4 /*yield*/, actionData()];
|
||||||
case 9:
|
case 9:
|
||||||
_c = _h.sent();
|
_c = _m.sent();
|
||||||
return [3 /*break*/, 11];
|
return [3 /*break*/, 11];
|
||||||
case 10:
|
case 10:
|
||||||
_c = actionData;
|
_c = actionData;
|
||||||
_h.label = 11;
|
_m.label = 11;
|
||||||
case 11:
|
case 11:
|
||||||
data = _c;
|
data = _c;
|
||||||
return [4 /*yield*/, store.operate(entity, {
|
_e = (_d = store).operate;
|
||||||
id: (0, uuid_1.generateNewId)(),
|
_f = [entity];
|
||||||
action: action,
|
_l = {};
|
||||||
data: data,
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||||
filter: filter2
|
case 12: return [4 /*yield*/, _e.apply(_d, _f.concat([(_l.id = _m.sent(),
|
||||||
}, context, {
|
_l.action = action,
|
||||||
|
_l.data = data,
|
||||||
|
_l.filter = filter2,
|
||||||
|
_l), context, {
|
||||||
dontCollect: true,
|
dontCollect: true,
|
||||||
})];
|
}]))];
|
||||||
case 12:
|
|
||||||
result = _h.sent();
|
|
||||||
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
|
||||||
return [3 /*break*/, 22];
|
|
||||||
case 13:
|
case 13:
|
||||||
_d = w, entity = _d.entity, projection = _d.projection, fn = _d.fn, filter = _d.filter;
|
result = _m.sent();
|
||||||
if (!(typeof filter === 'function')) return [3 /*break*/, 15];
|
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
||||||
return [4 /*yield*/, filter()];
|
return [3 /*break*/, 23];
|
||||||
case 14:
|
case 14:
|
||||||
_e = _h.sent();
|
_g = w, entity = _g.entity, projection = _g.projection, fn = _g.fn, filter = _g.filter;
|
||||||
return [3 /*break*/, 16];
|
if (!(typeof filter === 'function')) return [3 /*break*/, 16];
|
||||||
|
return [4 /*yield*/, filter()];
|
||||||
case 15:
|
case 15:
|
||||||
_e = filter;
|
_h = _m.sent();
|
||||||
_h.label = 16;
|
return [3 /*break*/, 17];
|
||||||
case 16:
|
case 16:
|
||||||
filter2 = _e;
|
_h = filter;
|
||||||
if (!(typeof projection === 'function')) return [3 /*break*/, 18];
|
_m.label = 17;
|
||||||
return [4 /*yield*/, projection()];
|
|
||||||
case 17:
|
case 17:
|
||||||
_f = _h.sent();
|
filter2 = _h;
|
||||||
return [3 /*break*/, 19];
|
if (!(typeof projection === 'function')) return [3 /*break*/, 19];
|
||||||
|
return [4 /*yield*/, projection()];
|
||||||
case 18:
|
case 18:
|
||||||
_f = projection;
|
_j = _m.sent();
|
||||||
_h.label = 19;
|
return [3 /*break*/, 20];
|
||||||
case 19:
|
case 19:
|
||||||
projection2 = _f;
|
_j = projection;
|
||||||
|
_m.label = 20;
|
||||||
|
case 20:
|
||||||
|
projection2 = _j;
|
||||||
return [4 /*yield*/, store.select(entity, {
|
return [4 /*yield*/, store.select(entity, {
|
||||||
data: projection2,
|
data: projection2,
|
||||||
filter: filter2,
|
filter: filter2,
|
||||||
|
|
@ -215,39 +218,39 @@ function initializeWatchers(store, contextBuilder, watchers) {
|
||||||
dontCollect: true,
|
dontCollect: true,
|
||||||
blockTrigger: true,
|
blockTrigger: true,
|
||||||
})];
|
})];
|
||||||
case 20:
|
|
||||||
rows = _h.sent();
|
|
||||||
return [4 /*yield*/, fn(context, rows)];
|
|
||||||
case 21:
|
case 21:
|
||||||
result = _h.sent();
|
rows = _m.sent();
|
||||||
|
return [4 /*yield*/, fn(context, rows)];
|
||||||
|
case 22:
|
||||||
|
result = _m.sent();
|
||||||
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
||||||
_h.label = 22;
|
_m.label = 23;
|
||||||
case 22: return [4 /*yield*/, context.commit()];
|
case 23: return [4 /*yield*/, context.commit()];
|
||||||
case 23:
|
|
||||||
_h.sent();
|
|
||||||
return [3 /*break*/, 26];
|
|
||||||
case 24:
|
case 24:
|
||||||
err_1 = _h.sent();
|
_m.sent();
|
||||||
return [4 /*yield*/, context.rollback()];
|
return [3 /*break*/, 27];
|
||||||
case 25:
|
case 25:
|
||||||
_h.sent();
|
err_1 = _m.sent();
|
||||||
console.error("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u53D1\u751F\u9519\u8BEF\uFF1A"), err_1);
|
return [4 /*yield*/, context.rollback()];
|
||||||
return [3 /*break*/, 26];
|
|
||||||
case 26:
|
case 26:
|
||||||
|
_m.sent();
|
||||||
|
console.error("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u53D1\u751F\u9519\u8BEF\uFF1A"), err_1);
|
||||||
|
return [3 /*break*/, 27];
|
||||||
|
case 27:
|
||||||
watchers_1_1 = watchers_1.next();
|
watchers_1_1 = watchers_1.next();
|
||||||
return [3 /*break*/, 3];
|
return [3 /*break*/, 3];
|
||||||
case 27: return [3 /*break*/, 30];
|
case 28: return [3 /*break*/, 31];
|
||||||
case 28:
|
|
||||||
e_1_1 = _h.sent();
|
|
||||||
e_1 = { error: e_1_1 };
|
|
||||||
return [3 /*break*/, 30];
|
|
||||||
case 29:
|
case 29:
|
||||||
|
e_1_1 = _m.sent();
|
||||||
|
e_1 = { error: e_1_1 };
|
||||||
|
return [3 /*break*/, 31];
|
||||||
|
case 30:
|
||||||
try {
|
try {
|
||||||
if (watchers_1_1 && !watchers_1_1.done && (_g = watchers_1.return)) _g.call(watchers_1);
|
if (watchers_1_1 && !watchers_1_1.done && (_k = watchers_1.return)) _k.call(watchers_1);
|
||||||
}
|
}
|
||||||
finally { if (e_1) throw e_1.error; }
|
finally { if (e_1) throw e_1.error; }
|
||||||
return [7 /*endfinally*/];
|
return [7 /*endfinally*/];
|
||||||
case 30:
|
case 31:
|
||||||
duration = Date.now() - start;
|
duration = Date.now() - start;
|
||||||
console.log("\u7B2C".concat(count, "\u6B21\u6267\u884Cwatchers\uFF0C\u5171\u6267\u884C").concat(watchers.length, "\u4E2A\uFF0C\u8017\u65F6").concat(duration, "\u6BEB\u79D2"));
|
console.log("\u7B2C".concat(count, "\u6B21\u6267\u884Cwatchers\uFF0C\u5171\u6267\u884C").concat(watchers.length, "\u4E2A\uFF0C\u8017\u65F6").concat(duration, "\u6BEB\u79D2"));
|
||||||
setTimeout(function () { return doWatchers(); }, 120000);
|
setTimeout(function () { return doWatchers(); }, 120000);
|
||||||
|
|
|
||||||
|
|
@ -1426,29 +1426,15 @@ var SingleNode = /** @class */ (function (_super) {
|
||||||
if (!this.dirty) {
|
if (!this.dirty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.operation) {
|
var filter = this.getFilter();
|
||||||
var operation_1 = {
|
var operation = this.operation ? (0, lodash_1.cloneDeep)(this.operation.operation) : {
|
||||||
id: (0, uuid_1.generateNewId)(),
|
id: (0, uuid_1.generateNewId)(),
|
||||||
action: 'update',
|
action: 'update',
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
if (this.id) {
|
if (filter) {
|
||||||
Object.assign(operation_1, {
|
|
||||||
filter: {
|
|
||||||
id: this.id,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.operation = {
|
|
||||||
operation: operation_1,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
var operation = (0, lodash_1.cloneDeep)(this.operation.operation);
|
|
||||||
if (this.id && !operation.filter) {
|
|
||||||
Object.assign(operation, {
|
Object.assign(operation, {
|
||||||
filter: {
|
filter: filter,
|
||||||
id: this.id,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (var ele in this.children) {
|
for (var ele in this.children) {
|
||||||
|
|
@ -1592,26 +1578,20 @@ var SingleNode = /** @class */ (function (_super) {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
SingleNode.prototype.getParentFilter = function (childNode) {
|
SingleNode.prototype.getParentFilter = function (childNode) {
|
||||||
var _a, _b, _c;
|
var _a, _b, _c, _d;
|
||||||
var filter = this.getFilter(true);
|
var filter = this.getFilter(true);
|
||||||
|
var value = this.getFreshValue();
|
||||||
|
var id = this.id;
|
||||||
for (var key in this.children) {
|
for (var key in this.children) {
|
||||||
if (childNode === this.children[key]) {
|
if (childNode === this.children[key]) {
|
||||||
var sliceIdx = key.indexOf(':');
|
var sliceIdx = key.indexOf(':');
|
||||||
var key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
var key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
||||||
// 此时如果operation中有相关的外键被设置则直接返回
|
|
||||||
var operationData = undefined;
|
|
||||||
if (this.operation) {
|
|
||||||
var _d = this.operation.operation, action = _d.action, data = _d.data;
|
|
||||||
if (action !== 'remove') {
|
|
||||||
operationData = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var rel = this.judgeRelation(key2);
|
var rel = this.judgeRelation(key2);
|
||||||
if (rel === 2) {
|
if (rel === 2) {
|
||||||
// 基于entity/entityId的多对一
|
// 基于entity/entityId的多对一
|
||||||
if (operationData === null || operationData === void 0 ? void 0 : operationData.entityId) {
|
if (value === null || value === void 0 ? void 0 : value.entityId) {
|
||||||
return {
|
return {
|
||||||
id: operationData.entityId,
|
id: value.entityId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (filter) {
|
else if (filter) {
|
||||||
|
|
@ -1634,9 +1614,9 @@ var SingleNode = /** @class */ (function (_super) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (typeof rel === 'string') {
|
else if (typeof rel === 'string') {
|
||||||
if (operationData && operationData["".concat(rel, "Id")]) {
|
if (value && value["".concat(rel, "Id")]) {
|
||||||
return {
|
return {
|
||||||
id: operationData["".concat(rel, "Id")],
|
id: value["".concat(rel, "Id")],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (filter) {
|
else if (filter) {
|
||||||
|
|
@ -1658,22 +1638,38 @@ var SingleNode = /** @class */ (function (_super) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(0, assert_1.assert)(rel instanceof Array);
|
(0, assert_1.assert)(rel instanceof Array);
|
||||||
if (filter) {
|
if (rel[1]) {
|
||||||
if (rel[1]) {
|
// 基于普通外键的一对多
|
||||||
// 基于普通外键的一对多
|
if (id || value) {
|
||||||
return _b = {},
|
return _b = {},
|
||||||
_b[rel[1].slice(0, rel[1].length - 2)] = filter,
|
_b[rel[1]] = id || value.id,
|
||||||
_b;
|
_b;
|
||||||
}
|
}
|
||||||
else {
|
else if (filter) {
|
||||||
// 基于entity/entityId的一对多
|
|
||||||
return _c = {},
|
return _c = {},
|
||||||
_c[this.entity] = filter,
|
_c[rel[1].slice(0, rel[1].length - 2)] = filter,
|
||||||
_c;
|
_c;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
// 基于entity/entityId的一对多
|
||||||
|
if (id || value) {
|
||||||
|
return {
|
||||||
|
entity: this.entity,
|
||||||
|
entityId: id || value.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (filter) {
|
||||||
|
return _d = {},
|
||||||
|
_d[this.entity] = filter,
|
||||||
|
_d;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ var oakBehavior = Behavior({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
reRender: function () {
|
reRender: function () {
|
||||||
return page_common_1.reRender.call(this, this.option);
|
return page_common_1.reRender.call(this, this.oakOption);
|
||||||
},
|
},
|
||||||
onLoad: function (query) {
|
onLoad: function (query) {
|
||||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||||
|
|
@ -78,7 +78,7 @@ var oakBehavior = Behavior({
|
||||||
return tslib_1.__generator(this, function (_b) {
|
return tslib_1.__generator(this, function (_b) {
|
||||||
switch (_b.label) {
|
switch (_b.label) {
|
||||||
case 0:
|
case 0:
|
||||||
_a = this.option, properties = _a.properties, path = _a.path;
|
_a = this.oakOption, properties = _a.properties, path = _a.path;
|
||||||
assignProps = function (data, property, type) {
|
assignProps = function (data, property, type) {
|
||||||
var _a;
|
var _a;
|
||||||
if (data[property]) {
|
if (data[property]) {
|
||||||
|
|
@ -126,7 +126,7 @@ var oakBehavior = Behavior({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(this.props.oakPath || (this.iAmThePage() && path))) return [3 /*break*/, 2];
|
if (!(this.props.oakPath || (this.iAmThePage() && path))) return [3 /*break*/, 2];
|
||||||
return [4 /*yield*/, page_common_1.onPathSet.call(this, this.option)];
|
return [4 /*yield*/, page_common_1.onPathSet.call(this, this.oakOption)];
|
||||||
case 1:
|
case 1:
|
||||||
_b.sent();
|
_b.sent();
|
||||||
return [3 /*break*/, 3];
|
return [3 /*break*/, 3];
|
||||||
|
|
@ -166,7 +166,7 @@ var oakBehavior = Behavior({
|
||||||
case 0:
|
case 0:
|
||||||
if (!(!this.state.oakLoadingMore &&
|
if (!(!this.state.oakLoadingMore &&
|
||||||
this.iAmThePage() &&
|
this.iAmThePage() &&
|
||||||
this.option.isList)) return [3 /*break*/, 2];
|
this.oakOption.isList)) return [3 /*break*/, 2];
|
||||||
return [4 /*yield*/, this.loadMore()];
|
return [4 /*yield*/, this.loadMore()];
|
||||||
case 1:
|
case 1:
|
||||||
_a.sent();
|
_a.sent();
|
||||||
|
|
@ -372,7 +372,7 @@ var oakBehavior = Behavior({
|
||||||
observers: {
|
observers: {
|
||||||
oakPath: function (data) {
|
oakPath: function (data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
page_common_1.onPathSet.call(this, this.option);
|
page_common_1.onPathSet.call(this, this.oakOption);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oakId: function (data) {
|
oakId: function (data) {
|
||||||
|
|
@ -381,12 +381,12 @@ var oakBehavior = Behavior({
|
||||||
},
|
},
|
||||||
pageLifetimes: {
|
pageLifetimes: {
|
||||||
show: function () {
|
show: function () {
|
||||||
var show = (this.option.lifetimes || {}).show;
|
var show = (this.oakOption.lifetimes || {}).show;
|
||||||
this.reRender();
|
this.reRender();
|
||||||
show && show.call(this);
|
show && show.call(this);
|
||||||
},
|
},
|
||||||
hide: function () {
|
hide: function () {
|
||||||
var hide = (this.option.lifetimes || {}).hide;
|
var hide = (this.oakOption.lifetimes || {}).hide;
|
||||||
hide && hide.call(this);
|
hide && hide.call(this);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -404,46 +404,15 @@ var oakBehavior = Behavior({
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
attached: function () {
|
|
||||||
var _a;
|
|
||||||
var attached = (this.option.lifetimes || {}).attached;
|
|
||||||
var i18nInstance = (0, i18n_1.getI18nInstanceWechatMp)();
|
|
||||||
if (i18nInstance) {
|
|
||||||
this.setState((_a = {},
|
|
||||||
_a[i18n_1.CURRENT_LOCALE_KEY] = i18nInstance.currentLocale,
|
|
||||||
_a[i18n_1.CURRENT_LOCALE_DATA] = i18nInstance.translations,
|
|
||||||
_a));
|
|
||||||
}
|
|
||||||
attached && attached.call(this);
|
|
||||||
},
|
|
||||||
detached: function () {
|
|
||||||
this.state.oakFullpath &&
|
|
||||||
(this.iAmThePage() || this.props.oakAutoUnmount) &&
|
|
||||||
page_common_1.destroyNode.call(this);
|
|
||||||
var detached = (this.option.lifetimes || {}).detached;
|
|
||||||
detached && detached.call(this);
|
|
||||||
},
|
|
||||||
ready: function () {
|
|
||||||
var ready = (this.option.lifetimes || {}).ready;
|
|
||||||
ready && ready.call(this);
|
|
||||||
},
|
|
||||||
moved: function () {
|
|
||||||
var moved = (this.option.lifetimes || {}).moved;
|
|
||||||
moved && moved.call(this);
|
|
||||||
},
|
|
||||||
error: function (err) {
|
|
||||||
var error = (this.option.lifetimes || {}).error;
|
|
||||||
error && error.call(this, err);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
function createComponent(option, features) {
|
function createComponent(option, features) {
|
||||||
var data = option.data, properties = option.properties, methods = option.methods, wechatMp = option.wechatMp, lifetimes = option.lifetimes, observers = option.observers;
|
var data = option.data, properties = option.properties, methods = option.methods, wechatMp = option.wechatMp, lifetimes = option.lifetimes, observers = option.observers;
|
||||||
var _a = lifetimes || {}, attached = _a.attached, show = _a.show, hide = _a.hide, created = _a.created, detached = _a.detached, restLifetimes = tslib_1.__rest(_a, ["attached", "show", "hide", "created", "detached"]);
|
var _a = lifetimes || {}, attached = _a.attached, show = _a.show, hide = _a.hide, created = _a.created, detached = _a.detached, ready = _a.ready, moved = _a.moved, error = _a.error;
|
||||||
var _b = wechatMp || {}, options = _b.options, externalClasses = _b.externalClasses;
|
var _b = wechatMp || {}, options = _b.options, externalClasses = _b.externalClasses;
|
||||||
return Component({
|
return Component({
|
||||||
externalClasses: externalClasses,
|
externalClasses: externalClasses,
|
||||||
options: options,
|
// options,
|
||||||
behaviors: [oakBehavior],
|
behaviors: [oakBehavior],
|
||||||
data: Object.assign({}, data, {
|
data: Object.assign({}, data, {
|
||||||
oakFullpath: '',
|
oakFullpath: '',
|
||||||
|
|
@ -453,7 +422,7 @@ function createComponent(option, features) {
|
||||||
observers: tslib_1.__assign({}, observers),
|
observers: tslib_1.__assign({}, observers),
|
||||||
pageLifetimes: {
|
pageLifetimes: {
|
||||||
show: function () {
|
show: function () {
|
||||||
this.reRender();
|
// this.reRender();
|
||||||
show && show.call(this);
|
show && show.call(this);
|
||||||
},
|
},
|
||||||
hide: function () {
|
hide: function () {
|
||||||
|
|
@ -464,8 +433,40 @@ function createComponent(option, features) {
|
||||||
created: function () {
|
created: function () {
|
||||||
this.oakOption = option;
|
this.oakOption = option;
|
||||||
this.features = features;
|
this.features = features;
|
||||||
|
this.subscribed = [];
|
||||||
created && created.call(this);
|
created && created.call(this);
|
||||||
},
|
},
|
||||||
|
attached: function () {
|
||||||
|
var _a;
|
||||||
|
var _this = this;
|
||||||
|
var i18nInstance = (0, i18n_1.getI18nInstanceWechatMp)();
|
||||||
|
if (i18nInstance) {
|
||||||
|
this.setState((_a = {},
|
||||||
|
_a[i18n_1.CURRENT_LOCALE_KEY] = i18nInstance.currentLocale,
|
||||||
|
_a[i18n_1.CURRENT_LOCALE_DATA] = i18nInstance.translations,
|
||||||
|
_a));
|
||||||
|
}
|
||||||
|
if (option.entity) {
|
||||||
|
this.subscribed.push(features.cache.subscribe(function () { return _this.reRender(); }));
|
||||||
|
}
|
||||||
|
attached && attached.call(this);
|
||||||
|
},
|
||||||
|
detached: function () {
|
||||||
|
this.subscribed.forEach(function (ele) { return ele(); });
|
||||||
|
this.state.oakFullpath &&
|
||||||
|
(this.iAmThePage() || this.props.oakAutoUnmount) &&
|
||||||
|
page_common_1.destroyNode.call(this);
|
||||||
|
detached && detached.call(this);
|
||||||
|
},
|
||||||
|
ready: function () {
|
||||||
|
ready && ready.call(this);
|
||||||
|
},
|
||||||
|
moved: function () {
|
||||||
|
moved && moved.call(this);
|
||||||
|
},
|
||||||
|
error: function (err) {
|
||||||
|
error && error.call(this, err);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,21 +41,6 @@ export class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Asyn
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async cascadeSelectAsync<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: OP) {
|
|
||||||
const selection2 = Object.assign({
|
|
||||||
action: 'select',
|
|
||||||
}, selection) as ED[T]['Operation'];
|
|
||||||
|
|
||||||
if (!option.blockTrigger) {
|
|
||||||
await this.executor.preOperation(entity, selection2, context, option);
|
|
||||||
}
|
|
||||||
const result = await super.cascadeSelectAsync(entity, selection2, context, option);
|
|
||||||
if (!option.blockTrigger) {
|
|
||||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
async operate<T extends keyof ED, OP extends DebugStoreOperateOption>(
|
async operate<T extends keyof ED, OP extends DebugStoreOperateOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
|
|
@ -73,7 +58,20 @@ export class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Asyn
|
||||||
option: OP
|
option: OP
|
||||||
) {
|
) {
|
||||||
assert(context.getCurrentTxnId());
|
assert(context.getCurrentTxnId());
|
||||||
return super.selectAsync(entity, selection, context, option);
|
const selection2 = Object.assign({
|
||||||
|
action: 'select',
|
||||||
|
}, selection) as ED[T]['Operation'];
|
||||||
|
|
||||||
|
// select的trigger应加在根结点的动作之前
|
||||||
|
if (!option.blockTrigger) {
|
||||||
|
await this.executor.preOperation(entity, selection2, context, option);
|
||||||
|
}
|
||||||
|
const result = await super.selectAsync(entity, selection, context, option);
|
||||||
|
|
||||||
|
if (!option.blockTrigger) {
|
||||||
|
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number> {
|
async count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number> {
|
||||||
|
|
|
||||||
|
|
@ -1402,29 +1402,15 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
||||||
if (!this.dirty) {
|
if (!this.dirty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.operation) {
|
const filter = this.getFilter();
|
||||||
const operation: ED[T]['Update'] = {
|
const operation: ED[T]['Update'] = this.operation ? cloneDeep(this.operation.operation) : {
|
||||||
id: generateNewId(),
|
id: generateNewId(),
|
||||||
action: 'update',
|
action: 'update',
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
if (this.id) {
|
if (filter) {
|
||||||
Object.assign(operation, {
|
|
||||||
filter: {
|
|
||||||
id: this.id!,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.operation = {
|
|
||||||
operation,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
let operation: ED[T]['Update'] = cloneDeep(this.operation.operation);
|
|
||||||
if (this.id && !operation.filter) {
|
|
||||||
Object.assign(operation, {
|
Object.assign(operation, {
|
||||||
filter: {
|
filter,
|
||||||
id: this.id,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1458,7 +1444,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
entity: this.entity,
|
entity: this.entity,
|
||||||
operation,
|
operation: operation!,
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1564,26 +1550,19 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
||||||
*/
|
*/
|
||||||
getParentFilter<T2 extends keyof ED>(childNode: Node<ED, keyof ED, Cxt, FrontCxt, AD>): ED[T2]['Selection']['filter'] | undefined {
|
getParentFilter<T2 extends keyof ED>(childNode: Node<ED, keyof ED, Cxt, FrontCxt, AD>): ED[T2]['Selection']['filter'] | undefined {
|
||||||
const filter = this.getFilter(true);
|
const filter = this.getFilter(true);
|
||||||
|
const value = this.getFreshValue();
|
||||||
|
const id = this.id;
|
||||||
|
|
||||||
for (const key in this.children) {
|
for (const key in this.children) {
|
||||||
if (childNode === this.children[key]) {
|
if (childNode === this.children[key]) {
|
||||||
const sliceIdx = key.indexOf(':');
|
const sliceIdx = key.indexOf(':');
|
||||||
const key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
const key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
||||||
|
|
||||||
// 此时如果operation中有相关的外键被设置则直接返回
|
|
||||||
let operationData: ED[T]['Update']['data'] | undefined = undefined;
|
|
||||||
if (this.operation) {
|
|
||||||
const { operation: { action, data } } = this.operation;
|
|
||||||
if (action !== 'remove') {
|
|
||||||
operationData = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const rel = this.judgeRelation(key2);
|
const rel = this.judgeRelation(key2);
|
||||||
if (rel === 2) {
|
if (rel === 2) {
|
||||||
// 基于entity/entityId的多对一
|
// 基于entity/entityId的多对一
|
||||||
if (operationData?.entityId) {
|
if (value?.entityId) {
|
||||||
return {
|
return {
|
||||||
id: operationData!.entityId!,
|
id: value!.entityId!,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (filter) {
|
else if (filter) {
|
||||||
|
|
@ -1606,9 +1585,9 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (typeof rel === 'string') {
|
else if (typeof rel === 'string') {
|
||||||
if (operationData && operationData[`${rel}Id`]) {
|
if (value && value[`${rel}Id`]) {
|
||||||
return {
|
return {
|
||||||
id: operationData[`${rel}Id`],
|
id: value[`${rel}Id`],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (filter) {
|
else if (filter) {
|
||||||
|
|
@ -1630,22 +1609,38 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(rel instanceof Array);
|
assert(rel instanceof Array);
|
||||||
if (filter) {
|
if (rel[1]) {
|
||||||
if (rel[1]) {
|
// 基于普通外键的一对多
|
||||||
// 基于普通外键的一对多
|
if (id || value) {
|
||||||
|
return {
|
||||||
|
[rel[1]]: id || value!.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (filter) {
|
||||||
return {
|
return {
|
||||||
[rel[1].slice(0, rel[1].length - 2)]: filter,
|
[rel[1].slice(0, rel[1].length - 2)]: filter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 基于entity/entityId的一对多
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 基于entity/entityId的一对多
|
||||||
|
if (id || value) {
|
||||||
|
return {
|
||||||
|
entity: this.entity,
|
||||||
|
entityId: id || value!.id,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (filter) {
|
||||||
return {
|
return {
|
||||||
[this.entity]: filter,
|
[this.entity]: filter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue