import { Socket } from "socket.io-client"; import { AutoUpdateManager } from "./AutoUpdateManagerClass.js"; import { DEMClientCallbacks } from "./AutoUpdatedClientObjectClass.js"; import { Constructor, IsData, LoggersType, IAutoUpdatedClientObjectBase, MongoId, IAutoUpdateManager, DEMVersionOptions, DEMErrorCode, EntityDescriptor, LazyLoadingOptions } from "./CommonTypes.js"; import { EventEmitter } from "eventemitter3"; import { IClientStorageAdapter, ClientDeltaSyncOptions } from "./sync/index.js"; export type WrappedInstances>> = { [K in keyof T]: AutoUpdateClientManager, WrappedInstances>; }; /** * Factory function initializing a dictionary of AutoUpdateClientManager instances. * Verifies versions, executes startup handshakes, and parallelizes reference resolution. * * @param defs - Dictionary mapping entity class names to their client constructor classes. * @param loggers - Logger callbacks interface. * @param socket - Socket.IO client socket connection. * @param doDebug - Flag indicating whether debug logs are emitted. * @param emitter - Shared event emitter for lifecycle notifications. * @param callbacks - Optional event callbacks (new, update, delete, progress). * @param versionOptions - Version compatibility validation options. * @param deltaSyncOptions - Delta sync storage and caching configuration. * @returns Promise resolving to the initialized client manager map. */ export declare function AUCManagerFactory>>(defs: T, loggers: LoggersType, socket: Socket, doDebug?: boolean, emitter?: EventEmitter, callbacks?: Partial<{ [K in keyof T]: Partial>; } & Partial>>, versionOptions?: DEMVersionOptions, deltaSyncOptions?: ClientDeltaSyncOptions | boolean, lazyLoadingOptions?: LazyLoadingOptions | boolean | Partial>): Promise>; export declare class AutoUpdateClientManager> = Record>> extends AutoUpdateManager { protected objects_: { [_id: string]: T; }; readonly managers: M; callbacks: DEMClientCallbacks; readonly socket: Socket; readonly versionOptions?: DEMVersionOptions; readonly deltaSyncOptions?: ClientDeltaSyncOptions; readonly storageAdapter?: IClientStorageAdapter; readonly deltaSyncEnabled: boolean; readonly lazyLoadingOptions?: LazyLoadingOptions | boolean; readonly isLazyLoadingEnabled: boolean; readonly defaultHydrationDepth: number; manifest: EntityDescriptor[]; lastRevision: number; /** * Clock offset in milliseconds between client local time and server clock calculated via Cristian's algorithm. */ serverTimeOffset: number; totalObjects: number; loadedObjects: number; private pendingMissingFetches; private pendingHydrations; private _cachedObjectsArray; private _reconnectHandler?; private _deauthHandler?; _isClosed: boolean; /** * Initializes an AutoUpdateClientManager instance. * * @param classParam - Constructor of the client object entity. * @param className - Managed entity class name. * @param socket - Socket.IO client socket connection. * @param loggers - Logging interfaces. * @param managers - Registry of sibling client managers. * @param emitter - Shared event emitter. * @param callbacks - Client event callbacks. * @param versionOptions - Version compatibility options. * @param deltaSyncOptions - Delta sync storage adapter configuration. * @param lazyLoadingOptions - Lazy loading manifest and hydration configuration. */ constructor(classParam: Constructor, className: string, socket: Socket, loggers: LoggersType, managers: M, emitter: EventEmitter, callbacks: DEMClientCallbacks, versionOptions?: DEMVersionOptions, deltaSyncOptions?: ClientDeltaSyncOptions | boolean, lazyLoadingOptions?: LazyLoadingOptions | boolean); /** * Normalizes loaded object count against total objects into a 0 to 1 progress fraction. * * @param loaded - Number of loaded objects. * @param total - Total count of expected objects. * @returns Normalized progress value between 0 and 1. */ normalizeProgress(loaded: number, total: number): number; /** * Registers socket event listeners for entity creation and deletion broadcasts. */ private startSocketListeners; /** * Retrieves the current time in milliseconds synchronized with the server clock via Cristian's algorithm. * * @returns Synchronized server timestamp in milliseconds. */ getSynchronizedTime(): number; /** * Deletes an object by ID from local cache, socket events, and persistent storage adapter. * * @param _id - Identifier of object to delete. * @param isRemote - Whether the deletion originates from a remote server broadcast or delta sync. * @returns Promise resolving to deletion outcome. */ deleteObject(_id: MongoId, isRemote?: boolean): Promise<{ success: boolean; message: string; code?: DEMErrorCode; }>; /** * Fetches startup data from the server or applies delta updates from local storage. * * @param t - Optional benchmark timer tracking object. * @returns Promise resolving when data has been loaded and initialized. */ loadFromServer(t?: { s: number; f: number; }): Promise; /** * Verifies structural schema compatibility between client and server class definitions. * * @param extraProperties - Properties present on client class but absent on server. * @param data - Server schema containing registered server property names. * @returns Object indicating whether manager is allowed to load and descriptive error message. */ private checkLoadability; /** * Retrieves an object from local memory by identifier. * * @param _id - Entity identifier. * @returns Managed object instance, null, or undefined. */ getObject(_id?: MongoId): T | null | undefined; /** * Dictionary map containing all managed object instances keyed by ID string. * * @returns Object dictionary keyed by string IDs. */ get objects(): { [_id: string]: T; }; /** * Array representation of all managed object instances, cached for fast reads. * * @returns Array containing all managed object instances. */ get objectsAsArray(): T[]; /** * Loads and hydrates an unhydrated entity on demand up to a designated reference depth. * Deduplicates concurrent in-flight hydration requests. * * @param _id - Unique identifier of the entity to hydrate. * @param options - Hydration options containing target reference depth. * @returns Promise resolving to the hydrated entity instance. */ loadObject(_id: MongoId, options?: { depth?: number; }): Promise; /** * Fetches an object missing from local client memory on demand from the server. * Deduplicates concurrent in-flight requests for the same entity ID. * * @param _id - Entity identifier of the missing object. * @returns Promise resolving to the retrieved object instance. * @throws {DEMError} Throws DEMErrorCode.MISSING_ID or MANAGERS_NOT_INITIALIZED. */ handleGetMissingObject(_id: MongoId): Promise; /** * Creates a new object instance on the server and registers it in local manager state. * * @param data - Object property payload omitting `_id`. * @returns Promise resolving to the newly created client entity. * @throws {DEMError} Throws DEMErrorCode.OBJECT_CREATE_FAILED on failure. */ createObject(data: Omit, "_id">): Promise; /** * Closes the manager and unbinds all socket event listeners. */ close(): void; }