@workspace-fs/core
Version:
Multi-project workspace manager for Firesystem with support for multiple sources
111 lines (89 loc) • 3.05 kB
text/typescript
import {
IReactiveFileSystem,
FileEntry,
FileStat,
FSEvent,
Disposable,
} from "@firesystem/core";
import type { Project } from "../types";
export class FileSystemProxy {
constructor(
private getActiveProject: () => Project | null,
private trackProjectAccess: (project: Project) => void,
private resetAutoDisableTimer: (projectId: string) => void,
) {}
/**
* Get active project's file system (for proxying)
*/
private getActiveFS(): IReactiveFileSystem {
const project = this.getActiveProject();
if (!project) {
throw new Error("No active project");
}
// Track access
this.trackProjectAccess(project);
this.resetAutoDisableTimer(project.id);
return project.fs;
}
// IReactiveFileSystem implementation (proxy to active project)
async readFile(path: string): Promise<FileEntry> {
return this.getActiveFS().readFile(path);
}
async writeFile(
path: string,
content: any,
metadata?: Record<string, any>,
): Promise<FileEntry> {
return this.getActiveFS().writeFile(path, content, metadata);
}
async deleteFile(path: string): Promise<void> {
return this.getActiveFS().deleteFile(path);
}
async mkdir(path: string, recursive?: boolean): Promise<FileEntry> {
return this.getActiveFS().mkdir(path, recursive);
}
async rmdir(path: string, recursive?: boolean): Promise<void> {
return this.getActiveFS().rmdir(path, recursive);
}
async exists(path: string): Promise<boolean> {
return this.getActiveFS().exists(path);
}
async stat(path: string): Promise<FileStat> {
return this.getActiveFS().stat(path);
}
async readDir(path: string): Promise<FileEntry[]> {
return this.getActiveFS().readDir(path);
}
async rename(oldPath: string, newPath: string): Promise<FileEntry> {
return this.getActiveFS().rename(oldPath, newPath);
}
async copy(sourcePath: string, targetPath: string): Promise<FileEntry> {
return this.getActiveFS().copy(sourcePath, targetPath);
}
async move(sourcePaths: string[], targetPath: string): Promise<void> {
return this.getActiveFS().move(sourcePaths, targetPath);
}
async glob(pattern: string): Promise<string[]> {
return this.getActiveFS().glob(pattern);
}
watch(path: string, callback: (event: FSEvent) => void): Disposable {
return this.getActiveFS().watch(path, callback);
}
watchGlob?(pattern: string, callback: (event: FSEvent) => void): Disposable {
const fs = this.getActiveFS();
if ("watchGlob" in fs && typeof fs.watchGlob === "function") {
return fs.watchGlob(pattern, callback);
}
throw new Error("Active file system does not support watchGlob");
}
async size(): Promise<number> {
return this.getActiveFS().size();
}
// Delegate permission methods to active FS
async canModify(path: string): Promise<boolean> {
return this.getActiveFS().canModify(path);
}
async canCreateIn(parentPath: string): Promise<boolean> {
return this.getActiveFS().canCreateIn(parentPath);
}
}