sandbox-fs 1.0.0 → 1.1.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 (60) hide show
  1. package/README.md +16 -0
  2. package/dist/FSModule.d.ts.map +1 -1
  3. package/dist/FSModule.js +81 -18
  4. package/dist/FSModule.js.map +1 -1
  5. package/dist/PathMapper.d.ts.map +1 -1
  6. package/dist/PathMapper.js +147 -41
  7. package/dist/PathMapper.js.map +1 -1
  8. package/dist/VirtualFileSystem.d.ts.map +1 -1
  9. package/dist/VirtualFileSystem.js +27 -1
  10. package/dist/VirtualFileSystem.js.map +1 -1
  11. package/dist/operations/newer.d.ts.map +1 -1
  12. package/dist/operations/newer.js +32 -3
  13. package/dist/operations/newer.js.map +1 -1
  14. package/dist/operations/read.d.ts.map +1 -1
  15. package/dist/operations/read.js +100 -14
  16. package/dist/operations/read.js.map +1 -1
  17. package/dist/utils/ErrorFilter.d.ts.map +1 -1
  18. package/dist/utils/ErrorFilter.js +21 -24
  19. package/dist/utils/ErrorFilter.js.map +1 -1
  20. package/dist/wrappers/VirtualDir.d.ts.map +1 -1
  21. package/dist/wrappers/VirtualDir.js +36 -35
  22. package/dist/wrappers/VirtualDir.js.map +1 -1
  23. package/dist/wrappers/VirtualDirent.d.ts.map +1 -1
  24. package/dist/wrappers/VirtualDirent.js +28 -9
  25. package/dist/wrappers/VirtualDirent.js.map +1 -1
  26. package/package.json +8 -4
  27. package/dist/FSModule.d.ts +0 -153
  28. package/dist/PathMapper.d.ts +0 -30
  29. package/dist/PathModule.d.ts +0 -69
  30. package/dist/ResourceTracker.d.ts +0 -74
  31. package/dist/VirtualFileSystem.d.ts +0 -145
  32. package/dist/index.d.ts +0 -9
  33. package/dist/operations/newer.d.ts +0 -36
  34. package/dist/operations/read.d.ts +0 -24
  35. package/dist/operations/symlink.d.ts +0 -8
  36. package/dist/operations/write.d.ts +0 -29
  37. package/dist/utils/ErrorFilter.d.ts +0 -6
  38. package/dist/utils/callbackify.d.ts +0 -9
  39. package/dist/wrappers/VirtualDir.d.ts +0 -34
  40. package/dist/wrappers/VirtualDirent.d.ts +0 -21
  41. package/example.js +0 -95
  42. package/example.ts +0 -32
  43. package/src/FSModule.ts +0 -546
  44. package/src/PathMapper.ts +0 -102
  45. package/src/PathModule.ts +0 -142
  46. package/src/ResourceTracker.ts +0 -162
  47. package/src/VirtualFileSystem.ts +0 -172
  48. package/src/index.ts +0 -9
  49. package/src/operations/newer.ts +0 -223
  50. package/src/operations/read.ts +0 -319
  51. package/src/operations/symlink.ts +0 -31
  52. package/src/operations/write.ts +0 -189
  53. package/src/utils/ErrorFilter.ts +0 -57
  54. package/src/utils/callbackify.ts +0 -54
  55. package/src/wrappers/VirtualDir.ts +0 -84
  56. package/src/wrappers/VirtualDirent.ts +0 -60
  57. package/test-data/example.txt +0 -1
  58. package/test-data/subdir/nested.txt +0 -1
  59. package/tsconfig.example.json +0 -8
  60. package/tsconfig.json +0 -21
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "sandbox-fs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A read-only virtual file system that maps Unix-style virtual paths to a real directory root",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "commonjs",
8
8
  "scripts": {
9
9
  "build": "tsc",
10
- "prepublishOnly": "npm run build"
10
+ "prepublishOnly": "npm run build",
11
+ "test": "npm run build && mocha -r ts-node/register 'test/**/*.spec.ts' --exit"
11
12
  },
12
13
  "keywords": [
13
14
  "filesystem",
@@ -17,13 +18,16 @@
17
18
  "readonly",
18
19
  "fs"
19
20
  ],
20
- "author": "",
21
+ "author": "Brian Choi",
21
22
  "license": "MIT",
