@componentor/fs 1.1.7

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.
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Options for readFile operation
3
+ */
4
+ interface ReadFileOptions {
5
+ /** Text encoding (e.g., 'utf-8'). If not provided, returns Uint8Array */
6
+ encoding?: string;
7
+ }
8
+ /**
9
+ * Options for writeFile operation
10
+ */
11
+ interface WriteFileOptions {
12
+ /** Text encoding for string data */
13
+ encoding?: string;
14
+ }
15
+ /**
16
+ * Entry for batch file write operation
17
+ */
18
+ interface BatchWriteEntry {
19
+ /** File path to write */
20
+ path: string;
21
+ /** Data to write (string or binary) */
22
+ data: string | Uint8Array;
23
+ }
24
+ /**
25
+ * Result entry for batch file read operation
26
+ */
27
+ interface BatchReadResult {
28
+ /** File path */
29
+ path: string;
30
+ /** File data (null if file doesn't exist or error occurred) */
31
+ data: Uint8Array | null;
32
+ /** Error if read failed */
33
+ error?: Error;
34
+ }
35
+ /**
36
+ * Options for readdir operation
37
+ */
38
+ interface ReaddirOptions {
39
+ /** Return Dirent objects instead of strings */
40
+ withFileTypes?: boolean;
41
+ }
42
+ /**
43
+ * Directory entry (Dirent-like object)
44
+ */
45
+ interface Dirent {
46
+ name: string;
47
+ isFile(): boolean;
48
+ isDirectory(): boolean;
49
+ isSymbolicLink(): boolean;
50
+ }
51
+ /**
52
+ * File statistics
53
+ */
54
+ interface Stats {
55
+ type: 'file' | 'dir' | 'symlink';
56
+ size: number;
57
+ mode: number;
58
+ ctime: Date;
59
+ ctimeMs: number;
60
+ mtime: Date;
61
+ mtimeMs: number;
62
+ target?: string;
63
+ isFile(): boolean;
64
+ isDirectory(): boolean;
65
+ isSymbolicLink(): boolean;
66
+ }
67
+ /**
68
+ * Options for rm operation
69
+ */
70
+ interface RmOptions {
71
+ /** Remove directories and their contents recursively */
72
+ recursive?: boolean;
73
+ /** Ignore if path doesn't exist */
74
+ force?: boolean;
75
+ }
76
+ /**
77
+ * Options for cp operation
78
+ */
79
+ interface CpOptions {
80
+ /** Copy directories recursively */
81
+ recursive?: boolean;
82
+ /** Overwrite existing files */
83
+ force?: boolean;
84
+ /** Throw if destination exists */
85
+ errorOnExist?: boolean;
86
+ }
87
+ /**
88
+ * Symlink definition for batch operations
89
+ */
90
+ interface SymlinkDefinition {
91
+ target: string;
92
+ path: string;
93
+ }
94
+ /**
95
+ * Disk usage result
96
+ */
97
+ interface DiskUsage {
98
+ path: string;
99
+ size: number;
100
+ }
101
+ /**
102
+ * Filesystem statistics (similar to Node.js fs.statfs)
103
+ */
104
+ interface StatFs {
105
+ /** Filesystem type (always 0 for OPFS) */
106
+ type: number;
107
+ /** Optimal transfer block size (simulated as 4096) */
108
+ bsize: number;
109
+ /** Total blocks in filesystem */
110
+ blocks: number;
111
+ /** Free blocks in filesystem */
112
+ bfree: number;
113
+ /** Available blocks for unprivileged users */
114
+ bavail: number;
115
+ /** Total file nodes (0 - not available in browser) */
116
+ files: number;
117
+ /** Free file nodes (0 - not available in browser) */
118
+ ffree: number;
119
+ /** Bytes used by origin (from Storage API) */
120
+ usage: number;
121
+ /** Total bytes available to origin (from Storage API) */
122
+ quota: number;
123
+ }
124
+
125
+ type Backend = 'main' | 'worker';
126
+ interface OPFSHybridOptions {
127
+ /** Backend for read operations (default: 'main') */
128
+ read?: Backend;
129
+ /** Backend for write operations (default: 'worker') */
130
+ write?: Backend;
131
+ /** Worker URL (required if using worker backend) */
132
+ workerUrl?: URL | string;
133
+ /** Enable verbose logging */
134
+ verbose?: boolean;
135
+ }
136
+ /**
137
+ * Hybrid OPFS implementation that routes operations to optimal backends
138
+ */
139
+ declare class OPFSHybrid {
140
+ private mainFs;
141
+ private workerFs;
142
+ private readBackend;
143
+ private writeBackend;
144
+ private workerUrl?;
145
+ private workerReady;
146
+ private verbose;
147
+ constructor(options?: OPFSHybridOptions);
148
+ /**
149
+ * Wait for all backends to be ready
150
+ */
151
+ ready(): Promise<void>;
152
+ /**
153
+ * Terminate worker if active
154
+ */
155
+ terminate(): void;
156
+ private getReadFs;
157
+ private getWriteFs;
158
+ readFile(path: string, options?: ReadFileOptions): Promise<Uint8Array | string>;
159
+ readFileBatch(paths: string[]): Promise<BatchReadResult[]>;
160
+ readdir(path: string, options?: ReaddirOptions): Promise<string[] | Dirent[]>;
161
+ stat(path: string): Promise<Stats>;
162
+ lstat(path: string): Promise<Stats>;
163
+ exists(path: string): Promise<boolean>;
164
+ access(path: string, mode?: number): Promise<void>;
165
+ readlink(path: string): Promise<string>;
166
+ realpath(path: string): Promise<string>;
167
+ statfs(path?: string): Promise<StatFs>;
168
+ du(path: string): Promise<DiskUsage>;
169
+ writeFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
170
+ writeFileBatch(entries: BatchWriteEntry[]): Promise<void>;
171
+ appendFile(path: string, data: string | Uint8Array, options?: WriteFileOptions): Promise<void>;
172
+ mkdir(path: string): Promise<void>;
173
+ rmdir(path: string): Promise<void>;
174
+ unlink(path: string): Promise<void>;
175
+ truncate(path: string, len?: number): Promise<void>;
176
+ symlink(target: string, path: string): Promise<void>;
177
+ symlinkBatch(symlinks: SymlinkDefinition[]): Promise<void>;
178
+ rename(oldPath: string, newPath: string): Promise<void>;
179
+ copyFile(src: string, dest: string, mode?: number): Promise<void>;
180
+ cp(src: string, dest: string, options?: CpOptions): Promise<void>;
181
+ rm(path: string, options?: RmOptions): Promise<void>;
182
+ chmod(path: string, mode: number): Promise<void>;
183
+ chown(path: string, uid: number, gid: number): Promise<void>;
184
+ utimes(path: string, atime: Date | number, mtime: Date | number): Promise<void>;
185
+ lutimes(path: string, atime: Date | number, mtime: Date | number): Promise<void>;
186
+ mkdtemp(prefix: string): Promise<string>;
187
+ /**
188
+ * Reset internal caches on both backends
189
+ */
190
+ resetCache(): Promise<void>;
191
+ /**
192
+ * Force full garbage collection on both backends
193
+ * More aggressive than resetCache() - reinitializes the worker's OPFS instance
194
+ */
195
+ gc(): Promise<void>;
196
+ }
197
+
198
+ export { type Backend, OPFSHybrid, type OPFSHybridOptions, OPFSHybrid as default };