Skip to content

Commit

Permalink
Fixed generated declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Mar 16, 2024
1 parent 9ca8eb2 commit 699abad
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/backends/AsyncStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class AsyncStoreFileSystem extends Async(FileSystem) {
return this._ready;
}

// @ts-expect-error 2611
public get metadata(): FileSystemMetadata {
return {
...super.metadata,
Expand Down
85 changes: 72 additions & 13 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,33 @@ export abstract class FileSystem {
public abstract syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}

/**
* @internal
*/
declare abstract class SyncFileSystem extends FileSystem {
get metadata(): FileSystemMetadata;
ready(): Promise<this>;
exists(path: string, cred: Cred): Promise<boolean>;
rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
stat(path: string, cred: Cred): Promise<Stats>;
createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
openFile(path: string, flag: FileFlag, cred: Cred): Promise<File>;
unlink(path: string, cred: Cred): Promise<void>;
rmdir(path: string, cred: Cred): Promise<void>;
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
readdir(path: string, cred: Cred): Promise<string[]>;
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
}

/**
* Implements the asynchronous API in terms of the synchronous API.
*
* @example ```ts
* class SyncFS extends Sync(FileSystem) {}
* ```
*/
export function Sync<T extends abstract new (...args) => FileSystem>(FS: T) {
export function Sync<T extends abstract new (...args) => 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 };
}
Expand Down Expand Up @@ -270,11 +285,31 @@ export function Sync<T extends abstract new (...args) => 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<Stats>): void;
}

export function Async<T extends abstract new (...args) => FileSystem>(FS: T) {
abstract class AsyncFileSystem extends FS {
export function Async<T extends abstract new (...args) => 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);
Expand Down Expand Up @@ -317,11 +352,35 @@ export function Async<T extends abstract new (...args) => 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<void>;
renameSync(oldPath: string, newPath: string, cred: Cred): void;
createFile(path: string, flag: FileFlag, mode: number, cred: Cred): Promise<File>;
createFileSync(path: string, flag: FileFlag, mode: number, cred: Cred): File;
unlink(path: string, cred: Cred): Promise<void>;
unlinkSync(path: string, cred: Cred): void;
rmdir(path: string, cred: Cred): Promise<void>;
rmdirSync(path: string, cred: Cred): void;
mkdir(path: string, mode: number, cred: Cred): Promise<void>;
mkdirSync(path: string, mode: number, cred: Cred): void;
link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
linkSync(srcpath: string, dstpath: string, cred: Cred): void;
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}

export function Readonly<T extends abstract new (...args) => FileSystem>(FS: T) {
abstract class ReadonlyFileSystem extends FS {
export function Readonly<T extends abstract new (...args) => 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<void> {
throw new ApiError(ErrorCode.EROFS);
Expand Down Expand Up @@ -380,5 +439,5 @@ export function Readonly<T extends abstract new (...args) => FileSystem>(FS: T)
}
/* eslint-enable @typescript-eslint/no-unused-vars */
}
return ReadonlyFileSystem;
return _ReadonlyFileSystem;
}

0 comments on commit 699abad

Please sign in to comment.