From 3ea86417c4349cf5d0f9f4f9d91f57c9a9d67d42 Mon Sep 17 00:00:00 2001 From: streamich Date: Fri, 16 Jun 2023 10:23:22 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20add=20File=20System=20Ac?= =?UTF-8?q?cess=20API=20TypeScript=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: 🧨 no breaking changes in this commit, but bumping to get this to v4 in NPM --- src/fsa/types.ts | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/fsa/types.ts diff --git a/src/fsa/types.ts b/src/fsa/types.ts new file mode 100644 index 000000000..9d55e5229 --- /dev/null +++ b/src/fsa/types.ts @@ -0,0 +1,109 @@ +export interface IPermissionStatus { + name: string; + state: 'granted' | 'denied' | 'prompt'; +} + +export interface IFileSystemHandle { + kind: 'file' | 'directory'; + name: string; + isSameEntry(fileSystemHandle: IFileSystemHandle): boolean; + queryPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): IPermissionStatus; + remove(options?: { recursive?: boolean }): Promise; + requestPermission(fileSystemHandlePermissionDescriptor: NodeFileSystemHandlePermissionDescriptor): IPermissionStatus; +} + +export interface NodeFileSystemHandlePermissionDescriptor { + mode: 'read' | 'readwrite'; +} + +export interface IFileSystemDirectoryHandle extends IFileSystemHandle { + keys(): AsyncIterableIterator; + entries(): AsyncIterableIterator<[string, IFileSystemHandle]>; + values(): AsyncIterableIterator; + getDirectoryHandle(name: string, options?: GetDirectoryHandleOptions): Promise; + getFileHandle(name: string, options?: GetFileHandleOptions): Promise; + removeEntry(name: string, options?: RemoveEntryOptions): Promise; + resolve(possibleDescendant: IFileSystemHandle): Promise; +} + +export interface GetDirectoryHandleOptions { + /** + * A boolean value, which defaults to `false`. When set to `true` if the directory + * is not found, one with the specified name will be created and returned. + */ + create?: boolean; +} + +export interface GetFileHandleOptions { + /** + * A Boolean. Default `false`. When set to `true` if the file is not found, + * one with the specified name will be created and returned. + */ + create?: boolean; +} + +export interface RemoveEntryOptions { + /** + * A boolean value, which defaults to `false`. When set to true entries will + * be removed recursively. + */ + recursive?: boolean; +} + +export interface IFileSystemFileHandle extends IFileSystemHandle { + getFile(): Promise; + createSyncAccessHandle: undefined | (() => Promise); + createWritable(options?: CreateWritableOptions): Promise; +} + +export interface CreateWritableOptions { + keepExistingData?: boolean; +} + +export interface IFileSystemSyncAccessHandle { + close(): Promise; + flush(): Promise; + getSize(): Promise; + read(buffer: ArrayBuffer | ArrayBufferView, options?: FileSystemReadWriteOptions): Promise; + truncate(newSize: number): Promise; + write(buffer: ArrayBuffer | ArrayBufferView | DataView, options?: FileSystemReadWriteOptions): Promise; +} + +export interface FileSystemReadWriteOptions { + /** + * A number representing the offset in bytes that the file should be read from. + */ + at?: number; +} + +export interface IFileSystemWritableFileStream extends WritableStream { + seek(position: number): Promise; + truncate(size: number): Promise; + write(chunk: Data): Promise; + write(params: FileSystemWritableFileStreamParams): Promise; +} + +export interface FileSystemWritableFileStreamParams { + type: 'write' | 'truncate' | 'seek'; + data?: Data; + position?: number; + size?: number; +} + +export type Data = + | ArrayBuffer + | ArrayBufferView + | Uint8Array + | Uint8ClampedArray + | Int8Array + | Uint16Array + | Int16Array + | Uint32Array + | Int32Array + | Float32Array + | Float64Array + | BigUint64Array + | BigInt64Array + | DataView + | Blob + | string;