import TreeStore from '../src/store'; import { EntityDict } from 'oak-domain/lib/base-app-domain'; import { SyncContext, SyncRowStore } from "oak-domain/lib/store/SyncRowStore"; import { OperateOption, OperationResult, SelectOption, AggregationResult, TxnOption, StorageSchema } from "oak-domain/lib/types"; /** * 实现一个同步的context和store用于测试 */ export class FrontendRuntimeContext extends SyncContext { isRoot(): boolean { return true; } getCurrentUserId(allowUnloggedIn?: boolean | undefined): string | undefined { return 'OAK_ROOT_ID'; } async toString(): Promise { throw new Error("Method not implemented."); } allowUserUpdate(): boolean { return true; } }; export class FrontendStore extends TreeStore implements SyncRowStore { operate(entity: T, operation: EntityDict[T]["Operation"], context: FrontendRuntimeContext, option: OP): OperationResult { return this.operateSync(entity, operation, context, option); } select(entity: T, selection: EntityDict[T]["Selection"], context: FrontendRuntimeContext, option: OP): Partial[] { return this.selectSync(entity, selection, context, option); } count(entity: T, selection: Pick, context: FrontendRuntimeContext, option: OP): number { return this.countSync(entity, selection, context, option); } aggregate(entity: T, aggregation: EntityDict[T]["Aggregation"], context: FrontendRuntimeContext, option: OP): AggregationResult { return this.aggregateSync(entity, aggregation, context, option); } begin(option?: TxnOption | undefined): string { return this.beginSync(); } commit(txnId: string): void { return this.commitSync(txnId); } rollback(txnId: string): void { return this.rollbackSync(txnId); } };