适配了新的selectOption,为refresh增加了getCount参数

This commit is contained in:
Xu Chang 2022-08-09 18:54:45 +08:00
parent e6363b1418
commit 772645d9d1
11 changed files with 115 additions and 99 deletions

View File

@ -1,4 +1,4 @@
import { EntityDict, OperationResult, OpRecord } from 'oak-domain/lib/types/Entity';
import { EntityDict, OperateOption, OperationResult, OpRecord, SelectOption } from 'oak-domain/lib/types/Entity';
import { StorageSchema } from "oak-domain/lib/types/Storage";
import { Checker, Context } from 'oak-domain/lib/types';
import { TreeStore } from 'oak-memory-tree-store';
@ -6,9 +6,9 @@ export declare class CacheStore<ED extends EntityDict, Cxt extends Context<ED>>
private executor;
private getFullDataFn?;
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString: string) => (store: CacheStore<ED, Cxt>) => Cxt, getFullDataFn?: () => any);
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, params?: Object): Promise<OperationResult<ED>>;
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option?: OperateOption): Promise<OperationResult<ED>>;
sync(opRecords: Array<OpRecord<ED>>, context: Cxt): Promise<void>;
select<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: Cxt, params?: Object): Promise<import("oak-domain/lib/types").SelectionResult<ED[T]["Schema"], S["data"]>>;
select<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: Cxt, option?: SelectOption): Promise<import("oak-domain/lib/types").SelectionResult<ED[T]["Schema"], S["data"]>>;
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
/**
* debug下用来获取debugStore的数据release下不能使用

View File

@ -64,7 +64,7 @@ var CacheStore = /** @class */ (function (_super) {
_this.getFullDataFn = getFullDataFn;
return _this;
}
CacheStore.prototype.operate = function (entity, operation, context, params) {
CacheStore.prototype.operate = function (entity, operation, context, option) {
return __awaiter(this, void 0, void 0, function () {
var autoCommit, result, err_1;
return __generator(this, function (_a) {
@ -81,7 +81,7 @@ var CacheStore = /** @class */ (function (_super) {
return [4 /*yield*/, this.executor.preOperation(entity, operation, context)];
case 3:
_a.sent();
return [4 /*yield*/, _super.prototype.operate.call(this, entity, operation, context, params)];
return [4 /*yield*/, _super.prototype.operate.call(this, entity, operation, context, option)];
case 4:
result = _a.sent();
return [4 /*yield*/, this.executor.postOperation(entity, operation, context)];
@ -140,7 +140,7 @@ var CacheStore = /** @class */ (function (_super) {
});
});
};
CacheStore.prototype.select = function (entity, selection, context, params) {
CacheStore.prototype.select = function (entity, selection, context, option) {
return __awaiter(this, void 0, void 0, function () {
var autoCommit, result, err_3;
return __generator(this, function (_a) {
@ -154,7 +154,7 @@ var CacheStore = /** @class */ (function (_super) {
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 6]);
return [4 /*yield*/, _super.prototype.select.call(this, entity, selection, context, params)];
return [4 /*yield*/, _super.prototype.select.call(this, entity, selection, context, option)];
case 3:
result = _a.sent();
return [3 /*break*/, 6];

View File

@ -1,7 +1,10 @@
import { EntityDict, OperationResult, Context, RowStore, DeduceCreateOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateParams, SelectionResult, SelectRowShape } from "oak-domain/lib/types";
import { EntityDict, SelectOption, Context, RowStore, DeduceCreateOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, SelectionResult, SelectRowShape } from "oak-domain/lib/types";
import { TreeStore } from 'oak-memory-tree-store';
import { StorageSchema, Trigger, Checker } from "oak-domain/lib/types";
interface DebugStoreOperationParams extends OperateParams {
interface DebugStoreOperateOption extends OperateOption {
noLock?: true;
}
interface DebugStoreSelectOption extends SelectOption {
noLock?: true;
omitTrigger?: true;
}
@ -16,10 +19,10 @@ export declare class DebugStore<ED extends EntityDict, Cxt extends Context<ED>>
remove: number;
commit: number;
});
protected cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, params?: DebugStoreOperationParams): Promise<OperationResult<ED>>;
protected cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, params?: DebugStoreOperationParams): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, params?: DebugStoreOperationParams): Promise<OperationResult<ED>>;
select<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: Cxt, params?: DebugStoreOperationParams): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
protected cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, option?: OperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
protected cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, option?: DebugStoreSelectOption): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], context: Cxt, option?: DebugStoreOperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
select<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, context: Cxt, option?: DebugStoreSelectOption): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
startInitializing(): void;

View File

@ -56,6 +56,7 @@ var oak_memory_tree_store_1 = require("oak-memory-tree-store");
var TriggerExecutor_1 = require("oak-domain/lib/store/TriggerExecutor");
var concurrent_1 = require("oak-domain/lib/utils/concurrent");
;
;
var DebugStore = /** @class */ (function (_super) {
__extends(DebugStore, _super);
function DebugStore(storageSchema, contextBuilder, initialData, initialStat) {
@ -66,16 +67,16 @@ var DebugStore = /** @class */ (function (_super) {
_this.rwLock = new concurrent_1.RWLock();
return _this;
}
DebugStore.prototype.cascadeUpdate = function (entity, operation, context, params) {
DebugStore.prototype.cascadeUpdate = function (entity, operation, context, option) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.executor.preOperation(entity, operation, context, params)];
case 0: return [4 /*yield*/, this.executor.preOperation(entity, operation, context, option)];
case 1:
_a.sent();
result = _super.prototype.cascadeUpdate.call(this, entity, operation, context, params);
return [4 /*yield*/, this.executor.postOperation(entity, operation, context, params)];
result = _super.prototype.cascadeUpdate.call(this, entity, operation, context, option);
return [4 /*yield*/, this.executor.postOperation(entity, operation, context, option)];
case 2:
_a.sent();
return [2 /*return*/, result];
@ -83,7 +84,7 @@ var DebugStore = /** @class */ (function (_super) {
});
});
};
DebugStore.prototype.cascadeSelect = function (entity, selection, context, params) {
DebugStore.prototype.cascadeSelect = function (entity, selection, context, option) {
return __awaiter(this, void 0, void 0, function () {
var selection2, result;
return __generator(this, function (_a) {
@ -92,16 +93,16 @@ var DebugStore = /** @class */ (function (_super) {
selection2 = Object.assign({
action: 'select',
}, selection);
if (!!(params === null || params === void 0 ? void 0 : params.omitTrigger)) return [3 /*break*/, 2];
return [4 /*yield*/, this.executor.preOperation(entity, selection2, context, params)];
if (!!(option === null || option === void 0 ? void 0 : option.omitTrigger)) return [3 /*break*/, 2];
return [4 /*yield*/, this.executor.preOperation(entity, selection2, context, option)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [4 /*yield*/, _super.prototype.cascadeSelect.call(this, entity, selection2, context, params)];
case 2: return [4 /*yield*/, _super.prototype.cascadeSelect.call(this, entity, selection2, context, option)];
case 3:
result = _a.sent();
if (!!(params === null || params === void 0 ? void 0 : params.omitTrigger)) return [3 /*break*/, 5];
return [4 /*yield*/, this.executor.postOperation(entity, selection2, context, params, result)];
if (!!(option === null || option === void 0 ? void 0 : option.omitTrigger)) return [3 /*break*/, 5];
return [4 /*yield*/, this.executor.postOperation(entity, selection2, context, option, result)];
case 4:
_a.sent();
_a.label = 5;
@ -110,13 +111,13 @@ var DebugStore = /** @class */ (function (_super) {
});
});
};
DebugStore.prototype.operate = function (entity, operation, context, params) {
DebugStore.prototype.operate = function (entity, operation, context, option) {
return __awaiter(this, void 0, void 0, function () {
var autoCommit, result, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(!params || !params.noLock)) return [3 /*break*/, 2];
if (!(!option || !option.noLock)) return [3 /*break*/, 2];
return [4 /*yield*/, this.rwLock.acquire('S')];
case 1:
_a.sent();
@ -130,7 +131,7 @@ var DebugStore = /** @class */ (function (_super) {
_a.label = 4;
case 4:
_a.trys.push([4, 6, , 8]);
return [4 /*yield*/, _super.prototype.operate.call(this, entity, operation, context, params)];
return [4 /*yield*/, _super.prototype.operate.call(this, entity, operation, context, option)];
case 5:
result = _a.sent();
return [3 /*break*/, 8];
@ -147,7 +148,7 @@ var DebugStore = /** @class */ (function (_super) {
_a.sent();
_a.label = 10;
case 10:
if (!params || !params.noLock) {
if (!option || !option.noLock) {
this.rwLock.release();
}
return [2 /*return*/, result];
@ -155,13 +156,13 @@ var DebugStore = /** @class */ (function (_super) {
});
});
};
DebugStore.prototype.select = function (entity, selection, context, params) {
DebugStore.prototype.select = function (entity, selection, context, option) {
return __awaiter(this, void 0, void 0, function () {
var autoCommit, result, err_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(!params || !params.noLock)) return [3 /*break*/, 2];
if (!(!option || !option.noLock)) return [3 /*break*/, 2];
return [4 /*yield*/, this.rwLock.acquire('S')];
case 1:
_a.sent();
@ -175,7 +176,7 @@ var DebugStore = /** @class */ (function (_super) {
_a.label = 4;
case 4:
_a.trys.push([4, 6, , 8]);
return [4 /*yield*/, _super.prototype.select.call(this, entity, selection, context, params)];
return [4 /*yield*/, _super.prototype.select.call(this, entity, selection, context, option)];
case 5:
result = _a.sent();
return [3 /*break*/, 8];
@ -192,7 +193,7 @@ var DebugStore = /** @class */ (function (_super) {
_a.sent();
_a.label = 10;
case 10:
if (!params || !params.noLock) {
if (!option || !option.noLock) {
this.rwLock.release();
}
return [2 /*return*/, result];

View File

@ -1,4 +1,4 @@
import { EntityDict, OperateParams, OpRecord, Context, AspectWrapper } from 'oak-domain/lib/types';
import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper } from 'oak-domain/lib/types';
import { CommonAspectDict } from 'oak-common-aspect';
import { Feature } from '../types/Feature';
import { CacheStore } from '../cacheStore/CacheStore';
@ -7,7 +7,10 @@ export declare class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD ex
context: Cxt;
private syncEventsCallbacks;
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, context: Cxt, cacheStore: CacheStore<ED, Cxt>);
refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], params?: object): Promise<import("oak-domain/lib/types").SelectionResult<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>>;
refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: SelectOption, getCount?: true): Promise<{
data: import("oak-domain/lib/types").SelectRowShape<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>[];
count?: number | undefined;
}>;
private sync;
/**
* operation只可能是测试权限
@ -15,11 +18,11 @@ export declare class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD ex
* @param operation
* @param scene
* @param commit
* @param params
* @param option
* @returns
*/
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], params?: OperateParams): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: object): Promise<import("oak-domain/lib/types").SelectRowShape<ED[T]["Schema"], S["data"]>[]>;
operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], option?: OperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: SelectOption): Promise<import("oak-domain/lib/types").SelectRowShape<ED[T]["Schema"], S["data"]>[]>;
judgeRelation(entity: keyof ED, attr: string): string | 0 | 2 | string[] | 1;
bindOnSync(callback: (opRecords: OpRecord<ED>[]) => Promise<void>): void;
unbindOnSync(callback: (opRecords: OpRecord<ED>[]) => Promise<void>): void;

View File

@ -88,7 +88,7 @@ var Cache = /** @class */ (function (_super) {
}); };
return _this;
}
Cache.prototype.refresh = function (entity, selection, params) {
Cache.prototype.refresh = function (entity, selection, option, getCount) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
@ -96,7 +96,8 @@ var Cache = /** @class */ (function (_super) {
case 0: return [4 /*yield*/, this.getAspectWrapper().exec('select', {
entity: entity,
selection: selection,
params: params,
option: option,
getCount: getCount,
})];
case 1:
result = (_a.sent()).result;
@ -128,10 +129,10 @@ var Cache = /** @class */ (function (_super) {
* @param operation
* @param scene
* @param commit
* @param params
* @param option
* @returns
*/
Cache.prototype.operate = function (entity, operation, params) {
Cache.prototype.operate = function (entity, operation, option) {
return __awaiter(this, void 0, void 0, function () {
var result, err_1;
return __generator(this, function (_a) {
@ -142,7 +143,7 @@ var Cache = /** @class */ (function (_super) {
_a.label = 2;
case 2:
_a.trys.push([2, 5, , 7]);
return [4 /*yield*/, this.cacheStore.operate(entity, operation, this.context, params)];
return [4 /*yield*/, this.cacheStore.operate(entity, operation, this.context, option)];
case 3:
result = _a.sent();
return [4 /*yield*/, this.context.rollback()];

View File

@ -610,16 +610,16 @@ var ListNode = /** @class */ (function (_super) {
};
ListNode.prototype.refresh = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, filters, sorters, pagination, entity, step, proj, sorterss, filterss, result;
var _a, filters, sorters, pagination, entity, step, proj, sorterss, filterss, _b, data, count;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = this, filters = _a.filters, sorters = _a.sorters, pagination = _a.pagination, entity = _a.entity;
step = pagination.step;
return [4 /*yield*/, this.getProjection()];
case 1:
proj = _b.sent();
proj = _c.sent();
(0, assert_1.assert)(proj);
return [4 /*yield*/, Promise.all(sorters.map(function (ele) { return __awaiter(_this, void 0, void 0, function () {
var sorter;
@ -635,7 +635,7 @@ var ListNode = /** @class */ (function (_super) {
});
}); }))];
case 2:
sorterss = (_b.sent()).filter(function (ele) { return !!ele; });
sorterss = (_c.sent()).filter(function (ele) { return !!ele; });
return [4 /*yield*/, Promise.all(filters.map(function (ele) { return __awaiter(_this, void 0, void 0, function () {
var filter;
return __generator(this, function (_a) {
@ -650,7 +650,7 @@ var ListNode = /** @class */ (function (_super) {
});
}); }))];
case 3:
filterss = _b.sent();
filterss = _c.sent();
this.refreshing = true;
return [4 /*yield*/, this.cache.refresh(entity, {
data: proj,
@ -658,13 +658,14 @@ var ListNode = /** @class */ (function (_super) {
sorter: sorterss,
indexFrom: 0,
count: step,
})];
}, undefined, true)];
case 4:
result = (_b.sent()).result;
_b = _c.sent(), data = _b.data, count = _b.count;
this.pagination.indexFrom = 0;
this.pagination.more = result.length === step;
this.pagination.more = data.length === step;
this.refreshing = false;
this.setValue(result);
this.pagination.total = count;
this.setValue(data);
return [2 /*return*/];
}
});
@ -672,7 +673,7 @@ var ListNode = /** @class */ (function (_super) {
};
ListNode.prototype.loadMore = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, filters, sorters, pagination, entity, step, more, proj, sorterss, filterss, result;
var _a, filters, sorters, pagination, entity, step, more, proj, sorterss, filterss, data;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
@ -725,11 +726,11 @@ var ListNode = /** @class */ (function (_super) {
count: step,
})];
case 4:
result = (_b.sent()).result;
data = (_b.sent()).data;
this.pagination.indexFrom = this.pagination.indexFrom + step;
this.pagination.more = result.length === step;
this.pagination.more = data.length === step;
this.refreshing = false;
this.appendValue(result);
this.appendValue(data);
return [2 /*return*/];
}
});
@ -1343,7 +1344,7 @@ var SingleNode = /** @class */ (function (_super) {
},
})];
case 2:
_a = __read.apply(void 0, [(_b.sent()).result, 1]), value = _a[0];
_a = __read.apply(void 0, [(_b.sent()).data, 1]), value = _a[0];
this.refreshing = false;
this.setValue(value);
_b.label = 3;

View File

@ -1,4 +1,4 @@
import { EntityDict, OperationResult, OpRecord } from 'oak-domain/lib/types/Entity';
import { EntityDict, OperateOption, OperationResult, OpRecord, SelectOption } from 'oak-domain/lib/types/Entity';
import { StorageSchema } from "oak-domain/lib/types/Storage";
import { TriggerExecutor } from 'oak-domain/lib/store/TriggerExecutor';
import { Checker, Context, Trigger } from 'oak-domain/lib/types';
@ -18,7 +18,7 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
entity: T,
operation: ED[T]['Operation'],
context: Cxt,
params?: Object
option?: OperateOption
): Promise<OperationResult<ED>> {
const autoCommit = !context.getCurrentTxnId();
let result;
@ -27,7 +27,7 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
}
try {
await this.executor.preOperation(entity, operation, context);
result = await super.operate(entity, operation, context, params);
result = await super.operate(entity, operation, context, option);
await this.executor.postOperation(entity, operation, context);
}
catch (err) {
@ -64,7 +64,7 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
entity: T,
selection: S,
context: Cxt,
params?: Object
option?: SelectOption
) {
const autoCommit = !context.getCurrentTxnId();
if (autoCommit) {
@ -73,7 +73,7 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
let result;
try {
result = await super.select(entity, selection, context, params);
result = await super.select(entity, selection, context, option);
}
catch (err) {
await context.rollback();

View File

@ -1,12 +1,16 @@
import { EntityDict, OperationResult, Context, RowStore, DeduceCreateOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateParams, SelectionResult, SelectRowShape } from "oak-domain/lib/types";
import { EntityDict, SelectOption, Context, RowStore, DeduceCreateOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, SelectionResult, SelectRowShape } from "oak-domain/lib/types";
import { TreeStore } from 'oak-memory-tree-store';
import { StorageSchema, Trigger, Checker } from "oak-domain/lib/types";
import { TriggerExecutor } from 'oak-domain/lib/store/TriggerExecutor';
import { RWLock } from 'oak-domain/lib/utils/concurrent';
interface DebugStoreOperationParams extends OperateParams {
noLock?: true,
omitTrigger?: true,
interface DebugStoreOperateOption extends OperateOption {
noLock?: true;
};
interface DebugStoreSelectOption extends SelectOption {
noLock?: true;
omitTrigger?: true;
};
export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends TreeStore<ED, Cxt> {
@ -20,24 +24,24 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
this.rwLock = new RWLock();
}
protected async cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, params?: DebugStoreOperationParams) {
await this.executor.preOperation(entity, operation, context, params);
const result = super.cascadeUpdate(entity, operation, context, params);
await this.executor.postOperation(entity, operation, context, params);
protected async cascadeUpdate<T extends keyof ED>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, option?: OperateOption) {
await this.executor.preOperation(entity, operation, context, option);
const result = super.cascadeUpdate(entity, operation, context, option);
await this.executor.postOperation(entity, operation, context, option);
return result;
}
protected async cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, params?: DebugStoreOperationParams): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]> {
protected async cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"]>(entity: T, selection: S, context: Cxt, option?: DebugStoreSelectOption): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]> {
const selection2 = Object.assign({
action: 'select',
}, selection) as ED[T]['Operation'];
if (!params?.omitTrigger) {
await this.executor.preOperation(entity, selection2, context, params);
if (!option?.omitTrigger) {
await this.executor.preOperation(entity, selection2, context, option);
}
const result = await super.cascadeSelect(entity, selection2 as any, context, params);
if (!params?.omitTrigger) {
await this.executor.postOperation(entity, selection2, context, params, result);
const result = await super.cascadeSelect(entity, selection2 as any, context, option);
if (!option?.omitTrigger) {
await this.executor.postOperation(entity, selection2, context, option, result);
}
return result;
}
@ -46,9 +50,9 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
entity: T,
operation: ED[T]['Operation'],
context: Cxt,
params?: DebugStoreOperationParams
option?: DebugStoreOperateOption
) {
if (!params || !params.noLock) {
if (!option || !option.noLock) {
await this.rwLock.acquire('S');
}
@ -58,7 +62,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
await context.begin();
}
try {
result = await super.operate(entity, operation, context, params);
result = await super.operate(entity, operation, context, option);
}
catch (err) {
await context.rollback();
@ -67,7 +71,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
if (autoCommit) {
await context.commit();
}
if (!params || !params.noLock) {
if (!option || !option.noLock) {
this.rwLock.release();
}
return result;
@ -77,9 +81,9 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
entity: T,
selection: S,
context: Cxt,
params?: DebugStoreOperationParams
option?: DebugStoreSelectOption
) {
if (!params || !params.noLock) {
if (!option || !option.noLock) {
await this.rwLock.acquire('S');
}
const autoCommit = !context.getCurrentTxnId();
@ -89,7 +93,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
let result: SelectionResult<ED[T]['Schema'], S['data']>;
try {
result = await super.select(entity, selection, context, params);
result = await super.select(entity, selection, context, option);
}
catch (err) {
await context.rollback();
@ -98,7 +102,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
if (autoCommit) {
await context.commit();
}
if (!params || !params.noLock) {
if (!option || !option.noLock) {
this.rwLock.release();
}
return result;

View File

@ -1,4 +1,4 @@
import { StorageSchema, EntityDict, OperateParams, OpRecord, Aspect, Checker, RowStore, Context, AspectWrapper } from 'oak-domain/lib/types';
import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper } from 'oak-domain/lib/types';
import { CommonAspectDict } from 'oak-common-aspect';
import { Action, Feature } from '../types/Feature';
import { pull } from 'oak-domain/lib/utils/lodash';
@ -29,11 +29,12 @@ export class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD extends Co
@Action
async refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], params?: object) {
async refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: SelectOption, getCount?: true) {
const { result } = await this.getAspectWrapper().exec('select', {
entity,
selection,
params,
option,
getCount,
});
return result;
}
@ -54,14 +55,14 @@ export class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD extends Co
* @param operation
* @param scene
* @param commit
* @param params
* @param option
* @returns
*/
async operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], params?: OperateParams) {
async operate<T extends keyof ED>(entity: T, operation: ED[T]['Operation'], option?: OperateOption) {
let result: Awaited<ReturnType<typeof this.cacheStore.operate>>;
await this.context.begin();
try {
result = await this.cacheStore.operate(entity, operation, this.context, params);
result = await this.cacheStore.operate(entity, operation, this.context, option);
await this.context.rollback();
}
@ -73,7 +74,7 @@ export class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD extends Co
}
async get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: object) {
async get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: SelectOption) {
const { result } = await this.cacheStore.select(entity, selection, this.context, params);
return result;
}

View File

@ -536,18 +536,20 @@ class ListNode<ED extends EntityDict,
}
));
this.refreshing = true;
const { result } = await this.cache.refresh(entity, {
// todo 什么时候该传getCount参数 (老王)
const { data, count } = await this.cache.refresh(entity, {
data: proj as any,
filter: filterss.length > 0 ? combineFilters(filterss.filter(ele => !!ele)) : undefined,
sorter: sorterss,
indexFrom: 0,
count: step,
});
}, undefined, true);
this.pagination.indexFrom = 0;
this.pagination.more = result.length === step;
this.pagination.more = data.length === step;
this.refreshing = false;
this.pagination.total = count;
this.setValue(result as any);
this.setValue(data);
}
async loadMore() {
@ -579,7 +581,7 @@ class ListNode<ED extends EntityDict,
}
));
this.refreshing = true;
const { result } = await this.cache.refresh(entity, {
const { data } = await this.cache.refresh(entity, {
data: proj as any,
filter: filterss.length > 0 ? combineFilters(filterss.filter(ele => !!ele)) : undefined,
sorter: sorterss,
@ -587,10 +589,10 @@ class ListNode<ED extends EntityDict,
count: step,
});
this.pagination.indexFrom = this.pagination.indexFrom + step;
this.pagination.more = result.length === step;
this.pagination.more = data.length === step;
this.refreshing = false;
this.appendValue(result as any);
this.appendValue(data);
}
resetUpdateData() {
@ -1027,14 +1029,14 @@ class SingleNode<ED extends EntityDict,
const projection = await this.getProjection();
if (this.id) {
this.refreshing = true;
const { result: [value] } = await this.cache.refresh(this.entity, {
const { data: [value] } = await this.cache.refresh(this.entity, {
data: projection,
filter: {
id: this.id,
},
} as any);
this.refreshing = false;
this.setValue(value as any);
this.setValue(value);
}
}