100 lines
4.5 KiB
TypeScript
100 lines
4.5 KiB
TypeScript
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||
import { AppLoader as GeneralAppLoader, Trigger, EntityDict, Watcher, OpRecord, FreeTimer, OperationResult, BaseTimer } from "oak-domain/lib/types";
|
||
import { BackendRuntimeContext } from 'oak-frontend-base/lib/context/BackendRuntimeContext';
|
||
import { IncomingHttpHeaders, IncomingMessage } from 'http';
|
||
import { Namespace } from 'socket.io';
|
||
import DataSubscriber from './cluster/DataSubscriber';
|
||
import Synchronizer from './Synchronizer';
|
||
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
|
||
import { InternalErrorHandler } from './types';
|
||
import { AppDbStore } from './DbStore';
|
||
export declare class AppLoader<ED extends EntityDict & BaseEntityDict, Cxt extends BackendRuntimeContext<ED>> extends GeneralAppLoader<ED, Cxt> {
|
||
protected dbStore: AppDbStore<ED, Cxt>;
|
||
private aspectDict;
|
||
private externalDependencies;
|
||
protected dataSubscriber?: DataSubscriber<ED, Cxt>;
|
||
protected synchronizer?: Synchronizer<ED, Cxt>;
|
||
protected contextBuilder: (store: AppDbStore<ED, Cxt>) => Cxt;
|
||
private nsSocket?;
|
||
private watcherTimerId?;
|
||
private scheduledJobs;
|
||
private internalErrorHandlers;
|
||
private watcherExecutingData;
|
||
regAllExceptionHandler(): void;
|
||
/**
|
||
* 注册一个内部错误处理器
|
||
* @param handler 内部错误处理器
|
||
*/
|
||
registerInternalErrorHandler(handler: InternalErrorHandler<ED, Cxt>): void;
|
||
/**
|
||
* 发布内部错误事件给注册的处理器
|
||
*/
|
||
private publishInternalError;
|
||
private requireSth;
|
||
protected makeContext(cxtStr?: string, headers?: IncomingHttpHeaders): Promise<Cxt>;
|
||
/**
|
||
* 获取数据库配置
|
||
* @returns 读取数据库配置
|
||
*/
|
||
private getDbConfig;
|
||
/**
|
||
* 获取同步配置
|
||
* @returns 读取同步配置
|
||
*/
|
||
private getSyncConfig;
|
||
constructor(path: string, nsSubscribe?: Namespace, nsSocket?: Namespace, nsServer?: Namespace);
|
||
protected registerTrigger(trigger: Trigger<ED, keyof ED, Cxt>): void;
|
||
protected initTriggers(): void;
|
||
protected initSocket(): void;
|
||
mount(initialize?: true): Promise<void>;
|
||
unmount(): Promise<void>;
|
||
execAspect(name: string, headers?: IncomingHttpHeaders, contextString?: string, params?: any): Promise<{
|
||
opRecords: OpRecord<ED>[];
|
||
result: any;
|
||
message?: string;
|
||
}>;
|
||
initialize(ifExists?: 'drop' | 'omit' | 'dropIfNotStatic'): Promise<void>;
|
||
getStore(): AppDbStore<ED, Cxt>;
|
||
getEndpoints(prefix: string): [string, "post" | "get" | "put" | "delete", string, (params: Record<string, string>, headers: IncomingHttpHeaders, req: IncomingMessage, body?: any) => Promise<{
|
||
headers?: Record<string, string | string[]>;
|
||
data: any;
|
||
statusCode?: number;
|
||
}>][];
|
||
protected operateInWatcher<T extends keyof ED>(entity: T, operation: ED[T]['Update'], context: Cxt, singleton?: true): Promise<OperationResult<ED>>;
|
||
protected selectInWatcher<T extends keyof ED>(entity: T, selection: ED[T]['Selection'], context: Cxt, forUpdate?: true, singleton?: true): Promise<Partial<ED[T]["Schema"]>[]>;
|
||
/**
|
||
* 检查某个数据是否正在被watcher执行
|
||
* @param name watcher名称
|
||
* @param dataId 数据ID
|
||
* @returns 如果没有正在执行则返回true,否则返回false
|
||
*/
|
||
private checkDataExecuting;
|
||
/**
|
||
* 过滤出未在执行中的数据行,并标记为执行中
|
||
* @returns [过滤后的行, 是否有行被跳过]
|
||
*/
|
||
private filterAndMarkExecutingRows;
|
||
/**
|
||
* 清理执行标记
|
||
*/
|
||
private cleanupExecutingMarks;
|
||
/**
|
||
* 解析 filter 和 projection(支持函数或静态值)
|
||
*/
|
||
private resolveFilterAndProjection;
|
||
/**
|
||
* 执行 WB 类型 watcher 的查询操作
|
||
*/
|
||
private selectForWBWatcher;
|
||
protected execWatcher(watcher: Watcher<ED, keyof ED, Cxt>): Promise<OperationResult<ED> | undefined>;
|
||
protected getCheckpointTs(): number;
|
||
protected checkpoint(): Promise<number>;
|
||
startWatchers(): void;
|
||
protected execBaseTimer(timer: BaseTimer<ED, Cxt>, context: Cxt): Promise<OperationResult<ED>> | undefined;
|
||
protected execFreeTimer(timer: FreeTimer<ED, Cxt>, contextBuilder: () => Promise<Cxt>): Promise<OperationResult<ED>> | undefined;
|
||
startTimers(): void;
|
||
execStartRoutines(): Promise<void>;
|
||
execStopRoutines(): Promise<void>;
|
||
execRoutine(routine: <Cxt extends AsyncContext<ED>>(context: Cxt) => Promise<void>): Promise<void>;
|
||
}
|