UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

183 lines (180 loc) 5.94 kB
import { AbsFileManager } from 'scriptable-abstract'; import { FileManagerState, FileManagerInstance, FileManagerOptions, FileManagerResetOptions, BookmarkSource, FileSystemEvent } from '../../types/file.js'; import { FileManagerType } from '../../utils/paths.js'; /** * Mock implementation of Scriptable's FileManager. * Provides a virtual file system implementation for testing. * @implements FileManager */ declare class MockFileManager extends AbsFileManager<FileManagerState> implements FileManagerInstance { private bookmarks; private static localInstance; private static iCloudInstance; private eventListeners; /** * @inheritdoc * Gets or creates a local file manager instance */ static local(): FileManager; /** * @inheritdoc * Gets or creates an iCloud file manager instance */ static iCloud(): FileManager; /** * @additional * Creates a new file manager instance */ static create(type: FileManagerType, options?: FileManagerOptions): MockFileManager; /** * @additional * Resets both local and iCloud instances */ static reset(options?: FileManagerResetOptions): void; /** * @additional * Reset this instance */ resetInstance(options?: FileManagerResetOptions): void; constructor(type: FileManagerType, options?: FileManagerOptions); /** * @inheritdoc * Read data from a file * @throws {FileManagerError} If file does not exist or is a directory */ read(filePath: string): Data; /** * @inheritdoc * Write data to a file * @throws {FileManagerError} If parent directory does not exist */ write(filePath: string, content: Data): void; /** * @inheritdoc * Read string content from a file * @throws {FileManagerError} If file does not exist or is a directory */ readString(filePath: string): string; /** * @inheritdoc * Write string content to a file * @throws {FileManagerError} If parent directory does not exist */ writeString(filePath: string, content: string): void; /** * @inheritdoc * Read image from a file * @throws {FileManagerError} If file does not exist or is a directory */ readImage(filePath: string): Image; /** * @inheritdoc * Write image to a file * @throws {FileManagerError} If parent directory does not exist */ writeImage(filePath: string, _image: Image): void; /** * @inheritdoc * Remove a file or directory * @throws {FileManagerError} If path does not exist */ remove(filePath: string): void; fileExists(filePath: string): boolean; isDirectory(filePath: string): boolean; /** * @inheritdoc * Create a directory * @throws {FileManagerError} If parent directory does not exist and createParents is false */ createDirectory(dirPath: string, createParents?: boolean): void; /** * @inheritdoc * List contents of a directory * @throws {FileManagerError} If directory does not exist */ listContents(directoryPath: string): string[]; documentsDirectory(): string; libraryDirectory(): string; cacheDirectory(): string; temporaryDirectory(): string; joinPath(lhs: string, rhs: string): string; /** * @inheritdoc * Move a file or directory * @throws {FileManagerError} If source or destination parent directory does not exist */ move(sourceFile: string, destinationFile: string): void; /** * @inheritdoc * Copy a file or directory * @throws {FileManagerError} If source file does not exist or destination parent directory does not exist */ copy(sourceFile: string, destinationFile: string): void; bookmarkedPath(name: string): string; bookmarkExists(name: string): boolean; createBookmark(name: string, path: string): void; removeBookmark(name: string): void; allFileBookmarks(): Array<{ name: string; path: string; source: BookmarkSource; }>; downloadFileFromiCloud(filePath: string): Promise<void>; isFileDownloaded(filePath: string): boolean; isFileStoredIniCloud(filePath: string): boolean; modificationDate(filePath: string): Date; creationDate(filePath: string): Date; fileSize(filePath: string): number; fileName(filePath: string, includeFileExtension?: boolean): string; fileExtension(filePath: string): string; getUTI(filePath: string): string; writeExtendedAttribute(filePath: string, attributeName: string, value: string): void; readExtendedAttribute(filePath: string, attributeName: string): string; allExtendedAttributes(filePath: string): string[]; removeExtendedAttribute(filePath: string, attributeName: string): void; addTag(filePath: string, tag: string): void; removeTag(filePath: string, tag: string): void; allTags(filePath: string): string[]; /** * @additional * Add a file system event listener */ addEventListener(listener: (event: FileSystemEvent) => void): void; /** * @additional * Remove a file system event listener */ removeEventListener(listener: (event: FileSystemEvent) => void): void; /** * @additional * Emit a file system event */ private emitEvent; /** * @additional * Wrap an error in a FileManagerError */ private wrapError; /** * @additional * Initialize base directories */ private initializeBaseDirectories; /** * @additional * Resolve a path to its normalized form */ private resolvePath; /** * @additional * Get a node from the file system */ private getNode; /** * @additional * Ensure a parent directory exists */ private ensureParentDirectory; private createNode; } export { MockFileManager };