@zenfs/core 1.7.2 → 1.8.1

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 (68) hide show
  1. package/dist/backends/backend.js +3 -4
  2. package/dist/backends/fetch.d.ts +17 -18
  3. package/dist/backends/fetch.js +95 -58
  4. package/dist/backends/index.d.ts +2 -1
  5. package/dist/backends/index.js +2 -1
  6. package/dist/backends/memory.d.ts +1 -1
  7. package/dist/backends/overlay.d.ts +8 -14
  8. package/dist/backends/overlay.js +38 -31
  9. package/dist/backends/passthrough.d.ts +8 -3
  10. package/dist/backends/passthrough.js +148 -4
  11. package/dist/backends/port/fs.d.ts +15 -49
  12. package/dist/backends/port/fs.js +28 -116
  13. package/dist/backends/port/rpc.d.ts +13 -6
  14. package/dist/backends/port/rpc.js +9 -7
  15. package/dist/backends/store/file_index.d.ts +38 -0
  16. package/dist/backends/store/file_index.js +76 -0
  17. package/dist/backends/store/fs.d.ts +39 -34
  18. package/dist/backends/store/fs.js +407 -238
  19. package/dist/backends/store/index_fs.d.ts +34 -0
  20. package/dist/backends/store/index_fs.js +67 -0
  21. package/dist/backends/store/inode.d.ts +26 -8
  22. package/dist/backends/store/inode.js +92 -91
  23. package/dist/backends/store/simple.d.ts +20 -20
  24. package/dist/backends/store/simple.js +3 -4
  25. package/dist/backends/store/store.d.ts +12 -12
  26. package/dist/backends/store/store.js +4 -6
  27. package/dist/devices.d.ts +44 -21
  28. package/dist/devices.js +110 -55
  29. package/dist/file.d.ts +111 -7
  30. package/dist/file.js +324 -92
  31. package/dist/filesystem.d.ts +44 -4
  32. package/dist/mixins/async.js +12 -6
  33. package/dist/mixins/mutexed.d.ts +8 -3
  34. package/dist/mixins/mutexed.js +57 -1
  35. package/dist/mixins/readonly.d.ts +17 -16
  36. package/dist/mixins/readonly.js +6 -0
  37. package/dist/mixins/sync.d.ts +1 -1
  38. package/dist/stats.d.ts +12 -6
  39. package/dist/stats.js +14 -6
  40. package/dist/utils.d.ts +23 -3
  41. package/dist/utils.js +58 -10
  42. package/dist/vfs/async.js +1 -1
  43. package/dist/vfs/constants.d.ts +2 -2
  44. package/dist/vfs/constants.js +2 -2
  45. package/dist/vfs/dir.js +3 -1
  46. package/dist/vfs/index.js +4 -1
  47. package/dist/vfs/promises.js +33 -13
  48. package/dist/vfs/shared.js +2 -0
  49. package/dist/vfs/sync.js +25 -13
  50. package/dist/vfs/types.d.ts +15 -0
  51. package/eslint.shared.js +1 -0
  52. package/package.json +2 -3
  53. package/readme.md +2 -2
  54. package/scripts/test.js +73 -11
  55. package/tests/common/mutex.test.ts +1 -1
  56. package/tests/fetch/run.sh +16 -0
  57. package/tests/fetch/server.ts +49 -0
  58. package/tests/fetch/setup.ts +13 -0
  59. package/tests/fs/read.test.ts +10 -10
  60. package/tests/fs/times.test.ts +2 -2
  61. package/tests/fs/write.test.ts +6 -11
  62. package/tests/setup/index.ts +38 -0
  63. package/tests/setup/port.ts +15 -0
  64. package/dist/backends/file_index.d.ts +0 -63
  65. package/dist/backends/file_index.js +0 -163
  66. package/tests/common/async.test.ts +0 -31
  67. package/tests/setup/cow+fetch.ts +0 -45
  68. /package/tests/fs/{appendFile.test.ts → append.test.ts} +0 -0
