sandbox-fs 1.0.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.
- package/LICENSE +21 -0
- package/README.md +418 -0
- package/dist/FSModule.d.ts +153 -0
- package/dist/FSModule.d.ts.map +1 -0
- package/dist/FSModule.js +555 -0
- package/dist/FSModule.js.map +1 -0
- package/dist/PathMapper.d.ts +30 -0
- package/dist/PathMapper.d.ts.map +1 -0
- package/dist/PathMapper.js +122 -0
- package/dist/PathMapper.js.map +1 -0
- package/dist/PathModule.d.ts +69 -0
- package/dist/PathModule.d.ts.map +1 -0
- package/dist/PathModule.js +159 -0
- package/dist/PathModule.js.map +1 -0
- package/dist/ResourceTracker.d.ts +74 -0
- package/dist/ResourceTracker.d.ts.map +1 -0
- package/dist/ResourceTracker.js +175 -0
- package/dist/ResourceTracker.js.map +1 -0
- package/dist/VirtualFileSystem.d.ts +145 -0
- package/dist/VirtualFileSystem.d.ts.map +1 -0
- package/dist/VirtualFileSystem.js +155 -0
- package/dist/VirtualFileSystem.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/operations/newer.d.ts +36 -0
- package/dist/operations/newer.d.ts.map +1 -0
- package/dist/operations/newer.js +239 -0
- package/dist/operations/newer.js.map +1 -0
- package/dist/operations/read.d.ts +24 -0
- package/dist/operations/read.d.ts.map +1 -0
- package/dist/operations/read.js +313 -0
- package/dist/operations/read.js.map +1 -0
- package/dist/operations/symlink.d.ts +8 -0
- package/dist/operations/symlink.d.ts.map +1 -0
- package/dist/operations/symlink.js +33 -0
- package/dist/operations/symlink.js.map +1 -0
- package/dist/operations/write.d.ts +29 -0
- package/dist/operations/write.d.ts.map +1 -0
- package/dist/operations/write.js +191 -0
- package/dist/operations/write.js.map +1 -0
- package/dist/utils/ErrorFilter.d.ts +6 -0
- package/dist/utils/ErrorFilter.d.ts.map +1 -0
- package/dist/utils/ErrorFilter.js +57 -0
- package/dist/utils/ErrorFilter.js.map +1 -0
- package/dist/utils/callbackify.d.ts +9 -0
- package/dist/utils/callbackify.d.ts.map +1 -0
- package/dist/utils/callbackify.js +48 -0
- package/dist/utils/callbackify.js.map +1 -0
- package/dist/wrappers/VirtualDir.d.ts +34 -0
- package/dist/wrappers/VirtualDir.d.ts.map +1 -0
- package/dist/wrappers/VirtualDir.js +72 -0
- package/dist/wrappers/VirtualDir.js.map +1 -0
- package/dist/wrappers/VirtualDirent.d.ts +21 -0
- package/dist/wrappers/VirtualDirent.d.ts.map +1 -0
- package/dist/wrappers/VirtualDirent.js +50 -0
- package/dist/wrappers/VirtualDirent.js.map +1 -0
- package/example.js +95 -0
- package/example.ts +32 -0
- package/package.json +29 -0
- package/src/FSModule.ts +546 -0
- package/src/PathMapper.ts +102 -0
- package/src/PathModule.ts +142 -0
- package/src/ResourceTracker.ts +162 -0
- package/src/VirtualFileSystem.ts +172 -0
- package/src/index.ts +9 -0
- package/src/operations/newer.ts +223 -0
- package/src/operations/read.ts +319 -0
- package/src/operations/symlink.ts +31 -0
- package/src/operations/write.ts +189 -0
- package/src/utils/ErrorFilter.ts +57 -0
- package/src/utils/callbackify.ts +54 -0
- package/src/wrappers/VirtualDir.ts +84 -0
- package/src/wrappers/VirtualDirent.ts +60 -0
- package/test-data/example.txt +1 -0
- package/test-data/subdir/nested.txt +1 -0
- package/tsconfig.example.json +8 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,145 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualFileSystem.d.ts","sourceRoot":"","sources":["../src/VirtualFileSystem.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,eAAe,CAAkB;IAEzC;;;;;OAKG;gBACS,OAAO,EAAE,UAAU;IAK/B;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAIvC;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,kBAAkB,IAAI,GAAG;IAIzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oBAAoB,IAAI,GAAG;IAI3B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAEpB;CACF"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VirtualFileSystem = void 0;
|
|
4
|
+
const PathMapper_1 = require("./PathMapper");
|
|
5
|
+
const ResourceTracker_1 = require("./ResourceTracker");
|
|
6
|
+
const FSModule_1 = require("./FSModule");
|
|
7
|
+
const PathModule_1 = require("./PathModule");
|
|
8
|
+
/**
|
|
9
|
+
* A read-only virtual file system that maps Unix-style virtual paths
|
|
10
|
+
* to a real directory root.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const vfs = new VirtualFileSystem({ root: '/opt/data' });
|
|
15
|
+
* const fs = vfs.createNodeFSModule();
|
|
16
|
+
* const path = vfs.createNodePathModule();
|
|
17
|
+
*
|
|
18
|
+
* // Read a file (real path: /opt/data/file.txt)
|
|
19
|
+
* const content = fs.readFileSync('/file.txt', 'utf8');
|
|
20
|
+
*
|
|
21
|
+
* // Write operations are denied
|
|
22
|
+
* fs.writeFileSync('/file.txt', 'data'); // throws EACCES
|
|
23
|
+
*
|
|
24
|
+
* // Clean up when done
|
|
25
|
+
* vfs.close();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class VirtualFileSystem {
|
|
29
|
+
/**
|
|
30
|
+
* Create a new VirtualFileSystem instance
|
|
31
|
+
*
|
|
32
|
+
* @param options - Configuration options
|
|
33
|
+
* @throws Error if root path doesn't exist or is not a directory
|
|
34
|
+
*/
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.pathMapper = new PathMapper_1.PathMapper(options.root);
|
|
37
|
+
this.resourceTracker = new ResourceTracker_1.ResourceTracker();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert a virtual path to a real filesystem path
|
|
41
|
+
*
|
|
42
|
+
* @param virtualPath - Virtual path (Unix-style, starts with /)
|
|
43
|
+
* @returns Real filesystem path (platform-native)
|
|
44
|
+
* @throws Error if path traversal is detected
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const vfs = new VirtualFileSystem({ root: 'C:\\data' });
|
|
49
|
+
* vfs.toRealPath('/foo/bar.txt'); // Returns: C:\data\foo\bar.txt
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
toRealPath(virtualPath) {
|
|
53
|
+
return this.pathMapper.toRealPath(virtualPath);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert a real filesystem path to a virtual path
|
|
57
|
+
*
|
|
58
|
+
* @param realPath - Real filesystem path (platform-native)
|
|
59
|
+
* @returns Virtual path (Unix-style, starts with /)
|
|
60
|
+
* @throws Error if real path is outside VFS root
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const vfs = new VirtualFileSystem({ root: 'C:\\data' });
|
|
65
|
+
* vfs.toVirtualPath('C:\\data\\foo\\bar.txt'); // Returns: /foo/bar.txt
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
toVirtualPath(realPath) {
|
|
69
|
+
return this.pathMapper.toVirtualPath(realPath);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a Node.js fs-compatible module
|
|
73
|
+
*
|
|
74
|
+
* Returns an object that matches the Node.js fs module API.
|
|
75
|
+
* All read operations work normally, write operations return EACCES,
|
|
76
|
+
* and symlink operations return EACCES. Error messages have real paths
|
|
77
|
+
* filtered out and replaced with virtual paths.
|
|
78
|
+
*
|
|
79
|
+
* @returns An fs-compatible object with both callback and promise APIs
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const vfs = new VirtualFileSystem({ root: '/opt/data' });
|
|
84
|
+
* const fs = vfs.createNodeFSModule();
|
|
85
|
+
*
|
|
86
|
+
* // Callback API
|
|
87
|
+
* fs.readFile('/file.txt', 'utf8', (err, data) => {
|
|
88
|
+
* if (err) throw err;
|
|
89
|
+
* console.log(data);
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* // Promise API
|
|
93
|
+
* const data = await fs.promises.readFile('/file.txt', 'utf8');
|
|
94
|
+
*
|
|
95
|
+
* // Sync API
|
|
96
|
+
* const data = fs.readFileSync('/file.txt', 'utf8');
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
createNodeFSModule() {
|
|
100
|
+
return (0, FSModule_1.createFSModule)(this.pathMapper, this.resourceTracker);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a Node.js path-compatible module
|
|
104
|
+
*
|
|
105
|
+
* Returns an object that matches the Node.js path module API.
|
|
106
|
+
* All operations use Unix-style paths with forward slashes.
|
|
107
|
+
* The virtual current working directory is always '/'.
|
|
108
|
+
*
|
|
109
|
+
* @returns A path-compatible object
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const vfs = new VirtualFileSystem({ root: '/opt/data' });
|
|
114
|
+
* const path = vfs.createNodePathModule();
|
|
115
|
+
*
|
|
116
|
+
* path.resolve('.'); // Returns: /
|
|
117
|
+
* path.resolve('foo/bar.txt'); // Returns: /foo/bar.txt
|
|
118
|
+
* path.join('/foo', 'bar'); // Returns: /foo/bar
|
|
119
|
+
* path.sep; // Returns: /
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
createNodePathModule() {
|
|
123
|
+
return (0, PathModule_1.createPathModule)();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Close the VFS and release all resources
|
|
127
|
+
*
|
|
128
|
+
* Closes all tracked file descriptors, destroys all streams,
|
|
129
|
+
* and marks the VFS as closed. After calling close(), all
|
|
130
|
+
* subsequent fs operations will throw EBADF errors.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const vfs = new VirtualFileSystem({ root: '/opt/data' });
|
|
135
|
+
* const fs = vfs.createNodeFSModule();
|
|
136
|
+
*
|
|
137
|
+
* const fd = fs.openSync('/file.txt', 'r');
|
|
138
|
+
*
|
|
139
|
+
* vfs.close(); // Closes fd and all other resources
|
|
140
|
+
*
|
|
141
|
+
* fs.readFileSync('/file.txt'); // Throws EBADF
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
close() {
|
|
145
|
+
this.resourceTracker.dispose();
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check if the VFS has been closed
|
|
149
|
+
*/
|
|
150
|
+
get closed() {
|
|
151
|
+
return this.resourceTracker.closed;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.VirtualFileSystem = VirtualFileSystem;
|
|
155
|
+
//# sourceMappingURL=VirtualFileSystem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VirtualFileSystem.js","sourceRoot":"","sources":["../src/VirtualFileSystem.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,uDAAoD;AACpD,yCAA4C;AAC5C,6CAAgD;AAchD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,iBAAiB;IAI5B;;;;;OAKG;IACH,YAAY,OAAmB;QAC7B,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,eAAe,GAAG,IAAI,iCAAe,EAAE,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,WAAmB;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,QAAgB;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,kBAAkB;QAChB,OAAO,IAAA,yBAAc,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/D,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,oBAAoB;QAClB,OAAO,IAAA,6BAAgB,GAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK;QACH,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;IACrC,CAAC;CACF;AAtID,8CAsIC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACtF,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* sandbox-fs - A read-only virtual file system for Node.js
|
|
4
|
+
*
|
|
5
|
+
* Maps Unix-style virtual paths to a real directory root while preventing
|
|
6
|
+
* write operations and filtering real paths from error messages.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.default = exports.VirtualFileSystem = void 0;
|
|
10
|
+
var VirtualFileSystem_1 = require("./VirtualFileSystem");
|
|
11
|
+
Object.defineProperty(exports, "VirtualFileSystem", { enumerable: true, get: function () { return VirtualFileSystem_1.VirtualFileSystem; } });
|
|
12
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return VirtualFileSystem_1.VirtualFileSystem; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yDAAsF;AAA7E,sHAAA,iBAAiB,OAAA;AAAE,4GAAA,iBAAiB,OAAW"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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;
|
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AAe,EAAE,eAAe,IACnF,aAAa,MAAM,EAAE,UAAU,GAAG,KAAG,EAAE,CAAC,SAAS,CAwB1D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,IACvF,aAAa,MAAM,EAAE,SAAS,GAAG,EAAE,WAAW,GAAG,KAAG,IAAI,CAgBjE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,IACzF,aAAa,MAAM,EAAE,WAAW,GAAG,KAAG,IAAI,CAenD"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createGlobOperation = createGlobOperation;
|
|
37
|
+
exports.createStatfsOperation = createStatfsOperation;
|
|
38
|
+
exports.createCpOperation = createCpOperation;
|
|
39
|
+
exports.createOpenAsBlobOperation = createOpenAsBlobOperation;
|
|
40
|
+
exports.createReadvOperation = createReadvOperation;
|
|
41
|
+
exports.createWatchOperation = createWatchOperation;
|
|
42
|
+
exports.createWatchFileOperation = createWatchFileOperation;
|
|
43
|
+
exports.createUnwatchFileOperation = createUnwatchFileOperation;
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const ErrorFilter_1 = require("../utils/ErrorFilter");
|
|
46
|
+
/**
|
|
47
|
+
* Wrap an async operation with error filtering and closed check
|
|
48
|
+
*/
|
|
49
|
+
async function wrapOperation(operation, pathMapper, resourceTracker) {
|
|
50
|
+
resourceTracker.assertNotClosed();
|
|
51
|
+
try {
|
|
52
|
+
return await operation();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw (0, ErrorFilter_1.filterError)(error, pathMapper);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create access denied error for write operations
|
|
60
|
+
*/
|
|
61
|
+
function createEACCESError(syscall, path) {
|
|
62
|
+
const error = new Error(`${syscall}: operation not permitted, ${syscall} '${path}'`);
|
|
63
|
+
error.code = 'EACCES';
|
|
64
|
+
error.errno = -13;
|
|
65
|
+
error.syscall = syscall;
|
|
66
|
+
error.path = path;
|
|
67
|
+
return error;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* glob - Pattern matching (Node.js 22+)
|
|
71
|
+
*/
|
|
72
|
+
function createGlobOperation(pathMapper, resourceTracker) {
|
|
73
|
+
return async function* (pattern, options) {
|
|
74
|
+
resourceTracker.assertNotClosed();
|
|
75
|
+
try {
|
|
76
|
+
// Check if glob is available (Node.js 22+)
|
|
77
|
+
if (typeof fs.promises.glob !== 'function') {
|
|
78
|
+
throw new Error('glob is not supported in this Node.js version');
|
|
79
|
+
}
|
|
80
|
+
// Convert pattern to real path context
|
|
81
|
+
const realRoot = pathMapper.getRoot();
|
|
82
|
+
if (options?.signal) {
|
|
83
|
+
resourceTracker.registerAbortListener(options.signal, () => { });
|
|
84
|
+
}
|
|
85
|
+
// Execute glob in real path context
|
|
86
|
+
const realOptions = { ...options, cwd: realRoot };
|
|
87
|
+
const globIterator = fs.promises.glob(pattern, realOptions);
|
|
88
|
+
for await (const realPath of globIterator) {
|
|
89
|
+
try {
|
|
90
|
+
// Convert real path back to virtual path
|
|
91
|
+
const virtualPath = pathMapper.toVirtualPath(realPath);
|
|
92
|
+
yield virtualPath;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// Skip paths that can't be converted (outside VFS root)
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw (0, ErrorFilter_1.filterError)(error, pathMapper);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* statfs - File system statistics (Node.js 19+)
|
|
107
|
+
*/
|
|
108
|
+
function createStatfsOperation(pathMapper, resourceTracker) {
|
|
109
|
+
return async (virtualPath, options) => {
|
|
110
|
+
return wrapOperation(async () => {
|
|
111
|
+
// Check if statfs is available (Node.js 19+)
|
|
112
|
+
if (typeof fs.promises.statfs !== 'function') {
|
|
113
|
+
throw new Error('statfs is not supported in this Node.js version');
|
|
114
|
+
}
|
|
115
|
+
const realPath = pathMapper.toRealPath(virtualPath);
|
|
116
|
+
if (options?.signal) {
|
|
117
|
+
resourceTracker.registerAbortListener(options.signal, () => { });
|
|
118
|
+
}
|
|
119
|
+
return fs.promises.statfs(realPath, options);
|
|
120
|
+
}, pathMapper, resourceTracker);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* cp - Copy files/directories (read source only, write dest is denied)
|
|
125
|
+
*/
|
|
126
|
+
function createCpOperation(pathMapper, resourceTracker) {
|
|
127
|
+
return async (source, destination, options) => {
|
|
128
|
+
// Always deny - this is a write operation
|
|
129
|
+
throw createEACCESError('cp', destination);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* openAsBlob - Open file as Blob (Node.js 19+)
|
|
134
|
+
*/
|
|
135
|
+
function createOpenAsBlobOperation(pathMapper, resourceTracker) {
|
|
136
|
+
return async (virtualPath, options) => {
|
|
137
|
+
return wrapOperation(async () => {
|
|
138
|
+
// Check if openAsBlob is available (Node.js 19+)
|
|
139
|
+
if (typeof fs.openAsBlob !== 'function') {
|
|
140
|
+
throw new Error('openAsBlob is not supported in this Node.js version');
|
|
141
|
+
}
|
|
142
|
+
const realPath = pathMapper.toRealPath(virtualPath);
|
|
143
|
+
if (options?.signal) {
|
|
144
|
+
resourceTracker.registerAbortListener(options.signal, () => { });
|
|
145
|
+
}
|
|
146
|
+
return fs.openAsBlob(realPath, options);
|
|
147
|
+
}, pathMapper, resourceTracker);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* readv - Vector read (Node.js 13+)
|
|
152
|
+
*/
|
|
153
|
+
function createReadvOperation(pathMapper, resourceTracker) {
|
|
154
|
+
return async (fd, buffers, position) => {
|
|
155
|
+
return wrapOperation(async () => {
|
|
156
|
+
if (!resourceTracker.isTracked(fd)) {
|
|
157
|
+
const error = new Error('bad file descriptor');
|
|
158
|
+
error.code = 'EBADF';
|
|
159
|
+
error.errno = -9;
|
|
160
|
+
error.syscall = 'readv';
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
// Check if readv is available
|
|
164
|
+
if (typeof fs.promises.readv !== 'function') {
|
|
165
|
+
throw new Error('readv is not supported in this Node.js version');
|
|
166
|
+
}
|
|
167
|
+
return fs.promises.readv(fd, buffers, position);
|
|
168
|
+
}, pathMapper, resourceTracker);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* watch - Watch for file changes
|
|
173
|
+
*/
|
|
174
|
+
function createWatchOperation(pathMapper, resourceTracker) {
|
|
175
|
+
return (virtualPath, options) => {
|
|
176
|
+
resourceTracker.assertNotClosed();
|
|
177
|
+
try {
|
|
178
|
+
const realPath = pathMapper.toRealPath(virtualPath);
|
|
179
|
+
const watcher = fs.watch(realPath, options);
|
|
180
|
+
// Wrap error events to filter paths
|
|
181
|
+
const originalOn = watcher.on.bind(watcher);
|
|
182
|
+
watcher.on = function (event, listener) {
|
|
183
|
+
if (event === 'error') {
|
|
184
|
+
const wrappedListener = (error) => {
|
|
185
|
+
listener((0, ErrorFilter_1.filterError)(error, pathMapper));
|
|
186
|
+
};
|
|
187
|
+
return originalOn(event, wrappedListener);
|
|
188
|
+
}
|
|
189
|
+
return originalOn(event, listener);
|
|
190
|
+
};
|
|
191
|
+
return watcher;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw (0, ErrorFilter_1.filterError)(error, pathMapper);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* watchFile - Watch a file for changes
|
|
200
|
+
*/
|
|
201
|
+
function createWatchFileOperation(pathMapper, resourceTracker) {
|
|
202
|
+
return (virtualPath, options, listener) => {
|
|
203
|
+
resourceTracker.assertNotClosed();
|
|
204
|
+
try {
|
|
205
|
+
const realPath = pathMapper.toRealPath(virtualPath);
|
|
206
|
+
// Handle both signatures: (path, listener) and (path, options, listener)
|
|
207
|
+
if (typeof options === 'function') {
|
|
208
|
+
fs.watchFile(realPath, options);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
fs.watchFile(realPath, options, listener);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
throw (0, ErrorFilter_1.filterError)(error, pathMapper);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* unwatchFile - Stop watching a file
|
|
221
|
+
*/
|
|
222
|
+
function createUnwatchFileOperation(pathMapper, resourceTracker) {
|
|
223
|
+
return (virtualPath, listener) => {
|
|
224
|
+
resourceTracker.assertNotClosed();
|
|
225
|
+
try {
|
|
226
|
+
const realPath = pathMapper.toRealPath(virtualPath);
|
|
227
|
+
if (listener) {
|
|
228
|
+
fs.unwatchFile(realPath, listener);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
fs.unwatchFile(realPath);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
throw (0, ErrorFilter_1.filterError)(error, pathMapper);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=newer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newer.js","sourceRoot":"","sources":["../../src/operations/newer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,kDAmCC;AAKD,sDAiBC;AAKD,8CAKC;AAKD,8DAiBC;AAKD,oDAmBC;AAKD,oDAyBC;AAKD,4DAiBC;AAKD,gEAgBC;AA9ND,uCAAyB;AAGzB,sDAAmD;AAEnD;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,SAA2B,EAC3B,UAAsB,EACtB,eAAgC;IAEhC,eAAe,CAAC,eAAe,EAAE,CAAC;IAClC,IAAI,CAAC;QACH,OAAO,MAAM,SAA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AC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/operations/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA8BpD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,IAChF,aAAa,MAAM,EAAE,UAAU,GAAG,KAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAY5E;AAED,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,IAC/E,aAAa,MAAM,EAAE,UAAU,GAAG,KAAG,OAAO,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,CAW9F;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,IAC5E,aAAa,MAAM,EAAE,UAAU,GAAG,KAAG,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,CAkBrE;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,eAAe,EA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