@zenfs/dom 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/access.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CreationOptions, FileSystem, InodeLike } from '@zenfs/core';
1
+ import type { FileSystem } from '@zenfs/core';
2
2
  import { IndexFS, Inode } from '@zenfs/core';
3
3
  export interface WebAccessOptions {
4
4
  handle: FileSystemDirectoryHandle;
@@ -9,7 +9,7 @@ export interface WebAccessOptions {
9
9
  */
10
10
  disableHandleCache?: boolean;
11
11
  }
12
- type HKindToType<T extends FileSystemHandleKind> = T extends 'directory' ? FileSystemDirectoryHandle : T extends 'file' ? FileSystemFileHandle : FileSystemHandle;
12
+ type HKindToType<T extends FileSystemHandleKind | null> = T extends 'directory' ? FileSystemDirectoryHandle : T extends 'file' ? FileSystemFileHandle : FileSystemHandle;
13
13
  declare const WebAccessFS_base: import("@zenfs/core").Mixin<typeof IndexFS, import("@zenfs/core").AsyncMixin>;
14
14
  /**
15
15
  * @todo Consider supporting synchronous stuff with `FileSystemFileHandle.createSyncAccessHandle()`\
@@ -40,6 +40,7 @@ export declare class WebAccessFS extends WebAccessFS_base {
40
40
  _sync: FileSystem;
41
41
  constructor(root: FileSystemDirectoryHandle, disableHandleCache?: boolean);
42
42
  stat(path: string): Promise<Inode>;
43
+ readdir(path: string): Promise<string[]>;
43
44
  protected remove(path: string): Promise<void>;
44
45
  protected removeSync(): void;
45
46
  read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
@@ -49,8 +50,8 @@ export declare class WebAccessFS extends WebAccessFS_base {
49
50
  * @deprecated @internal @hidden
50
51
  */
51
52
  writeFile(path: string, data: Uint8Array): Promise<void>;
52
- mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
53
- protected get<const T extends FileSystemHandleKind | null>(kind: T | undefined, path: string): Promise<T extends FileSystemHandleKind ? HKindToType<T> : FileSystemHandle>;
53
+ _mkdir(path: string): Promise<void>;
54
+ protected get<const T extends FileSystemHandleKind | null>(kind: T | undefined, path: string): Promise<HKindToType<T>>;
54
55
  }
55
56
  declare const _WebAccess: {
56
57
  readonly name: "WebAccess";
package/dist/access.js CHANGED
@@ -107,8 +107,16 @@ export class WebAccessFS extends Async(IndexFS) {
107
107
  return inode;
108
108
  }
109
109
  }
110
+ async readdir(path) {
111
+ const dirHandle = await this.get('directory', path);
112
+ return await Array.fromAsync(dirHandle.keys());
113
+ }
110
114
  async remove(path) {
111
115
  const handle = await this.get('directory', dirname(path));
116
+ for (const p of this._handles.keys())
117
+ if (dirname(p) == path)
118
+ this._handles.delete(p);
119
+ this._handles.delete(path);
112
120
  await handle.removeEntry(basename(path), { recursive: true }).catch(ex => _throw(convertException(ex, path)));
113
121
  }
114
122
  removeSync() {
@@ -174,13 +182,11 @@ export class WebAccessFS extends Async(IndexFS) {
174
182
  async writeFile(path, data) {
175
183
  return this.write(path, data, 0);
176
184
  }
177
- async mkdir(path, options) {
178
- const inode = await super.mkdir(path, options);
185
+ async _mkdir(path) {
179
186
  const handle = await this.get('directory', dirname(path));
180
187
  const dir = await handle.getDirectoryHandle(basename(path), { create: true }).catch((ex) => _throw(convertException(ex, path)));
181
188
  if (!this.disableHandleCache)
182
189
  this._handles.set(path, dir);
183
- return inode;
184
190
  }
185
191
  async get(kind = null, path) {
186
192
  const maybeHandle = this._handles.get(path);
@@ -204,10 +210,16 @@ export class WebAccessFS extends Async(IndexFS) {
204
210
  return handle;
205
211
  }
206
212
  catch (ex) {
207
- if (ex.name == 'TypeMismatchError')
208
- throw withErrno(kind == 'file' ? 'EISDIR' : 'ENOTDIR');
209
- else
213
+ if (ex.name != 'TypeMismatchError')
210
214
  throw convertException(ex, path);
215
+ else if (kind === null) {
216
+ const handle = await dir.getFileHandle(parts.at(-1)).catch(ex => _throw(convertException(ex, path)));
217
+ if (!this.disableHandleCache)
218
+ this._handles.set(path, handle);
219
+ return handle;
220
+ }
221
+ else
222
+ throw withErrno(kind == 'file' ? 'EISDIR' : 'ENOTDIR');
211
223
  }
212
224
  }
213
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenfs/dom",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "DOM backends for ZenFS",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -61,7 +61,7 @@
61
61
  "typescript-eslint": "^8.8.1"
62
62
  },
63
63
  "peerDependencies": {
64
- "@zenfs/core": "^2.1.0",
64
+ "@zenfs/core": "^2.3.11",
65
65
  "kerium": "^1.3.4",
66
66
  "utilium": "^2.0.0"
67
67
  },