import { EntityDict, StorageSchema, OpRecord } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { AspectDict as CommonAspectDict } from 'oak-common-aspect'; import { NamedFilterItem, NamedSorterItem } from "../types/NamedCondition"; import { Cache } from './cache'; import { Pagination } from '../types/Pagination'; import { Feature } from '../types/Feature'; export declare const MODI_NEXT_PATH_SUFFIX = ":next"; type LegalOperation = ED[T]['CreateSingle'] | ED[T]['Update'] | ED[T]['Remove']; /** * 树结点上的更新日志管理 */ declare class UpdateLogManager { private logs; private schema; private entity; maxLsn: number; constructor(schema: StorageSchema, entity: T, maxLsn?: number); /** * 合并两个filter完全一致的更新 * @param oper1 * @param oper2 */ private mergeOperation; /** * 增加一条更新日志记录 * @param lsn * @param action * @param data * @param filter */ push(lsn: number, oper2: Omit, "id">): void; undo(filter: ED[T]['Update']['filter']): void; /** * 将lsn大于传入lsn的日志全部回滚 * @param lsn */ rollback(lsn: number): void; makeOperations(): LegalOperation[]; isEmpty(): boolean; } declare abstract class Node extends Feature { private zombie; private count; protected executing: boolean; protected dirty?: boolean; protected loading: number; protected loadingMore: boolean; private extraData; increaseCount(): number; decreaseCount(): number; getCount(): number; setZombie(zombie: boolean): void; isZombie(): boolean; abstract getModiOperations(): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; abstract setDirty(): void; isDirty(): boolean; isExecuting(): boolean; setExecuting(executing: boolean): void; isLoading(): boolean; protected setLoading(loading: number): void; isLoadingMore(): boolean; saveExtraData(key: string, data: any): void; loadExtraData(key: string): any; abstract getParent(): Node | undefined; } declare abstract class EntityNode extends Node { protected entity: T; protected schema: StorageSchema; protected projection?: ED[T]['Selection']['data'] | (() => ED[T]['Selection']['data']); protected parent?: SingleNode | ListNode | VirtualNode; protected cache: Cache; protected ulManager: UpdateLogManager; constructor(entity: T, schema: StorageSchema, cache: Cache, projection?: ED[T]['Selection']['data'] | (() => Promise), parent?: SingleNode | ListNode | VirtualNode); getEntity(): T; getSchema(): StorageSchema; abstract checkIfClean(): void; setDirty(): void; getParent(): SingleNode | ListNode | VirtualNode | undefined; protected getProjection(): ED[T]['Selection']['data'] | undefined; setProjection(projection: ED[T]['Selection']['data']): void; protected judgeRelation(attr: string): string | 0 | 1 | string[] | 2 | -1; } declare class ListNode extends EntityNode { protected children: Record>; private filters; private sorters; private getTotal?; private pagination; private sr; private syncHandler; setFiltersAndSortedApplied(): void; setLoading(loading: number): void; setUnloading(loading: number): void; startLoading(): void; endLoading(): void; checkIfClean(): void; getModiOperations(): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; onCacheSync(records: OpRecord[]): void; destroy(): void; constructor(entity: T, schema: StorageSchema, cache: Cache, projection?: ED[T]['Selection']['data'] | (() => Promise), parent?: SingleNode | VirtualNode, path?: string, filters?: NamedFilterItem[], sorters?: NamedSorterItem[], getTotal?: number, pagination?: Pick); getPagination(): Pagination; setPagination(pagination: Pick, dontRefresh?: true): void; addChild(path: string, node: SingleNode): void; removeChild(path: string): void; getChild(path: string): SingleNode; getNamedFilters(): (NamedFilterItem & { applied?: boolean | undefined; })[]; getNamedFilterByName(name: string): (NamedFilterItem & { applied?: boolean | undefined; }) | undefined; setNamedFilters(filters: NamedFilterItem[], refresh?: boolean): void; addNamedFilter(filter: NamedFilterItem, refresh?: boolean): void; removeNamedFilter(filter: NamedFilterItem, refresh?: boolean): void; removeNamedFilterByName(name: string, refresh?: boolean): void; getNamedSorters(): (NamedSorterItem & { applied?: boolean | undefined; })[]; getNamedSorterByName(name: string): (NamedSorterItem & { applied?: boolean | undefined; }) | undefined; setNamedSorters(sorters: NamedSorterItem[], refresh?: boolean): void; addNamedSorter(sorter: NamedSorterItem, refresh?: boolean): void; removeNamedSorter(sorter: NamedSorterItem, refresh?: boolean): void; removeNamedSorterByName(name: string, refresh: boolean): void; getFreshValue(inModi?: boolean): Array>; private addItemInner; addItem(lsn: number, item: Omit & { id?: string; }): string; addItems(lsn: number, items: Array & { id?: string; }>): string[]; private removeItemInner; removeItem(lsn: number, id: string): void; removeItems(lsn: number, ids: string[]): void; private recoverItemInner; recoverItem(id: string): void; recoverItems(ids: string[]): void; resetItem(id: string): void; private preProcessUpdateData; private updateItemInner; /** * 目前只支持根据itemId进行更新 * @param data * @param id * @param beforeExecute * @param afterExecute */ updateItem(lsn: number, data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action']): void; updateItems(lsn: number, data: Record, ids: string[], action?: ED[T]['Action']): void; composeOperations(includeModiBranch?: boolean): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; getProjection(): ED[T]["Selection"]["data"] | undefined; private constructFilters; constructSelection(withParent?: true, ignoreNewParent?: boolean, ignoreUnapplied?: true): { data: ED[T]["Selection"]["data"] | undefined; filter: ED[T]["Selection"]["filter"] | undefined; sorter: ED[T]["Selection"]["sorter"]; total: number | undefined; indexFrom: number; count: number; }; /** * 存留查询结果 */ saveRefreshResult(sr: Awaited['select']>>, append?: boolean, currentPage?: number): void; refresh(pageNumber?: number, append?: boolean): Promise; loadMore(): Promise; setCurrentPage(currentPage: number): void; clean(lsn?: number, dontPublish?: true): void; getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined; } declare class SingleNode extends EntityNode { private id?; private sr; protected children: { [K: string]: SingleNode | ListNode; }; private filters?; constructor(entity: T, schema: StorageSchema, cache: Cache, path: string, projection?: ED[T]['Selection']['data'] | (() => Promise), parent?: SingleNode | VirtualNode | ListNode, id?: string, filters?: NamedFilterItem[]); getModiOperations(): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; setFiltersAndSortedApplied(): void; setLoading(loading: number): void; setUnloading(loading: number): void; startLoading(): void; endLoading(): void; checkIfClean(): void; destroy(): void; getChild(path: string): SingleNode | ListNode; setId(id: string): void; unsetId(): void; getId(): string | undefined; getChildren(): { [K: string]: SingleNode | ListNode; }; addChild(path: string, node: SingleNode | ListNode): void; removeChild(path: string): void; getFreshValue(inModi?: boolean): Partial | undefined; private refreshListChildren; create(lsn: number, data: Partial>): void; update(lsn: number, data: ED[T]['Update']['data'], action?: ED[T]['Action']): void; remove(lsn: number): void; setDirty(): void; /** * * @param includeModiBranch 如果显式置了boolean,代表只要考虑前项路径或者后项路径 * @returns */ composeOperations(includeModiBranch?: boolean): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; getProjection(withDecendants?: boolean): ED[T]["Selection"]["data"] | undefined; private passRsToChild; saveRefreshResult(data: Record): void; refresh(): Promise; clean(lsn?: number, dontPublish?: true): void; private getFilter; getIntrinsticFilters(): ED[T]["Selection"]["filter"] | undefined; /** * getParentFilter不能假设一定已经有数据,只能根据当前filter的条件去构造 * @param childNode * @param disableOperation * @returns */ getParentFilter(childNode: ListNode, ignoreNewParent?: boolean): ED[T2]['Selection']['filter'] | undefined; } declare class VirtualNode extends Node { protected children: Record | ListNode | VirtualNode>; constructor(path?: string, parent?: VirtualNode); getModiOperations(): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; setDirty(): void; setFiltersAndSortedApplied(): void; addChild(path: string, child: SingleNode | ListNode | VirtualNode): void; removeChild(path: string): void; getChild(path: string): VirtualNode | SingleNode | ListNode; getParent(): undefined; destroy(): void; getFreshValue(): undefined; refresh(): Promise; composeOperations(includeModiBranch?: boolean): Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }> | undefined; setExecuting(executing: boolean): void; clean(lsn?: number, dontPublish?: true): void; checkIfClean(): void; } export type CreateNodeOptions = { path: string; entity?: T; isList?: boolean; getTotal?: number; projection?: ED[T]['Selection']['data'] | (() => ED[T]['Selection']['data']); pagination?: Pick; filters?: NamedFilterItem[]; sorters?: NamedSorterItem[]; beforeExecute?: (operations: ED[T]['Operation'][]) => Promise; afterExecute?: (operations: ED[T]['Operation'][]) => Promise; id?: string; zombie: boolean; }; export declare class RunningTree extends Feature { private logSerailNumber; private cache; private schema; private root; constructor(cache: Cache, schema: StorageSchema); createNode(options: CreateNodeOptions, isPage: boolean): ListNode | SingleNode | VirtualNode; private checkSingleNodeIsModiNode; checkIsModiNode(path: string): boolean; private findNode; destroyNode(path: string, isPage: boolean): void; begin(): () => void; redoBranchOperations(path: string, allowInTxn?: boolean): void; redoBranchModis(path: string): void; getFreshValue(path: string): Partial | Partial[] | undefined; isDirty(path: string): boolean; addItem(path: string, data: Omit & { id?: string; }): string; addItems(path: string, data: Array & { id?: string; }>): string[]; removeItem(path: string, id: string): void; removeItems(path: string, ids: string[]): void; updateItem(path: string, data: ED[T]['Update']['data'], id: string, action?: ED[T]['Action']): void; updateItems(path: string, data: ED[T]['Update']['data'], ids: string[], action?: ED[T]['Action']): void; recoverItem(path: string, id: string): void; recoverItems(path: string, ids: string[]): void; resetItem(path: string, id: string): void; create(path: string, data: Omit): void; update(path: string, data: ED[T]['Update']['data'], action?: ED[T]['Action']): void; remove(path: string): void; isLoading(path: string): boolean | undefined; isLoadingMore(path: string): boolean | undefined; isExecuting(path: string): boolean; isListDescandent(path: string): boolean; refresh(path: string, pageNumber?: number): Promise; loadMore(path: string): Promise; getPagination(path: string): Pagination; setId(path: string, id: string): void; unsetId(path: string): void; getId(path: string): string | undefined; getEntity(path: string): keyof ED; setPageSize(path: string, pageSize: number): void; setCurrentPage(path: string, currentPage: number): void; getNamedFilters(path: string): (NamedFilterItem & { applied?: boolean | undefined; })[]; getNamedFilterByName(path: string, name: string): (NamedFilterItem & { applied?: boolean | undefined; }) | undefined; setNamedFilters(path: string, filters: NamedFilterItem[], refresh?: boolean): void; addNamedFilter(path: string, filter: NamedFilterItem, refresh?: boolean): void; removeNamedFilter(path: string, filter: NamedFilterItem, refresh?: boolean): void; removeNamedFilterByName(path: string, name: string, refresh?: boolean): void; getNamedSorters(path: string): (NamedSorterItem & { applied?: boolean | undefined; })[]; getNamedSorterByName(path: string, name: string): (NamedSorterItem & { applied?: boolean | undefined; }) | undefined; setNamedSorters(path: string, sorters: NamedSorterItem[], refresh?: boolean): void; addNamedSorter(path: string, sorter: NamedSorterItem, refresh?: boolean): void; removeNamedSorter(path: string, sorter: NamedSorterItem, refresh?: boolean): void; removeNamedSorterByName(path: string, name: string, refresh?: boolean): void; getIntrinsticFilters(path: string): ED[keyof ED]["Selection"]["filter"] | undefined; getOperations(path: string): { entity: keyof ED; operation: ED[keyof ED]["Operation"]; }[] | undefined; execute(path: string, action?: ED[T]['Action'], opers?: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; }>): Promise<{ result: import("oak-domain/lib/types").OperationResult[] | Awaited>; message: string | null | undefined; } | { message: string; }>; savePoint(): number; /** * 将path上的更新清除 * @param path * @param lsn 要清除到某个指定的savepoint,不设则完全清空 * @param dontPublish */ clean(path: string, lsn?: number, dontPublish?: true): void; getRoot(): Record | ListNode | VirtualNode>; saveExtraData(path: string, key: string, data: any): void; loadExtraData(path: string, key: string): any; } export {};