@interactive-inc/docs-client 1.0.19 → 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.
- package/.env.local +3 -0
- package/build/doc-file-system-BQAOBIO-.d.ts +337 -0
- package/build/file-system-json.d.ts +223 -0
- package/build/file-system-json.js +1043 -0
- package/build/file-system-mock.d.ts +92 -0
- package/build/file-system-mock.js +901 -0
- package/build/file-system-octokit.d.ts +173 -0
- package/build/file-system-octokit.js +1002 -0
- package/build/file-system.d.ts +117 -0
- package/build/file-system.js +537 -0
- package/build/index.d.ts +1006 -1292
- package/build/index.js +3032 -3722
- package/package.json +8 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { b as DocFileSystemReadInterface, a as DocPathSystem, c as DocFileSystemWriteInterface } from './doc-file-system-BQAOBIO-.js';
|
|
2
|
+
export { D as DocFileSystem, d as DocFileSystemInterface } from './doc-file-system-BQAOBIO-.js';
|
|
3
|
+
|
|
4
|
+
type Props$1 = {
|
|
5
|
+
basePath: string;
|
|
6
|
+
pathSystem?: DocPathSystem;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Read-only file system implementation
|
|
10
|
+
*/
|
|
11
|
+
declare class DocFileSystemRead implements DocFileSystemReadInterface {
|
|
12
|
+
protected readonly basePath: string;
|
|
13
|
+
protected readonly pathSystem: DocPathSystem;
|
|
14
|
+
constructor(props: Props$1);
|
|
15
|
+
/**
|
|
16
|
+
* Read file content at the specified path
|
|
17
|
+
*/
|
|
18
|
+
readFile(relativePath: string): Promise<string | null | Error>;
|
|
19
|
+
/**
|
|
20
|
+
* Get file name from path
|
|
21
|
+
*/
|
|
22
|
+
readFileName(relativePath: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get file extension from path
|
|
25
|
+
*/
|
|
26
|
+
readFileExtension(relativePath: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Get directory path where the file exists
|
|
29
|
+
*/
|
|
30
|
+
readFileDirectory(relativePath: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get list of entries in directory
|
|
33
|
+
*/
|
|
34
|
+
readDirectoryFileNames(relativePath?: string): Promise<string[] | Error>;
|
|
35
|
+
readDirectoryFilePaths(relativePath: string): Promise<string[] | Error>;
|
|
36
|
+
/**
|
|
37
|
+
* Check if path is a directory
|
|
38
|
+
*/
|
|
39
|
+
isDirectory(relativePath: string): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Check if path is a file
|
|
42
|
+
*/
|
|
43
|
+
isFile(relativePath: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if file or directory exists
|
|
46
|
+
*/
|
|
47
|
+
exists(relativePath: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if directory exists
|
|
50
|
+
*/
|
|
51
|
+
directoryExists(relativePath: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Check if file exists
|
|
54
|
+
*/
|
|
55
|
+
fileExists(relativePath: string): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Get base path
|
|
58
|
+
*/
|
|
59
|
+
getBasePath(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Convert relative path to absolute path
|
|
62
|
+
*/
|
|
63
|
+
resolve(relativePath: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Get file size in bytes
|
|
66
|
+
*/
|
|
67
|
+
getFileSize(relativePath: string): Promise<number | Error>;
|
|
68
|
+
/**
|
|
69
|
+
* Get file last modified time
|
|
70
|
+
*/
|
|
71
|
+
getFileModifiedTime(relativePath: string): Promise<Date | Error>;
|
|
72
|
+
/**
|
|
73
|
+
* Get file creation time
|
|
74
|
+
*/
|
|
75
|
+
getFileCreatedTime(relativePath: string): Promise<Date | Error>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type Props = {
|
|
79
|
+
basePath: string;
|
|
80
|
+
pathSystem?: DocPathSystem;
|
|
81
|
+
reader?: DocFileSystemReadInterface;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Write-only file system implementation
|
|
85
|
+
*/
|
|
86
|
+
declare class DocFileSystemWrite implements DocFileSystemWriteInterface {
|
|
87
|
+
protected readonly basePath: string;
|
|
88
|
+
protected readonly pathSystem: DocPathSystem;
|
|
89
|
+
private readonly reader?;
|
|
90
|
+
constructor(props: Props);
|
|
91
|
+
/**
|
|
92
|
+
* Write content to file at the specified path (creates directory if needed)
|
|
93
|
+
*/
|
|
94
|
+
writeFile(relativePath: string, content: string): Promise<Error | null>;
|
|
95
|
+
/**
|
|
96
|
+
* Delete file at the specified path
|
|
97
|
+
*/
|
|
98
|
+
deleteFile(relativePath: string): Promise<Error | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Create directory
|
|
101
|
+
*/
|
|
102
|
+
createDirectory(relativePath: string): Promise<Error | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Create directory if it doesn't exist
|
|
105
|
+
*/
|
|
106
|
+
ensureDirectoryExists(relativePath: string): Promise<Error | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Copy file
|
|
109
|
+
*/
|
|
110
|
+
copyFile(sourcePath: string, destinationPath: string): Promise<Error | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Move file
|
|
113
|
+
*/
|
|
114
|
+
moveFile(sourcePath: string, destinationPath: string): Promise<Error | null>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { DocFileSystemRead, DocFileSystemWrite };
|
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
// lib/modules/path-system/doc-path-system.ts
|
|
2
|
+
var DocPathSystem = class {
|
|
3
|
+
separator = "/";
|
|
4
|
+
/**
|
|
5
|
+
* Join paths
|
|
6
|
+
*/
|
|
7
|
+
join(...paths) {
|
|
8
|
+
const parts = [];
|
|
9
|
+
for (const path of paths) {
|
|
10
|
+
if (path === "") continue;
|
|
11
|
+
const segments = path.split(this.separator).filter(Boolean);
|
|
12
|
+
parts.push(...segments);
|
|
13
|
+
}
|
|
14
|
+
if (parts.length === 0) {
|
|
15
|
+
return ".";
|
|
16
|
+
}
|
|
17
|
+
const isAbsolute = paths[0]?.startsWith(this.separator);
|
|
18
|
+
const joined = parts.join(this.separator);
|
|
19
|
+
return isAbsolute ? `${this.separator}${joined}` : joined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get filename with extension
|
|
23
|
+
*/
|
|
24
|
+
basename(path, ext) {
|
|
25
|
+
const segments = path.split(this.separator);
|
|
26
|
+
const filename = segments[segments.length - 1] || "";
|
|
27
|
+
if (ext && filename.endsWith(ext)) {
|
|
28
|
+
return filename.slice(0, -ext.length);
|
|
29
|
+
}
|
|
30
|
+
return filename;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get directory name
|
|
34
|
+
*/
|
|
35
|
+
dirname(path) {
|
|
36
|
+
const segments = path.split(this.separator);
|
|
37
|
+
if (segments.length <= 1) {
|
|
38
|
+
return ".";
|
|
39
|
+
}
|
|
40
|
+
segments.pop();
|
|
41
|
+
const dir = segments.join(this.separator);
|
|
42
|
+
return dir || ".";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get extension
|
|
46
|
+
*/
|
|
47
|
+
extname(path) {
|
|
48
|
+
const basename = this.basename(path);
|
|
49
|
+
const lastDot = basename.lastIndexOf(".");
|
|
50
|
+
if (lastDot <= 0) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
return basename.slice(lastDot);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Calculate relative path
|
|
57
|
+
*/
|
|
58
|
+
relative(from, to) {
|
|
59
|
+
const fromSegments = from.split(this.separator).filter(Boolean);
|
|
60
|
+
const toSegments = to.split(this.separator).filter(Boolean);
|
|
61
|
+
let commonLength = 0;
|
|
62
|
+
for (let i = 0; i < Math.min(fromSegments.length, toSegments.length); i++) {
|
|
63
|
+
if (fromSegments[i] === toSegments[i]) {
|
|
64
|
+
commonLength++;
|
|
65
|
+
} else {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const upCount = fromSegments.length - commonLength;
|
|
70
|
+
const upSegments = Array(upCount).fill("..");
|
|
71
|
+
const downSegments = toSegments.slice(commonLength);
|
|
72
|
+
const segments = [...upSegments, ...downSegments];
|
|
73
|
+
return segments.length > 0 ? segments.join(this.separator) : ".";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert to absolute path
|
|
77
|
+
*/
|
|
78
|
+
resolve(...paths) {
|
|
79
|
+
let resolved = "";
|
|
80
|
+
for (const path of paths) {
|
|
81
|
+
if (path.startsWith(this.separator)) {
|
|
82
|
+
resolved = path;
|
|
83
|
+
} else if (path !== "") {
|
|
84
|
+
resolved = resolved ? this.join(resolved, path) : path;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return resolved || ".";
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Normalize path
|
|
91
|
+
*/
|
|
92
|
+
normalize(path) {
|
|
93
|
+
const isAbsolute = path.startsWith(this.separator);
|
|
94
|
+
const segments = path.split(this.separator).filter(Boolean);
|
|
95
|
+
const normalized = [];
|
|
96
|
+
for (const segment of segments) {
|
|
97
|
+
if (segment === "..") {
|
|
98
|
+
if (normalized.length > 0 && normalized[normalized.length - 1] !== "..") {
|
|
99
|
+
normalized.pop();
|
|
100
|
+
} else if (!isAbsolute) {
|
|
101
|
+
normalized.push("..");
|
|
102
|
+
}
|
|
103
|
+
} else if (segment !== ".") {
|
|
104
|
+
normalized.push(segment);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (normalized.length === 0) {
|
|
108
|
+
return isAbsolute ? this.separator : ".";
|
|
109
|
+
}
|
|
110
|
+
const result = normalized.join(this.separator);
|
|
111
|
+
return isAbsolute ? `${this.separator}${result}` : result;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if path is absolute
|
|
115
|
+
*/
|
|
116
|
+
isAbsolute(path) {
|
|
117
|
+
return path.startsWith(this.separator);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// lib/modules/file-system/doc-file-system-read.ts
|
|
122
|
+
import * as fs from "fs/promises";
|
|
123
|
+
var DocFileSystemRead = class {
|
|
124
|
+
basePath;
|
|
125
|
+
pathSystem;
|
|
126
|
+
constructor(props) {
|
|
127
|
+
this.basePath = props.basePath;
|
|
128
|
+
this.pathSystem = props.pathSystem ?? new DocPathSystem();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Read file content at the specified path
|
|
132
|
+
*/
|
|
133
|
+
async readFile(relativePath) {
|
|
134
|
+
try {
|
|
135
|
+
const exists = await this.exists(relativePath);
|
|
136
|
+
if (!exists) return null;
|
|
137
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
138
|
+
return await fs.readFile(fullPath, "utf-8");
|
|
139
|
+
} catch (error) {
|
|
140
|
+
return error instanceof Error ? error : new Error(`Failed to read file at ${relativePath}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get file name from path
|
|
145
|
+
*/
|
|
146
|
+
readFileName(relativePath) {
|
|
147
|
+
return this.pathSystem.basename(relativePath);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get file extension from path
|
|
151
|
+
*/
|
|
152
|
+
readFileExtension(relativePath) {
|
|
153
|
+
return this.pathSystem.extname(relativePath);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get directory path where the file exists
|
|
157
|
+
*/
|
|
158
|
+
readFileDirectory(relativePath) {
|
|
159
|
+
return this.pathSystem.dirname(relativePath);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get list of entries in directory
|
|
163
|
+
*/
|
|
164
|
+
async readDirectoryFileNames(relativePath = "") {
|
|
165
|
+
try {
|
|
166
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
167
|
+
return await fs.readdir(fullPath);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
return error instanceof Error ? error : new Error(`Failed to read directory at ${relativePath}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async readDirectoryFilePaths(relativePath) {
|
|
173
|
+
try {
|
|
174
|
+
const fileNames = await this.readDirectoryFileNames(relativePath);
|
|
175
|
+
if (fileNames instanceof Error) {
|
|
176
|
+
return fileNames;
|
|
177
|
+
}
|
|
178
|
+
return fileNames.map(
|
|
179
|
+
(fileName) => this.pathSystem.join(relativePath, fileName)
|
|
180
|
+
);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return error instanceof Error ? error : new Error(`Failed to read directory file paths at ${relativePath}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Check if path is a directory
|
|
187
|
+
*/
|
|
188
|
+
async isDirectory(relativePath) {
|
|
189
|
+
try {
|
|
190
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
191
|
+
const stats = await fs.stat(fullPath);
|
|
192
|
+
return stats.isDirectory();
|
|
193
|
+
} catch {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Check if path is a file
|
|
199
|
+
*/
|
|
200
|
+
async isFile(relativePath) {
|
|
201
|
+
try {
|
|
202
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
203
|
+
const stats = await fs.stat(fullPath);
|
|
204
|
+
return stats.isFile();
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Check if file or directory exists
|
|
211
|
+
*/
|
|
212
|
+
async exists(relativePath) {
|
|
213
|
+
try {
|
|
214
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
215
|
+
await fs.access(fullPath);
|
|
216
|
+
return true;
|
|
217
|
+
} catch {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if directory exists
|
|
223
|
+
*/
|
|
224
|
+
async directoryExists(relativePath) {
|
|
225
|
+
return this.isDirectory(relativePath);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Check if file exists
|
|
229
|
+
*/
|
|
230
|
+
async fileExists(relativePath) {
|
|
231
|
+
return this.isFile(relativePath);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Get base path
|
|
235
|
+
*/
|
|
236
|
+
getBasePath() {
|
|
237
|
+
return this.basePath;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Convert relative path to absolute path
|
|
241
|
+
*/
|
|
242
|
+
resolve(relativePath) {
|
|
243
|
+
return this.pathSystem.join(this.basePath, relativePath);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get file size in bytes
|
|
247
|
+
*/
|
|
248
|
+
async getFileSize(relativePath) {
|
|
249
|
+
try {
|
|
250
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
251
|
+
const stats = await fs.stat(fullPath);
|
|
252
|
+
return stats.size;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return error instanceof Error ? error : new Error(`Failed to get file size at ${relativePath}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get file last modified time
|
|
259
|
+
*/
|
|
260
|
+
async getFileModifiedTime(relativePath) {
|
|
261
|
+
try {
|
|
262
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
263
|
+
const stats = await fs.stat(fullPath);
|
|
264
|
+
return stats.mtime;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return error instanceof Error ? error : new Error(`Failed to get file modified time at ${relativePath}`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get file creation time
|
|
271
|
+
*/
|
|
272
|
+
async getFileCreatedTime(relativePath) {
|
|
273
|
+
try {
|
|
274
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
275
|
+
const stats = await fs.stat(fullPath);
|
|
276
|
+
return stats.birthtime;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
return error instanceof Error ? error : new Error(`Failed to get file created time at ${relativePath}`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// lib/modules/file-system/doc-file-system-write.ts
|
|
284
|
+
import * as fs2 from "fs/promises";
|
|
285
|
+
var DocFileSystemWrite = class {
|
|
286
|
+
basePath;
|
|
287
|
+
pathSystem;
|
|
288
|
+
reader;
|
|
289
|
+
constructor(props) {
|
|
290
|
+
this.basePath = props.basePath;
|
|
291
|
+
this.pathSystem = props.pathSystem ?? new DocPathSystem();
|
|
292
|
+
this.reader = props.reader;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Write content to file at the specified path (creates directory if needed)
|
|
296
|
+
*/
|
|
297
|
+
async writeFile(relativePath, content) {
|
|
298
|
+
try {
|
|
299
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
300
|
+
const dirPath = this.pathSystem.dirname(fullPath);
|
|
301
|
+
await fs2.mkdir(dirPath, { recursive: true });
|
|
302
|
+
await fs2.writeFile(fullPath, content, "utf-8");
|
|
303
|
+
return null;
|
|
304
|
+
} catch (error) {
|
|
305
|
+
return error instanceof Error ? error : new Error(`Failed to write file at ${relativePath}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Delete file at the specified path
|
|
310
|
+
*/
|
|
311
|
+
async deleteFile(relativePath) {
|
|
312
|
+
try {
|
|
313
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
314
|
+
await fs2.unlink(fullPath);
|
|
315
|
+
return null;
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return new Error(`Failed to delete file at ${relativePath}: ${error}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Create directory
|
|
322
|
+
*/
|
|
323
|
+
async createDirectory(relativePath) {
|
|
324
|
+
try {
|
|
325
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
326
|
+
await fs2.mkdir(fullPath, { recursive: true });
|
|
327
|
+
return null;
|
|
328
|
+
} catch (error) {
|
|
329
|
+
return error instanceof Error ? error : new Error(`Failed to create directory at ${relativePath}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Create directory if it doesn't exist
|
|
334
|
+
*/
|
|
335
|
+
async ensureDirectoryExists(relativePath) {
|
|
336
|
+
try {
|
|
337
|
+
if (this.reader) {
|
|
338
|
+
const exists = await this.reader.exists(relativePath);
|
|
339
|
+
if (exists) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const result = await this.createDirectory(relativePath);
|
|
344
|
+
if (result instanceof Error) {
|
|
345
|
+
return result;
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
} catch (error) {
|
|
349
|
+
return error instanceof Error ? error : new Error(`Failed to ensure directory exists at ${relativePath}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Copy file
|
|
354
|
+
*/
|
|
355
|
+
async copyFile(sourcePath, destinationPath) {
|
|
356
|
+
try {
|
|
357
|
+
const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
|
|
358
|
+
const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
|
|
359
|
+
await fs2.copyFile(sourceFullPath, destFullPath);
|
|
360
|
+
return null;
|
|
361
|
+
} catch (error) {
|
|
362
|
+
return error instanceof Error ? error : new Error(
|
|
363
|
+
`Failed to copy file from ${sourcePath} to ${destinationPath}`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Move file
|
|
369
|
+
*/
|
|
370
|
+
async moveFile(sourcePath, destinationPath) {
|
|
371
|
+
try {
|
|
372
|
+
const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
|
|
373
|
+
const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
|
|
374
|
+
await fs2.rename(sourceFullPath, destFullPath);
|
|
375
|
+
return null;
|
|
376
|
+
} catch (error) {
|
|
377
|
+
return error instanceof Error ? error : new Error(
|
|
378
|
+
`Failed to move file from ${sourcePath} to ${destinationPath}`
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// lib/modules/file-system/doc-file-system.ts
|
|
385
|
+
var DocFileSystem = class {
|
|
386
|
+
reader;
|
|
387
|
+
writer;
|
|
388
|
+
basePath;
|
|
389
|
+
pathSystem;
|
|
390
|
+
constructor(props) {
|
|
391
|
+
this.basePath = props.basePath;
|
|
392
|
+
this.pathSystem = props.pathSystem ?? new DocPathSystem();
|
|
393
|
+
this.reader = props.reader ?? new DocFileSystemRead({
|
|
394
|
+
basePath: this.basePath,
|
|
395
|
+
pathSystem: this.pathSystem
|
|
396
|
+
});
|
|
397
|
+
this.writer = props.writer ?? new DocFileSystemWrite({
|
|
398
|
+
basePath: this.basePath,
|
|
399
|
+
pathSystem: this.pathSystem,
|
|
400
|
+
reader: this.reader
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Read file content at the specified path
|
|
405
|
+
*/
|
|
406
|
+
async readFile(relativePath) {
|
|
407
|
+
return this.reader.readFile(relativePath);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Write content to file at the specified path (creates directory if needed)
|
|
411
|
+
*/
|
|
412
|
+
async writeFile(relativePath, content) {
|
|
413
|
+
return this.writer.writeFile(relativePath, content);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Delete file at the specified path
|
|
417
|
+
*/
|
|
418
|
+
async deleteFile(relativePath) {
|
|
419
|
+
return this.writer.deleteFile(relativePath);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Get file name from path
|
|
423
|
+
*/
|
|
424
|
+
readFileName(relativePath) {
|
|
425
|
+
return this.reader.readFileName(relativePath);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get file extension from path
|
|
429
|
+
*/
|
|
430
|
+
readFileExtension(relativePath) {
|
|
431
|
+
return this.reader.readFileExtension(relativePath);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get directory path where the file exists
|
|
435
|
+
*/
|
|
436
|
+
readFileDirectory(relativePath) {
|
|
437
|
+
return this.reader.readFileDirectory(relativePath);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Get list of entries in directory
|
|
441
|
+
*/
|
|
442
|
+
async readDirectoryFileNames(relativePath = "") {
|
|
443
|
+
return this.reader.readDirectoryFileNames(relativePath);
|
|
444
|
+
}
|
|
445
|
+
async readDirectoryFilePaths(relativePath) {
|
|
446
|
+
return this.reader.readDirectoryFilePaths(relativePath);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Check if path is a directory
|
|
450
|
+
*/
|
|
451
|
+
async isDirectory(relativePath) {
|
|
452
|
+
return this.reader.isDirectory(relativePath);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Check if path is a file
|
|
456
|
+
*/
|
|
457
|
+
async isFile(relativePath) {
|
|
458
|
+
return this.reader.isFile(relativePath);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Check if file or directory exists
|
|
462
|
+
*/
|
|
463
|
+
async exists(relativePath) {
|
|
464
|
+
return this.reader.exists(relativePath);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Check if directory exists
|
|
468
|
+
*/
|
|
469
|
+
async directoryExists(relativePath) {
|
|
470
|
+
return this.reader.directoryExists(relativePath);
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Check if file exists
|
|
474
|
+
*/
|
|
475
|
+
async fileExists(relativePath) {
|
|
476
|
+
return this.reader.fileExists(relativePath);
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Get base path
|
|
480
|
+
*/
|
|
481
|
+
getBasePath() {
|
|
482
|
+
return this.reader.getBasePath();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Convert relative path to absolute path
|
|
486
|
+
*/
|
|
487
|
+
resolve(relativePath) {
|
|
488
|
+
return this.reader.resolve(relativePath);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Create directory
|
|
492
|
+
*/
|
|
493
|
+
async createDirectory(relativePath) {
|
|
494
|
+
return this.writer.createDirectory(relativePath);
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Get file size in bytes
|
|
498
|
+
*/
|
|
499
|
+
async getFileSize(relativePath) {
|
|
500
|
+
return this.reader.getFileSize(relativePath);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Create directory if it doesn't exist
|
|
504
|
+
*/
|
|
505
|
+
async ensureDirectoryExists(relativePath) {
|
|
506
|
+
return this.writer.ensureDirectoryExists(relativePath);
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Copy file
|
|
510
|
+
*/
|
|
511
|
+
async copyFile(sourcePath, destinationPath) {
|
|
512
|
+
return this.writer.copyFile(sourcePath, destinationPath);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Move file
|
|
516
|
+
*/
|
|
517
|
+
async moveFile(sourcePath, destinationPath) {
|
|
518
|
+
return this.writer.moveFile(sourcePath, destinationPath);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Get file last modified time
|
|
522
|
+
*/
|
|
523
|
+
async getFileModifiedTime(relativePath) {
|
|
524
|
+
return this.reader.getFileModifiedTime(relativePath);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Get file creation time
|
|
528
|
+
*/
|
|
529
|
+
async getFileCreatedTime(relativePath) {
|
|
530
|
+
return this.reader.getFileCreatedTime(relativePath);
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
export {
|
|
534
|
+
DocFileSystem,
|
|
535
|
+
DocFileSystemRead,
|
|
536
|
+
DocFileSystemWrite
|
|
537
|
+
};
|