22
23
  "engines": {
23
24
  "node": ">=18.0.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@types/node": "^18.0.0",
27
- "typescript": "^5.0.0"
28
+ "typescript": "^5.0.0",
29
+ "mocha": "^10.0.0",
30
+ "ts-node": "^10.0.0",
31
+ "@types/mocha": "^10.0.0"
28
32
  }
29
33
  }
@@ -1,153 +0,0 @@
1
- import * as fs from 'fs';
2
- import type { PathMapper } from './PathMapper';
3
- import type { ResourceTracker } from './ResourceTracker';
4
- /**
5
- * Create a Node.js fs-compatible module
6
- */
7
- export declare function createFSModule(pathMapper: PathMapper, resourceTracker: ResourceTracker): {
8
- promises: {
9
- readFile: (virtualPath: string, options?: any) => Promise<Buffer | string>;
10
- readdir: (virtualPath: string, options?: any) => Promise<string[] | Buffer[] | fs.Dirent[]>;
11
- stat: (virtualPath: string, options?: any) => Promise<fs.Stats>;
12
- lstat: (virtualPath: string, options?: any) => Promise<fs.Stats>;
13
- access: (virtualPath: string, mode?: number) => Promise<void>;
14
- realpath: (virtualPath: string, options?: any) => Promise<string | Buffer>;
15
- open: (virtualPath: string, flags?: string | number, mode?: number) => Promise<number>;
16
- read: (fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null) => Promise<{
17
- bytesRead: number;
18
- buffer: NodeJS.ArrayBufferView;
19
- }>;
20
- close: (fd: number) => Promise<void>;
21
- fstat: (fd: number, options?: any) => Promise<fs.Stats>;
22
- opendir: (virtualPath: string, options?: any) => Promise<import("./wrappers/VirtualDir").VirtualDir>;
23
- exists: (virtualPath: string) => Promise<boolean>;
24
- writeFile: (path: string, data: any, options?: any) => Promise<void>;
25
- appendFile: (path: string, data: any, options?: any) => Promise<void>;
26
- mkdir: (path: string, options?: any) => Promise<void | string>;
27
- rmdir: (path: string, options?: any) => Promise<void>;
28
- rm: (path: string, options?: any) => Promise<void>;
29
- unlink: (path: string) => Promise<void>;
30
- rename: (oldPath: string, newPath: string) => Promise<void>;
31
- copyFile: (src: string, dest: string, mode?: number) => Promise<void>;
32
- truncate: (path: string, len?: number) => Promise<void>;
33
- ftruncate: (fd: number, len?: number) => Promise<void>;
34
- chmod: (path: string, mode: string | number) => Promise<void>;
35
- fchmod: (fd: number, mode: string | number) => Promise<void>;
36
- lchmod: (path: string, mode: string | number) => Promise<void>;
37
- chown: (path: string, uid: number, gid: number) => Promise<void>;
38
- fchown: (fd: number, uid: number, gid: number) => Promise<void>;
39
- lchown: (path: string, uid: number, gid: number) => Promise<void>;
40
- utimes: (path: string, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
41
- futimes: (fd: number, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
42
- lutimes: (path: string, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
43
- write: (fd: number, buffer: any, offset?: any, length?: any, position?: any) => Promise<any>;
44
- writev: (fd: number, buffers: NodeJS.ArrayBufferView[], position?: number) => Promise<any>;
45
- fsync: (fd: number) => Promise<void>;
46
- fdatasync: (fd: number) => Promise<void>;
47
- symlink: (target: string, path: string, type?: string) => Promise<void>;
48
- link: (existingPath: string, newPath: string) => Promise<void>;
49
- readlink: (path: string, options?: any) => Promise<string | Buffer>;
50
- glob: (pattern: string, options?: any) => AsyncIterableIterator<string>;
51
- statfs: (virtualPath: string, options?: any) => Promise<fs.StatsFsBase<any>>;
52
- cp: (source: string, destination: string, options?: any) => Promise<void>;
53
- openAsBlob: (virtualPath: string, options?: any) => Promise<Blob>;
54
- readv: (fd: number, buffers: NodeJS.ArrayBufferView[], position?: number) => Promise<number>;
55
- };
56
- constants: typeof fs.constants;
57
- Stats: typeof fs.Stats;
58
- Dirent: typeof fs.Dirent;
59
- ReadStream: typeof fs.ReadStream;
60
- WriteStream: typeof fs.WriteStream;
61
- watch: (virtualPath: string, options?: any) => fs.FSWatcher;
62
- watchFile: (virtualPath: string, options: any, listener?: any) => void;
63
- unwatchFile: (virtualPath: string, listener?: any) => void;
64
- createReadStream: (virtualPath: string, options?: any) => fs.ReadStream;
65
- createWriteStream: (path: string, options?: any) => never;
66
- readFileSync: (path: string, options?: any) => NonSharedBuffer;
67
- readdirSync: (path: string, options?: any) => string[];
68
- statSync: (path: string, options?: any) => fs.Stats;
69
- lstatSync: (path: string, options?: any) => fs.Stats;
70
- accessSync: (path: string, mode?: number) => void;
71
- realpathSync: (path: string, options?: any) => string;
72
- openSync: (path: string, flags?: string | number, mode?: number) => number;
73
- readSync: (fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null) => number;
74
- closeSync: (fd: number) => void;
75
- fstatSync: (fd: number, options?: any) => fs.Stats;
76
- opendirSync: (path: string, options?: any) => any;
77
- existsSync: (path: string) => boolean;
78
- writeFileSync: (path: string) => never;
79
- appendFileSync: (path: string) => never;
80
- mkdirSync: (path: string) => never;
81
- rmdirSync: (path: string) => never;
82
- rmSync: (path: string) => never;
83
- unlinkSync: (path: string) => never;
84
- renameSync: (oldPath: string) => never;
85
- copyFileSync: (src: string, dest: string) => never;
86
- truncateSync: (path: string) => never;
87
- ftruncateSync: (fd: number) => never;
88
- chmodSync: (path: string) => never;
89
- fchmodSync: (fd: number) => never;
90
- lchmodSync: (path: string) => never;
91
- chownSync: (path: string) => never;
92
- fchownSync: (fd: number) => never;
93
- lchownSync: (path: string) => never;
94
- utimesSync: (path: string) => never;
95
- futimesSync: (fd: number) => never;
96
- lutimesSync: (path: string) => never;
97
- writeSync: (fd: number) => never;
98
- writevSync: (fd: number) => never;
99
- fsyncSync: (fd: number) => never;
100
- fdatasyncSync: (fd: number) => never;
101
- symlinkSync: (target: string, path: string) => never;
102
- linkSync: (existingPath: string, newPath: string) => never;
103
- readlinkSync: (path: string) => never;
104
- cpSync: (source: string, destination: string) => never;
105
- statfsSync: (path: string, options?: any) => fs.StatsFs;
106
- readvSync: (fd: number, buffers: NodeJS.ArrayBufferView[], position?: number) => any;
107
- readFile: (virtualPath: string, options: any, args_2: (err: Error | null, result?: string | Buffer<ArrayBufferLike> | undefined) => void) => void;
108
- readdir: (virtualPath: string, options: any, args_2: (err: Error | null, result?: string[] | Buffer<ArrayBufferLike>[] | fs.Dirent<string>[] | undefined) => void) => void;
109
- stat: (virtualPath: string, options: any, args_2: (err: Error | null, result?: fs.Stats | undefined) => void) => void;
110
- lstat: (virtualPath: string, options: any, args_2: (err: Error | null, result?: fs.Stats | undefined) => void) => void;
111
- access: (virtualPath: string, mode: number | undefined, args_2: (err: Error | null) => void) => void;
112
- realpath: (virtualPath: string, options: any, args_2: (err: Error | null, result?: string | Buffer<ArrayBufferLike> | undefined) => void) => void;
113
- open: (virtualPath: string, flags: string | number | undefined, mode: number | undefined, args_3: (err: Error | null, result?: number | undefined) => void) => void;
114
- read: (fd: number, buffer: NodeJS.ArrayBufferView<ArrayBufferLike>, offset: number, length: number, position: number | null, args_5: (err: Error | null, result?: {
115
- bytesRead: number;
116
- buffer: NodeJS.ArrayBufferView;
117
- } | undefined) => void) => void;
118
- close: (fd: number, args_1: (err: Error | null) => void) => void;
119
- fstat: (fd: number, options: any, args_2: (err: Error | null, result?: fs.Stats | undefined) => void) => void;
120
- opendir: (virtualPath: string, options: any, args_2: (err: Error | null, result?: import("./wrappers/VirtualDir").VirtualDir | undefined) => void) => void;
121
- exists: (path: string, callback: (exists: boolean) => void) => void;
122
- writeFile: (path: string, data: any, options: any, args_3: (err: Error | null) => void) => void;
123
- appendFile: (path: string, data: any, options: any, args_3: (err: Error | null) => void) => void;
124
- mkdir: (path: string, options: any, args_2: (err: Error | null, result?: string | void | undefined) => void) => void;
125
- rmdir: (path: string, options: any, args_2: (err: Error | null) => void) => void;
126
- rm: (path: string, options: any, args_2: (err: Error | null) => void) => void;
127
- unlink: (path: string, args_1: (err: Error | null) => void) => void;
128
- rename: (oldPath: string, newPath: string, args_2: (err: Error | null) => void) => void;
129
- copyFile: (src: string, dest: string, mode: number | undefined, args_3: (err: Error | null) => void) => void;
130
- truncate: (path: string, len: number | undefined, args_2: (err: Error | null) => void) => void;
131
- ftruncate: (fd: number, len: number | undefined, args_2: (err: Error | null) => void) => void;
132
- chmod: (path: string, mode: string | number, args_2: (err: Error | null) => void) => void;
133
- fchmod: (fd: number, mode: string | number, args_2: (err: Error | null) => void) => void;
134
- lchmod: (path: string, mode: string | number, args_2: (err: Error | null) => void) => void;
135
- chown: (path: string, uid: number, gid: number, args_3: (err: Error | null) => void) => void;
136
- fchown: (fd: number, uid: number, gid: number, args_3: (err: Error | null) => void) => void;
137
- lchown: (path: string, uid: number, gid: number, args_3: (err: Error | null) => void) => void;
138
- utimes: (path: string, atime: string | number | Date, mtime: string | number | Date, args_3: (err: Error | null) => void) => void;
139
- futimes: (fd: number, atime: string | number | Date, mtime: string | number | Date, args_3: (err: Error | null) => void) => void;
140
- lutimes: (path: string, atime: string | number | Date, mtime: string | number | Date, args_3: (err: Error | null) => void) => void;
141
- write: (fd: number, buffer: any, offset: any, length: any, position: any, args_5: (err: Error | null, result?: any) => void) => void;
142
- writev: (fd: number, buffers: NodeJS.ArrayBufferView<ArrayBufferLike>[], position: number | undefined, args_3: (err: Error | null, result?: any) => void) => void;
143
- fsync: (fd: number, args_1: (err: Error | null) => void) => void;
144
- fdatasync: (fd: number, args_1: (err: Error | null) => void) => void;
145
- symlink: (target: string, path: string, type: string | undefined, args_3: (err: Error | null) => void) => void;
146
- link: (existingPath: string, newPath: string, args_2: (err: Error | null) => void) => void;
147
- readlink: (path: string, options: any, args_2: (err: Error | null, result?: string | Buffer<ArrayBufferLike> | undefined) => void) => void;
148
- statfs: (virtualPath: string, options: any, args_2: (err: Error | null, result?: fs.StatsFsBase<any> | undefined) => void) => void;
149
- cp: (source: string, destination: string, options: any, args_3: (err: Error | null) => void) => void;
150
- openAsBlob: (virtualPath: string, options: any, args_2: (err: Error | null, result?: Blob | undefined) => void) => void;
151
- readv: (fd: number, buffers: NodeJS.ArrayBufferView<ArrayBufferLike>[], position: number | undefined, args_3: (err: Error | null, result?: number | undefined) => void) => void;
152
- };
153
- //# sourceMappingURL=FSModule.d.ts.map
@@ -1,30 +0,0 @@
1
- /**
2
- * Handles conversion between virtual Unix-style paths and real platform-native paths
3
- */
4
- export declare class PathMapper {
5
- private readonly normalizedRoot;
6
- constructor(rootPath: string);
7
- /**
8
- * Get the normalized root path
9
- */
10
- getRoot(): string;
11
- /**
12
- * Convert a virtual path (Unix-style with forward slashes) to a real platform-native path
13
- * @param virtualPath - Virtual path starting with /
14
- * @returns Real absolute path
15
- * @throws Error if path traversal is detected
16
- */
17
- toRealPath(virtualPath: string): string;
18
- /**
19
- * Convert a real platform-native path to a virtual Unix-style path
20
- * @param realPath - Real absolute path
21
- * @returns Virtual path starting with /
22
- * @throws Error if real path is not within VFS root
23
- */
24
- toVirtualPath(realPath: string): string;
25
- /**
26
- * Check if a real path is within the VFS root
27
- */
28
- isWithinRoot(realPath: string): boolean;
29
- }
30
- //# sourceMappingURL=PathMapper.d.ts.map
@@ -1,69 +0,0 @@
1
- import * as path from 'path';
2
- /**
3
- * Creates a path module that operates in virtual path space
4
- * All paths use Unix-style forward slashes
5
- * Fixed virtual CWD of '/'
6
- */
7
- export declare function createPathModule(): {
8
- /**
9
- * Normalize a path, reducing '..' and '.' parts
10
- */
11
- normalize(p: string): string;
12
- /**
13
- * Join all path segments together and normalize the result
14
- */
15
- join(...paths: string[]): string;
16
- /**
17
- * Resolve a sequence of paths to an absolute path
18
- */
19
- resolve(...paths: string[]): string;
20
- /**
21
- * Return the relative path from 'from' to 'to'
22
- */
23
- relative(from: string, to: string): string;
24
- /**
25
- * Return the directory name of a path
26
- */
27
- dirname(p: string): string;
28
- /**
29
- * Return the last portion of a path
30
- */
31
- basename(p: string, ext?: string): string;
32
- /**
33
- * Return the extension of the path
34
- */
35
- extname(p: string): string;
36
- /**
37
- * Parse a path into an object
38
- */
39
- parse(p: string): path.ParsedPath;
40
- /**
41
- * Format a path object into a string
42
- */
43
- format(pathObject: path.FormatInputPathObject): string;
44
- /**
45
- * Check if a path is absolute
46
- */
47
- isAbsolute(p: string): boolean;
48
- /**
49
- * Convert path to namespaced path (Windows-only, no-op in virtual space)
50
- */
51
- toNamespacedPath(p: string): string;
52
- /**
53
- * Path segment separator (always / in virtual space)
54
- */
55
- sep: string;
56
- /**
57
- * Path delimiter (always : in virtual space)
58
- */
59
- delimiter: string;
60
- /**
61
- * POSIX-specific methods (same as main module in virtual space)
62
- */
63
- posix: any;
64
- /**
65
- * Windows-specific methods (same as main module in virtual space)
66
- */
67
- win32: any;
68
- };
69
- //# sourceMappingURL=PathModule.d.ts.map
@@ -1,74 +0,0 @@
1
- import { Readable, Writable } from 'stream';
2
- /**
3
- * Information about a tracked file descriptor
4
- */
5
- export interface FDInfo {
6
- fd: number;
7
- virtualPath: string;
8
- realPath: string;
9
- flags: string | number;
10
- mode?: number;
11
- isStream: boolean;
12
- }
13
- /**
14
- * Manages lifecycle of file descriptors and streams to prevent resource leaks
15
- * and ensure proper cleanup when VFS is closed
16
- */
17
- export declare class ResourceTracker {
18
- private fdMap;
19
- private streams;
20
- private abortControllers;
21
- private _closed;
22
- /**
23
- * Check if the VFS has been closed
24
- */
25
- get closed(): boolean;
26
- /**
27
- * Assert that the VFS is not closed, throwing EBADF if it is
28
- */
29
- assertNotClosed(): void;
30
- /**
31
- * Track a file descriptor
32
- */
33
- trackFD(fd: number, info: Omit<FDInfo, 'fd'>): void;
34
- /**
35
- * Get information about a tracked file descriptor
36
- */
37
- getFD(fd: number): FDInfo | undefined;
38
- /**
39
- * Check if a file descriptor is tracked
40
- */
41
- isTracked(fd: number): boolean;
42
- /**
43
- * Untrack a file descriptor (when closed)
44
- */
45
- untrackFD(fd: number): FDInfo | undefined;
46
- /**
47
- * Track a stream
48
- */
49
- trackStream(stream: Readable | Writable): void;
50
- /**
51
- * Untrack a stream (when closed)
52
- */
53
- untrackStream(stream: Readable | Writable): void;
54
- /**
55
- * Register an AbortSignal listener for cleanup
56
- */
57
- registerAbortListener(signal: AbortSignal | undefined, cleanup: () => void): void;
58
- /**
59
- * Dispose all tracked resources and mark as closed
60
- */
61
- dispose(): void;
62
- /**
63
- * Get all tracked file descriptors (for debugging)
64
- */
65
- getAllFDs(): FDInfo[];
66
- /**
67
- * Get count of tracked resources
68
- */
69
- getResourceCount(): {
70
- fds: number;
71
- streams: number;
72
- };
73
- }
74
- //# sourceMappingURL=ResourceTracker.d.ts.map
@@ -1,145 +0,0 @@
1
- /**
2
- * Options for creating a VirtualFileSystem
3
- */
4
- export interface VFSOptions {
5
- /**
6
- * The real filesystem path to use as the VFS root.
7
- * Can be a Windows path (C:\data) or Unix path (/opt/data).
8
- * All virtual paths will be mapped relative to this root.
9
- */
10
- root: string;
11
- }
12
- /**
13
- * A read-only virtual file system that maps Unix-style virtual paths
14
- * to a real directory root.
15
- *
16
- * @example
17
- * ```typescript
18
- * const vfs = new VirtualFileSystem({ root: '/opt/data' });
19
- * const fs = vfs.createNodeFSModule();
20
- * const path = vfs.createNodePathModule();
21
- *
22
- * // Read a file (real path: /opt/data/file.txt)
23
- * const content = fs.readFileSync('/file.txt', 'utf8');
24
- *
25
- * // Write operations are denied
26
- * fs.writeFileSync('/file.txt', 'data'); // throws EACCES
27
- *
28
- * // Clean up when done
29
- * vfs.close();
30
- * ```
31
- */
32
- export declare class VirtualFileSystem {
33
- private pathMapper;
34
- private resourceTracker;
35
- /**
36
- * Create a new VirtualFileSystem instance
37
- *
38
- * @param options - Configuration options
39
- * @throws Error if root path doesn't exist or is not a directory
40
- */
41
- constructor(options: VFSOptions);
42
- /**
43
- * Convert a virtual path to a real filesystem path
44
- *
45
- * @param virtualPath - Virtual path (Unix-style, starts with /)
46
- * @returns Real filesystem path (platform-native)
47
- * @throws Error if path traversal is detected
48
- *
49
- * @example
50
- * ```typescript
51
- * const vfs = new VirtualFileSystem({ root: 'C:\\data' });
52
- * vfs.toRealPath('/foo/bar.txt'); // Returns: C:\data\foo\bar.txt
53
- * ```
54
- */
55
- toRealPath(virtualPath: string): string;
56
- /**
57
- * Convert a real filesystem path to a virtual path
58
- *
59
- * @param realPath - Real filesystem path (platform-native)
60
- * @returns Virtual path (Unix-style, starts with /)
61
- * @throws Error if real path is outside VFS root
62
- *
63
- * @example
64
- * ```typescript
65
- * const vfs = new VirtualFileSystem({ root: 'C:\\data' });
66
- * vfs.toVirtualPath('C:\\data\\foo\\bar.txt'); // Returns: /foo/bar.txt
67
- * ```
68
- */
69
- toVirtualPath(realPath: string): string;
70
- /**
71
- * Create a Node.js fs-compatible module
72
- *
73
- * Returns an object that matches the Node.js fs module API.
74
- * All read operations work normally, write operations return EACCES,
75
- * and symlink operations return EACCES. Error messages have real paths
76
- * filtered out and replaced with virtual paths.
77
- *
78
- * @returns An fs-compatible object with both callback and promise APIs
79
- *
80
- * @example
81
- * ```typescript
82
- * const vfs = new VirtualFileSystem({ root: '/opt/data' });
83
- * const fs = vfs.createNodeFSModule();
84
- *
85
- * // Callback API
86
- * fs.readFile('/file.txt', 'utf8', (err, data) => {
87
- * if (err) throw err;
88
- * console.log(data);
89
- * });
90
- *
91
- * // Promise API
92
- * const data = await fs.promises.readFile('/file.txt', 'utf8');
93
- *
94
- * // Sync API
95
- * const data = fs.readFileSync('/file.txt', 'utf8');
96
- * ```
97
- */
98
- createNodeFSModule(): any;
99
- /**
100
- * Create a Node.js path-compatible module
101
- *
102
- * Returns an object that matches the Node.js path module API.
103
- * All operations use Unix-style paths with forward slashes.
104
- * The virtual current working directory is always '/'.
105
- *
106
- * @returns A path-compatible object
107
- *
108
- * @example
109
- * ```typescript
110
- * const vfs = new VirtualFileSystem({ root: '/opt/data' });
111
- * const path = vfs.createNodePathModule();
112
- *
113
- * path.resolve('.'); // Returns: /
114
- * path.resolve('foo/bar.txt'); // Returns: /foo/bar.txt
115
- * path.join('/foo', 'bar'); // Returns: /foo/bar
116
- * path.sep; // Returns: /
117
- * ```
118
- */
119
- createNodePathModule(): any;
120
- /**
121
- * Close the VFS and release all resources
122
- *
123
- * Closes all tracked file descriptors, destroys all streams,
124
- * and marks the VFS as closed. After calling close(), all
125
- * subsequent fs operations will throw EBADF errors.
126
- *
127
- * @example
128
- * ```typescript
129
- * const vfs = new VirtualFileSystem({ root: '/opt/data' });
130
- * const fs = vfs.createNodeFSModule();
131
- *
132
- * const fd = fs.openSync('/file.txt', 'r');
133
- *
134
- * vfs.close(); // Closes fd and all other resources
135
- *
136
- * fs.readFileSync('/file.txt'); // Throws EBADF
137
- * ```
138
- */
139
- close(): void;
140
- /**
141
- * Check if the VFS has been closed
142
- */
143
- get closed(): boolean;
144
- }
145
- //# sourceMappingURL=VirtualFileSystem.d.ts.map
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * sandbox-fs - A read-only virtual file system for Node.js
3
- *
4
- * Maps Unix-style virtual paths to a real directory root while preventing
5
- * write operations and filtering real paths from error messages.
6
- */
7
- export { VirtualFileSystem, VirtualFileSystem as default } from './VirtualFileSystem';
8
- export type { VFSOptions } from './VirtualFileSystem';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1,36 +0,0 @@
1
- import * as fs from 'fs';
2
- import type { PathMapper } from '../PathMapper';
3
- import type { ResourceTracker } from '../ResourceTracker';
4
- /**
5
- * glob - Pattern matching (Node.js 22+)
6
- */
7
- export declare function createGlobOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (pattern: string, options?: any) => AsyncIterableIterator<string>;
8
- /**
9
- * statfs - File system statistics (Node.js 19+)
10
- */
11
- export declare function createStatfsOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<fs.StatsFsBase<any>>;
12
- /**
13
- * cp - Copy files/directories (read source only, write dest is denied)
14
- */
15
- export declare function createCpOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (source: string, destination: string, options?: any) => Promise<void>;
16
- /**
17
- * openAsBlob - Open file as Blob (Node.js 19+)
18
- */
19
- export declare function createOpenAsBlobOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<Blob>;
20
- /**
21
- * readv - Vector read (Node.js 13+)
22
- */
23
- export declare function createReadvOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (fd: number, buffers: NodeJS.ArrayBufferView[], position?: number) => Promise<number>;
24
- /**
25
- * watch - Watch for file changes
26
- */
27
- export declare function createWatchOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => fs.FSWatcher;
28
- /**
29
- * watchFile - Watch a file for changes
30
- */
31
- export declare function createWatchFileOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options: any, listener?: any) => void;
32
- /**
33
- * unwatchFile - Stop watching a file
34
- */
35
- export declare function createUnwatchFileOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, listener?: any) => void;
36
- //# sourceMappingURL=newer.d.ts.map
@@ -1,24 +0,0 @@
1
- import * as fs from 'fs';
2
- import type { PathMapper } from '../PathMapper';
3
- import type { ResourceTracker } from '../ResourceTracker';
4
- import { VirtualDir } from '../wrappers/VirtualDir';
5
- /**
6
- * Read file operations
7
- */
8
- export declare function createReadFileOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<Buffer | string>;
9
- export declare function createReaddirOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<string[] | Buffer[] | fs.Dirent[]>;
10
- export declare function createStatOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<fs.Stats>;
11
- export declare function createLstatOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<fs.Stats>;
12
- export declare function createAccessOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, mode?: number) => Promise<void>;
13
- export declare function createRealpathOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<string | Buffer>;
14
- export declare function createOpenOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, flags?: string | number, mode?: number) => Promise<number>;
15
- export declare function createReadOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (fd: number, buffer: NodeJS.ArrayBufferView, offset: number, length: number, position: number | null) => Promise<{
16
- bytesRead: number;
17
- buffer: NodeJS.ArrayBufferView;
18
- }>;
19
- export declare function createCloseOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (fd: number) => Promise<void>;
20
- export declare function createFstatOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (fd: number, options?: any) => Promise<fs.Stats>;
21
- export declare function createOpendirOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => Promise<VirtualDir>;
22
- export declare function createExistsOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string) => Promise<boolean>;
23
- export declare function createCreateReadStreamOperation(pathMapper: PathMapper, resourceTracker: ResourceTracker): (virtualPath: string, options?: any) => fs.ReadStream;
24
- //# sourceMappingURL=read.d.ts.map
@@ -1,8 +0,0 @@
1
- /**
2
- * All symlink operations return EACCES (access denied)
3
- * This module provides all symlink-related fs operations
4
- */
5
- export declare function createSymlinkOperation(): (target: string, path: string, type?: string) => Promise<void>;
6
- export declare function createLinkOperation(): (existingPath: string, newPath: string) => Promise<void>;
7
- export declare function createReadlinkOperation(): (path: string, options?: any) => Promise<string | Buffer>;
8
- //# sourceMappingURL=symlink.d.ts.map
@@ -1,29 +0,0 @@
1
- /**
2
- * All write operations return EACCES (access denied)
3
- * This module provides all write-related fs operations
4
- */
5
- export declare function createWriteFileOperation(): (path: string, data: any, options?: any) => Promise<void>;
6
- export declare function createAppendFileOperation(): (path: string, data: any, options?: any) => Promise<void>;
7
- export declare function createMkdirOperation(): (path: string, options?: any) => Promise<void | string>;
8
- export declare function createRmdirOperation(): (path: string, options?: any) => Promise<void>;
9
- export declare function createRmOperation(): (path: string, options?: any) => Promise<void>;
10
- export declare function createUnlinkOperation(): (path: string) => Promise<void>;
11
- export declare function createRenameOperation(): (oldPath: string, newPath: string) => Promise<void>;
12
- export declare function createCopyFileOperation(): (src: string, dest: string, mode?: number) => Promise<void>;
13
- export declare function createTruncateOperation(): (path: string, len?: number) => Promise<void>;
14
- export declare function createFtruncateOperation(): (fd: number, len?: number) => Promise<void>;
15
- export declare function createChmodOperation(): (path: string, mode: string | number) => Promise<void>;
16
- export declare function createFchmodOperation(): (fd: number, mode: string | number) => Promise<void>;
17
- export declare function createLchmodOperation(): (path: string, mode: string | number) => Promise<void>;
18
- export declare function createChownOperation(): (path: string, uid: number, gid: number) => Promise<void>;
19
- export declare function createFchownOperation(): (fd: number, uid: number, gid: number) => Promise<void>;
20
- export declare function createLchownOperation(): (path: string, uid: number, gid: number) => Promise<void>;
21
- export declare function createUtimesOperation(): (path: string, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
22
- export declare function createFutimesOperation(): (fd: number, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
23
- export declare function createLutimesOperation(): (path: string, atime: string | number | Date, mtime: string | number | Date) => Promise<void>;
24
- export declare function createWriteOperation(): (fd: number, buffer: any, offset?: any, length?: any, position?: any) => Promise<any>;
25
- export declare function createWritevOperation(): (fd: number, buffers: NodeJS.ArrayBufferView[], position?: number) => Promise<any>;
26
- export declare function createCreateWriteStreamOperation(): (path: string, options?: any) => never;
27
- export declare function createFsyncOperation(): (fd: number) => Promise<void>;
28
- export declare function createFdatasyncOperation(): (fd: number) => Promise<void>;
29
- //# sourceMappingURL=write.d.ts.map
@@ -1,6 +0,0 @@
1
- import type { PathMapper } from "../PathMapper";
2
- /**
3
- * Filter error messages to replace real paths with virtual paths
4
- */
5
- export declare function filterError(error: Error, pathMapper: PathMapper): Error;
6
- //# sourceMappingURL=ErrorFilter.d.ts.map
@@ -1,9 +0,0 @@
1
- /**
2
- * Convert a promise-based function to a callback-based function
3
- */
4
- export declare function callbackify<T extends any[], R>(fn: (...args: T) => Promise<R>): (...args: [...T, (err: Error | null, result?: R) => void]) => void;
5
- /**
6
- * Callbackify for void-returning promises
7
- */
8
- export declare function callbackifyVoid<T extends any[]>(fn: (...args: T) => Promise<void>): (...args: [...T, (err: Error | null) => void]) => void;
9
- //# sourceMappingURL=callbackify.d.ts.map