From 50d2a1ee8214a2ae379687e39d56d8076fe6f5ef Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 16 Jun 2023 11:12:36 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20setup=20fsa=20to=20node?= =?UTF-8?q?=20utility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fsa-to-node/FsaNodeFs.ts | 261 +++++++++++++++++++++++++++++++++++ src/fsa-to-node/constants.ts | 3 + src/fsa-to-node/types.ts | 1 + 3 files changed, 265 insertions(+) create mode 100644 src/fsa-to-node/FsaNodeFs.ts create mode 100644 src/fsa-to-node/constants.ts create mode 100644 src/fsa-to-node/types.ts diff --git a/src/fsa-to-node/FsaNodeFs.ts b/src/fsa-to-node/FsaNodeFs.ts new file mode 100644 index 000000000..06fd0fc14 --- /dev/null +++ b/src/fsa-to-node/FsaNodeFs.ts @@ -0,0 +1,261 @@ +import type {FsCallbackApi} from '../node/types'; +import type * as misc from '../node/types/misc'; +import type * as opts from '../node/types/options'; +import type * as fsa from '../fsa/types'; + +const notImplemented: ((...args: unknown[]) => unknown) = () => { + throw new Error('Not implemented'); +}; + +/** + * Constructs a Node.js `fs` API from a File System Access API + * [`FileSystemDirectoryHandle` object](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle). + */ +export class FsaNodeFs implements FsCallbackApi { + public constructor (protected readonly root: fsa.IFileSystemDirectoryHandle) {} + + public readonly open: FsCallbackApi['open'] = (path: misc.PathLike, flags: misc.TFlags, a?: misc.TMode | misc.TCallback, b?: misc.TCallback | string) => { + throw new Error('Not implemented'); + }; + + public readonly close: FsCallbackApi['close'] = (fd: number, callback: misc.TCallback): void => { + throw new Error('Not implemented'); + }; + + public readonly read: FsCallbackApi['read'] = ( + fd: number, + buffer: Buffer | ArrayBufferView | DataView, + offset: number, + length: number, + position: number, + callback: (err?: Error | null, bytesRead?: number, buffer?: Buffer | ArrayBufferView | DataView) => void, + ): void => { + throw new Error('Not implemented'); + }; + + public readonly readFile: FsCallbackApi['readFile'] = (id: misc.TFileId, a?: opts.IReadFileOptions | string | misc.TCallback, b?: misc.TCallback) => { + throw new Error('Not implemented'); + }; + + public readonly write: FsCallbackApi['write'] = (fd: number, a?, b?, c?, d?, e?) => { + throw new Error('Not implemented'); + }; + + writeFile(id: misc.TFileId, data: misc.TData, callback: misc.TCallback); + writeFile( + id: misc.TFileId, + data: misc.TData, + options: opts.IWriteFileOptions | string, + callback: misc.TCallback, + ); + writeFile(id: misc.TFileId, data: misc.TData, a: misc.TCallback | opts.IWriteFileOptions | string, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + copyFile(src: misc.PathLike, dest: misc.PathLike, callback: misc.TCallback); + copyFile(src: misc.PathLike, dest: misc.PathLike, flags: misc.TFlagsCopy, callback: misc.TCallback); + copyFile(src: misc.PathLike, dest: misc.PathLike, a, b?) { + throw new Error('Not implemented'); + } + + link(existingPath: misc.PathLike, newPath: misc.PathLike, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + unlink(path: misc.PathLike, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + symlink(target: misc.PathLike, path: misc.PathLike, callback: misc.TCallback); + symlink(target: misc.PathLike, path: misc.PathLike, type: misc.symlink.Type, callback: misc.TCallback); + symlink(target: misc.PathLike, path: misc.PathLike, a: misc.symlink.Type | misc.TCallback, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + realpath(path: misc.PathLike, callback: misc.TCallback); + realpath(path: misc.PathLike, options: opts.IRealpathOptions | string, callback: misc.TCallback); + realpath(path: misc.PathLike, a: misc.TCallback | opts.IRealpathOptions | string, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + lstat(path: misc.PathLike, callback: misc.TCallback): void; + lstat(path: misc.PathLike, options: opts.IStatOptions, callback: misc.TCallback): void; + lstat(path: misc.PathLike, a: misc.TCallback | opts.IStatOptions, b?: misc.TCallback): void { + throw new Error('Not implemented'); + } + + stat(path: misc.PathLike, callback: misc.TCallback): void; + stat(path: misc.PathLike, options: opts.IStatOptions, callback: misc.TCallback): void; + stat(path: misc.PathLike, a: misc.TCallback | opts.IStatOptions, b?: misc.TCallback): void { + throw new Error('Not implemented'); + } + + fstat(fd: number, callback: misc.TCallback): void; + fstat(fd: number, options: opts.IFStatOptions, callback: misc.TCallback): void; + fstat(fd: number, a: misc.TCallback | opts.IFStatOptions, b?: misc.TCallback): void { + throw new Error('Not implemented'); + } + + rename(oldPath: misc.PathLike, newPath: misc.PathLike, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + exists(path: misc.PathLike, callback: (exists: boolean) => void): void { + throw new Error('Not implemented'); + } + + access(path: misc.PathLike, callback: misc.TCallback); + access(path: misc.PathLike, mode: number, callback: misc.TCallback); + access(path: misc.PathLike, a: misc.TCallback | number, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + appendFile(id: misc.TFileId, data: misc.TData, callback: misc.TCallback); + appendFile( + id: misc.TFileId, + data: misc.TData, + options: opts.IAppendFileOptions | string, + callback: misc.TCallback, + ); + appendFile(id: misc.TFileId, data: misc.TData, a, b?) { + throw new Error('Not implemented'); + } + + readdir(path: misc.PathLike, callback: misc.TCallback); + readdir( + path: misc.PathLike, + options: opts.IReaddirOptions | string, + callback: misc.TCallback, + ); + readdir(path: misc.PathLike, a?, b?) { + throw new Error('Not implemented'); + } + + readlink(path: misc.PathLike, callback: misc.TCallback); + readlink(path: misc.PathLike, options: opts.IOptions, callback: misc.TCallback); + readlink(path: misc.PathLike, a: misc.TCallback | opts.IOptions, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + fsyncSync(fd: number): void { + throw new Error('Not implemented'); + } + + fsync(fd: number, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + fdatasync(fd: number, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + ftruncate(fd: number, callback: misc.TCallback); + ftruncate(fd: number, len: number, callback: misc.TCallback); + ftruncate(fd: number, a: misc.TCallback | number, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + truncate(id: misc.TFileId, callback: misc.TCallback); + truncate(id: misc.TFileId, len: number, callback: misc.TCallback); + truncate(id: misc.TFileId, a: misc.TCallback | number, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + futimes(fd: number, atime: misc.TTime, mtime: misc.TTime, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + utimes(path: misc.PathLike, atime: misc.TTime, mtime: misc.TTime, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + mkdir(path: misc.PathLike, callback: misc.TCallback); + mkdir( + path: misc.PathLike, + mode: misc.TMode | (opts.IMkdirOptions & { recursive?: false }), + callback: misc.TCallback, + ); + mkdir(path: misc.PathLike, mode: opts.IMkdirOptions & { recursive: true }, callback: misc.TCallback); + mkdir(path: misc.PathLike, mode: misc.TMode | opts.IMkdirOptions, callback: misc.TCallback); + mkdir(path: misc.PathLike, a: misc.TCallback | misc.TMode | opts.IMkdirOptions, b?: misc.TCallback | misc.TCallback) { + throw new Error('Not implemented'); + } + + mkdirp(path: misc.PathLike, callback: misc.TCallback); + mkdirp(path: misc.PathLike, mode: misc.TMode, callback: misc.TCallback); + mkdirp(path: misc.PathLike, a: misc.TCallback | misc.TMode, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + mkdtemp(prefix: string, callback: misc.TCallback): void; + mkdtemp(prefix: string, options: opts.IOptions, callback: misc.TCallback); + mkdtemp(prefix: string, a: misc.TCallback | opts.IOptions, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + rmdir(path: misc.PathLike, callback: misc.TCallback); + rmdir(path: misc.PathLike, options: opts.IRmdirOptions, callback: misc.TCallback); + rmdir(path: misc.PathLike, a: misc.TCallback | opts.IRmdirOptions, b?: misc.TCallback) { + throw new Error('Not implemented'); + } + + rm(path: misc.PathLike, callback: misc.TCallback): void; + rm(path: misc.PathLike, options: opts.IRmOptions, callback: misc.TCallback): void; + rm(path: misc.PathLike, a: misc.TCallback | opts.IRmOptions, b?: misc.TCallback): void { + throw new Error('Not implemented'); + } + + fchmod(fd: number, mode: misc.TMode, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + chmod(path: misc.PathLike, mode: misc.TMode, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + lchmod(path: misc.PathLike, mode: misc.TMode, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + fchown(fd: number, uid: number, gid: number, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + chown(path: misc.PathLike, uid: number, gid: number, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + lchown(path: misc.PathLike, uid: number, gid: number, callback: misc.TCallback): void { + throw new Error('Not implemented'); + } + + watchFile(path: misc.PathLike, listener: (curr: misc.IStats, prev: misc.IStats) => void): misc.IStatWatcher; + watchFile( + path: misc.PathLike, + options: opts.IWatchFileOptions, + listener: (curr: misc.IStats, prev: misc.IStats) => void, + ): misc.IStatWatcher; + watchFile(path: misc.PathLike, a, b?): misc.IStatWatcher { + throw new Error('Not implemented'); + } + + unwatchFile(path: misc.PathLike, listener?: (curr: misc.IStats, prev: misc.IStats) => void): void { + throw new Error('Not implemented'); + } + + createReadStream(path: misc.PathLike, options?: opts.IReadStreamOptions | string): misc.IReadStream { + throw new Error('Not implemented'); + } + + createWriteStream(path: misc.PathLike, options?: opts.IWriteStreamOptions | string): misc.IWriteStream { + throw new Error('Not implemented'); + } + + watch( + path: misc.PathLike, + options?: opts.IWatchOptions | string, + listener?: (eventType: string, filename: string) => void, + ): misc.IFSWatcher { + throw new Error('Not implemented'); + } +} diff --git a/src/fsa-to-node/constants.ts b/src/fsa-to-node/constants.ts new file mode 100644 index 000000000..d8e4bdcec --- /dev/null +++ b/src/fsa-to-node/constants.ts @@ -0,0 +1,3 @@ +export const enum FsaToNodeConstants { + Separator = '/', +} diff --git a/src/fsa-to-node/types.ts b/src/fsa-to-node/types.ts new file mode 100644 index 000000000..259bd72e7 --- /dev/null +++ b/src/fsa-to-node/types.ts @@ -0,0 +1 @@ +export type FsLocation = [folder: string[], file: string];