小的适配
This commit is contained in:
parent
a5659d4538
commit
67e6995ef5
|
|
@ -1,11 +1,12 @@
|
|||
import { Context as ContextInterface } from 'oak-domain/lib/types/Context';
|
||||
import { EntityDef } from 'oak-domain/lib/types/Entity';
|
||||
import { EntityDef, OperationResult } from 'oak-domain/lib/types/Entity';
|
||||
import TreeStore from './store';
|
||||
export declare class Context<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}> implements ContextInterface<ED> {
|
||||
rowStore: TreeStore<ED>;
|
||||
uuid?: string;
|
||||
result?: OperationResult<ED>;
|
||||
constructor(store: TreeStore<ED>);
|
||||
on(event: 'commit' | 'rollback', callback: (context: ContextInterface<ED>) => Promise<void>): void;
|
||||
begin(options?: object): Promise<void>;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ const uuid_1 = require("uuid");
|
|||
class Context {
|
||||
rowStore;
|
||||
uuid;
|
||||
result;
|
||||
constructor(store) {
|
||||
this.rowStore = store;
|
||||
}
|
||||
|
|
@ -18,6 +19,9 @@ class Context {
|
|||
(0, assert_1.default)(!this.uuid);
|
||||
this.uuid = (0, uuid_1.v4)();
|
||||
this.rowStore.begin(this.uuid);
|
||||
this.result = {
|
||||
operations: [],
|
||||
};
|
||||
}
|
||||
async commit() {
|
||||
(0, assert_1.default)(this.uuid);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EntityDef, SelectionResult, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation } from "oak-domain/lib/types/Entity";
|
||||
import { EntityDef, SelectionResult, DeduceCreateSingleOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperationResult } from "oak-domain/lib/types/Entity";
|
||||
import { CascadeStore } from 'oak-domain/lib/schema/CascadeStore';
|
||||
import { StorageSchema } from 'oak-domain/lib/types/Storage';
|
||||
import { Context } from "./context";
|
||||
|
|
@ -56,10 +56,10 @@ export default class TreeStore<ED extends {
|
|||
private translateAttribute;
|
||||
private translateFilter;
|
||||
private translateSorter;
|
||||
protected selectAbjointRow<T extends keyof ED>(entity: T, selection: Omit<ED[T]['Selection'], 'indexFrom' | 'count' | 'data' | 'sorter'>, context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>>;
|
||||
protected selectAbjointRow<T extends keyof ED>(entity: T, selection: Omit<ED[T]['Selection'], 'indexFrom' | 'count' | 'data' | 'sorter'>, context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>['result']>;
|
||||
protected updateAbjointRow<T extends keyof ED>(entity: T, operation: DeduceCreateSingleOperation<ED[T]['Schema']> | DeduceUpdateOperation<ED[T]['Schema']> | DeduceRemoveOperation<ED[T]['Schema']>, context: Context<ED>, params?: Object): Promise<void>;
|
||||
private doOperation;
|
||||
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Context<ED>, params?: Object): Promise<void>;
|
||||
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Context<ED>, params?: Object): Promise<OperationResult<ED>>;
|
||||
protected formProjection<T extends keyof ED>(entity: T, row: ED[T]['Schema'], data: ED[T]['Selection']['data'], result: Partial<ED[T]['Schema']>, nodeDict: NodeDict, context: Context<ED>): Promise<void>;
|
||||
private formResult;
|
||||
select<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Context<ED>, params?: Object): Promise<SelectionResult<ED, T>>;
|
||||
|
|
|
|||
15
lib/store.js
15
lib/store.js
|
|
@ -623,8 +623,11 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
async doOperation(entity, operation, context, params) {
|
||||
const { action } = operation;
|
||||
if (action === 'select') {
|
||||
// return this.cascadeSelect(entity, operation as any, context, params);
|
||||
(0, assert_1.default)(false);
|
||||
const result = await this.cascadeSelect(entity, operation, context, params);
|
||||
const ids = result.map((ele) => ele.id);
|
||||
(0, lodash_1.assign)(context.result, {
|
||||
ids,
|
||||
});
|
||||
}
|
||||
else {
|
||||
return this.cascadeUpdate(entity, operation, context, params);
|
||||
|
|
@ -648,6 +651,7 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
if (autoCommit) {
|
||||
await context.commit();
|
||||
}
|
||||
return context.result;
|
||||
}
|
||||
async formProjection(entity, row, data, result, nodeDict, context) {
|
||||
const row2 = row;
|
||||
|
|
@ -736,7 +740,12 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
}
|
||||
async select(entity, selection, context, params) {
|
||||
const rows = await this.cascadeSelect(entity, selection, context, params);
|
||||
return await this.formResult(entity, rows, selection, context);
|
||||
const result = await this.formResult(entity, rows, selection, context);
|
||||
const { stats } = context.result;
|
||||
return {
|
||||
result,
|
||||
stats,
|
||||
};
|
||||
}
|
||||
async count(entity, selection, context, params) {
|
||||
const rows = await this.cascadeSelect(entity, (0, lodash_1.assign)({}, selection, {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ export class Context<ED extends {
|
|||
assert(!this.uuid);
|
||||
this.uuid = v4();
|
||||
this.rowStore.begin(this.uuid);
|
||||
this.result = {};
|
||||
this.result = {
|
||||
operations: [],
|
||||
};
|
||||
}
|
||||
async commit(): Promise<void> {
|
||||
assert(this.uuid);
|
||||
|
|
|
|||
Loading…
Reference in New Issue