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