diff --git a/src/backends/AsyncStore.ts b/src/backends/AsyncStore.ts index 4485884f4..7581f9b2a 100644 --- a/src/backends/AsyncStore.ts +++ b/src/backends/AsyncStore.ts @@ -172,6 +172,7 @@ export class AsyncStoreFileSystem extends Async(FileSystem) { return this._ready; } + // @ts-expect-error 2611 public get metadata(): FileSystemMetadata { return { ...super.metadata, diff --git a/src/filesystem.ts b/src/filesystem.ts index 2f6479521..b8e326bca 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -206,18 +206,33 @@ export abstract class FileSystem { public abstract syncSync(path: string, data: Uint8Array, stats: Readonly): void; } +/** + * @internal + */ +declare abstract class SyncFileSystem extends FileSystem { + get metadata(): FileSystemMetadata; + ready(): Promise; + exists(path: string, cred: Cred): Promise; + rename(oldPath: string, newPath: string, cred: Cred): Promise; + stat(path: string, cred: Cred): Promise; + createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise; + openFile(path: string, flag: FileFlag, cred: Cred): Promise; + unlink(path: string, cred: Cred): Promise; + rmdir(path: string, cred: Cred): Promise; + mkdir(path: string, mode: number, cred: Cred): Promise; + readdir(path: string, cred: Cred): Promise; + link(srcpath: string, dstpath: string, cred: Cred): Promise; + sync(path: string, data: Uint8Array, stats: Readonly): Promise; +} + /** * Implements the asynchronous API in terms of the synchronous API. - * - * @example ```ts - * class SyncFS extends Sync(FileSystem) {} - * ``` */ -export function Sync FileSystem>(FS: T) { +export function Sync FileSystem>(FS: T): (abstract new (...args) => SyncFileSystem) & T { /** * Implements the asynchronous API in terms of the synchronous API. */ - abstract class SyncFileSystem extends FS { + abstract class _SyncFileSystem extends FS implements SyncFileSystem { public get metadata(): FileSystemMetadata { return { ...super.metadata, synchronous: true }; } @@ -270,11 +285,31 @@ export function Sync FileSystem>(FS: T) { return this.syncSync(path, data, stats); } } - return SyncFileSystem; + return _SyncFileSystem; +} + +/** + * @internal + */ +declare abstract class AsyncFileSystem { + get metadata(): FileSystemMetadata; + renameSync(oldPath: string, newPath: string, cred: Cred): void; + statSync(path: string, cred: Cred): Stats; + createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File; + openFileSync(path: string, flag: FileFlag, cred: Cred): File; + unlinkSync(path: string, cred: Cred): void; + rmdirSync(path: string, cred: Cred): void; + mkdirSync(path: string, mode: number, cred: Cred): void; + readdirSync(path: string, cred: Cred): string[]; + linkSync(srcpath: string, dstpath: string, cred: Cred): void; + syncSync(path: string, data: Uint8Array, stats: Readonly): void; } -export function Async FileSystem>(FS: T) { - abstract class AsyncFileSystem extends FS { +export function Async FileSystem>(FS: T): (abstract new (...args) => AsyncFileSystem) & T { + abstract class _AsyncFileSystem extends FS implements AsyncFileSystem { + public get metadata(): FileSystemMetadata { + return { ...super.metadata, synchronous: false }; + } /* eslint-disable @typescript-eslint/no-unused-vars */ public renameSync(oldPath: string, newPath: string, cred: Cred): void { throw new ApiError(ErrorCode.ENOTSUP); @@ -317,11 +352,35 @@ export function Async FileSystem>(FS: T) { } } /* eslint-enable @typescript-eslint/no-unused-vars */ - return AsyncFileSystem; + return _AsyncFileSystem; +} + +/** + * @internal + */ +declare abstract class ReadonlyFileSystem { + get metadata(): FileSystemMetadata; + rename(oldPath: string, newPath: string, cred: Cred): Promise; + renameSync(oldPath: string, newPath: string, cred: Cred): void; + createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise; + createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File; + unlink(path: string, cred: Cred): Promise; + unlinkSync(path: string, cred: Cred): void; + rmdir(path: string, cred: Cred): Promise; + rmdirSync(path: string, cred: Cred): void; + mkdir(path: string, mode: number, cred: Cred): Promise; + mkdirSync(path: string, mode: number, cred: Cred): void; + link(srcpath: string, dstpath: string, cred: Cred): Promise; + linkSync(srcpath: string, dstpath: string, cred: Cred): void; + sync(path: string, data: Uint8Array, stats: Readonly): Promise; + syncSync(path: string, data: Uint8Array, stats: Readonly): void; } -export function Readonly FileSystem>(FS: T) { - abstract class ReadonlyFileSystem extends FS { +export function Readonly FileSystem>(FS: T): (abstract new (...args) => ReadonlyFileSystem) & T { + abstract class _ReadonlyFileSystem extends FS implements ReadonlyFileSystem { + public get metadata(): FileSystemMetadata { + return { ...super.metadata, readonly: true }; + } /* eslint-disable @typescript-eslint/no-unused-vars */ public async rename(oldPath: string, newPath: string, cred: Cred): Promise { throw new ApiError(ErrorCode.EROFS); @@ -380,5 +439,5 @@ export function Readonly FileSystem>(FS: T) } /* eslint-enable @typescript-eslint/no-unused-vars */ } - return ReadonlyFileSystem; + return _ReadonlyFileSystem; }