适配了connector的接口改造
This commit is contained in:
parent
fa2750628b
commit
fd5dba5556
|
|
@ -11,14 +11,20 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
|
|||
private syncEventsCallbacks;
|
||||
private contextBuilder?;
|
||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, contextBuilder: () => FrontCxt, store: CacheStore<ED, FrontCxt>);
|
||||
exec<K extends keyof AD>(name: K, params: Parameters<AD[K]>[0], callback?: (result: Awaited<ReturnType<AD[K]>>, opRecords: OpRecord<ED>[]) => void): Promise<any>;
|
||||
exec<K extends keyof AD>(name: K, params: Parameters<AD[K]>[0], callback?: (result: Awaited<ReturnType<AD[K]>>, opRecords?: OpRecord<ED>[]) => void): Promise<{
|
||||
result: Awaited<ReturnType<AD[K]>>;
|
||||
message: string | null | undefined;
|
||||
}>;
|
||||
refresh<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true, callback?: (result: Awaited<ReturnType<AD['select']>>) => void): Promise<{
|
||||
data: Partial<ED[T]['Schema']>[];
|
||||
count?: number | undefined;
|
||||
}>;
|
||||
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option?: OP): Promise<import("oak-domain/lib/types").AggregationResult<ED[keyof ED]["Schema"]>>;
|
||||
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option?: OP, callback?: (result: Awaited<ReturnType<AD['operate']>>) => void): Promise<any>;
|
||||
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter'>, option?: OP, callback?: (result: Awaited<ReturnType<AD['count']>>) => void): Promise<any>;
|
||||
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option?: OP, callback?: (result: Awaited<ReturnType<AD['operate']>>) => void): Promise<{
|
||||
result: Awaited<ReturnType<AD["operate"]>>;
|
||||
message: string | null | undefined;
|
||||
}>;
|
||||
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter'>, option?: OP, callback?: (result: Awaited<ReturnType<AD['count']>>) => void): Promise<number>;
|
||||
private sync;
|
||||
/**
|
||||
* 前端缓存做operation只可能是测试权限,必然回滚
|
||||
|
|
|
|||
|
|
@ -31,17 +31,22 @@ var Cache = /** @class */ (function (_super) {
|
|||
}
|
||||
Cache.prototype.exec = function (name, params, callback) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var _a, result, opRecords, e_1, opRecord;
|
||||
var _a, result, opRecords, message, e_1, opRecord;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_b.trys.push([0, 2, , 3]);
|
||||
return [4 /*yield*/, this.aspectWrapper.exec(name, params)];
|
||||
case 1:
|
||||
_a = _b.sent(), result = _a.result, opRecords = _a.opRecords;
|
||||
_a = _b.sent(), result = _a.result, opRecords = _a.opRecords, message = _a.message;
|
||||
callback && callback(result, opRecords);
|
||||
this.sync(opRecords);
|
||||
return [2 /*return*/, result];
|
||||
if (opRecords) {
|
||||
this.sync(opRecords);
|
||||
}
|
||||
return [2 /*return*/, {
|
||||
result: result,
|
||||
message: message,
|
||||
}];
|
||||
case 2:
|
||||
e_1 = _b.sent();
|
||||
// 如果是数据不一致错误,这里可以让用户知道
|
||||
|
|
@ -69,7 +74,7 @@ var Cache = /** @class */ (function (_super) {
|
|||
getCount: getCount,
|
||||
}, callback)];
|
||||
case 1:
|
||||
result = _a.sent();
|
||||
result = (_a.sent()).result;
|
||||
return [2 /*return*/, result];
|
||||
}
|
||||
});
|
||||
|
|
@ -108,6 +113,7 @@ var Cache = /** @class */ (function (_super) {
|
|||
};
|
||||
Cache.prototype.count = function (entity, selection, option, callback) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.exec('count', {
|
||||
|
|
@ -115,7 +121,9 @@ var Cache = /** @class */ (function (_super) {
|
|||
selection: selection,
|
||||
option: option,
|
||||
}, callback)];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
case 1:
|
||||
result = (_a.sent()).result;
|
||||
return [2 /*return*/, result];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -236,13 +244,13 @@ var Cache = /** @class */ (function (_super) {
|
|||
if (!allowMiss) {
|
||||
var missedRows_1 = err.getRows();
|
||||
this.exec('fetchRows', missedRows_1, function (result, opRecords) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var opRecords_1, opRecords_1_1, record, d, missedRows_2, missedRows_2_1, mr;
|
||||
var e_4, _a, e_5, _b;
|
||||
return tslib_1.__generator(this, function (_c) {
|
||||
var _a, _b, record, d, missedRows_2, missedRows_2_1, mr;
|
||||
var e_4, _c, e_5, _d;
|
||||
return tslib_1.__generator(this, function (_e) {
|
||||
try {
|
||||
// missedRows理论上一定要取到,不能为空集。否则就是程序员有遗漏
|
||||
for (opRecords_1 = tslib_1.__values(opRecords), opRecords_1_1 = opRecords_1.next(); !opRecords_1_1.done; opRecords_1_1 = opRecords_1.next()) {
|
||||
record = opRecords_1_1.value;
|
||||
for (_a = tslib_1.__values(opRecords), _b = _a.next(); !_b.done; _b = _a.next()) {
|
||||
record = _b.value;
|
||||
d = record.d;
|
||||
(0, assert_1.default)(Object.keys(d).length > 0, '在通过fetchRow取不一致数据时返回了空数据,请拿该程序员祭天。');
|
||||
try {
|
||||
|
|
@ -254,7 +262,7 @@ var Cache = /** @class */ (function (_super) {
|
|||
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (missedRows_2_1 && !missedRows_2_1.done && (_b = missedRows_2.return)) _b.call(missedRows_2);
|
||||
if (missedRows_2_1 && !missedRows_2_1.done && (_d = missedRows_2.return)) _d.call(missedRows_2);
|
||||
}
|
||||
finally { if (e_5) throw e_5.error; }
|
||||
}
|
||||
|
|
@ -263,7 +271,7 @@ var Cache = /** @class */ (function (_super) {
|
|||
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (opRecords_1_1 && !opRecords_1_1.done && (_a = opRecords_1.return)) _a.call(opRecords_1);
|
||||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
||||
}
|
||||
finally { if (e_4) throw e_4.error; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,17 @@ export declare class Port<ED extends EntityDict & BaseEntityDict, Cxt extends As
|
|||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>);
|
||||
importEntity<T extends keyof ED>(entity: T, id: string, file: File, option: Object): Promise<{
|
||||
result: Awaited<ReturnType<AD["importEntity"]>>;
|
||||
opRecords: import("oak-domain/lib/types").OpRecord<ED>[];
|
||||
opRecords?: import("oak-domain/lib/types").OpRecord<ED>[] | undefined;
|
||||
message?: string | null | undefined;
|
||||
}>;
|
||||
exportEntity<T extends keyof ED>(entity: T, id: string, filter?: ED[T]['Selection']['filter']): Promise<{
|
||||
result: Awaited<ReturnType<AD["exportEntity"]>>;
|
||||
opRecords: import("oak-domain/lib/types").OpRecord<ED>[];
|
||||
opRecords?: import("oak-domain/lib/types").OpRecord<ED>[] | undefined;
|
||||
message?: string | null | undefined;
|
||||
}>;
|
||||
getImportationTemplate<T extends keyof ED>(id: string): Promise<{
|
||||
result: Awaited<ReturnType<AD["getImportationTemplate"]>>;
|
||||
opRecords: import("oak-domain/lib/types").OpRecord<ED>[];
|
||||
opRecords?: import("oak-domain/lib/types").OpRecord<ED>[] | undefined;
|
||||
message?: string | null | undefined;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,9 +234,9 @@ export declare class RunningTree<ED extends EntityDict & BaseEntityDict, Cxt ext
|
|||
}[] | undefined;
|
||||
isCreation(path: string): boolean;
|
||||
execute<T extends keyof ED>(path: string, action?: ED[T]['Action']): Promise<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]["Operation"];
|
||||
}[]>;
|
||||
result: Awaited<ReturnType<AD["operate"]>>;
|
||||
message: string | null | undefined;
|
||||
}>;
|
||||
clean(path: string): void;
|
||||
getRoot(): Record<string, SingleNode<ED, keyof ED, Cxt, FrontCxt, AD> | ListNode<ED, keyof ED, Cxt, FrontCxt, AD> | VirtualNode<ED, Cxt, FrontCxt, AD>>;
|
||||
subscribeNode(callback: () => any, path: string): () => void;
|
||||
|
|
|
|||
|
|
@ -2240,7 +2240,7 @@ var RunningTree = /** @class */ (function (_super) {
|
|||
};
|
||||
RunningTree.prototype.execute = function (path, action) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var node, operations, entities, err_3;
|
||||
var node, operations, entities, result, err_3;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
|
|
@ -2274,11 +2274,11 @@ var RunningTree = /** @class */ (function (_super) {
|
|||
node.setExecuting(false);
|
||||
})];
|
||||
case 3:
|
||||
_a.sent();
|
||||
result = _a.sent();
|
||||
return [4 /*yield*/, node.doAfterTrigger()];
|
||||
case 4:
|
||||
_a.sent();
|
||||
return [2 /*return*/, operations];
|
||||
return [2 /*return*/, result];
|
||||
case 5:
|
||||
err_3 = _a.sent();
|
||||
node.setExecuting(false);
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ function initialize(storageSchema, createFeatures, frontendContextBuilder, backe
|
|||
case 8: return [2 /*return*/, {
|
||||
result: result,
|
||||
opRecords: contextBackend.opRecords,
|
||||
message: contextBackend.getMessage(),
|
||||
}];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -27,17 +27,18 @@ function initialize(storageSchema, createFeatures, frontendContextBuilder, conne
|
|||
var cacheStore = new CacheStore_1.CacheStore(storageSchema);
|
||||
var wrapper = {
|
||||
exec: function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
||||
var context, _a, result, opRecords;
|
||||
var context, _a, result, opRecords, message;
|
||||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
context = frontendContextBuilder(features)(cacheStore);
|
||||
return [4 /*yield*/, connector.callAspect(name, params, context)];
|
||||
case 1:
|
||||
_a = _b.sent(), result = _a.result, opRecords = _a.opRecords;
|
||||
_a = _b.sent(), result = _a.result, opRecords = _a.opRecords, message = _a.message;
|
||||
return [2 /*return*/, {
|
||||
result: result,
|
||||
opRecords: opRecords,
|
||||
message: message,
|
||||
}];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ function loadMore() {
|
|||
exports.loadMore = loadMore;
|
||||
function execute(action, path, messageProps) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var fullpath, messageData;
|
||||
var fullpath, message, messageData;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
|
|
@ -311,11 +311,11 @@ function execute(action, path, messageProps) {
|
|||
: this.state.oakFullpath;
|
||||
return [4 /*yield*/, this.features.runningTree.execute(fullpath, action)];
|
||||
case 1:
|
||||
_a.sent();
|
||||
message = (_a.sent()).message;
|
||||
if (messageProps !== false) {
|
||||
messageData = {
|
||||
type: 'success',
|
||||
content: '操作成功',
|
||||
content: message || '操作成功',
|
||||
};
|
||||
if (typeof messageProps === 'object') {
|
||||
Object.assign(messageData, messageProps);
|
||||
|
|
|
|||
|
|
@ -52,15 +52,20 @@ export class Cache<
|
|||
async exec<K extends keyof AD>(
|
||||
name: K,
|
||||
params: Parameters<AD[K]>[0],
|
||||
callback?: (result: Awaited<ReturnType<AD[K]>>, opRecords: OpRecord<ED>[]) => void
|
||||
callback?: (result: Awaited<ReturnType<AD[K]>>, opRecords?: OpRecord<ED>[]) => void
|
||||
) {
|
||||
try {
|
||||
const { result, opRecords } = await this.aspectWrapper.exec(name, params);
|
||||
const { result, opRecords, message } = await this.aspectWrapper.exec(name, params);
|
||||
callback && callback(result, opRecords);
|
||||
this.sync(opRecords);
|
||||
return result;
|
||||
if (opRecords) {
|
||||
this.sync(opRecords);
|
||||
}
|
||||
return {
|
||||
result,
|
||||
message,
|
||||
};
|
||||
}
|
||||
catch(e) {
|
||||
catch (e) {
|
||||
// 如果是数据不一致错误,这里可以让用户知道
|
||||
if (e instanceof OakException) {
|
||||
const { opRecord } = e;
|
||||
|
|
@ -79,7 +84,7 @@ export class Cache<
|
|||
getCount?: true,
|
||||
callback?: (result: Awaited<ReturnType<AD['select']>>) => void,
|
||||
) {
|
||||
const result = await this.exec('select', {
|
||||
const { result } = await this.exec('select', {
|
||||
entity,
|
||||
selection,
|
||||
option,
|
||||
|
|
@ -91,7 +96,7 @@ export class Cache<
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
async aggregate<T extends keyof ED, OP extends SelectOption>(
|
||||
entity: T,
|
||||
aggregation: ED[T]['Aggregation'],
|
||||
|
|
@ -124,11 +129,13 @@ export class Cache<
|
|||
option?: OP,
|
||||
callback?: (result: Awaited<ReturnType<AD['count']>>) => void,
|
||||
) {
|
||||
return await this.exec('count', {
|
||||
const { result } = await this.exec('count', {
|
||||
entity,
|
||||
selection,
|
||||
option,
|
||||
}, callback);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private sync(records: OpRecord<ED>[]) {
|
||||
|
|
@ -248,7 +255,7 @@ export class Cache<
|
|||
const missedRows = err.getRows();
|
||||
this.exec('fetchRows', missedRows, async (result, opRecords) => {
|
||||
// missedRows理论上一定要取到,不能为空集。否则就是程序员有遗漏
|
||||
for (const record of opRecords) {
|
||||
for (const record of opRecords!) {
|
||||
const { d } = record as SelectOpResult<ED>;
|
||||
assert(Object.keys(d).length > 0, '在通过fetchRow取不一致数据时返回了空数据,请拿该程序员祭天。');
|
||||
for (const mr of missedRows) {
|
||||
|
|
|
|||
|
|
@ -2299,7 +2299,7 @@ export class RunningTree<
|
|||
));
|
||||
assert(entities.length === 1);
|
||||
|
||||
await this.cache.exec('operate', {
|
||||
const result = await this.cache.exec('operate', {
|
||||
entity: entities[0],
|
||||
operation: operations.filter(ele => !!ele).map(ele => ele.operation),
|
||||
}, () => {
|
||||
|
|
@ -2310,7 +2310,7 @@ export class RunningTree<
|
|||
|
||||
await node.doAfterTrigger();
|
||||
|
||||
return operations;
|
||||
return result;
|
||||
}
|
||||
catch (err) {
|
||||
node.setExecuting(false);
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ export function initialize<
|
|||
return {
|
||||
result,
|
||||
opRecords: contextBackend.opRecords,
|
||||
message: contextBackend.getMessage(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -64,10 +64,11 @@ export function initialize<
|
|||
const wrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> = {
|
||||
exec: async (name, params) => {
|
||||
const context = frontendContextBuilder(features)(cacheStore);
|
||||
const { result, opRecords } = await connector.callAspect(name as string, params, context);
|
||||
const { result, opRecords, message } = await connector.callAspect(name as string, params, context);
|
||||
return {
|
||||
result,
|
||||
opRecords,
|
||||
message,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -312,11 +312,11 @@ export async function execute<
|
|||
const fullpath = path
|
||||
? `${this.state.oakFullpath}.${path}`
|
||||
: this.state.oakFullpath;
|
||||
await this.features.runningTree.execute(fullpath, action);
|
||||
const { message } = await this.features.runningTree.execute(fullpath, action);
|
||||
if (messageProps !== false) {
|
||||
const messageData: MessageProps = {
|
||||
type: 'success',
|
||||
content: '操作成功',
|
||||
content: message || '操作成功',
|
||||
};
|
||||
if (typeof messageProps === 'object') {
|
||||
Object.assign(messageData, messageProps);
|
||||
|
|
|
|||
Loading…
Reference in New Issue