@zenfs/core 0.1.0 → 0.2.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.
Files changed (44) hide show
  1. package/dist/ApiError.d.ts +51 -14
  2. package/dist/ApiError.js +60 -34
  3. package/dist/FileIndex.d.ts +32 -35
  4. package/dist/FileIndex.js +93 -109
  5. package/dist/backends/AsyncMirror.d.ts +42 -43
  6. package/dist/backends/AsyncMirror.js +146 -133
  7. package/dist/backends/AsyncStore.d.ts +29 -28
  8. package/dist/backends/AsyncStore.js +139 -189
  9. package/dist/backends/InMemory.d.ts +16 -13
  10. package/dist/backends/InMemory.js +29 -14
  11. package/dist/backends/Locked.d.ts +8 -28
  12. package/dist/backends/Locked.js +44 -148
  13. package/dist/backends/OverlayFS.d.ts +26 -34
  14. package/dist/backends/OverlayFS.js +208 -371
  15. package/dist/backends/SyncStore.d.ts +54 -72
  16. package/dist/backends/SyncStore.js +159 -161
  17. package/dist/backends/backend.d.ts +45 -29
  18. package/dist/backends/backend.js +83 -13
  19. package/dist/backends/index.d.ts +6 -7
  20. package/dist/backends/index.js +5 -6
  21. package/dist/browser.min.js +5 -7
  22. package/dist/browser.min.js.map +4 -4
  23. package/dist/emulation/callbacks.d.ts +36 -67
  24. package/dist/emulation/callbacks.js +90 -46
  25. package/dist/emulation/constants.js +1 -1
  26. package/dist/emulation/promises.d.ts +228 -129
  27. package/dist/emulation/promises.js +414 -172
  28. package/dist/emulation/shared.d.ts +10 -10
  29. package/dist/emulation/shared.js +18 -20
  30. package/dist/emulation/sync.d.ts +25 -25
  31. package/dist/emulation/sync.js +187 -73
  32. package/dist/file.d.ts +166 -170
  33. package/dist/file.js +199 -218
  34. package/dist/filesystem.d.ts +68 -241
  35. package/dist/filesystem.js +59 -383
  36. package/dist/index.d.ts +7 -44
  37. package/dist/index.js +13 -52
  38. package/dist/inode.d.ts +37 -28
  39. package/dist/inode.js +123 -65
  40. package/dist/stats.d.ts +21 -19
  41. package/dist/stats.js +35 -56
  42. package/dist/utils.d.ts +26 -9
  43. package/dist/utils.js +73 -102
  44. package/package.json +4 -3
@@ -1,15 +1,16 @@
1
1
  import { Cred } from '../cred.js';
2
2
  import { FileFlag, PreloadFile } from '../file.js';
3
- import { SynchronousFileSystem } from '../filesystem.js';
4
- import { Stats } from '../stats.js';
3
+ import { SyncFileSystem, type FileSystemMetadata } from '../filesystem.js';
4
+ import { type Ino, Inode } from '../inode.js';
5
+ import { Stats, FileType } from '../stats.js';
5
6
  /**
6
7
  * Represents a *synchronous* key-value store.
7
8
  */
