UNPKG

dehub

Version:
157 lines (156 loc) 5.06 kB
/** * DEHub类型定义模块 * 包含了DEHub系统中使用的所有类型定义、接口和工具函数 * @module DETypes */ /** * 事件上下文接口 * 解除与DEHub模块的循环依赖 */ export interface IEventContext { readonly sender: any; readonly event: string; readonly stage: EventStage; readonly detail?: any; readonly status?: ObjectStatus; readonly attribute?: string; readonly property?: string; readonly database?: string; cancel: boolean; readonly output: DERecord; readonly components: Map<string, IDEComp<any>>; } export type ObjTag = Record<string, string>; export interface ObjWithTag extends DERecord { readonly tag: Tag; } export declare class Tag { #private; constructor(tag: ObjTag); get members(): ObjTag; get path(): string; get keys(): string[]; equal(others: Tag | ObjTag | string): boolean; toString(): string; } export type DERecord = Record<string, any>; export type DEEventFunction = (context: IEventContext) => void | Promise<void>; export declare enum EventNames { ValueChanged = "$valueChanged", StatusChanging = "$statusChanged", Submit = "$submit", StateChanging = "$stateChanged", Mounting = "$mount", Registration = "$reg", WillUnmount = "$unmount", ComponentsLoaded = "$allCmpLoaded", Exception = "$error" } export interface DECompOption { autoReady?: boolean; useSession?: boolean; } export interface IDEComp<T> extends ObjWithTag { readonly state: T; readonly options: DECompOption; update: (target: Partial<T>, deep?: boolean) => Promise<Partial<T>>; readonly isReady: boolean; waitReady: () => Promise<void>; onStateChanging: (callback: DEEventFunction) => void; removeHandler: (callback: DEEventFunction) => void; destroy: () => Promise<void>; [propery: string]: any; } export declare enum ObjectStatus { New = "new", Ready = "ready", Loading = "loading", Clear = "clear", Reset = "reset", Uploading = "uploading", Deleting = "deleting", Deleted = "deleted", Failed = "failed", Timeout = "Timeout" } export type DatasetOptions = (Tag | [Tag, DEDataOptions?])[]; export interface DEDataOptions { loadingMode?: 'none' | 'localDB' | 'custom'; default?: DERecord; state?: DERecord; timeout?: number; database?: string; saveDirtyData?: boolean; autoLoad?: boolean; retryInterval?: number; retryLimit?: number; expireTime?: number; } export declare enum EventStage { PreOperation = "pre", PostOperation = "post" } export interface IDataObject { data: DERecord; default?: DERecord; virtual: DERecord; expires?: number; state?: DERecord; status: ObjectStatus; retryStatus?: ObjectStatus; retryCount?: number; } export interface ICompoentObject<T> { options: DERecord; state: T; } export interface IData extends ObjWithTag { readonly options: DEDataOptions; status: ObjectStatus; readonly default: DERecord; readonly original: DERecord; readonly data: DERecord; readonly dirty: DERecord; readonly virtual: DERecord; readonly keys: string[]; readonly expires?: number; state?: DERecord; updateState: (state: DERecord) => void; get: (attribute: string) => any; set: (attribute: string, value: any, isVirtual?: boolean) => Promise<DERecord>; update: (target: DERecord, noTrigger: boolean | undefined) => DERecord; submit: (target?: DERecord, mergeData?: boolean) => void; reset: () => void; delete: () => void; load: (force?: boolean) => void; clear: () => void; until: (status: ObjectStatus.Deleted | ObjectStatus.Ready | ObjectStatus.Failed | ObjectStatus.Timeout) => Promise<void>; destroy: () => Promise<void>; } export interface EmitContext { readonly sender: ObjWithTag | IData | IDEComp<any>; readonly event: string; readonly stage: EventStage; readonly detail?: any; readonly status?: ObjectStatus; readonly attribute?: string; readonly property?: string; readonly database?: string; } export interface DataUpdateArgs { value: any; preImage?: any; postImage?: any; } export declare const MAX_TAG_KEYS = 10; export declare const TagsSerializer: { toPath: (tag: ObjTag) => string; selfAndChildTags: (baseTags: Tag) => string[]; fromPath: (path: string) => ObjTag; }; export declare const mergeObject: (objA: any, objB: any, deep?: boolean) => any; export declare const clearNullNodes: (obj: any) => any; export declare const getDiff: (obj1: Record<string, any>, obj2: Record<string, any>) => Record<string, any>; export declare const sleep: (millisecond: number) => Promise<void>; export declare const rejectedCheck: (results: PromiseSettledResult<any>[]) => void; export declare const DataProxy: (obj: DERecord) => DERecord;