From a4268c65c5893083ae154861937212e3d87cafc0 Mon Sep 17 00:00:00 2001 From: streamich Date: Wed, 14 Jun 2023 14:44:25 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20setup=20node-to-fsa=20fo?= =?UTF-8?q?lder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/node-to-fsa/NodeFileSystemFileHandle.ts | 30 +++++++++++++ src/node-to-fsa/NodeFileSystemHandle.ts | 43 +++++++++++++++++++ .../NodeFileSystemSyncAccessHandle.ts | 1 + .../NodeFileSystemWritableFileStream.ts | 6 +++ src/node-to-fsa/NodePermissionStatus.ts | 9 ++++ src/node-to-fsa/README.md | 1 + src/node-to-fsa/types.ts | 3 ++ src/promises.ts | 2 +- 8 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/node-to-fsa/NodeFileSystemFileHandle.ts create mode 100644 src/node-to-fsa/NodeFileSystemHandle.ts create mode 100644 src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts create mode 100644 src/node-to-fsa/NodeFileSystemWritableFileStream.ts create mode 100644 src/node-to-fsa/NodePermissionStatus.ts create mode 100644 src/node-to-fsa/README.md create mode 100644 src/node-to-fsa/types.ts diff --git a/src/node-to-fsa/NodeFileSystemFileHandle.ts b/src/node-to-fsa/NodeFileSystemFileHandle.ts new file mode 100644 index 000000000..4581cd115 --- /dev/null +++ b/src/node-to-fsa/NodeFileSystemFileHandle.ts @@ -0,0 +1,30 @@ +import {IFileHandle} from "../promises"; +import {NodeFileSystemHandle} from "./NodeFileSystemHandle"; +import {NodeFileSystemSyncAccessHandle} from "./NodeFileSystemSyncAccessHandle"; + +export class NodeFileSystemFileHandle extends NodeFileSystemHandle { + constructor (name: string, protected readonly handle: IFileHandle) { + super('file', name); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/getFile + */ + public async getFile(): Promise { + throw new Error('Not implemented'); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createSyncAccessHandle + */ + public async createSyncAccessHandle(): Promise { + throw new Error('Not implemented'); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle/createWritable + */ + public async createWritable({keepExistingData = false}: {keepExistingData?: boolean} = {keepExistingData: false}): Promise { + throw new Error('Not implemented'); + } +} diff --git a/src/node-to-fsa/NodeFileSystemHandle.ts b/src/node-to-fsa/NodeFileSystemHandle.ts new file mode 100644 index 000000000..713e35337 --- /dev/null +++ b/src/node-to-fsa/NodeFileSystemHandle.ts @@ -0,0 +1,43 @@ +import {NodePermissionStatus} from "./NodePermissionStatus"; +import type {NodeFileSystemHandlePermissionDescriptor} from "./types"; + +/** + * Represents a File System Access API file handle `FileSystemHandle` object, + * which was created from a Node.js `fs` module. + * + * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle) + */ +export abstract class NodeFileSystemHandle { + constructor ( + public readonly kind: 'file' | 'directory', + public readonly name: string, + ) {} + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/isSameEntry + */ + public isSameEntry(fileSystemHandle: NodeFileSystemHandle): boolean { + throw new Error('Not implemented'); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/queryPermission + */ + public queryPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): NodePermissionStatus { + throw new Error('Not implemented'); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/remove + */ + public async remove({recursive}: {recursive?: boolean} = {recursive: false}): Promise { + throw new Error('Not implemented'); + } + + /** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission + */ + public requestPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): NodePermissionStatus { + throw new Error('Not implemented'); + } +} diff --git a/src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts b/src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts new file mode 100644 index 000000000..eea0e95bd --- /dev/null +++ b/src/node-to-fsa/NodeFileSystemSyncAccessHandle.ts @@ -0,0 +1 @@ +export class NodeFileSystemSyncAccessHandle {} diff --git a/src/node-to-fsa/NodeFileSystemWritableFileStream.ts b/src/node-to-fsa/NodeFileSystemWritableFileStream.ts new file mode 100644 index 000000000..8f3d80986 --- /dev/null +++ b/src/node-to-fsa/NodeFileSystemWritableFileStream.ts @@ -0,0 +1,6 @@ +/** + * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream + */ +export class NodeFileSystemWritableFileStream extends WritableStream { + +} diff --git a/src/node-to-fsa/NodePermissionStatus.ts b/src/node-to-fsa/NodePermissionStatus.ts new file mode 100644 index 000000000..edf9fd5a7 --- /dev/null +++ b/src/node-to-fsa/NodePermissionStatus.ts @@ -0,0 +1,9 @@ +/** + * @see [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus) + */ +export class NodePermissionStatus { + constructor ( + public readonly name: string, + public readonly state: 'granted' | 'denied' | 'prompt', + ) {} +} diff --git a/src/node-to-fsa/README.md b/src/node-to-fsa/README.md new file mode 100644 index 000000000..24bcc2e8a --- /dev/null +++ b/src/node-to-fsa/README.md @@ -0,0 +1 @@ +This adapter code converts an instance of [Node.js FS API](https://nodejs.org/api/fs.html) to a [File System Access API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API) (FSA) instance. diff --git a/src/node-to-fsa/types.ts b/src/node-to-fsa/types.ts new file mode 100644 index 000000000..ede9a08c0 --- /dev/null +++ b/src/node-to-fsa/types.ts @@ -0,0 +1,3 @@ +export interface NodeFileSystemHandlePermissionDescriptor { + mode: 'read' | 'readwrite'; +} diff --git a/src/promises.ts b/src/promises.ts index 5bd2fca9d..2a20d7c63 100644 --- a/src/promises.ts +++ b/src/promises.ts @@ -19,7 +19,7 @@ import { import Stats from './Stats'; import Dirent from './Dirent'; import { TDataOut } from './encoding'; -import { PathLike, symlink } from 'fs'; +import type { PathLike, symlink } from 'fs'; function promisify( vol: Volume,