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

72 lines
2.8 KiB
JavaScript
Raw 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.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheStore = void 0;
const tslib_1 = require("tslib");
const oak_memory_tree_store_1 = require("oak-memory-tree-store");
const assert_1 = require("oak-domain/lib/utils/assert");
const SyncTriggerExecutor_1 = tslib_1.__importDefault(require("./SyncTriggerExecutor"));
;
class CacheStore extends oak_memory_tree_store_1.TreeStore {
triggerExecutor;
constructor(storageSchema) {
super(storageSchema);
this.triggerExecutor = new SyncTriggerExecutor_1.default();
}
aggregate(entity, aggregation, context, option) {
return this.aggregateSync(entity, aggregation, context, option);
}
cascadeUpdate(entity, operation, context, option) {
(0, assert_1.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) {
(0, assert_1.assert)(context.getCurrentTxnId());
const result = super.operateSync(entity, operation, context, option);
return result;
}
sync(opRecords, context) {
(0, assert_1.assert)(context.getCurrentTxnId());
super.sync(opRecords, context, {});
}
check(entity, operation, context, checkerTypes) {
(0, assert_1.assert)(context.getCurrentTxnId());
// check不再支持CascadeOperation了不然处理不了data为undefined通过filter来check create
this.triggerExecutor.check(entity, operation, context, undefined, checkerTypes);
}
select(entity, selection, context, option) {
(0, assert_1.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) {
(0, assert_1.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);
}
}
exports.CacheStore = CacheStore;