@interactive-inc/docs-client 1.0.20 → 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/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 +1225 -2115
- package/build/index.js +3540 -5376
- package/package.json +6 -2
|
@@ -0,0 +1,901 @@
|
|
|
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
|
+
|
|
534
|
+
// lib/modules/file-system/doc-file-system-mock.ts
|
|
535
|
+
var mockDirectoryData = {
|
|
536
|
+
"docs/index.md": `---
|
|
537
|
+
icon: \u{1F4DA}
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
# Documentation
|
|
541
|
+
|
|
542
|
+
Welcome to the documentation!`,
|
|
543
|
+
"docs/guide/index.md": `---
|
|
544
|
+
icon: \u{1F4D6}
|
|
545
|
+
---
|
|
546
|
+
|
|
547
|
+
# Guide
|
|
548
|
+
|
|
549
|
+
This is a guide.`,
|
|
550
|
+
"docs/guide/getting-started.md": `# Getting Started
|
|
551
|
+
|
|
552
|
+
Let's get started!`,
|
|
553
|
+
"docs/guide/advanced.md": `# Advanced
|
|
554
|
+
|
|
555
|
+
Advanced topics here.`,
|
|
556
|
+
"docs/api/index.md": `---
|
|
557
|
+
icon: \u{1F527}
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
# API
|
|
561
|
+
|
|
562
|
+
API documentation.`,
|
|
563
|
+
"docs/api/reference.md": `# API Reference
|
|
564
|
+
|
|
565
|
+
Complete API reference.`
|
|
566
|
+
};
|
|
567
|
+
var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
568
|
+
files = /* @__PURE__ */ new Map();
|
|
569
|
+
_pathSystem;
|
|
570
|
+
_basePath;
|
|
571
|
+
constructor(props) {
|
|
572
|
+
super(props);
|
|
573
|
+
this._pathSystem = props.pathSystem;
|
|
574
|
+
this._basePath = props.basePath.endsWith("/") ? props.basePath.slice(0, -1) : props.basePath;
|
|
575
|
+
if (!props.skipDefaultFiles) {
|
|
576
|
+
this.setupTestFiles(mockDirectoryData);
|
|
577
|
+
}
|
|
578
|
+
Object.freeze(this);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* PathSystem accessor (for testing)
|
|
582
|
+
*/
|
|
583
|
+
getPathSystem() {
|
|
584
|
+
return this._pathSystem;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Normalize path using basePath
|
|
588
|
+
*/
|
|
589
|
+
normalizePath(filePath) {
|
|
590
|
+
if (filePath.startsWith(this._basePath)) {
|
|
591
|
+
return filePath;
|
|
592
|
+
}
|
|
593
|
+
const cleanPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
594
|
+
return `${this._basePath}/${cleanPath}`;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Create instance (mock data is automatically loaded)
|
|
598
|
+
*/
|
|
599
|
+
static create(basePath = "/test") {
|
|
600
|
+
const pathSystem = new DocPathSystem();
|
|
601
|
+
return new _DocFileSystemMock({ basePath, pathSystem });
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Factory method for testing
|
|
605
|
+
*/
|
|
606
|
+
static createWithFiles(props) {
|
|
607
|
+
const pathSystem = new DocPathSystem();
|
|
608
|
+
const basePath = props.basePath ?? "/test";
|
|
609
|
+
const fileSystem = new _DocFileSystemMock({
|
|
610
|
+
basePath,
|
|
611
|
+
pathSystem,
|
|
612
|
+
skipDefaultFiles: true
|
|
613
|
+
});
|
|
614
|
+
if (props.fileContents) {
|
|
615
|
+
const now = /* @__PURE__ */ new Date();
|
|
616
|
+
for (const [path, content] of Object.entries(props.fileContents)) {
|
|
617
|
+
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
618
|
+
const normalizedPath = path.startsWith(basePath) ? path : `${basePath}/${cleanPath}`;
|
|
619
|
+
fileSystem.files.set(normalizedPath, {
|
|
620
|
+
content,
|
|
621
|
+
modifiedTime: now,
|
|
622
|
+
createdTime: now,
|
|
623
|
+
size: new TextEncoder().encode(content).length
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return fileSystem;
|
|
628
|
+
}
|
|
629
|
+
async readFile(filePath) {
|
|
630
|
+
try {
|
|
631
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
632
|
+
const file = this.files.get(normalizedPath);
|
|
633
|
+
return file ? file.content : null;
|
|
634
|
+
} catch (error) {
|
|
635
|
+
return error instanceof Error ? error : new Error(`Failed to read file at ${filePath}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
async writeFile(filePath, content) {
|
|
639
|
+
try {
|
|
640
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
641
|
+
const now = /* @__PURE__ */ new Date();
|
|
642
|
+
const existing = this.files.get(normalizedPath);
|
|
643
|
+
this.files.set(normalizedPath, {
|
|
644
|
+
content,
|
|
645
|
+
modifiedTime: now,
|
|
646
|
+
createdTime: existing?.createdTime ?? now,
|
|
647
|
+
size: new TextEncoder().encode(content).length
|
|
648
|
+
});
|
|
649
|
+
return null;
|
|
650
|
+
} catch (error) {
|
|
651
|
+
return error instanceof Error ? error : new Error(`Failed to write file at ${filePath}`);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
async deleteFile(filePath) {
|
|
655
|
+
try {
|
|
656
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
657
|
+
this.files.delete(normalizedPath);
|
|
658
|
+
return null;
|
|
659
|
+
} catch (error) {
|
|
660
|
+
return new Error(`Failed to delete file at ${filePath}: ${error}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
async exists(filePath) {
|
|
664
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
665
|
+
if (this.files.has(normalizedPath)) {
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
const dirPath = normalizedPath.endsWith("/") ? normalizedPath : `${normalizedPath}/`;
|
|
669
|
+
for (const path of this.files.keys()) {
|
|
670
|
+
if (path.startsWith(dirPath)) {
|
|
671
|
+
return true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
async copyFile(source, destination) {
|
|
677
|
+
try {
|
|
678
|
+
const normalizedSource = this.normalizePath(source);
|
|
679
|
+
const normalizedDest = this.normalizePath(destination);
|
|
680
|
+
const file = this.files.get(normalizedSource);
|
|
681
|
+
if (!file) {
|
|
682
|
+
return new Error(`Source file not found: ${normalizedSource}`);
|
|
683
|
+
}
|
|
684
|
+
this.files.set(normalizedDest, {
|
|
685
|
+
...file,
|
|
686
|
+
createdTime: /* @__PURE__ */ new Date()
|
|
687
|
+
});
|
|
688
|
+
return null;
|
|
689
|
+
} catch (error) {
|
|
690
|
+
return error instanceof Error ? error : new Error(`Failed to copy file from ${source} to ${destination}`);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
async moveFile(source, destination) {
|
|
694
|
+
try {
|
|
695
|
+
const normalizedSource = this.normalizePath(source);
|
|
696
|
+
const normalizedDest = this.normalizePath(destination);
|
|
697
|
+
const file = this.files.get(normalizedSource);
|
|
698
|
+
if (!file) {
|
|
699
|
+
return new Error(`Source file not found: ${normalizedSource}`);
|
|
700
|
+
}
|
|
701
|
+
this.files.set(normalizedDest, file);
|
|
702
|
+
this.files.delete(normalizedSource);
|
|
703
|
+
return null;
|
|
704
|
+
} catch (error) {
|
|
705
|
+
return error instanceof Error ? error : new Error(`Failed to move file from ${source} to ${destination}`);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
async readDirectory(directoryPath) {
|
|
709
|
+
const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
|
|
710
|
+
const entries = /* @__PURE__ */ new Set();
|
|
711
|
+
for (const path of this.files.keys()) {
|
|
712
|
+
if (path.startsWith(dirPath)) {
|
|
713
|
+
const relativePath = path.slice(dirPath.length);
|
|
714
|
+
const firstSegment = relativePath.split("/")[0];
|
|
715
|
+
if (firstSegment) {
|
|
716
|
+
entries.add(firstSegment);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return Array.from(entries).sort();
|
|
721
|
+
}
|
|
722
|
+
async readDirectoryRecursive(directoryPath) {
|
|
723
|
+
const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
|
|
724
|
+
const files = [];
|
|
725
|
+
for (const path of this.files.keys()) {
|
|
726
|
+
if (path.startsWith(dirPath)) {
|
|
727
|
+
files.push(path);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return files.sort();
|
|
731
|
+
}
|
|
732
|
+
async readDirectoryFilePaths(directoryPath) {
|
|
733
|
+
try {
|
|
734
|
+
const normalizedDir = this.normalizePath(directoryPath);
|
|
735
|
+
const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
|
|
736
|
+
const files = [];
|
|
737
|
+
for (const path of this.files.keys()) {
|
|
738
|
+
if (path.startsWith(dirPath) && !path.slice(dirPath.length).includes("/")) {
|
|
739
|
+
const relativePath = path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
|
|
740
|
+
files.push(relativePath);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return files.sort();
|
|
744
|
+
} catch (error) {
|
|
745
|
+
return error instanceof Error ? error : new Error(`Failed to read directory file paths at ${directoryPath}`);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
async createDirectory(_directoryPath) {
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
async deleteDirectory(directoryPath) {
|
|
752
|
+
const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
|
|
753
|
+
for (const path of this.files.keys()) {
|
|
754
|
+
if (path.startsWith(dirPath)) {
|
|
755
|
+
this.files.delete(path);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
async getFileSize(filePath) {
|
|
760
|
+
try {
|
|
761
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
762
|
+
const file = this.files.get(normalizedPath);
|
|
763
|
+
if (!file) {
|
|
764
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
765
|
+
}
|
|
766
|
+
return file.size;
|
|
767
|
+
} catch (error) {
|
|
768
|
+
return error instanceof Error ? error : new Error(`Failed to get file size at ${filePath}`);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
async getFileModifiedTime(filePath) {
|
|
772
|
+
try {
|
|
773
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
774
|
+
const file = this.files.get(normalizedPath);
|
|
775
|
+
if (!file) {
|
|
776
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
777
|
+
}
|
|
778
|
+
return file.modifiedTime;
|
|
779
|
+
} catch (error) {
|
|
780
|
+
return error instanceof Error ? error : new Error(`Failed to get file modified time at ${filePath}`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
async getFileCreatedTime(filePath) {
|
|
784
|
+
try {
|
|
785
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
786
|
+
const file = this.files.get(normalizedPath);
|
|
787
|
+
if (!file) {
|
|
788
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
789
|
+
}
|
|
790
|
+
return file.createdTime;
|
|
791
|
+
} catch (error) {
|
|
792
|
+
return error instanceof Error ? error : new Error(`Failed to get file created time at ${filePath}`);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
async isDirectory(relativePath) {
|
|
796
|
+
const normalizedPath = this.normalizePath(relativePath);
|
|
797
|
+
const dirPath = normalizedPath.endsWith("/") ? normalizedPath : `${normalizedPath}/`;
|
|
798
|
+
for (const path of this.files.keys()) {
|
|
799
|
+
if (path.startsWith(dirPath)) {
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
async isFile(relativePath) {
|
|
806
|
+
const normalizedPath = this.normalizePath(relativePath);
|
|
807
|
+
return this.files.has(normalizedPath);
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Get list of entries in directory
|
|
811
|
+
*/
|
|
812
|
+
async readDirectoryFileNames(directoryPath = "") {
|
|
813
|
+
try {
|
|
814
|
+
const normalizedDir = directoryPath === "" ? this._basePath : this.normalizePath(directoryPath);
|
|
815
|
+
const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
|
|
816
|
+
const entries = /* @__PURE__ */ new Set();
|
|
817
|
+
for (const path of this.files.keys()) {
|
|
818
|
+
if (path.startsWith(dirPath)) {
|
|
819
|
+
const relativePath = path.slice(dirPath.length);
|
|
820
|
+
const firstSegment = relativePath.split("/")[0];
|
|
821
|
+
if (firstSegment) {
|
|
822
|
+
entries.add(firstSegment);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return Array.from(entries).sort();
|
|
827
|
+
} catch (error) {
|
|
828
|
+
return error instanceof Error ? error : new Error(`Failed to read directory at ${directoryPath}`);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Check if directory exists
|
|
833
|
+
*/
|
|
834
|
+
async directoryExists(relativePath) {
|
|
835
|
+
return this.isDirectory(relativePath);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Check if file exists
|
|
839
|
+
*/
|
|
840
|
+
async fileExists(relativePath) {
|
|
841
|
+
return this.isFile(relativePath);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Create directory if it doesn't exist
|
|
845
|
+
*/
|
|
846
|
+
async ensureDirectoryExists(_relativePath) {
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Clear all files
|
|
851
|
+
*/
|
|
852
|
+
clear() {
|
|
853
|
+
this.files.clear();
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Check file existence (for testing)
|
|
857
|
+
*/
|
|
858
|
+
hasFile(filePath) {
|
|
859
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
860
|
+
return this.files.has(normalizedPath);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Get file content (sync version, for testing)
|
|
864
|
+
*/
|
|
865
|
+
getFileContent(filePath) {
|
|
866
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
867
|
+
return this.files.get(normalizedPath)?.content;
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Get all file paths (for testing)
|
|
871
|
+
*/
|
|
872
|
+
getAllFilePaths() {
|
|
873
|
+
return Array.from(this.files.keys()).map((path) => {
|
|
874
|
+
return path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
|
|
875
|
+
}).sort();
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Get file count (for testing)
|
|
879
|
+
*/
|
|
880
|
+
getFileCount() {
|
|
881
|
+
return this.files.size;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Setup test data
|
|
885
|
+
*/
|
|
886
|
+
setupTestFiles(files) {
|
|
887
|
+
const now = /* @__PURE__ */ new Date();
|
|
888
|
+
for (const [path, content] of Object.entries(files)) {
|
|
889
|
+
const normalizedPath = this.normalizePath(path);
|
|
890
|
+
this.files.set(normalizedPath, {
|
|
891
|
+
content,
|
|
892
|
+
modifiedTime: now,
|
|
893
|
+
createdTime: now,
|
|
894
|
+
size: new TextEncoder().encode(content).length
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
export {
|
|
900
|
+
DocFileSystemMock
|
|
901
|
+
};
|