@zenfs/core 1.7.2 → 1.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.
Files changed (62) 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 +7 -2
  8. package/dist/backends/overlay.js +32 -9
  9. package/dist/backends/passthrough.d.ts +4 -0
  10. package/dist/backends/passthrough.js +128 -0
  11. package/dist/backends/port/fs.d.ts +9 -44
  12. package/dist/backends/port/fs.js +93 -116
  13. package/dist/backends/port/rpc.d.ts +8 -5
  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 +55 -34
  18. package/dist/backends/store/fs.js +417 -233
  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 +11 -10
  28. package/dist/devices.js +15 -11
  29. package/dist/file.d.ts +111 -7
  30. package/dist/file.js +319 -71
  31. package/dist/filesystem.d.ts +22 -4
  32. package/dist/mixins/mutexed.d.ts +7 -2
  33. package/dist/mixins/mutexed.js +56 -0
  34. package/dist/mixins/sync.d.ts +1 -1
  35. package/dist/stats.d.ts +12 -6
  36. package/dist/stats.js +14 -6
  37. package/dist/utils.d.ts +17 -3
  38. package/dist/utils.js +32 -10
  39. package/dist/vfs/constants.d.ts +2 -2
  40. package/dist/vfs/constants.js +2 -2
  41. package/dist/vfs/dir.js +3 -1
  42. package/dist/vfs/index.js +4 -1
  43. package/dist/vfs/promises.js +31 -11
  44. package/dist/vfs/shared.js +2 -0
  45. package/dist/vfs/sync.js +25 -13
  46. package/dist/vfs/types.d.ts +15 -0
  47. package/package.json +2 -3
  48. package/readme.md +2 -2
  49. package/scripts/test.js +73 -11
  50. package/tests/common/mutex.test.ts +1 -1
  51. package/tests/fetch/run.sh +16 -0
  52. package/tests/fetch/server.ts +49 -0
  53. package/tests/fetch/setup.ts +13 -0
  54. package/tests/fs/read.test.ts +10 -10
  55. package/tests/fs/times.test.ts +2 -2
  56. package/tests/setup/index.ts +38 -0
  57. package/tests/setup/port.ts +15 -0
  58. package/dist/backends/file_index.d.ts +0 -63
  59. package/dist/backends/file_index.js +0 -163
  60. package/tests/common/async.test.ts +0 -31
  61. package/tests/setup/cow+fetch.ts +0 -45
  62. /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,50 @@ 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
+ /**
77
+ * Used by lazy file
78
+ * @internal
79
+ */
80
+ read(path: string, offset: number, length: number): Promise<Uint8Array>;
81
+ /**
82
+ * Used by lazy file
83
+ * @internal
84
+ */
85
+ readSync(path: string, offset: number, length: number): Uint8Array;
86
+ /**
87
+ * Used by lazy file
88
+ * @internal
89
+ */
90
+ write(path: string, data: Uint8Array, offset: number): Promise<void>;
91
+ /**
92
+ * Used by lazy file
93
+ * @internal
94
+ */
95
+ writeSync(path: string, data: Uint8Array, offset: number): void;
61
96
  /**
62
97
  * Checks if the root directory exists. Creates it if it doesn't.
63
98
  */
@@ -80,7 +115,7 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
80
115
  * the parent.
81
116
  * @return string The ID of the file's inode in the file system.
82
117
  */
83
- protected _findInodeSync(tx: Transaction, path: string, syscall: string, visited?: Set<string>): bigint;
118
+ private _findInodeSync;
84
119
  /**
85
120
  * Finds the Inode of `path`.
86
121
  * @param path The path to look up.
@@ -94,31 +129,17 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
94
129
  * @todo memoize/cache
95
130
  */
96
131
  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
132
  /**
112
133
  * Adds a new node under a random ID. Retries before giving up in
113
134
  * the exceedingly unlikely chance that we try to reuse a random id.
114
135
  */
115
- private allocNew;
136
+ protected allocNew(tx: Transaction, path: string, syscall: string): Promise<number>;
116
137
  /**
117
138
  * Creates a new node under a random ID. Retries before giving up in
118
139
  * the exceedingly unlikely chance that we try to reuse a random id.
119
140
  * @return The ino that the data was stored under.
120
141
  */
121
- private allocNewSync;
142
+ protected allocNewSync(tx: Transaction, path: string, syscall: string): number;
122
143
  /**
123
144
  * Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
124
145
  * Note: This will commit the transaction.
@@ -127,7 +148,7 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
127
148
  * @param mode The mode to create the new file with.
128
149
  * @param data The data to store at the file's data node.
129
150
  */
130
- private commitNew;
151
+ protected commitNew(path: string, type: FileType, options: PureCreationOptions, data: Uint8Array, syscall: string): Promise<Inode>;
131
152
  /**
132
153
  * Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
133
154
  * Note: This will commit the transaction.
@@ -137,19 +158,19 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
137
158
  * @param data The data to store at the file's data node.
138
159
  * @return The Inode for the new file.
139
160
  */
140
- private commitNewSync;
161
+ protected commitNewSync(path: string, type: FileType, options: PureCreationOptions, data: Uint8Array, syscall: string): Inode;
141
162
  /**
142
163
  * Remove all traces of `path` from the file system.
143
164
  * @param path The path to remove from the file system.
144
165
  * @param isDir Does the path belong to a directory, or a file?
145
166
  * @todo Update mtime.
146
167
  */
147
- private remove;
168
+ protected remove(path: string, isDir: boolean, syscall: string): Promise<void>;
148
169
  /**
149
170
  * Remove all traces of `path` from the file system.
150
171
  * @param path The path to remove from the file system.
151
172
  * @param isDir Does the path belong to a directory, or a file?
152
173
  * @todo Update mtime.
153
174
  */
154
- private removeSync;
175
+ protected removeSync(path: string, isDir: boolean, syscall: string): void;
155
176
  }