oak-frontend-base/es/cacheStore/CacheStore.js

67 lines
2.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { TreeStore } from 'oak-memory-tree-store';
import { assert } from 'oak-domain/lib/utils/assert';
import SyncTriggerExecutor from './SyncTriggerExecutor';
;
export class CacheStore extends TreeStore {
triggerExecutor;
constructor(storageSchema) {
super(storageSchema);
this.triggerExecutor = new SyncTriggerExecutor();
}
aggregate(entity, aggregation, context, option) {
return this.aggregateSync(entity, aggregation, context, option);
}
cascadeUpdate(entity, operation, context, option) {
assert(context.getCurrentTxnId());
if (!option.blockTrigger) {
this.triggerExecutor.check(entity, operation, context, 'before', option.checkerTypes);
}
if (operation.data) {
// 有时前台需要测试某个action行为data会传undefined
const result = super.cascadeUpdate(entity, operation, context, option);
if (!option.blockTrigger) {
this.triggerExecutor.check(entity, operation, context, 'after', option.checkerTypes);
}
return result;
}
return {};
}
operate(entity, operation, context, option) {
assert(context.getCurrentTxnId());
const result = super.operateSync(entity, operation, context, option);
return result;
}
sync(opRecords, context) {
assert(context.getCurrentTxnId());
super.sync(opRecords, context, {});
}
check(entity, operation, context, checkerTypes) {
assert(context.getCurrentTxnId());
// check不再支持CascadeOperation了不然处理不了data为undefined通过filter来check create
this.triggerExecutor.check(entity, operation, context, undefined, checkerTypes);
}
select(entity, selection, context, option) {
assert(context.getCurrentTxnId());
return super.selectSync(entity, selection, context, option);
}
registerChecker(checker) {
this.triggerExecutor.registerChecker(checker, this.getSchema());
}
/* registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>) {
this.triggerExecutor.registerTrigger(trigger);
} */
count(entity, selection, context, option) {
assert(context.getCurrentTxnId());
return super.countSync(entity, selection, context, option);
}
begin(option) {
return super.beginSync();
}
commit(txnId) {
return super.commitSync(txnId);
}
rollback(txnId) {
return super.rollbackSync(txnId);
}
}