8
- export interface SyncKeyValueStore {
9
+ export interface SyncStore {
9
10
  /**
10
11
  * The name of the key-value store.
11
12
  */
12
- name(): string;
13
+ name: string;
13
14
  /**
14
15
  * Empties the key-value store completely.
15
16
  */
@@ -17,43 +18,43 @@ export interface SyncKeyValueStore {
17
18
  /**
18
19
  * Begins a new read-only transaction.
19
20
  */
20
- beginTransaction(type: 'readonly'): SyncKeyValueROTransaction;
21
+ beginTransaction(type: 'readonly'): SyncROTransaction;
21
22
  /**
22
23
  * Begins a new read-write transaction.
23
24
  */
24
- beginTransaction(type: 'readwrite'): SyncKeyValueRWTransaction;
25
- beginTransaction(type: string): SyncKeyValueROTransaction;
25
+ beginTransaction(type: 'readwrite'): SyncRWTransaction;
26
+ beginTransaction(type: string): SyncROTransaction;
26
27
  }
27
28
  /**
28
29
  * A read-only transaction for a synchronous key value store.
29
30
  */
30
- export interface SyncKeyValueROTransaction {
31
+ export interface SyncROTransaction {
31
32
  /**
32
33
  * Retrieves the data at the given key. Throws an ApiError if an error occurs
33
34
  * or if the key does not exist.
34
- * @param key The key to look under for data.
35
+ * @param ino The key to look under for data.
35
36
  * @return The data stored under the key, or undefined if not present.
36
37
  */
37
- get(key: string): Uint8Array | undefined;
38
+ get(ino: Ino): Uint8Array | undefined;
38
39
  }
39
40
  /**
40
41
  * A read-write transaction for a synchronous key value store.
41
42
  */
42
- export interface SyncKeyValueRWTransaction extends SyncKeyValueROTransaction {
43
+ export interface SyncRWTransaction extends SyncROTransaction {
43
44
  /**
44
45
  * Adds the data to the store under the given key.
45
- * @param key The key to add the data under.
46
+ * @param ino The key to add the data under.
46
47
  * @param data The data to add to the store.
47
48
  * @param overwrite If 'true', overwrite any existing data. If 'false',
48
49
  * avoids storing the data if the key exists.
49
50
  * @return True if storage succeeded, false otherwise.
50
51
  */
51
- put(key: string, data: Uint8Array, overwrite: boolean): boolean;
52
+ put(ino: Ino, data: Uint8Array, overwrite: boolean): boolean;
52
53
  /**
53
54
  * Deletes the data at the given key.
54
- * @param key The key to delete from the store.
55
+ * @param ino The key to delete from the store.
55
56
  */
56
- del(key: string): void;
57
+ remove(ino: Ino): void;
57
58
  /**
58
59
  * Commits the transaction.
59
60
  */
@@ -68,66 +69,54 @@ export interface SyncKeyValueRWTransaction extends SyncKeyValueROTransaction {
68
69
  * support for transactions and such.
69
70
  */
70
71
  export interface SimpleSyncStore {
71
- get(key: string): Uint8Array | undefined;
72
- put(key: string, data: Uint8Array, overwrite: boolean): boolean;
73
- del(key: string): void;
72
+ get(ino: Ino): Uint8Array | undefined;
73
+ put(ino: Ino, data: Uint8Array, overwrite: boolean): boolean;
74
+ remove(ino: Ino): void;
74
75
  }
75
76
  /**
76
77
  * A simple RW transaction for simple synchronous key-value stores.
77
78
  */
78
- export declare class SimpleSyncRWTransaction implements SyncKeyValueRWTransaction {
79
- private store;
79
+ export declare class SimpleSyncRWTransaction implements SyncRWTransaction {
80
+ protected store: SimpleSyncStore;
80
81
  /**
81
82
  * Stores data in the keys we modify prior to modifying them.
82
83
  * Allows us to roll back commits.
83
84
  */
84
- private originalData;
85
+ protected originalData: Map<Ino, Uint8Array>;
85
86
  /**
86
87
  * List of keys modified in this transaction, if any.
87
88
  */
88
- private modifiedKeys;
89
+ protected modifiedKeys: Set<Ino>;
89
90
  constructor(store: SimpleSyncStore);
90
- get(key: string): Uint8Array | undefined;
91
- put(key: string, data: Uint8Array, overwrite: boolean): boolean;
92
- del(key: string): void;
91
+ get(ino: Ino): Uint8Array | undefined;
92
+ put(ino: Ino, data: Uint8Array, overwrite: boolean): boolean;
93
+ remove(ino: Ino): void;
93
94
  commit(): void;
94
95
  abort(): void;
95
- private _has;
96
96
  /**
97
97
  * Stashes given key value pair into `originalData` if it doesn't already
98
98
  * exist. Allows us to stash values the program is requesting anyway to
99
99
  * prevent needless `get` requests if the program modifies the data later
100
100
  * on during the transaction.
101
101
  */
102
- private stashOldValue;
102
+ protected stashOldValue(ino: Ino, value: Uint8Array | undefined): void;
103
103
  /**
104
104
  * Marks the given key as modified, and stashes its value if it has not been
105
105
  * stashed already.
106
106
  */
107
- private markModified;
107
+ protected markModified(ino: Ino): void;
108
108
  }
109
- export interface SyncKeyValueFileSystemOptions {
109
+ export interface SyncFileSystemOptions {
110
110
  /**
111
111
  * The actual key-value store to read from/write to.
112
112
  */
113
- store: SyncKeyValueStore;
114
- /**
115
- * Should the file system support properties (mtime/atime/ctime/chmod/etc)?
116
- * Enabling this slightly increases the storage space per file, and adds
117
- * atime updates every time a file is accessed, mtime updates every time
118
- * a file is modified, and permission checks on every operation.
119
- *
120
- * Defaults to *false*.
121
- */
122
- supportProps?: boolean;
123
- /**
124
- * Should the file system support links?
125
- */
126
- supportLinks?: boolean;
113
+ store: SyncStore;
127
114
  }
128
- export declare class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem> {
129
- constructor(_fs: SyncKeyValueFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
115
+ export declare class SyncStoreFile extends PreloadFile<SyncStoreFileSystem> {
116
+ constructor(_fs: SyncStoreFileSystem, _path: string, _flag: FileFlag, _stat: Stats, contents?: Uint8Array);
117
+ sync(): Promise<void>;
130
118
  syncSync(): void;
119
+ close(): Promise<void>;
131
120
  closeSync(): void;
132
121
  }
133
122
  /**
@@ -139,35 +128,28 @@ export declare class SyncKeyValueFile extends PreloadFile<SyncKeyValueFileSystem
139
128
  * @todo Introduce Node ID caching.
140
129
  * @todo Check modes.
141
130
  */
142
- export declare class SyncKeyValueFileSystem extends SynchronousFileSystem {
143
- static isAvailable(): boolean;
144
- private store;
145
- constructor(options: SyncKeyValueFileSystemOptions);
146
- getName(): string;
147
- isReadOnly(): boolean;
148
- supportsSymlinks(): boolean;
149
- supportsProps(): boolean;
150
- supportsSynch(): boolean;
131
+ export declare class SyncStoreFileSystem extends SyncFileSystem {
132
+ protected store: SyncStore;
133
+ constructor(options: SyncFileSystemOptions);
134
+ get metadata(): FileSystemMetadata;
151
135
  /**
152
136
  * Delete all contents stored in the file system.
153
137
  */
154
138
  empty(): void;
155
- accessSync(p: string, mode: number, cred: Cred): void;
156
139
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
157
140
  statSync(p: string, cred: Cred): Stats;
158
- createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): SyncKeyValueFile;
159
- openFileSync(p: string, flag: FileFlag, cred: Cred): SyncKeyValueFile;
141
+ createFileSync(p: string, flag: FileFlag, mode: number, cred: Cred): SyncStoreFile;
142
+ openFileSync(p: string, flag: FileFlag, cred: Cred): SyncStoreFile;
160
143
  unlinkSync(p: string, cred: Cred): void;
161
144
  rmdirSync(p: string, cred: Cred): void;
162
145
  mkdirSync(p: string, mode: number, cred: Cred): void;
163
146
  readdirSync(p: string, cred: Cred): string[];
164
- chmodSync(p: string, mode: number, cred: Cred): void;
165
- chownSync(p: string, new_uid: number, new_gid: number, cred: Cred): void;
166
- _syncSync(p: string, data: Uint8Array, stats: Stats): void;
147
+ syncSync(p: string, data: Uint8Array, stats: Readonly<Stats>): void;
148
+ linkSync(existing: string, newpath: string, cred: Cred): void;
167
149
  /**
168
150
  * Checks if the root directory exists. Creates it if it doesn't.
169
151
  */
170
- private makeRootDirectory;
152
+ protected makeRootDirectory(): void;
171
153
  /**
172
154
  * Helper function for findINode.
173
155
  * @param parent The parent directory of the file we are attempting to find.
@@ -175,35 +157,35 @@ export declare class SyncKeyValueFileSystem extends SynchronousFileSystem {
175
157
  * the parent.
176
158
  * @return string The ID of the file's inode in the file system.
177
159
  */
178
- private _findINode;
160
+ protected _findINode(tx: SyncROTransaction, parent: string, filename: string, visited?: Set<string>): Ino;
179
161
  /**
180
162
  * Finds the Inode of the given path.
181
163
  * @param p The path to look up.
182
164
  * @return The Inode of the path p.
183
165
  * @todo memoize/cache
184
166
  */
185
- private findINode;
167
+ protected findINode(tx: SyncROTransaction, p: string): Inode;
186
168
  /**
187
169
  * Given the ID of a node, retrieves the corresponding Inode.
188
170
  * @param tx The transaction to use.
189
171
  * @param p The corresponding path to the file (used for error messages).
190
172
  * @param id The ID to look up.
191
173
  */
192
- private getINode;
174
+ protected getINode(tx: SyncROTransaction, id: Ino, p?: string): Inode;
193
175
  /**
194
- * Given the Inode of a directory, retrieves the corresponding directory
195
- * listing.
176
+ * Given the Inode of a directory, retrieves the corresponding directory listing.
196
177
  */
197
- private getDirListing;
178
+ protected getDirListing(tx: SyncROTransaction, inode: Inode, p?: string): {
179
+ [fileName: string]: Ino;
180
+ };
198
181
  /**
199
182
  * Creates a new node under a random ID. Retries 5 times before giving up in
200
183
  * the exceedingly unlikely chance that we try to reuse a random GUID.
201
184
  * @return The GUID that the data was stored under.
202
185
  */
203
- private addNewNode;
186
+ protected addNewNode(tx: SyncRWTransaction, data: Uint8Array): Ino;
204
187
  /**
205
- * Commits a new file (well, a FILE or a DIRECTORY) to the file system with
206
- * the given mode.
188
+ * Commits a new file (well, a FILE or a DIRECTORY) to the file system with the given mode.
207
189
  * Note: This will commit the transaction.
208
190
  * @param p The path to the new file.
209
191
  * @param type The type of the new file.
@@ -211,12 +193,12 @@ export declare class SyncKeyValueFileSystem extends SynchronousFileSystem {
211
193
  * @param data The data to store at the file's data node.
212
194
  * @return The Inode for the new file.
213
195
  */
214
- private commitNewFile;
196
+ protected commitNewFile(p: string, type: FileType, mode: number, cred: Cred, data?: Uint8Array): Inode;
215
197
  /**
216
198
  * Remove all traces of the given path from the file system.
217
199
  * @param p The path to remove from the file system.
218
200
  * @param isDir Does the path belong to a directory, or a file?
219
201
  * @todo Update mtime.
220
202
  */
221
- private removeEntry;
203
+ protected removeEntry(p: string, isDir: boolean, cred: Cred): void;
222
204
  }