UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

102 lines (101 loc) 4.72 kB
/** * StorageBase.ts * * ARCHITECTURE DOCUMENTATION * ========================== * * This is the base implementation for all storage types in MCTools. * It provides the event dispatching infrastructure for file/folder change notifications. * * EVENTS (for real-time synchronization): * --------------------------------------- * - onFileAdded: Dispatched by notifyFileAdded() when a new file is detected * - onFileRemoved: Dispatched by notifyFileRemoved() when a file is deleted * - onFileContentsUpdated: Dispatched by notifyFileContentsUpdated() when content changes * - onFolderAdded: Dispatched by notifyFolderAdded() when a folder is created * - onFolderRemoved: Dispatched by notifyFolderRemoved() when a folder is deleted * - onFolderMoved: Dispatched by notifyFolderMoved() when a folder is renamed/moved * * These events power the sync pipeline: * NodeStorage (watcher) -> HttpServer -> WebSocket -> HttpStorage -> MCWorld -> WorldView * * SUBCLASSES: * ----------- * - NodeStorage: Local file system (server-side, adds fs.watch() support) * - HttpStorage: HTTP-based storage (client-side, receives WebSocket notifications) * - ZipStorage: ZIP file storage (in-memory) * - BrowserStorage: Browser local storage * - VirtualFolderStorage: Aggregates multiple folders * * HOW TO ADD A NEW STORAGE TYPE: * ------------------------------ * 1. Extend StorageBase * 2. Implement abstract rootFolder and getAvailable() * 3. Create corresponding FolderBase and FileBase subclasses * 4. If supporting watching, implement IWatchableStorage from IStorageWatcher.ts * 5. Call notify*() methods when changes are detected */ import IStorage, { IFileUpdateEvent, IFolderMove, StorageErrorStatus } from "./IStorage"; import IFolder from "./IFolder"; import IFile, { FileUpdateType } from "./IFile"; import IVersionContent from "./IVersionContent"; export declare const MaxRecentVersionsToConsider = 100; export declare const WeRecentlyChangedItThresholdMs = 50; export default abstract class StorageBase implements IStorage { #private; abstract rootFolder: IFolder; isContentUpdated: boolean; readOnly: boolean; scanForChangesPhase: number; static readonly slashFolderDelimiter = "/"; priorVersions: IVersionContent[]; currentVersionId: string | undefined; containerFile?: IFile | undefined; available?: boolean | undefined; errorStatus?: StorageErrorStatus; errorMessage?: string; channelId?: string; get folderDelimiter(): string; get storagePath(): string | undefined; set storagePath(newStoragePath: string | undefined); resetContentUpdated(): void; get onFileAdded(): import("ste-events").IEvent<StorageBase, IFile>; get onFileRemoved(): import("ste-events").IEvent<StorageBase, string>; get onFileContentsUpdated(): import("ste-events").IEvent<StorageBase, IFileUpdateEvent>; get onFolderMoved(): import("ste-events").IEvent<StorageBase, IFolderMove>; get onFolderAdded(): import("ste-events").IEvent<StorageBase, IFolder>; get onFolderRemoved(): import("ste-events").IEvent<StorageBase, string>; ensureFolderFromStorageRelativePath(path: string): Promise<IFolder>; notifyFileAdded(file: IFile): void; notifyFolderAdded(folder: IFolder): void; notifyFolderRemoved(folder: IFolder): void; notifyFileContentsUpdated(fileEvent: IFileUpdateEvent): void; notifyFolderMoved(folderMove: IFolderMove): void; notifyFileRemoved(fileName: string): void; incrementalScanForChanges(): Promise<void>; scanForChanges(): Promise<void>; notifyPathWasUpdatedExternal(path: string): Promise<void>; /** * Called when a new file is detected externally (e.g., by fs.watch in Electron). * Creates the file object in the folder tree and fires the onFileAdded event. * * @param path The full path to the newly added file */ notifyPathWasAddedExternal(path: string): Promise<void>; /** * Called when a file is deleted externally (e.g., by fs.watch in Electron). * Removes the file from the folder tree and fires the onFileRemoved event. * * @param path The full path to the removed file */ notifyPathWasRemovedExternal(path: string): Promise<void>; getFolderList(): IFolder[]; _addFolders(folder: IFolder, folderList: IFolder[]): void; setToVersion(versionId: string): void; trimAfterVersion(versionId: string): void; addVersion(versionContent: IVersionContent, updateType: FileUpdateType): void; joinPath(pathA: string, pathB: string): string; static getParentFolderPath(path: string): string; abstract getAvailable(): Promise<boolean>; getUsesPollingBasedUpdating(): boolean; }