@@ -1,19 +1,22 @@
1
1
  import type { File } from '../../file.js';
2
- import { FileSystem, type FileSystemMetadata } from '../../filesystem.js';
3
- import { Inode } from './inode.js';
4
- import type { Stats } from '../../stats.js';
2
+ import type { CreationOptions, FileSystemMetadata, PureCreationOptions } from '../../filesystem.js';
3
+ import { FileSystem } from '../../filesystem.js';
4
+ import type { FileType, Stats } from '../../stats.js';
5
+ import { Index } from './file_index.js';
6
+ import { Inode, type InodeLike } from './inode.js';
5
7
  import type { Store, Transaction } from './store.js';
6
8
  /**
7
9
  * A file system which uses a key-value store.
8
10
  *
9
11
  * We use a unique ID for each node in the file system. The root node has a fixed ID.
10
- * @todo Introduce Node ID caching.
11
- * @todo Check modes.
12
+ *
13
+ * @todo Introduce Node ID caching?
14
+ * @todo Check modes?
12
15
  * @internal
13
16
  */
14
17
  export declare class StoreFS<T extends Store = Store> extends FileSystem {
15
- protected store: T;
16
- private _initialized;
18
+ protected readonly store: T;
19
+ protected _initialized: boolean;
17
20
  ready(): Promise<void>;
18
21
  constructor(store: T);
19
22
  metadata(): FileSystemMetadata;
@@ -27,6 +30,18 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
27
30
  * @deprecated
28
31
  */
29
32
  emptySync(): void;
33
+ /**
34
+ * Load an index into the StoreFS.
35
+ * You *must* manually add non-directory files
36
+ */
37
+ loadIndex(index: Index): Promise<void>;
38
+ /**
39
+ * Load an index into the StoreFS.
40
+ * You *must* manually add non-directory files
41
+ */
42
+ loadIndexSync(index: Index): void;
43
+ createIndex(): Promise<Index>;
44
+ createIndexSync(): Index;
30
45
  /**
31
46
  * @todo Make rename compatible with the cache.
32
47
  */
@@ -34,30 +49,34 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
34
49
  renameSync(oldPath: string, newPath: string): void;
35
50
  stat(path: string): Promise<Stats>;
36
51
  statSync(path: string): Stats;
37
- createFile(path: string, flag: string, mode: number): Promise<File>;
38
- createFileSync(path: string, flag: string, mode: number): File;
52
+ createFile(path: string, flag: string, mode: number, options: CreationOptions): Promise<File>;
53
+ createFileSync(path: string, flag: string, mode: number, options: CreationOptions): File;
39
54
  openFile(path: string, flag: string): Promise<File>;
40
55
  openFileSync(path: string, flag: string): File;
41
56
  unlink(path: string): Promise<void>;
42
57
  unlinkSync(path: string): void;
43
58
  rmdir(path: string): Promise<void>;
44
59
  rmdirSync(path: string): void;
45
- mkdir(path: string, mode: number): Promise<void>;
46
- mkdirSync(path: string, mode: number): void;
60
+ mkdir(path: string, mode: number, options: CreationOptions): Promise<void>;
61
+ mkdirSync(path: string, mode: number, options: CreationOptions): void;
47
62
  readdir(path: string): Promise<string[]>;
48
63
  readdirSync(path: string): string[];
49
64
  /**
50
65
  * Updated the inode and data node at `path`
51
66
  * @todo Ensure mtime updates properly, and use that to determine if a data update is required.
52
67
  */
53
- sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
68
+ sync(path: string, data?: Uint8Array, metadata?: Readonly<InodeLike>): Promise<void>;
54
69
  /**
55
70
  * Updated the inode and data node at `path`
56
71
  * @todo Ensure mtime updates properly, and use that to determine if a data update is required.
57
72
  */
58
- syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
73
+ syncSync(path: string, data?: Uint8Array, metadata?: Readonly<InodeLike>): void;
59
74
  link(target: string, link: string): Promise<void>;
60
75
  linkSync(target: string, link: string): void;
76
+ read(path: string, buffer: Uint8Array, offset: number, end: number): Promise<void>;
77
+ readSync(path: string, buffer: Uint8Array, offset: number, end: number): void;
78
+ write(path: string, data: Uint8Array, offset: number): Promise<void>;
79
+ writeSync(path: string, data: Uint8Array, offset: number): void;
61
80
  /**
62
81
  * Checks if the root directory exists. Creates it if it doesn't.
63
82
  */
@@ -80,7 +99,7 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
80
99
  * the parent.
81
100
  * @return string The ID of the file's inode in the file system.
82
101
  */
83
- protected _findInodeSync(tx: Transaction, path: string, syscall: string, visited?: Set<string>): bigint;
102
+ private _findInodeSync;
84
103
  /**
85
104
  * Finds the Inode of `path`.
86
105
  * @param path The path to look up.
@@ -94,31 +113,17 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
94
113
  * @todo memoize/cache
95
114
  */
96
115
  protected findInodeSync(tx: Transaction, path: string, syscall: string, visited?: Set<string>): Inode;
97
- /**
98
- * Given an ID, retrieves the corresponding data.
99
- * @param tx The transaction to use.
100
- * @param path The corresponding path to the file (used for error messages).
101
- * @param id The ID to look up.
102
- */
103
- private get;
104
- /**
105
- * Given an ID, retrieves the corresponding data.
106
- * @param tx The transaction to use.
107
- * @param path The corresponding path to the file (used for error messages).
108
- * @param id The ID to look up.
109
- */
110
- private getSync;
111
116
  /**
112
117
  * Adds a new node under a random ID. Retries before giving up in
113
118
  * the exceedingly unlikely chance that we try to reuse a random id.
114
119
  */
115
- private allocNew;
120
+ protected allocNew(tx: Transaction, path: string, syscall: string): Promise<number>;
116
121
  /**
117
122
  * Creates a new node under a random ID. Retries before giving up in
118
123
  * the exceedingly unlikely chance that we try to reuse a random id.
119
124
  * @return The ino that the data was stored under.
120
125
  */
121
- private allocNewSync;
126
+ protected allocNewSync(tx: Transaction, path: string, syscall: string): number;
122
127
  /**
123
128
  * Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
124
129
  * Note: This will commit the transaction.
@@ -127,7 +132,7 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
127
132
  * @param mode The mode to create the new file with.
128
133
  * @param data The data to store at the file's data node.
129
134
  */
130
- private commitNew;
135
+ protected commitNew(path: string, type: FileType, options: PureCreationOptions, data: Uint8Array, syscall: string): Promise<Inode>;
131
136
  /**
132
137
  * Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
133
138
  * Note: This will commit the transaction.
@@ -137,19 +142,19 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
137
142
  * @param data The data to store at the file's data node.
138
143
  * @return The Inode for the new file.
139
144
  */
140
- private commitNewSync;
145
+ protected commitNewSync(path: string, type: FileType, options: PureCreationOptions, data: Uint8Array, syscall: string): Inode;
141
146
  /**
142
147
  * Remove all traces of `path` from the file system.
143
148
  * @param path The path to remove from the file system.
144
149
  * @param isDir Does the path belong to a directory, or a file?
145
150
  * @todo Update mtime.
146
151
  */
147
- private remove;
152
+ protected remove(path: string, isDir: boolean, syscall: string): Promise<void>;
148
153
  /**
149
154
  * Remove all traces of `path` from the file system.
150
155
  * @param path The path to remove from the file system.
151
156
  * @param isDir Does the path belong to a directory, or a file?
152
157
  * @todo Update mtime.
153
158
  */
154
- private removeSync;
159
+ protected removeSync(path: string, isDir: boolean, syscall: string): void;
155
160
  }