@happyvertical/files 0.74.8

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,209 @@
1
+ import { statSync } from 'node:fs';
2
+ /**
3
+ * Checks if a path is a file (legacy compatibility function)
4
+ *
5
+ * This function provides backward compatibility with the existing @happyvertical/files API.
6
+ * It synchronously checks if the given path exists and is a file (not a directory).
7
+ *
8
+ * @param file - Path to check
9
+ * @returns File stats object if the path is a file, false otherwise
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const stats = isFile('/path/to/document.txt');
14
+ * if (stats) {
15
+ * console.log(`File size: ${stats.size} bytes`);
16
+ * console.log(`Modified: ${stats.mtime}`);
17
+ * }
18
+ * ```
19
+ *
20
+ * @deprecated Use the async filesystem interface methods instead
21
+ */
22
+ export declare const isFile: (file: string) => false | ReturnType<typeof statSync>;
23
+ /**
24
+ * Checks if a path is a directory (legacy compatibility function)
25
+ *
26
+ * This function provides backward compatibility with the existing @happyvertical/files API.
27
+ * It synchronously checks if the given path exists and is a directory.
28
+ *
29
+ * @param dir - Path to check
30
+ * @returns True if the path is a directory, false if it doesn't exist
31
+ * @throws {Error} If the path exists but is not a directory
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * try {
36
+ * const isDir = isDirectory('/path/to/folder');
37
+ * if (isDir) {
38
+ * console.log('Path is a directory');
39
+ * } else {
40
+ * console.log('Directory does not exist');
41
+ * }
42
+ * } catch (error) {
43
+ * console.error('Path exists but is not a directory');
44
+ * }
45
+ * ```
46
+ *
47
+ * @deprecated Use the async filesystem interface methods instead
48
+ */
49
+ export declare const isDirectory: (dir: string) => boolean;
50
+ /**
51
+ * Creates a directory if it doesn't exist (legacy compatibility function)
52
+ *
53
+ * This function provides backward compatibility with the existing @happyvertical/files API.
54
+ * It ensures a directory exists by creating it (and any parent directories) if needed.
55
+ *
56
+ * @param dir - Directory path to create
57
+ * @returns Promise that resolves when the directory exists or has been created
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * await ensureDirectoryExists('/path/to/nested/directory');
62
+ * console.log('Directory is ready for use');
63
+ * ```
64
+ *
65
+ * @deprecated Use the async filesystem interface createDirectory method instead
66
+ */
67
+ export declare const ensureDirectoryExists: (dir: string) => Promise<void>;
68
+ /**
69
+ * Uploads data to a URL using PUT method (legacy compatibility function)
70
+ *
71
+ * This function provides backward compatibility with the existing @happyvertical/files API.
72
+ * It performs an HTTP PUT request to upload data to a remote URL.
73
+ *
74
+ * @param url - URL to upload data to
75
+ * @param data - String or Buffer data to upload
76
+ * @returns Promise that resolves with the Response object
77
+ * @throws {Error} If the upload fails (network error or non-2xx response)
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const response = await upload('https://api.example.com/files/document.txt', 'file content');
82
+ * console.log('Upload successful:', response.status);
83
+ *
84
+ * // Upload binary data
85
+ * const imageBuffer = await fs.readFile('image.png');
86
+ * await upload('https://api.example.com/files/image.png', imageBuffer);
87
+ * ```
88
+ *
89
+ * @deprecated Use the async filesystem interface upload method instead
90
+ */
91
+ export declare const upload: (url: string, data: string | Buffer) => Promise<Response>;
92
+ /**
93
+ * Downloads a file from a URL and saves it to a local file (legacy compatibility function)
94
+ *
95
+ * This function provides backward compatibility with the existing @happyvertical/files API.
96
+ * It downloads content from a URL and writes it to a local file using streaming
97
+ * to handle large files efficiently.
98
+ *
99
+ * @param url - URL to download from
100
+ * @param filepath - Local file path to save to
101
+ * @returns Promise that resolves when the download is complete
102
+ * @throws {Error} If the download fails (network error, file write error, etc.)
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * await download('https://example.com/document.pdf', './downloads/document.pdf');
107
+ * console.log('Download complete');
108
+ *
109
+ * // Download with error handling
110
+ * try {
111
+ * await download('https://example.com/large-file.zip', './temp/file.zip');
112
+ * } catch (error) {
113
+ * console.error('Download failed:', error.message);
114
+ * }
115
+ * ```
116
+ *
117
+ * @deprecated Use the async filesystem interface download method instead
118
+ */
119
+ export declare function download(url: string, filepath: string): Promise<void>;
120
+ /**
121
+ * Downloads a file with caching support (legacy compatibility function)
122
+ *
123
+ * This function provides backward compatibility with the existing @happyvertical/files API.
124
+ * It downloads a file only if it doesn't already exist locally, implementing
125
+ * a simple caching mechanism to avoid redundant downloads.
126
+ *
127
+ * @param url - URL to download from
128
+ * @param targetPath - Optional custom target path. If null, uses a generated path in temp directory
129
+ * @returns Promise that resolves with the path to the downloaded file (either cached or newly downloaded)
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Download with auto-generated cache path
134
+ * const filePath = await downloadFileWithCache('https://example.com/data.json');
135
+ * console.log('File available at:', filePath);
136
+ *
137
+ * // Download to specific path
138
+ * const customPath = await downloadFileWithCache(
139
+ * 'https://example.com/document.pdf',
140
+ * './cache/document.pdf'
141
+ * );
142
+ * ```
143
+ *
144
+ * @deprecated Use the async filesystem interface downloadWithCache method instead
145
+ */
146
+ export declare const downloadFileWithCache: (url: string, targetPath?: string | null) => Promise<string>;
147
+ /**
148
+ * Options for listing files in a directory
149
+ */
150
+ interface ListFilesOptions {
151
+ /**
152
+ * Optional regular expression to filter files by name
153
+ */
154
+ match?: RegExp;
155
+ }
156
+ /**
157
+ * Lists files in a directory with optional filtering (legacy compatibility function)
158
+ *
159
+ * This function provides backward compatibility with the existing @happyvertical/files API.
160
+ * It returns only files (not directories) from the specified directory, with
161
+ * optional regular expression filtering.
162
+ *
163
+ * @param dirPath - Directory path to list files from
164
+ * @param options - Filtering options
165
+ * @param options.match - Optional regular expression to filter files by name
166
+ * @returns Promise that resolves with an array of file names (not full paths)
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * // List all files
171
+ * const allFiles = await listFiles('/path/to/directory');
172
+ * console.log('Files:', allFiles);
173
+ *
174
+ * // List only JavaScript files
175
+ * const jsFiles = await listFiles('/project/src', { match: /\.js$/ });
176
+ * console.log('JS files:', jsFiles);
177
+ *
178
+ * // List image files
179
+ * const images = await listFiles('/photos', { match: /\.(jpg|png|gif)$/i });
180
+ * ```
181
+ *
182
+ * @deprecated Use the async filesystem interface list method instead
183
+ */
184
+ export declare const listFiles: (dirPath: string, options?: ListFilesOptions) => Promise<string[]>;
185
+ /**
186
+ * Gets data from cache if available and not expired
187
+ *
188
+ * @param file - Cache file identifier
189
+ * @param expiry - Cache expiry time in milliseconds
190
+ * @returns Promise that resolves with the cached data or undefined if not found/expired
191
+ */
192
+ export declare function getCached(file: string, expiry?: number): Promise<string | undefined>;
193
+ /**
194
+ * Sets data in cache
195
+ *
196
+ * @param file - Cache file identifier
197
+ * @param data - Data to cache
198
+ * @returns Promise that resolves when the data is cached
199
+ */
200
+ export declare function setCached(file: string, data: string): Promise<void>;
201
+ /**
202
+ * Gets the MIME type for a file or URL based on its extension
203
+ *
204
+ * @param fileOrUrl - File path or URL to get MIME type for
205
+ * @returns MIME type string, defaults to 'application/octet-stream' if not found
206
+ */
207
+ export declare function getMimeType(fileOrUrl: string): string;
208
+ export {};
209
+ //# sourceMappingURL=legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../src/legacy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA8C,QAAQ,EAAE,MAAM,SAAS,CAAC;AAY/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,KAAG,KAAK,GAAG,UAAU,CAAC,OAAO,QAAQ,CAOvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,OAWzC,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,GAAU,KAAK,MAAM,KAAG,OAAO,CAAC,IAAI,CAKrE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,MAAM,GACjB,KAAK,MAAM,EACX,MAAM,MAAM,GAAG,MAAM,KACpB,OAAO,CAAC,QAAQ,CAiBlB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmC3E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,qBAAqB,GAChC,KAAK,MAAM,EACX,aAAY,MAAM,GAAG,IAAW,KAC/B,OAAO,CAAC,MAAM,CAchB,CAAC;AAEF;;GAEG;AACH,UAAU,gBAAgB;IACxB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS,GACpB,SAAS,MAAM,EACf,UAAS,gBAAkC,KAC1C,OAAO,CAAC,MAAM,EAAE,CASlB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,+BAY5D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAIzD;AA+BD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAcrD"}
@@ -0,0 +1,332 @@
1
+ import { BaseFilesystemProvider } from '../shared/base';
2
+ import { CreateDirOptions, FileInfo, FileStats, FilesystemCapabilities, ListOptions, LocalOptions, ReadOptions, WriteOptions } from '../shared/types';
3
+ /**
4
+ * Local filesystem provider using Node.js fs module with full feature support
5
+ *
6
+ * This provider implements all filesystem operations using the Node.js built-in
7
+ * fs/promises module. It supports all standard file operations including reading,
8
+ * writing, directory management, and caching. The provider operates within a
9
+ * configurable root path for security and organization.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * // Create provider with default settings (current working directory)
14
+ * const fs = new LocalFilesystemProvider();
15
+ *
16
+ * // Create provider with custom base path
17
+ * const fs = new LocalFilesystemProvider({ basePath: '/app/data' });
18
+ *
19
+ * // Use the provider
20
+ * await fs.write('config.json', JSON.stringify({ key: 'value' }));
21
+ * const content = await fs.read('config.json');
22
+ * ```
23
+ */
24
+ export declare class LocalFilesystemProvider extends BaseFilesystemProvider {
25
+ private readonly rootPath;
26
+ constructor(options?: LocalOptions);
27
+ /**
28
+ * Resolve a relative path to an absolute path within the root directory
29
+ *
30
+ * This method validates the path, normalizes it, and resolves it relative to
31
+ * the configured root path. It ensures path safety by preventing directory
32
+ * traversal attacks.
33
+ *
34
+ * @param path - Relative path to resolve
35
+ * @returns Absolute path within the root directory
36
+ * @throws {FilesystemError} When path is invalid or contains directory traversal
37
+ *
38
+ * @internal
39
+ */
40
+ private resolvePath;
41
+ private resolveCachePath;
42
+ /**
43
+ * Check if a file or directory exists at the specified path
44
+ *
45
+ * Uses Node.js fs.access() to check for file existence without reading
46
+ * the file contents. This is more efficient than trying to read or stat
47
+ * the file when only existence needs to be verified.
48
+ *
49
+ * @param path - Path to check for existence
50
+ * @returns Promise resolving to true if the path exists, false otherwise
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const exists = await fs.exists('config.json');
55
+ * if (exists) {
56
+ * console.log('Config file found');
57
+ * }
58
+ * ```
59
+ */
60
+ exists(path: string): Promise<boolean>;
61
+ /**
62
+ * Read file contents as string or Buffer
63
+ *
64
+ * Reads the entire contents of a file into memory. For large files, consider
65
+ * using streaming approaches to avoid memory issues.
66
+ *
67
+ * @param path - Path to the file to read
68
+ * @param options - Read options including encoding and raw mode
69
+ * @param options.encoding - Text encoding for string output (default: 'utf8')
70
+ * @param options.raw - If true, returns Buffer instead of string
71
+ * @returns Promise resolving to file contents as string or Buffer
72
+ * @throws {FileNotFoundError} When the file doesn't exist
73
+ * @throws {PermissionError} When read access is denied
74
+ * @throws {FilesystemError} For other filesystem errors
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Read as UTF-8 string (default)
79
+ * const text = await fs.read('document.txt');
80
+ *
81
+ * // Read as Buffer for binary data
82
+ * const buffer = await fs.read('image.png', { raw: true });
83
+ *
84
+ * // Read with specific encoding
85
+ * const latin1Text = await fs.read('legacy.txt', { encoding: 'latin1' });
86
+ * ```
87
+ */
88
+ read(path: string, options?: ReadOptions): Promise<string | Buffer>;
89
+ /**
90
+ * Write content to a file
91
+ *
92
+ * Creates or overwrites a file with the provided content. Can automatically
93
+ * create parent directories if they don't exist. Supports both string and
94
+ * binary data.
95
+ *
96
+ * @param path - Path where the file should be written
97
+ * @param content - Content to write (string or Buffer)
98
+ * @param options - Write options
99
+ * @param options.encoding - Text encoding for string content
100
+ * @param options.mode - File permissions (e.g., 0o644)
101
+ * @param options.createParents - Whether to create parent directories (default: true)
102
+ * @returns Promise that resolves when the file is written
103
+ * @throws {FileNotFoundError} When parent directory doesn't exist and createParents is false
104
+ * @throws {PermissionError} When write access is denied
105
+ * @throws {FilesystemError} For other filesystem errors
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Write text file
110
+ * await fs.write('config.json', JSON.stringify({ key: 'value' }));
111
+ *
112
+ * // Write binary data
113
+ * const imageBuffer = await someImageProcessing();
114
+ * await fs.write('output.png', imageBuffer);
115
+ *
116
+ * // Write with specific permissions
117
+ * await fs.write('secret.txt', 'sensitive data', { mode: 0o600 });
118
+ *
119
+ * // Write without creating parent directories
120
+ * await fs.write('existing/dir/file.txt', 'content', { createParents: false });
121
+ * ```
122
+ */
123
+ write(path: string, content: string | Buffer, options?: WriteOptions): Promise<void>;
124
+ /**
125
+ * Delete a file or empty directory
126
+ *
127
+ * Removes a file or directory from the filesystem. For directories, they must
128
+ * be empty. Use recursive deletion utilities for non-empty directories.
129
+ *
130
+ * @param path - Path to the file or directory to delete
131
+ * @returns Promise that resolves when the item is deleted
132
+ * @throws {FileNotFoundError} When the file or directory doesn't exist
133
+ * @throws {PermissionError} When delete access is denied
134
+ * @throws {DirectoryNotEmptyError} When trying to delete a non-empty directory
135
+ * @throws {FilesystemError} For other filesystem errors
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * // Delete a file
140
+ * await fs.delete('temp.txt');
141
+ *
142
+ * // Delete an empty directory
143
+ * await fs.delete('empty-dir/');
144
+ * ```
145
+ */
146
+ delete(path: string): Promise<void>;
147
+ /**
148
+ * Copy a file from source to destination
149
+ *
150
+ * Creates an exact copy of a file at the destination path. Will create
151
+ * parent directories if they don't exist and createMissing is enabled.
152
+ * The operation preserves file contents but not necessarily all metadata.
153
+ *
154
+ * @param sourcePath - Path to the source file
155
+ * @param destPath - Path where the copy should be created
156
+ * @returns Promise that resolves when the file is copied
157
+ * @throws {FileNotFoundError} When the source file doesn't exist
158
+ * @throws {PermissionError} When read/write access is denied
159
+ * @throws {FilesystemError} For other filesystem errors
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Copy a file
164
+ * await fs.copy('original.txt', 'backup.txt');
165
+ *
166
+ * // Copy to a different directory
167
+ * await fs.copy('data.json', 'backup/data-copy.json');
168
+ * ```
169
+ */
170
+ copy(sourcePath: string, destPath: string): Promise<void>;
171
+ /**
172
+ * Move/rename a file from source to destination
173
+ *
174
+ * Moves a file to a new location, effectively combining copy and delete
175
+ * operations. This is atomic on most filesystems when moving within the
176
+ * same filesystem. Will create parent directories if they don't exist.
177
+ *
178
+ * @param sourcePath - Path to the source file
179
+ * @param destPath - Path where the file should be moved
180
+ * @returns Promise that resolves when the file is moved
181
+ * @throws {FileNotFoundError} When the source file doesn't exist
182
+ * @throws {PermissionError} When move access is denied
183
+ * @throws {FilesystemError} For other filesystem errors
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Rename a file
188
+ * await fs.move('old-name.txt', 'new-name.txt');
189
+ *
190
+ * // Move to a different directory
191
+ * await fs.move('temp.txt', 'archive/temp.txt');
192
+ * ```
193
+ */
194
+ move(sourcePath: string, destPath: string): Promise<void>;
195
+ /**
196
+ * Create a directory at the specified path
197
+ *
198
+ * Creates a new directory with optional recursive creation of parent
199
+ * directories. Supports setting directory permissions.
200
+ *
201
+ * @param path - Path where the directory should be created
202
+ * @param options - Directory creation options
203
+ * @param options.recursive - Whether to create parent directories (default: true)
204
+ * @param options.mode - Directory permissions (e.g., 0o755)
205
+ * @returns Promise that resolves when the directory is created
206
+ * @throws {PermissionError} When create access is denied
207
+ * @throws {FilesystemError} For other filesystem errors
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * // Create directory with parents
212
+ * await fs.createDirectory('path/to/new/dir');
213
+ *
214
+ * // Create directory with specific permissions
215
+ * await fs.createDirectory('private-dir', { mode: 0o700 });
216
+ *
217
+ * // Create directory without parent creation
218
+ * await fs.createDirectory('existing-parent/new-dir', { recursive: false });
219
+ * ```
220
+ */
221
+ createDirectory(path: string, options?: CreateDirOptions): Promise<void>;
222
+ /**
223
+ * List the contents of a directory
224
+ *
225
+ * Returns an array of FileInfo objects describing each item in the directory.
226
+ * Supports filtering, recursive listing, and detailed metadata retrieval.
227
+ *
228
+ * @param path - Path to the directory to list
229
+ * @param options - Listing options
230
+ * @param options.recursive - Whether to include subdirectories recursively
231
+ * @param options.filter - RegExp or string pattern to filter file names
232
+ * @param options.detailed - Whether to include MIME types and extended metadata
233
+ * @returns Promise resolving to array of FileInfo objects
234
+ * @throws {FileNotFoundError} When the directory doesn't exist
235
+ * @throws {PermissionError} When read access is denied
236
+ * @throws {FilesystemError} For other filesystem errors
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // List all files and directories
241
+ * const items = await fs.list('/path/to/dir');
242
+ * items.forEach(item => {
243
+ * console.log(`${item.name} (${item.isDirectory ? 'dir' : 'file'})`);
244
+ * });
245
+ *
246
+ * // List only text files
247
+ * const textFiles = await fs.list('/documents', { filter: /\.txt$/ });
248
+ *
249
+ * // Recursive listing with detailed info
250
+ * const allFiles = await fs.list('/project', {
251
+ * recursive: true,
252
+ * detailed: true
253
+ * });
254
+ * ```
255
+ */
256
+ list(path: string, options?: ListOptions): Promise<FileInfo[]>;
257
+ /**
258
+ * Get detailed file or directory statistics
259
+ *
260
+ * Returns comprehensive metadata about a file or directory including size,
261
+ * timestamps, permissions, and ownership information.
262
+ *
263
+ * @param path - Path to the file or directory
264
+ * @returns Promise resolving to FileStats object with detailed metadata
265
+ * @throws {FileNotFoundError} When the path doesn't exist
266
+ * @throws {PermissionError} When stat access is denied
267
+ * @throws {FilesystemError} For other filesystem errors
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const stats = await fs.getStats('document.pdf');
272
+ * console.log(`Size: ${stats.size} bytes`);
273
+ * console.log(`Modified: ${stats.mtime}`);
274
+ * console.log(`Is file: ${stats.isFile}`);
275
+ * console.log(`Permissions: ${stats.mode.toString(8)}`);
276
+ * ```
277
+ */
278
+ getStats(path: string): Promise<FileStats>;
279
+ /**
280
+ * Get the MIME type for a file based on its extension
281
+ *
282
+ * Determines the MIME type by examining the file extension. Returns a
283
+ * standard MIME type string that can be used for content-type headers
284
+ * or file type detection.
285
+ *
286
+ * @param path - Path to the file
287
+ * @returns Promise resolving to MIME type string (e.g., 'text/plain', 'image/png')
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const mimeType = await fs.getMimeType('document.pdf');
292
+ * console.log(mimeType); // 'application/pdf'
293
+ *
294
+ * const imageMime = await fs.getMimeType('photo.jpg');
295
+ * console.log(imageMime); // 'image/jpeg'
296
+ * ```
297
+ */
298
+ getMimeType(path: string): Promise<string>;
299
+ /**
300
+ * Upload data to a URL using PUT method (legacy)
301
+ */
302
+ uploadToUrl(url: string, data: string | Buffer): Promise<Response>;
303
+ /**
304
+ * Download a file from a URL and save it to a local file (legacy)
305
+ */
306
+ downloadFromUrl(url: string, filepath: string): Promise<void>;
307
+ /**
308
+ * Download a file with caching support (legacy)
309
+ */
310
+ downloadFileWithCache(url: string, targetPath?: string | null): Promise<string>;
311
+ /**
312
+ * Get data from cache if available and not expired (legacy)
313
+ */
314
+ getCached(file: string, expiry?: number): Promise<string | undefined>;
315
+ /**
316
+ * Set data in cache (legacy)
317
+ */
318
+ setCached(file: string, data: string): Promise<void>;
319
+ /**
320
+ * Cache implementation using file system
321
+ */
322
+ cache: {
323
+ get: (key: string, expiry?: number) => Promise<string | undefined>;
324
+ set: (key: string, data: string) => Promise<void>;
325
+ clear: (key?: string) => Promise<void>;
326
+ };
327
+ /**
328
+ * Get provider capabilities
329
+ */
330
+ getCapabilities(): Promise<FilesystemCapabilities>;
331
+ }
332
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/node/local.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,sBAAsB,EAG3B,KAAK,WAAW,EAChB,KAAK,YAAY,EAEjB,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,uBAAwB,SAAQ,sBAAsB;IACjE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,GAAE,YAAiB;IAOtC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,gBAAgB;IAuBxB;;;;;;;;;;;;;;;;;OAiBG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5C;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IA0B3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,KAAK,CACT,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,I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G,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAe3E;;OAEG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1D;;OAEG;IACH,KAAK;mBACc,MAAM,WAAW,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;mBAIrD,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;sBAIjC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;MAiB1C;IAEF;;OAEG;IACG,eAAe,IAAI,OAAO,CAAC,sBAAsB,CAAC;CAkCzD"}
@@ -0,0 +1,87 @@
1
+ import { BaseFilesystemProvider } from '../shared/base';
2
+ import { CreateDirOptions, DownloadOptions, FileInfo, FileStats, FilesystemCapabilities, GoogleDriveOptions, ListOptions, ReadOptions, UploadOptions, WriteOptions } from '../shared/types';
3
+ /**
4
+ * Google Drive filesystem provider using the Drive API v3
5
+ *
6
+ * Supports three authentication modes:
7
+ * - OAuth2: clientId + clientSecret + refreshToken (auto-refreshes)
8
+ * - Service account: serviceAccountKey JSON string
9
+ * - Access token: short-lived token (no auto-refresh)
10
+ *
11
+ * Maps hierarchical paths to Google Drive file IDs via folder traversal
12
+ * with an in-memory TTL cache for performance.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const fs = new GoogleDriveProvider({
17
+ * type: 'gdrive',
18
+ * clientId: 'xxx',
19
+ * clientSecret: 'yyy',
20
+ * refreshToken: 'zzz',
21
+ * });
22
+ *
23
+ * await fs.write('documents/readme.txt', 'Hello');
24
+ * const content = await fs.read('documents/readme.txt');
25
+ * ```
26
+ */
27
+ export declare class GoogleDriveProvider extends BaseFilesystemProvider {
28
+ private options;
29
+ private drive;
30
+ private rootFolderId;
31
+ private pathCache;
32
+ private pathCacheTTL;
33
+ private pageSize;
34
+ constructor(options: GoogleDriveOptions);
35
+ /**
36
+ * Lazily initialize the Google Drive client on first use
37
+ */
38
+ private getDrive;
39
+ /**
40
+ * Resolve a hierarchical path like "folder/sub/file.txt" to a Drive file ID
41
+ * by walking each segment. Results are cached with a configurable TTL.
42
+ */
43
+ private resolvePathToId;
44
+ /**
45
+ * Resolve a path to an ID, throwing FileNotFoundError if it doesn't exist
46
+ */
47
+ private requireId;
48
+ /**
49
+ * Ensure all parent folders exist for a given path, creating them if needed.
50
+ * Returns the parent folder ID and the final segment name.
51
+ */
52
+ private ensureParents;
53
+ /**
54
+ * Invalidate cache entries that are prefixed by the given path
55
+ */
56
+ private invalidateCache;
57
+ /**
58
+ * Wrap a Drive API call and map HTTP errors to typed filesystem errors
59
+ */
60
+ private wrapApiCall;
61
+ /** Checks whether a non-trashed file or folder exists at the given path. */
62
+ exists(path: string): Promise<boolean>;
63
+ /**
64
+ * Read a file from Google Drive. Google Docs native types (Document,
65
+ * Spreadsheet, Presentation, Drawing) are automatically exported to a
66
+ * portable format (plain text, CSV, PDF, PNG respectively).
67
+ */
68
+ read(path: string, options?: ReadOptions): Promise<string | Buffer>;
69
+ /** Write content to Drive. Updates the file in-place if it already exists, otherwise creates it. */
70
+ write(path: string, content: string | Buffer, options?: WriteOptions): Promise<void>;
71
+ /** Moves the file to the Drive trash rather than permanently deleting it. */
72
+ delete(path: string): Promise<void>;
73
+ copy(sourcePath: string, destPath: string): Promise<void>;
74
+ /** Moves a file by updating its parent references (single API call, not copy+delete). */
75
+ move(sourcePath: string, destPath: string): Promise<void>;
76
+ createDirectory(path: string, options?: CreateDirOptions): Promise<void>;
77
+ /** Lists non-trashed children of a folder, with optional pagination via {@link GoogleDriveOptions.pageSize}. */
78
+ list(path: string, options?: ListOptions): Promise<FileInfo[]>;
79
+ /** Returns file metadata. Mode is synthetic (0o755 for folders, 0o644 for files); uid/gid are always 0. */
80
+ getStats(path: string): Promise<FileStats>;
81
+ getMimeType(path: string): Promise<string>;
82
+ upload(localPath: string, remotePath: string, _options?: UploadOptions): Promise<void>;
83
+ /** Downloads a file from Drive to the local filesystem, defaulting to the provider's cache directory. */
84
+ download(remotePath: string, localPath?: string, _options?: DownloadOptions): Promise<string>;
85
+ getCapabilities(): Promise<FilesystemCapabilities>;
86
+ }
87
+ //# sourceMappingURL=gdrive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gdrive.d.ts","sourceRoot":"","sources":["../../src/providers/gdrive.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,sBAAsB,EAE3B,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAEhB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AAsDzB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,mBAAoB,SAAQ,sBAAsB;IAOjD,OAAO,CAAC,OAAO;IAN3B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBAEL,OAAO,EAAE,kBAAkB;IAO/C;;OAEG;YACW,QAAQ;IAmDtB;;;OAGG;YACW,eAAe;IAoC7B;;OAEG;YACW,SAAS;IAMvB;;;OAGG;YACW,aAAa;IAsC3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAavB;;OAEG;YACW,WAAW;IA2CzB,4EAA4E;IACtE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK5C;;;;OAIG;IACG,IAAI,CACR,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;I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Options, UploadOptions, WriteOptions } from '../shared/types';
3
+ export declare class S3FilesystemProvider extends BaseFilesystemProvider {
4
+ private readonly options;
5
+ private readonly client;
6
+ private readonly bucket;
7
+ constructor(options: S3Options);
8
+ private normalizeS3Path;
9
+ private toDirectoryKey;
10
+ private isRootPath;
11
+ private toDirectoryStats;
12
+ private headDirectoryMarker;
13
+ private directoryHasChildren;
14
+ private getDefaultDownloadTarget;
15
+ private bodyToBuffer;
16
+ private head;
17
+ private toFileInfo;
18
+ exists(path: string): Promise<boolean>;
19
+ read(path: string, options?: ReadOptions): Promise<string | Buffer>;
20
+ write(path: string, content: string | Buffer, options?: WriteOptions): Promise<void>;
21
+ delete(path: string): Promise<void>;
22
+ copy(sourcePath: string, destPath: string): Promise<void>;
23
+ move(sourcePath: string, destPath: string): Promise<void>;
24
+ createDirectory(path: string, _options?: CreateDirOptions): Promise<void>;
25
+ list(path: string, options?: ListOptions): Promise<FileInfo[]>;
26
+ getStats(path: string): Promise<FileStats>;
27
+ getMimeType(path: string): Promise<string>;
28
+ upload(localPath: string, remotePath: string, _options?: UploadOptions): Promise<void>;
29
+ download(remotePath: string, localPath?: string, _options?: DownloadOptions): Promise<string>;
30
+ getCapabilities(): Promise<FilesystemCapabilities>;
31
+ }
32
+ //# sourceMappingURL=s3.d.ts.map