把select和operate的option改成了泛型
This commit is contained in:
parent
8099fc4e25
commit
7448f291a3
|
|
@ -6,9 +6,9 @@ export declare class CacheStore<ED extends EntityDict, Cxt extends Context<ED>>
|
||||||
private executor;
|
private executor;
|
||||||
private getFullDataFn?;
|
private getFullDataFn?;
|
||||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString: string) => (store: CacheStore<ED, Cxt>) => Cxt, getFullDataFn?: () => any);
|
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, option?: OperateOption): Promise<OperationResult<ED>>;
|
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option?: OP): Promise<OperationResult<ED>>;
|
||||||
sync(opRecords: Array<OpRecord<ED>>, context: Cxt): Promise<void>;
|
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, option?: SelectOption): Promise<import("oak-domain/lib/types").SelectionResult<ED[T]["Schema"], S["data"]>>;
|
select<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(entity: T, selection: S, context: Cxt, option?: OP): Promise<import("oak-domain/lib/types").SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||||
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
||||||
/**
|
/**
|
||||||
* 这个函数是在debug下用来获取debugStore的数据,release下不能使用
|
* 这个函数是在debug下用来获取debugStore的数据,release下不能使用
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ export declare class DebugStore<ED extends EntityDict, Cxt extends Context<ED>>
|
||||||
remove: number;
|
remove: number;
|
||||||
commit: 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, option?: OperateOption): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
protected cascadeUpdate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, option?: OP): 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']>[]>;
|
protected cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"], OP extends DebugStoreSelectOption>(entity: T, selection: S, context: Cxt, option?: OP): 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>>;
|
operate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option?: OP): 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"]>>;
|
select<T extends keyof ED, S extends ED[T]['Selection'], OP extends DebugStoreSelectOption>(entity: T, selection: S, context: Cxt, option?: OP): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||||
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
||||||
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
||||||
startInitializing(): void;
|
startInitializing(): void;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ export declare class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD ex
|
||||||
context: Cxt;
|
context: Cxt;
|
||||||
private syncEventsCallbacks;
|
private syncEventsCallbacks;
|
||||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, context: Cxt, cacheStore: CacheStore<ED, Cxt>);
|
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, context: Cxt, cacheStore: CacheStore<ED, Cxt>);
|
||||||
refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: SelectOption, getCount?: true): Promise<{
|
refresh<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true): Promise<{
|
||||||
data: import("oak-domain/lib/types").SelectRowShape<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>[];
|
data: import("oak-domain/lib/types").SelectRowShape<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>[];
|
||||||
count?: number | undefined;
|
count?: number | undefined;
|
||||||
}>;
|
}>;
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
|
||||||
this.getFullDataFn = getFullDataFn;
|
this.getFullDataFn = getFullDataFn;
|
||||||
}
|
}
|
||||||
|
|
||||||
async operate<T extends keyof ED>(
|
async operate<T extends keyof ED, OP extends OperateOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option?: OperateOption
|
option?: OP
|
||||||
): Promise<OperationResult<ED>> {
|
): Promise<OperationResult<ED>> {
|
||||||
const autoCommit = !context.getCurrentTxnId();
|
const autoCommit = !context.getCurrentTxnId();
|
||||||
let result;
|
let result;
|
||||||
|
|
@ -60,11 +60,11 @@ export class CacheStore<ED extends EntityDict, Cxt extends Context<ED>> extends
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async select<T extends keyof ED, S extends ED[T]['Selection']>(
|
async select<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
selection: S,
|
selection: S,
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option?: SelectOption
|
option?: OP
|
||||||
) {
|
) {
|
||||||
const autoCommit = !context.getCurrentTxnId();
|
const autoCommit = !context.getCurrentTxnId();
|
||||||
if (autoCommit) {
|
if (autoCommit) {
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,14 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
|
||||||
this.rwLock = new RWLock();
|
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, option?: OperateOption) {
|
protected async cascadeUpdate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, option?: OP) {
|
||||||
await this.executor.preOperation(entity, operation, context, option);
|
await this.executor.preOperation(entity, operation, context, option);
|
||||||
const result = super.cascadeUpdate(entity, operation, context, option);
|
const result = super.cascadeUpdate(entity, operation, context, option);
|
||||||
await this.executor.postOperation(entity, operation, context, option);
|
await this.executor.postOperation(entity, operation, context, option);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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']>[]> {
|
protected async cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"], OP extends DebugStoreSelectOption>(entity: T, selection: S, context: Cxt, option?: OP): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]> {
|
||||||
const selection2 = Object.assign({
|
const selection2 = Object.assign({
|
||||||
action: 'select',
|
action: 'select',
|
||||||
}, selection) as ED[T]['Operation'];
|
}, selection) as ED[T]['Operation'];
|
||||||
|
|
@ -46,11 +46,11 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async operate<T extends keyof ED>(
|
async operate<T extends keyof ED, OP extends DebugStoreOperateOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
operation: ED[T]['Operation'],
|
operation: ED[T]['Operation'],
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option?: DebugStoreOperateOption
|
option?: OP
|
||||||
) {
|
) {
|
||||||
if (!option || !option.noLock) {
|
if (!option || !option.noLock) {
|
||||||
await this.rwLock.acquire('S');
|
await this.rwLock.acquire('S');
|
||||||
|
|
@ -77,11 +77,11 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async select<T extends keyof ED, S extends ED[T]['Selection']>(
|
async select<T extends keyof ED, S extends ED[T]['Selection'], OP extends DebugStoreSelectOption>(
|
||||||
entity: T,
|
entity: T,
|
||||||
selection: S,
|
selection: S,
|
||||||
context: Cxt,
|
context: Cxt,
|
||||||
option?: DebugStoreSelectOption
|
option?: OP
|
||||||
) {
|
) {
|
||||||
if (!option || !option.noLock) {
|
if (!option || !option.noLock) {
|
||||||
await this.rwLock.acquire('S');
|
await this.rwLock.acquire('S');
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ export class Cache<ED extends EntityDict, Cxt extends Context<ED>, AD extends Co
|
||||||
|
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
async refresh<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], option?: SelectOption, getCount?: true) {
|
async refresh<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true) {
|
||||||
const { result } = await this.getAspectWrapper().exec('select', {
|
const { result } = await this.getAspectWrapper().exec('select', {
|
||||||
entity,
|
entity,
|
||||||
selection,
|
selection,
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,4 @@ import { OakException } from 'oak-domain/lib/types/Exception';
|
||||||
|
|
||||||
const e = new OakException('ddddd');
|
const e = new OakException('ddddd');
|
||||||
|
|
||||||
console.log(e.constructor.name);
|
console.log(e.name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue