oak-domain/lib/store/AsyncRowStore.d.ts

77 lines
4.7 KiB
TypeScript
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.

/// <reference types="node" />
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, Context, TxnOption, OpRecord, AggregationResult, ClusterInfo, OakException } from "../types";
import { EntityDict as BaseEntityDict } from '../base-app-domain';
import { IncomingHttpHeaders } from "http";
/**
* 服务器端执行的异步环境的底层抽象
*/
export declare abstract class AsyncContext<ED extends EntityDict & BaseEntityDict> implements Context {
rowStore: AsyncRowStore<ED, this>;
private uuid?;
opRecords: OpRecord<ED>[];
private scene?;
headers?: IncomingHttpHeaders;
clusterInfo?: ClusterInfo;
opResult: OperationResult<ED>;
private message?;
events: {
commit: Array<(records: OpRecord<ED>[], cxtStr: string) => Promise<void>>;
rollback: Array<(records: OpRecord<ED>[], cxtStr: string) => Promise<void>>;
};
/**
* 在返回结果前调用,对数据行进行一些预处理,比如将一些敏感的列隐藏
*/
abstract refineOpRecords(): Promise<void>;
constructor(store: AsyncRowStore<ED, AsyncContext<ED>>);
restartToExecute(routine: (context: this) => Promise<any>): Promise<void>;
getHeader(key: string): string | string[] | undefined;
getScene(): string | undefined;
setScene(scene?: string): void;
private resetEvents;
on(event: 'commit' | 'rollback', callback: (records: OpRecord<ED>[], cxtStr: string) => Promise<void>): void;
saveOpRecord<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): void;
/**
* 查询某operation所处理的row ids
* 如果该operation还未执行可能返回空数组不知道实际关联的row id但是在after的trigger中返回是准确的ids值此时如果是空数组说明没有有关row id
* @param id
*/
getRowIdsOfOperation(operation: ED[keyof ED]['Operation']): string[];
/**
* 一个context中不应该有并发的事务这里将事务串行化使用的时候千万要注意不要自己等自己
* @param options
*/
begin(options?: TxnOption): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option: OP): Promise<OperationResult<ED>>;
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option: OP): Promise<AggregationResult<ED[T]["Schema"]>>;
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option: OP): Promise<number>;
exec(script: string, txnId?: string): Promise<void>;
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
getCurrentTxnId(): string | undefined;
getSchema(): import("../types").StorageSchema<ED>;
setMessage(message: string): void;
getMessage(): string | undefined;
abstract isRoot(): boolean;
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
abstract setCurrentUserId(userId: string | undefined): void;
abstract toString(): Promise<string>;
protected abstract getSerializedData(): Promise<object>;
abstract initialize(data?: any, later?: boolean): Promise<void>;
abstract allowUserUpdate(): boolean;
abstract openRootMode(): () => void;
abstract tryDeduceException(err: Error): Promise<OakException<any> | void>;
}
export interface AsyncRowStore<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>> extends RowStore<ED> {
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]['Schema']>[]>;
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): Promise<number>;
begin(option?: TxnOption): Promise<string>;
commit(txnId: string): Promise<void>;
rollback(txnId: string): Promise<void>;
exec(script: string, txnId?: string): Promise<void>;
checkRelationAsync<T extends keyof ED, Cxt extends AsyncContext<ED>>(entity: T, operation: Omit<ED[T]['Operation'] | ED[T]['Selection'], 'id'>, context: Cxt): Promise<void>;
}