import {Directory, DirectoryContent, File, ShallowDirectory} from "./model"; export interface FileSystemEvent { type: keyof Events; correlation?: Correlation; } export interface UnexpectedErrorEvent extends FileSystemEvent { type: 'unexpectedError'; stack?: string; } export interface FileCreatedEvent extends FileSystemEvent { type: 'fileCreated'; fullPath: string; newContent: string; } export interface FileChangedEvent extends FileSystemEvent { type: 'fileChanged'; fullPath: string; newContent: string; } export interface FileDeletedEvent extends FileSystemEvent { type: 'fileDeleted'; fullPath: string; } export interface DirectoryCreatedEvent extends FileSystemEvent { type: 'directoryCreated'; fullPath: string; } export interface DirectoryDeletedEvent extends FileSystemEvent { type: 'directoryDeleted'; fullPath: string; } export interface Disposable { dispose(): void } export function isDisposable(fs: any): fs is Disposable { return !!fs && typeof fs.dispose === 'function'; } export type ListenerFn = (event: T) => any; export type Events = { unexpectedError: UnexpectedErrorEvent; fileCreated: FileCreatedEvent; fileChanged: FileChangedEvent; fileDeleted: FileDeletedEvent; directoryCreated: DirectoryCreatedEvent; directoryDeleted: DirectoryDeletedEvent; } export const fileSystemEventNames: Array = ['unexpectedError', 'fileCreated', 'fileChanged', 'fileDeleted', 'directoryCreated', 'directoryDeleted']; export const fileSystemAsyncMethods: Array = ['saveFile', 'deleteFile', 'deleteDirectory', 'loadTextFile', 'loadDirectoryTree', 'ensureDirectory', 'loadDirectoryChildren']; export type Correlation = string; export interface EventEmitter { listeners(event: S, exists: boolean): Array> | boolean; listeners(event: S): Array>; on(event: S, fn: ListenerFn, context?: any): this; addListener(event: S, fn: ListenerFn, context?: any): this; once(event: S, fn: ListenerFn, context?: any): this; removeListener(event: S, fn?: ListenerFn, context?: any, once?: boolean): this; removeAllListeners(event: S): this; off(event: S, fn?: ListenerFn, context?: any, once?: boolean): this; eventNames(): Array } export interface FileSystem { readonly events: EventEmitter; readonly baseUrl: string; saveFile(fullPath: string, newContent: string): Promise; deleteFile(fullPath: string): Promise; deleteDirectory(fullPath: string, recursive?: boolean): Promise; ensureDirectory(fullPath: string): Promise; loadTextFile(fullPath: string): Promise; loadDirectoryTree(fullPath?: string): Promise; loadDirectoryChildren(fullPath: string): Promise<(File | ShallowDirectory)[]>; } export interface FileSystemReadSync extends FileSystem { loadTextFileSync(fullPath: string): string; loadDirectoryTreeSync(fullPath?: string): Directory; loadDirectoryContentSync(fullPath?: string): DirectoryContent; loadDirectoryChildrenSync(fullPath: string): Array; }