@zenfs/core 0.7.10 → 0.8.0

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.
@@ -11,10 +11,10 @@ export type ListingTree = {
11
11
  /**
12
12
  * @internal
13
13
  */
14
- export interface ListingQueueNode<T> {
14
+ export interface ListingQueueNode<TData> {
15
15
  pwd: string;
16
16
  tree: ListingTree;
17
- parent: IndexDirInode<T>;
17
+ parent: IndexDirInode<TData>;
18
18
  }
19
19
  /**
20
20
  * A simple class for storing a filesystem index. Assumes that all paths passed
@@ -25,19 +25,19 @@ export interface ListingQueueNode<T> {
25
25
  *
26
26
  * @internal
27
27
  */
28
- export declare class FileIndex<T> {
28
+ export declare class FileIndex<TData> {
29
29
  /**
30
30
  * Static method for constructing indices from a JSON listing.
31
31
  * @param listing Directory listing generated by tools
32
32
  * @return A new FileIndex object.
33
33
  */
34
34
  static FromListing<T>(listing: ListingTree): FileIndex<T>;
35
- protected _index: Map<string, IndexDirInode<T>>;
35
+ protected _index: Map<string, IndexDirInode<TData>>;
36
36
  /**
37
37
  * Constructs a new FileIndex.
38
38
  */
39
39
  constructor();
40
- files(): IndexFileInode<T>[];
40
+ files(): IndexFileInode<TData>[];
41
41
  /**
42
42
  * Adds the given absolute path to the index if it is not already in the index.
43
43
  * Creates any needed parent directories.
@@ -50,7 +50,7 @@ export declare class FileIndex<T> {
50
50
  * @todo If adding fails and implicitly creates directories, we do not clean up
51
51
  * the new empty directories.
52
52
  */
53
- add(path: string, inode: IndexInode<T>): boolean;
53
+ add(path: string, inode: IndexInode<TData>): boolean;
54
54
  /**
55
55
  * Adds the given absolute path to the index if it is not already in the index.
56
56
  * The path is added without special treatment (no joining of adjacent separators, etc).
@@ -62,13 +62,13 @@ export declare class FileIndex<T> {
62
62
  * different).
63
63
  * @todo If adding fails and implicitly creates directories, we do not clean up the new empty directories.
64
64
  */
65
- addFast(path: string, inode: IndexInode<T>): boolean;
65
+ addFast(path: string, inode: IndexInode<TData>): boolean;
66
66
  /**
67
67
  * Removes the given path. Can be a file or a directory.
68
68
  * @return The removed item,
69
69
  * or null if it did not exist.
70
70
  */
71
- remove(path: string): IndexInode<T> | null;
71
+ remove(path: string): IndexInode<TData> | null;
72
72
  /**
73
73
  * Retrieves the directory listing of the given path.
74
74
  * @return An array of files in the given path, or 'null' if it does not exist.
@@ -78,29 +78,29 @@ export declare class FileIndex<T> {
78
78
  * Returns the inode of the given item.
79
79
  * @return Returns null if the item does not exist.
80
80
  */
81
- get(path: string): IndexInode<T> | null;
81
+ get(path: string): IndexInode<TData> | null;
82
82
  }
83
83
  /**
84
84
  * Generic interface for file/directory inodes.
85
85
  * Note that Stats objects are what we use for file inodes.
86
86
  */
87
- export declare abstract class IndexInode<T> {
88
- data?: T;
89
- constructor(data?: T);
87
+ export declare abstract class IndexInode<TData> {
88
+ data?: TData;
89
+ constructor(data?: TData);
90
90
  /**
91
91
  * Whether this inode is for a file
92
92
  */
93
- abstract isFile(): this is IndexFileInode<T>;
93
+ abstract isFile(): this is IndexFileInode<TData>;
94
94
  /**
95
95
  * Whether this inode is for a directory
96
96
  */
97
- abstract isDirectory(): this is IndexDirInode<T>;
97
+ abstract isDirectory(): this is IndexDirInode<TData>;
98
98
  abstract toStats(): Stats;
99
99
  }
100
100
  /**
101
101
  * Inode for a file. Stores an arbitrary (filesystem-specific) data payload.
102
102
  */
103
- export declare class IndexFileInode<T> extends IndexInode<T> {
103
+ export declare class IndexFileInode<TData> extends IndexInode<TData> {
104
104
  isFile(): boolean;
105
105
  isDirectory(): boolean;
106
106
  toStats(): Stats;
@@ -108,11 +108,11 @@ export declare class IndexFileInode<T> extends IndexInode<T> {
108
108
  /**
109
109
  * Inode for a directory. Currently only contains the directory listing.
110
110
  */
111
- export declare class IndexDirInode<T> extends IndexInode<T> {
111
+ export declare class IndexDirInode<TData> extends IndexInode<TData> {
112
112
  /**
113
113
  * @internal
114
114
  */
115
- _listing: Map<string, IndexInode<T>>;
115
+ _listing: Map<string, IndexInode<TData>>;
116
116
  isFile(): boolean;
117
117
  isDirectory(): boolean;
118
118
  /**
@@ -135,7 +135,7 @@ export declare class IndexDirInode<T> extends IndexInode<T> {
135
135
  * Returns the inode for the indicated item, or null if it does not exist.
136
136
  * @param path Name of item in this directory.
137
137
  */
138
- get(path: string): IndexInode<T> | null;
138
+ get(path: string): IndexInode<TData> | null;
139
139
  /**
140
140
  * Add the given item to the directory listing. Note that the given inode is
141
141
  * not copied, and will be mutated by the DirInode if it is a DirInode.
@@ -144,16 +144,16 @@ export declare class IndexDirInode<T> extends IndexInode<T> {
144
144
  * item to add to the directory inode.
145
145
  * @return True if it was added, false if it already existed.
146
146
  */
147
- add(path: string, inode: IndexInode<T>): boolean;
147
+ add(path: string, inode: IndexInode<TData>): boolean;
148
148
  /**
149
149
  * Removes the given item from the directory listing.
150
150
  * @param p Name of item to remove from the directory listing.
151
151
  * @return Returns the item
152
152
  * removed, or null if the item did not exist.
153
153
  */
154
- remove(p: string): IndexInode<T> | null;
154
+ remove(p: string): IndexInode<TData> | null;
155
155
  }
156
- declare const FileIndexFS_base: (abstract new (...args: any[]) => {
156
+ declare const IndexFS_base: (abstract new (...args: any[]) => {
157
157
  metadata(): import("./filesystem.js").FileSystemMetadata;
158
158
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
159
159
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
@@ -179,8 +179,8 @@ declare const FileIndexFS_base: (abstract new (...args: any[]) => {
179
179
  exists(path: string, cred: Cred): Promise<boolean>;
180
180
  existsSync(path: string, cred: Cred): boolean;
181
181
  }) & typeof FileSystem;
182
- export declare abstract class FileIndexFS<TIndex> extends FileIndexFS_base {
183
- protected _index: FileIndex<TIndex>;
182
+ export declare abstract class IndexFS<TData> extends IndexFS_base {
183
+ protected _index: FileIndex<TData>;
184
184
  constructor(index: ListingTree);
185
185
  stat(path: string): Promise<Stats>;
186
186
  statSync(path: string): Stats;
@@ -188,44 +188,16 @@ export declare abstract class FileIndexFS<TIndex> extends FileIndexFS_base {
188
188
  openFileSync(path: string, flag: string, cred: Cred): NoSyncFile<this>;
189
189
  readdir(path: string): Promise<string[]>;
190
190
  readdirSync(path: string): string[];
191
- protected abstract statFileInode(inode: IndexFileInode<TIndex>, path: string): Promise<Stats>;
192
- protected abstract statFileInodeSync(inode: IndexFileInode<TIndex>, path: string): Stats;
193
- protected abstract openFileInode(inode: IndexFileInode<TIndex>, path: string, flag: string): Promise<NoSyncFile<this>>;
194
- protected abstract openFileInodeSync(inode: IndexFileInode<TIndex>, path: string, flag: string): NoSyncFile<this>;
191
+ protected abstract statFileInode(inode: IndexFileInode<TData>, path: string): Promise<Stats>;
192
+ protected abstract statFileInodeSync(inode: IndexFileInode<TData>, path: string): Stats;
193
+ protected abstract openFileInode(inode: IndexFileInode<TData>, path: string, flag: string): Promise<NoSyncFile<this>>;
194
+ protected abstract openFileInodeSync(inode: IndexFileInode<TData>, path: string, flag: string): NoSyncFile<this>;
195
195
  }
196
- export declare abstract class SyncFileIndexFS<TIndex> extends FileIndexFS<TIndex> {
197
- protected statFileInode(inode: IndexFileInode<TIndex>, path: string): Promise<Stats>;
198
- protected openFileInode(inode: IndexFileInode<TIndex>, path: string, flag: string): Promise<NoSyncFile<this>>;
196
+ export declare abstract class SyncIndexFS<TData> extends IndexFS<TData> {
197
+ protected statFileInode(inode: IndexFileInode<TData>, path: string): Promise<Stats>;
198
+ protected openFileInode(inode: IndexFileInode<TData>, path: string, flag: string): Promise<NoSyncFile<this>>;
199
199
  }
200
- declare const AsyncFileIndexFS_base: (abstract new (...args: any[]) => {
201
- _sync: FileSystem;
202
- metadata(): import("./filesystem.js").FileSystemMetadata;
203
- ready(): Promise<any>;
204
- renameSync(oldPath: string, newPath: string, cred: Cred): void;
205
- statSync(path: string, cred: Cred): Stats;
206
- createFileSync(path: string, flag: string, mode: number, cred: Cred): import("./file.js").File;
207
- openFileSync(path: string, flag: string, cred: Cred): import("./file.js").File;
208
- unlinkSync(path: string, cred: Cred): void;
209
- rmdirSync(path: string, cred: Cred): void;
210
- mkdirSync(path: string, mode: number, cred: Cred): void;
211
- readdirSync(path: string, cred: Cred): string[];
212
- linkSync(srcpath: string, dstpath: string, cred: Cred): void;
213
- syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
214
- rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
215
- stat(path: string, cred: Cred): Promise<Stats>;
216
- openFile(path: string, flag: string, cred: Cred): Promise<import("./file.js").File>;
217
- createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("./file.js").File>;
218
- unlink(path: string, cred: Cred): Promise<void>;
219
- rmdir(path: string, cred: Cred): Promise<void>;
220
- mkdir(path: string, mode: number, cred: Cred): Promise<void>;
221
- readdir(path: string, cred: Cred): Promise<string[]>;
222
- exists(path: string, cred: Cred): Promise<boolean>;
223
- existsSync(path: string, cred: Cred): boolean;
224
- link(srcpath: string, dstpath: string, cred: Cred): Promise<void>;
225
- sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
226
- }) & (abstract new (index: ListingTree) => FileIndexFS<unknown>);
227
- export declare abstract class AsyncFileIndexFS<TIndex> extends AsyncFileIndexFS_base {
228
- _index: FileIndex<TIndex>;
200
+ export declare abstract class AsyncIndexFS<TData> extends IndexFS<TData> {
229
201
  protected statFileInodeSync(): Stats;
230
202
  protected openFileInodeSync(): NoSyncFile<this>;
231
203
  }
package/dist/FileIndex.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ApiError, ErrorCode } from './ApiError.js';
2
2
  import { basename, dirname, join } from './emulation/path.js';
3
3
  import { NoSyncFile, flagToMode, isWriteable } from './file.js';
4
- import { FileSystem, Async, Readonly } from './filesystem.js';
4
+ import { FileSystem, Readonly } from './filesystem.js';
5
5
  import { FileType, Stats } from './stats.js';
6
6
  /**
7
7
  * A simple class for storing a filesystem index. Assumes that all paths passed
@@ -298,7 +298,7 @@ export class IndexDirInode extends IndexInode {
298
298
  return item;
299
299
  }
300
300
  }
301
- export class FileIndexFS extends Readonly(FileSystem) {
301
+ export class IndexFS extends Readonly(FileSystem) {
302
302
  constructor(index) {
303
303
  super();
304
304
  this._index = FileIndex.FromListing(index);
@@ -340,7 +340,7 @@ export class FileIndexFS extends Readonly(FileSystem) {
340
340
  throw ApiError.With('ENOENT', path, 'openFile');
341
341
  }
342
342
  if (!inode.toStats().hasAccess(flagToMode(flag), cred)) {
343
- throw ApiError.With('EACCESS', path, 'openFile');
343
+ throw ApiError.With('EACCES', path, 'openFile');
344
344
  }
345
345
  if (inode.isDirectory()) {
346
346
  const stats = inode.stats;
@@ -390,7 +390,7 @@ export class FileIndexFS extends Readonly(FileSystem) {
390
390
  throw ApiError.With('ENOTDIR', path, 'readdirSync');
391
391
  }
392
392
  }
393
- export class SyncFileIndexFS extends FileIndexFS {
393
+ export class SyncIndexFS extends IndexFS {
394
394
  async statFileInode(inode, path) {
395
395
  return this.statFileInodeSync(inode, path);
396
396
  }
@@ -398,7 +398,7 @@ export class SyncFileIndexFS extends FileIndexFS {
398
398
  return this.openFileInodeSync(inode, path, flag);
399
399
  }
400
400
  }
401
- export class AsyncFileIndexFS extends Async((FileIndexFS)) {
401
+ export class AsyncIndexFS extends IndexFS {
402
402
  statFileInodeSync() {
403
403
  throw new ApiError(ErrorCode.ENOTSUP);
404
404
  }
@@ -83,8 +83,14 @@ declare const AsyncStoreFS_base: (abstract new (...args: any[]) => {
83
83
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
84
84
  stat(path: string, cred: Cred): Promise<Stats>;
85
85
  openFile(path: string, flag: string, cred: Cred): Promise<import("../file.js").File>;
86
- createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>;
87
- unlink(path: string, cred: Cred): Promise<void>;
86
+ createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>; /**
87
+ * Promise that resolves to the store
88
+ */
89
+ unlink(path: string, cred: Cred): Promise<void>; /**
90
+ * An asynchronous file system which uses an async store to store its data.
91
+ * @see AsyncStore
92
+ * @internal
93
+ */
88
94
  rmdir(path: string, cred: Cred): Promise<void>;
89
95
  mkdir(path: string, mode: number, cred: Cred): Promise<void>;
90
96
  readdir(path: string, cred: Cred): Promise<string[]>;
@@ -46,7 +46,6 @@ export class UnlockedOverlayFS extends FileSystem {
46
46
  return {
47
47
  ...super.metadata(),
48
48
  name: OverlayFS.name,
49
- supportsProperties: this._readable.metadata().supportsProperties && this._writable.metadata().supportsProperties,
50
49
  };
51
50
  }
52
51
  getOverlayedFileSystems() {
@@ -1,5 +1,5 @@
1
+ import type { RequiredKeys } from 'utilium';
1
2
  import { FileSystem } from '../filesystem.js';
2
- import { type RequiredKeys } from '../utils.js';
3
3
  type OptionType = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
4
4
  /**
5
5
  * Resolves the type of Backend.options from the options interface