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(trigger: Trigger) { 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); } }