Skip to content

Commit

Permalink
fix: Add back types (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting authored Nov 15, 2021
1 parent 9faa10d commit f56afb3
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 511 deletions.
531 changes: 23 additions & 508 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
"test:node": "node test/test-node.js",
"test:deno": "deno run --allow-read --allow-write --allow-net test/test-deno.js",
"test:wpt-in-deno": "deno run --allow-read --allow-write --allow-net test/test-wpt-in-deno.js",
"build": "rm -rf dist && rollup -c rollup.config.js"
"build": "rm -rf dist && rollup -c rollup.config.js",
"prepublishOnly": "rm -rf types && tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jimmywarting/native-file-system-adapter.git"
},
"engines": {
"node": ">=14.8.0"
},
"types": "types",
"keywords": [
"filesystem",
"file",
Expand Down Expand Up @@ -56,7 +61,8 @@
"rollup-plugin-multi-input": "^1.3.1",
"rollup-plugin-terser": "^7.0.2",
"standard": "^16.0.3",
"tape": "^5.2.2"
"tape": "^5.2.2",
"typescript": "^4.4.4"
},
"standard": {
"globals": [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"lib": ["es2019", "dom"],
"outDir": "./types/"
},
"include": ["src/*.js"]
"include": ["mod.js"]
}
1 change: 1 addition & 0 deletions types/mod.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/es6.js";
22 changes: 22 additions & 0 deletions types/src/FileSystemDirectoryHandle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export default FileSystemDirectoryHandle;
export class FileSystemDirectoryHandle extends FileSystemHandle {
constructor(adapter: any);
getDirectoryHandle(name: string, options?: {
create?: boolean;
}): Promise<FileSystemDirectoryHandle>;
entries(): AsyncGenerator<[string, FileSystemHandle | FileSystemDirectoryHandle]>;
getEntries(): AsyncGenerator<import("./FileSystemFileHandle.js").default | FileSystemDirectoryHandle, void, unknown>;
getFileHandle(name: string, options?: {
create?: boolean;
}): Promise<import("./FileSystemFileHandle.js").default>;
removeEntry(name: string, options?: {
recursive?: boolean;
}): Promise<any>;
resolve(possibleDescendant: any): Promise<any[]>;
keys(): AsyncGenerator<any, void, unknown>;
values(): AsyncGenerator<FileSystemHandle | FileSystemDirectoryHandle, void, unknown>;
[kAdapter]: any;
[Symbol.asyncIterator](): AsyncGenerator<[string, FileSystemHandle | FileSystemDirectoryHandle], any, any>;
}
import FileSystemHandle from "./FileSystemHandle.js";
declare const kAdapter: unique symbol;
12 changes: 12 additions & 0 deletions types/src/FileSystemFileHandle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default FileSystemFileHandle;
export class FileSystemFileHandle extends FileSystemHandle {
constructor(adapter: any);
createWritable(options?: {
keepExistingData?: boolean;
}): Promise<FileSystemWritableFileStream>;
getFile(): Promise<File>;
[kAdapter]: any;
}
import FileSystemHandle from "./FileSystemHandle.js";
import FileSystemWritableFileStream from "./FileSystemWritableFileStream.js";
declare const kAdapter: unique symbol;
20 changes: 20 additions & 0 deletions types/src/FileSystemHandle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default FileSystemHandle;
export class FileSystemHandle {
constructor(adapter: FileSystemHandle & {
writable;
});
name: string;
kind: ('file' | 'directory');
queryPermission({ mode }?: {
mode?: string;
}): Promise<any>;
requestPermission({ mode }?: {
mode?: string;
}): Promise<any>;
remove(options?: {
recursive?: boolean;
}): Promise<void>;
isSameEntry(other: FileSystemHandle): Promise<any>;
[kAdapter]: any;
}
declare const kAdapter: unique symbol;
8 changes: 8 additions & 0 deletions types/src/FileSystemWritableFileStream.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default FileSystemWritableFileStream;
export class FileSystemWritableFileStream extends WritableStream<any> {
constructor(...args: any[]);
private _closed;
seek(position: number): Promise<void>;
truncate(size: number): Promise<void>;
write(data: any): Promise<void>;
}
8 changes: 8 additions & 0 deletions types/src/adapters/downloader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class FileHandle {
constructor(name?: string);
name: string;
kind: string;
getFile(): Promise<void>;
isSameEntry(other: any): Promise<boolean>;
createWritable(options?: object): Promise<WritableStreamDefaultWriter<any>>;
}
46 changes: 46 additions & 0 deletions types/src/adapters/memory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export class Sink {
constructor(fileHandle: FileHandle, file: File);
fileHandle: FileHandle;
file: File;
size: number;
position: number;
write(chunk: any): void;
close(): void;
}
export class FileHandle {
constructor(name?: string, file?: File, writable?: boolean);
_file: File;
name: string;
kind: string;
_deleted: boolean;
writable: boolean;
readable: boolean;
getFile(): Promise<File>;
createWritable(opts: any): Promise<Sink>;
isSameEntry(other: any): Promise<boolean>;
_destroy(): Promise<void>;
}
export class FolderHandle {
constructor(name: string, writable?: boolean);
name: string;
kind: string;
_deleted: boolean;
_entries: {
[x: string]: (FolderHandle | FileHandle);
};
writable: boolean;
readable: boolean;
entries(): AsyncGenerator<[string, FileHandle | FolderHandle]>;
isSameEntry(other: any): Promise<boolean>;
getDirectoryHandle(name: string, opts: {
create: boolean;
}): Promise<FolderHandle>;
getFileHandle(name: string, opts: {
create: boolean;
}): Promise<FileHandle>;
removeEntry(name: any, opts: any): Promise<void>;
_destroy(recursive: any): Promise<void>;
}
declare function _default(): FolderHandle;
export default _default;
declare const File_1: typeof window.File;
39 changes: 39 additions & 0 deletions types/src/adapters/sandbox.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export class FileHandle {
constructor(file: FileEntry, writable?: boolean);
file: FileEntry;
kind: string;
writable: boolean;
readable: boolean;
get name(): string;
isSameEntry(other: any): boolean;
getFile(): Promise<File>;
createWritable(opts: any): Promise<Sink>;
}
export class FolderHandle {
constructor(dir: DirectoryEntry, writable?: boolean);
dir: DirectoryEntry;
writable: boolean;
readable: boolean;
kind: string;
name: string;
isSameEntry(other: FolderHandle): boolean;
entries(): AsyncGenerator<[string, FileHandle | FolderHandle]>;
getDirectoryHandle(name: string, opts: {
create: boolean;
}): Promise<FolderHandle>;
getFileHandle(name: string, opts: {
create: boolean;
}): Promise<FileHandle>;
removeEntry(name: string, opts: {
recursive: boolean;
}): Promise<any>;
}
declare function _default(opts?: {}): Promise<any>;
export default _default;
declare class Sink {
constructor(writer: FileWriter, fileEntry: FileEntry);
writer: FileWriter;
fileEntry: FileEntry;
write(chunk: BlobPart | any): Promise<any>;
close(): Promise<any>;
}
9 changes: 9 additions & 0 deletions types/src/es6.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import FileSystemDirectoryHandle from "./FileSystemDirectoryHandle.js";
import FileSystemFileHandle from "./FileSystemFileHandle.js";
import FileSystemHandle from "./FileSystemHandle.js";
import FileSystemWritableFileStream from "./FileSystemWritableFileStream.js";
import getOriginPrivateDirectory from "./getOriginPrivateDirectory.js";
import showDirectoryPicker from "./showDirectoryPicker.js";
import showOpenFilePicker from "./showOpenFilePicker.js";
import showSaveFilePicker from "./showSaveFilePicker.js";
export { FileSystemDirectoryHandle, FileSystemFileHandle, FileSystemHandle, FileSystemWritableFileStream, getOriginPrivateDirectory, showDirectoryPicker, showOpenFilePicker, showSaveFilePicker };
3 changes: 3 additions & 0 deletions types/src/getOriginPrivateDirectory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default getOriginPrivateDirectory;
export type FileSystemDirectoryHandle = import('./FileSystemDirectoryHandle.js').default;
declare function getOriginPrivateDirectory(driver?: object | undefined, options?: {}): Promise<import("./FileSystemDirectoryHandle.js").default>;
5 changes: 5 additions & 0 deletions types/src/showDirectoryPicker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default showDirectoryPicker;
export type FileSystemDirectoryHandle = import('./FileSystemDirectoryHandle.js').default;
export function showDirectoryPicker(options?: {
_preferPolyfill?: boolean;
}): Promise<FileSystemDirectoryHandle>;
8 changes: 8 additions & 0 deletions types/src/showOpenFilePicker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default showOpenFilePicker;
export type FileSystemFileHandle = import('./FileSystemFileHandle.js').default;
export function showOpenFilePicker(options?: {
multiple?: boolean;
excludeAcceptAllOption?: boolean;
accepts?: any[];
_preferPolyfill?: boolean;
}): Promise<FileSystemFileHandle[]>;
9 changes: 9 additions & 0 deletions types/src/showSaveFilePicker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default showSaveFilePicker;
export type FileSystemFileHandle = import('./FileSystemFileHandle.js').default;
export function showSaveFilePicker(options?: {
excludeAcceptAllOption?: boolean;
accepts?: any[];
suggestedName?: string;
_name?: string;
_preferPolyfill?: boolean;
}): Promise<import("./FileSystemFileHandle.js").default>;
18 changes: 18 additions & 0 deletions types/src/util.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function fromDataTransfer(entries: any): Promise<import("./FileSystemDirectoryHandle.js").default>;
export function getDirHandlesFromInput(input: any): Promise<import("./FileSystemDirectoryHandle.js").default>;
export function getFileHandlesFromInput(input: any): Promise<import("./FileSystemFileHandle.js").default[]>;
export namespace errors {
const INVALID: string[];
const GONE: string[];
const MISMATCH: string[];
const MOD_ERR: string[];
function SYNTAX(m: any): string[];
const SECURITY: string[];
const DISALLOWED: string[];
}
export namespace config {
const writable: {
new <W = any>(underlyingSink?: UnderlyingSink<W>, strategy?: QueuingStrategy<W>): WritableStream<W>;
prototype: WritableStream<any>;
};
}

0 comments on commit f56afb3

Please sign in to comment.