@interactive-inc/docs-client 1.0.1 → 1.0.3
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/index.d.ts +72 -66
- package/build/index.js +391 -128
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -1878,6 +1878,9 @@ var DocFileRelationReference = class {
|
|
|
1878
1878
|
}
|
|
1879
1879
|
async read() {
|
|
1880
1880
|
const files = await this.readFiles();
|
|
1881
|
+
if (files instanceof Error) {
|
|
1882
|
+
return files;
|
|
1883
|
+
}
|
|
1881
1884
|
return new DocRelationValue({
|
|
1882
1885
|
path: this.path,
|
|
1883
1886
|
files: files.map((value) => value.toJson())
|
|
@@ -1892,9 +1895,15 @@ var DocFileRelationReference = class {
|
|
|
1892
1895
|
return [];
|
|
1893
1896
|
}
|
|
1894
1897
|
const filePaths = await this.fileSystem.readDirectoryFilePaths(this.path);
|
|
1898
|
+
if (filePaths instanceof Error) {
|
|
1899
|
+
return filePaths;
|
|
1900
|
+
}
|
|
1895
1901
|
const files = [];
|
|
1896
1902
|
for (const filePath of filePaths) {
|
|
1897
1903
|
const file = await this.readFile(filePath);
|
|
1904
|
+
if (file instanceof Error) {
|
|
1905
|
+
return file;
|
|
1906
|
+
}
|
|
1898
1907
|
if (file === null) continue;
|
|
1899
1908
|
files.push(file);
|
|
1900
1909
|
}
|
|
@@ -1908,6 +1917,9 @@ var DocFileRelationReference = class {
|
|
|
1908
1917
|
return null;
|
|
1909
1918
|
}
|
|
1910
1919
|
const content = await this.fileSystem.readFile(filePath);
|
|
1920
|
+
if (content instanceof Error) {
|
|
1921
|
+
return content;
|
|
1922
|
+
}
|
|
1911
1923
|
if (content === null) {
|
|
1912
1924
|
return null;
|
|
1913
1925
|
}
|
|
@@ -1940,6 +1952,9 @@ var DocFileRelationReference = class {
|
|
|
1940
1952
|
*/
|
|
1941
1953
|
async readSlugs() {
|
|
1942
1954
|
const files = await this.readFiles();
|
|
1955
|
+
if (files instanceof Error) {
|
|
1956
|
+
return files;
|
|
1957
|
+
}
|
|
1943
1958
|
return files.map((file) => file.id);
|
|
1944
1959
|
}
|
|
1945
1960
|
/**
|
|
@@ -1947,6 +1962,9 @@ var DocFileRelationReference = class {
|
|
|
1947
1962
|
*/
|
|
1948
1963
|
async count() {
|
|
1949
1964
|
const files = await this.readFiles();
|
|
1965
|
+
if (files instanceof Error) {
|
|
1966
|
+
return files;
|
|
1967
|
+
}
|
|
1950
1968
|
return files.length;
|
|
1951
1969
|
}
|
|
1952
1970
|
/**
|
|
@@ -1954,6 +1972,9 @@ var DocFileRelationReference = class {
|
|
|
1954
1972
|
*/
|
|
1955
1973
|
async isEmpty() {
|
|
1956
1974
|
const count = await this.count();
|
|
1975
|
+
if (count instanceof Error) {
|
|
1976
|
+
return count;
|
|
1977
|
+
}
|
|
1957
1978
|
return count === 0;
|
|
1958
1979
|
}
|
|
1959
1980
|
};
|
|
@@ -3178,7 +3199,7 @@ schema: {}
|
|
|
3178
3199
|
${yamlStr}
|
|
3179
3200
|
---
|
|
3180
3201
|
|
|
3181
|
-
${this.
|
|
3202
|
+
${this.toMarkdownText()}`;
|
|
3182
3203
|
}
|
|
3183
3204
|
/**
|
|
3184
3205
|
* Output in JSON format
|
|
@@ -3273,6 +3294,9 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3273
3294
|
}
|
|
3274
3295
|
async read() {
|
|
3275
3296
|
const content = await this.fileSystem.readFile(this.filePath);
|
|
3297
|
+
if (content instanceof Error) {
|
|
3298
|
+
return content;
|
|
3299
|
+
}
|
|
3276
3300
|
if (content === null) {
|
|
3277
3301
|
const dirPath = this.pathSystem.dirname(this.filePath);
|
|
3278
3302
|
const dirName = this.pathSystem.basename(dirPath);
|
|
@@ -3330,14 +3354,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3330
3354
|
* Write content to file
|
|
3331
3355
|
*/
|
|
3332
3356
|
async writeContent(content) {
|
|
3333
|
-
await this.fileSystem.writeFile(this.filePath, content);
|
|
3357
|
+
return await this.fileSystem.writeFile(this.filePath, content);
|
|
3334
3358
|
}
|
|
3335
3359
|
/**
|
|
3336
3360
|
* Write entity
|
|
3337
3361
|
*/
|
|
3338
3362
|
async write(entity) {
|
|
3339
3363
|
const content = entity.content.toText();
|
|
3340
|
-
await this.fileSystem.writeFile(this.filePath, content);
|
|
3364
|
+
return await this.fileSystem.writeFile(this.filePath, content);
|
|
3341
3365
|
}
|
|
3342
3366
|
/**
|
|
3343
3367
|
* Create new file with default content
|
|
@@ -3350,7 +3374,13 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3350
3374
|
"",
|
|
3351
3375
|
`Please describe the overview of ${dirName} here.`
|
|
3352
3376
|
].join("\n");
|
|
3353
|
-
await this.fileSystem.writeFile(
|
|
3377
|
+
const writeResult = await this.fileSystem.writeFile(
|
|
3378
|
+
this.filePath,
|
|
3379
|
+
defaultContent
|
|
3380
|
+
);
|
|
3381
|
+
if (writeResult instanceof Error) {
|
|
3382
|
+
return writeResult;
|
|
3383
|
+
}
|
|
3354
3384
|
return null;
|
|
3355
3385
|
}
|
|
3356
3386
|
/**
|
|
@@ -3367,6 +3397,9 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3367
3397
|
}
|
|
3368
3398
|
async relations() {
|
|
3369
3399
|
const indexFile = await this.read();
|
|
3400
|
+
if (indexFile instanceof Error) {
|
|
3401
|
+
return indexFile;
|
|
3402
|
+
}
|
|
3370
3403
|
const schema = indexFile.content.meta().schema();
|
|
3371
3404
|
if (!schema) {
|
|
3372
3405
|
return [];
|
|
@@ -3391,10 +3424,14 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3391
3424
|
}
|
|
3392
3425
|
async readRelations() {
|
|
3393
3426
|
const relations = await this.relations();
|
|
3427
|
+
if (relations instanceof Error) {
|
|
3428
|
+
return relations;
|
|
3429
|
+
}
|
|
3394
3430
|
const files = [];
|
|
3395
3431
|
for (const relation of relations) {
|
|
3396
3432
|
const entity = await relation.read();
|
|
3397
3433
|
if (entity === null) continue;
|
|
3434
|
+
if (entity instanceof Error) continue;
|
|
3398
3435
|
files.push(entity);
|
|
3399
3436
|
}
|
|
3400
3437
|
return files;
|
|
@@ -3428,7 +3465,13 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3428
3465
|
archiveDirectoryName,
|
|
3429
3466
|
fileName
|
|
3430
3467
|
);
|
|
3431
|
-
await this.fileSystem.moveFile(
|
|
3468
|
+
const moveResult = await this.fileSystem.moveFile(
|
|
3469
|
+
this.filePath,
|
|
3470
|
+
archivePath
|
|
3471
|
+
);
|
|
3472
|
+
if (moveResult instanceof Error) {
|
|
3473
|
+
throw moveResult;
|
|
3474
|
+
}
|
|
3432
3475
|
return new _DocFileIndexReference({
|
|
3433
3476
|
path: archivePath,
|
|
3434
3477
|
fileSystem: this.fileSystem,
|
|
@@ -3451,7 +3494,13 @@ var DocFileIndexReference = class _DocFileIndexReference {
|
|
|
3451
3494
|
this.pathSystem.dirname(dirPath),
|
|
3452
3495
|
fileName
|
|
3453
3496
|
);
|
|
3454
|
-
await this.fileSystem.moveFile(
|
|
3497
|
+
const moveResult = await this.fileSystem.moveFile(
|
|
3498
|
+
this.filePath,
|
|
3499
|
+
restorePath
|
|
3500
|
+
);
|
|
3501
|
+
if (moveResult instanceof Error) {
|
|
3502
|
+
throw moveResult;
|
|
3503
|
+
}
|
|
3455
3504
|
return new _DocFileIndexReference({
|
|
3456
3505
|
path: restorePath,
|
|
3457
3506
|
fileSystem: this.fileSystem,
|
|
@@ -3507,9 +3556,15 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
3507
3556
|
}
|
|
3508
3557
|
async read() {
|
|
3509
3558
|
const content = await this.fileSystem.readFile(this.path);
|
|
3559
|
+
if (content instanceof Error) {
|
|
3560
|
+
return content;
|
|
3561
|
+
}
|
|
3510
3562
|
const actualPath = this.path;
|
|
3511
3563
|
if (content === null) {
|
|
3512
3564
|
const archivedContent = await this.fileSystem.readFile(this.archivedPath);
|
|
3565
|
+
if (archivedContent instanceof Error) {
|
|
3566
|
+
return archivedContent;
|
|
3567
|
+
}
|
|
3513
3568
|
if (archivedContent !== null) {
|
|
3514
3569
|
const contentValue2 = DocFileMdContentValue.fromMarkdown(
|
|
3515
3570
|
archivedContent,
|
|
@@ -3569,7 +3624,10 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
3569
3624
|
*/
|
|
3570
3625
|
async write(entity) {
|
|
3571
3626
|
const content = entity.content.toText();
|
|
3572
|
-
await this.fileSystem.writeFile(this.path, content);
|
|
3627
|
+
const writeResult = await this.fileSystem.writeFile(this.path, content);
|
|
3628
|
+
if (writeResult instanceof Error) {
|
|
3629
|
+
return writeResult;
|
|
3630
|
+
}
|
|
3573
3631
|
return null;
|
|
3574
3632
|
}
|
|
3575
3633
|
async writeText(text) {
|
|
@@ -3597,13 +3655,13 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
3597
3655
|
* Copy file
|
|
3598
3656
|
*/
|
|
3599
3657
|
async copyTo(destinationPath) {
|
|
3600
|
-
await this.fileSystem.copyFile(this.path, destinationPath);
|
|
3658
|
+
return await this.fileSystem.copyFile(this.path, destinationPath);
|
|
3601
3659
|
}
|
|
3602
3660
|
/**
|
|
3603
3661
|
* Move file
|
|
3604
3662
|
*/
|
|
3605
3663
|
async moveTo(destinationPath) {
|
|
3606
|
-
await this.fileSystem.moveFile(this.path, destinationPath);
|
|
3664
|
+
return await this.fileSystem.moveFile(this.path, destinationPath);
|
|
3607
3665
|
}
|
|
3608
3666
|
/**
|
|
3609
3667
|
* Move file to archive and return new reference
|
|
@@ -3616,7 +3674,10 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
3616
3674
|
archiveDirectoryName,
|
|
3617
3675
|
fileName
|
|
3618
3676
|
);
|
|
3619
|
-
await this.moveTo(archivePath);
|
|
3677
|
+
const moveResult = await this.moveTo(archivePath);
|
|
3678
|
+
if (moveResult instanceof Error) {
|
|
3679
|
+
throw moveResult;
|
|
3680
|
+
}
|
|
3620
3681
|
return new _DocFileMdReference({
|
|
3621
3682
|
path: archivePath,
|
|
3622
3683
|
fileSystem: this.fileSystem,
|
|
@@ -3639,7 +3700,10 @@ var DocFileMdReference = class _DocFileMdReference {
|
|
|
3639
3700
|
this.pathSystem.dirname(dirPath),
|
|
3640
3701
|
fileName
|
|
3641
3702
|
);
|
|
3642
|
-
await this.moveTo(restorePath);
|
|
3703
|
+
const moveResult = await this.moveTo(restorePath);
|
|
3704
|
+
if (moveResult instanceof Error) {
|
|
3705
|
+
throw moveResult;
|
|
3706
|
+
}
|
|
3643
3707
|
return new _DocFileMdReference({
|
|
3644
3708
|
path: restorePath,
|
|
3645
3709
|
fileSystem: this.fileSystem,
|
|
@@ -3902,6 +3966,9 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3902
3966
|
}
|
|
3903
3967
|
async read() {
|
|
3904
3968
|
const content = await this.fileSystem.readFile(this.path);
|
|
3969
|
+
if (content instanceof Error) {
|
|
3970
|
+
return content;
|
|
3971
|
+
}
|
|
3905
3972
|
if (content === null) {
|
|
3906
3973
|
return new Error(`File not found at ${this.path}.`);
|
|
3907
3974
|
}
|
|
@@ -3937,19 +4004,19 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3937
4004
|
* Write content to file
|
|
3938
4005
|
*/
|
|
3939
4006
|
async writeContent(content) {
|
|
3940
|
-
await this.fileSystem.writeFile(this.path, content);
|
|
4007
|
+
return await this.fileSystem.writeFile(this.path, content);
|
|
3941
4008
|
}
|
|
3942
4009
|
/**
|
|
3943
4010
|
* Write entity
|
|
3944
4011
|
*/
|
|
3945
4012
|
async write(entity) {
|
|
3946
|
-
await this.fileSystem.writeFile(this.path, entity.value.content);
|
|
4013
|
+
return await this.fileSystem.writeFile(this.path, entity.value.content);
|
|
3947
4014
|
}
|
|
3948
4015
|
/**
|
|
3949
4016
|
* Write raw content
|
|
3950
4017
|
*/
|
|
3951
4018
|
async writeRaw(content) {
|
|
3952
|
-
await this.fileSystem.writeFile(this.path, content);
|
|
4019
|
+
return await this.fileSystem.writeFile(this.path, content);
|
|
3953
4020
|
}
|
|
3954
4021
|
/**
|
|
3955
4022
|
* Delete file
|
|
@@ -3967,13 +4034,13 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
3967
4034
|
* Copy file
|
|
3968
4035
|
*/
|
|
3969
4036
|
async copyTo(destinationPath) {
|
|
3970
|
-
await this.fileSystem.copyFile(this.path, destinationPath);
|
|
4037
|
+
return await this.fileSystem.copyFile(this.path, destinationPath);
|
|
3971
4038
|
}
|
|
3972
4039
|
/**
|
|
3973
4040
|
* Move file
|
|
3974
4041
|
*/
|
|
3975
4042
|
async moveTo(destinationPath) {
|
|
3976
|
-
await this.fileSystem.moveFile(this.path, destinationPath);
|
|
4043
|
+
return await this.fileSystem.moveFile(this.path, destinationPath);
|
|
3977
4044
|
}
|
|
3978
4045
|
/**
|
|
3979
4046
|
* Get file size in bytes
|
|
@@ -4004,7 +4071,10 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
4004
4071
|
archiveDirectoryName,
|
|
4005
4072
|
fileName
|
|
4006
4073
|
);
|
|
4007
|
-
await this.moveTo(archivePath);
|
|
4074
|
+
const moveResult = await this.moveTo(archivePath);
|
|
4075
|
+
if (moveResult instanceof Error) {
|
|
4076
|
+
throw moveResult;
|
|
4077
|
+
}
|
|
4008
4078
|
return new _DocFileUnknownReference({
|
|
4009
4079
|
path: archivePath,
|
|
4010
4080
|
fileSystem: this.fileSystem,
|
|
@@ -4026,7 +4096,10 @@ var DocFileUnknownReference = class _DocFileUnknownReference {
|
|
|
4026
4096
|
this.pathSystem.dirname(dirPath),
|
|
4027
4097
|
fileName
|
|
4028
4098
|
);
|
|
4029
|
-
await this.moveTo(restorePath);
|
|
4099
|
+
const moveResult = await this.moveTo(restorePath);
|
|
4100
|
+
if (moveResult instanceof Error) {
|
|
4101
|
+
throw moveResult;
|
|
4102
|
+
}
|
|
4030
4103
|
return new _DocFileUnknownReference({
|
|
4031
4104
|
path: restorePath,
|
|
4032
4105
|
fileSystem: this.fileSystem,
|
|
@@ -4078,6 +4151,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4078
4151
|
const filePaths = await this.fileSystem.readDirectoryFilePaths(
|
|
4079
4152
|
this.relativePath
|
|
4080
4153
|
);
|
|
4154
|
+
if (filePaths instanceof Error) {
|
|
4155
|
+
return filePaths;
|
|
4156
|
+
}
|
|
4081
4157
|
return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
|
|
4082
4158
|
}
|
|
4083
4159
|
async archivedFileNames() {
|
|
@@ -4086,10 +4162,17 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4086
4162
|
this.archiveDirectoryName
|
|
4087
4163
|
);
|
|
4088
4164
|
const filePaths = await this.fileSystem.readDirectoryFilePaths(archivePath);
|
|
4165
|
+
if (filePaths instanceof Error) {
|
|
4166
|
+
return filePaths;
|
|
4167
|
+
}
|
|
4089
4168
|
return filePaths.map((p) => this.pathSystem.basename(p)).filter((name) => name.includes("."));
|
|
4090
4169
|
}
|
|
4091
4170
|
async *filesGenerator() {
|
|
4092
4171
|
const fileNames = await this.fileNames();
|
|
4172
|
+
if (fileNames instanceof Error) {
|
|
4173
|
+
yield fileNames;
|
|
4174
|
+
return;
|
|
4175
|
+
}
|
|
4093
4176
|
for (const fileName of fileNames) {
|
|
4094
4177
|
if (fileName === "index.md") continue;
|
|
4095
4178
|
if (fileName.endsWith(".md")) {
|
|
@@ -4110,6 +4193,10 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4110
4193
|
});
|
|
4111
4194
|
}
|
|
4112
4195
|
const archivedFileNames = await this.archivedFileNames();
|
|
4196
|
+
if (archivedFileNames instanceof Error) {
|
|
4197
|
+
yield archivedFileNames;
|
|
4198
|
+
return;
|
|
4199
|
+
}
|
|
4113
4200
|
for (const fileName of archivedFileNames) {
|
|
4114
4201
|
if (fileName === this.indexFileName) continue;
|
|
4115
4202
|
if (fileName.endsWith(".md")) {
|
|
@@ -4141,6 +4228,10 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4141
4228
|
async *mdFilesGenerator() {
|
|
4142
4229
|
const generator = this.filesGenerator();
|
|
4143
4230
|
for await (const file of generator) {
|
|
4231
|
+
if (file instanceof Error) {
|
|
4232
|
+
yield file;
|
|
4233
|
+
return;
|
|
4234
|
+
}
|
|
4144
4235
|
if (file instanceof DocFileMdReference) {
|
|
4145
4236
|
yield file;
|
|
4146
4237
|
}
|
|
@@ -4149,6 +4240,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4149
4240
|
async files() {
|
|
4150
4241
|
const files = [];
|
|
4151
4242
|
for await (const ref of this.filesGenerator()) {
|
|
4243
|
+
if (ref instanceof Error) {
|
|
4244
|
+
return ref;
|
|
4245
|
+
}
|
|
4152
4246
|
files.push(ref);
|
|
4153
4247
|
}
|
|
4154
4248
|
return files;
|
|
@@ -4156,6 +4250,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4156
4250
|
async mdFiles() {
|
|
4157
4251
|
const refs = [];
|
|
4158
4252
|
for await (const file of this.mdFilesGenerator()) {
|
|
4253
|
+
if (file instanceof Error) {
|
|
4254
|
+
return file;
|
|
4255
|
+
}
|
|
4159
4256
|
refs.push(file);
|
|
4160
4257
|
}
|
|
4161
4258
|
return refs;
|
|
@@ -4190,6 +4287,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4190
4287
|
async readFiles() {
|
|
4191
4288
|
const entities = [];
|
|
4192
4289
|
for await (const file of this.filesGenerator()) {
|
|
4290
|
+
if (file instanceof Error) {
|
|
4291
|
+
return file;
|
|
4292
|
+
}
|
|
4193
4293
|
const entity = await file.read();
|
|
4194
4294
|
if (entity instanceof Error) continue;
|
|
4195
4295
|
entities.push(entity);
|
|
@@ -4199,6 +4299,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4199
4299
|
async readMdFiles() {
|
|
4200
4300
|
const entities = [];
|
|
4201
4301
|
for await (const file of this.filesGenerator()) {
|
|
4302
|
+
if (file instanceof Error) {
|
|
4303
|
+
return file;
|
|
4304
|
+
}
|
|
4202
4305
|
const entity = await file.read();
|
|
4203
4306
|
if (entity instanceof Error) continue;
|
|
4204
4307
|
if (entity instanceof DocFileUnknownEntity) continue;
|
|
@@ -4209,6 +4312,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4209
4312
|
async readUnknownFiles() {
|
|
4210
4313
|
const entities = [];
|
|
4211
4314
|
for await (const file of this.filesGenerator()) {
|
|
4315
|
+
if (file instanceof Error) {
|
|
4316
|
+
return file;
|
|
4317
|
+
}
|
|
4212
4318
|
const entity = await file.read();
|
|
4213
4319
|
if (entity instanceof Error) continue;
|
|
4214
4320
|
if (entity instanceof DocFileMdEntity) continue;
|
|
@@ -4223,6 +4329,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4223
4329
|
const allFileNames = await this.fileSystem.readDirectoryFileNames(
|
|
4224
4330
|
this.relativePath
|
|
4225
4331
|
);
|
|
4332
|
+
if (allFileNames instanceof Error) {
|
|
4333
|
+
return allFileNames;
|
|
4334
|
+
}
|
|
4226
4335
|
const directoryNames = [];
|
|
4227
4336
|
for (const fileName of allFileNames) {
|
|
4228
4337
|
if (fileName.startsWith(this.archiveDirectoryName)) continue;
|
|
@@ -4240,6 +4349,9 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4240
4349
|
*/
|
|
4241
4350
|
async directories() {
|
|
4242
4351
|
const directoryNames = await this.directoryNames();
|
|
4352
|
+
if (directoryNames instanceof Error) {
|
|
4353
|
+
return directoryNames;
|
|
4354
|
+
}
|
|
4243
4355
|
return directoryNames.map((dirName) => {
|
|
4244
4356
|
const dirPath = this.pathSystem.join(this.relativePath, dirName);
|
|
4245
4357
|
return new _DocDirectoryReference({
|
|
@@ -4306,7 +4418,10 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4306
4418
|
if (content === null) {
|
|
4307
4419
|
return new Error("Entity content is undefined");
|
|
4308
4420
|
}
|
|
4309
|
-
await this.fileSystem.writeFile(filePath, content);
|
|
4421
|
+
const writeResult = await this.fileSystem.writeFile(filePath, content);
|
|
4422
|
+
if (writeResult instanceof Error) {
|
|
4423
|
+
return writeResult;
|
|
4424
|
+
}
|
|
4310
4425
|
return null;
|
|
4311
4426
|
}
|
|
4312
4427
|
async exists() {
|
|
@@ -4333,7 +4448,10 @@ var DocDirectoryReference = class _DocDirectoryReference {
|
|
|
4333
4448
|
pathSystem: this.pathSystem,
|
|
4334
4449
|
config: this.props.config
|
|
4335
4450
|
});
|
|
4336
|
-
await fileRef.writeDefault();
|
|
4451
|
+
const writeResult = await fileRef.writeDefault();
|
|
4452
|
+
if (writeResult instanceof Error) {
|
|
4453
|
+
throw writeResult;
|
|
4454
|
+
}
|
|
4337
4455
|
return fileRef;
|
|
4338
4456
|
}
|
|
4339
4457
|
};
|
|
@@ -4470,6 +4588,9 @@ var DocFileTreeSystem = class {
|
|
|
4470
4588
|
*/
|
|
4471
4589
|
async buildFileTree(directoryPath = "") {
|
|
4472
4590
|
const fileNames = await this.props.fileSystem.readDirectoryFileNames(directoryPath);
|
|
4591
|
+
if (fileNames instanceof Error) {
|
|
4592
|
+
return fileNames;
|
|
4593
|
+
}
|
|
4473
4594
|
const results = [];
|
|
4474
4595
|
for (const fileName of fileNames) {
|
|
4475
4596
|
if (fileName === this.props.archiveDirectoryName) continue;
|
|
@@ -4478,10 +4599,16 @@ var DocFileTreeSystem = class {
|
|
|
4478
4599
|
const isDirectory = await this.props.fileSystem.isDirectory(filePath);
|
|
4479
4600
|
if (!isDirectory) {
|
|
4480
4601
|
const fileNode = await this.createFileNode(fileName, filePath);
|
|
4602
|
+
if (fileNode instanceof Error) {
|
|
4603
|
+
return fileNode;
|
|
4604
|
+
}
|
|
4481
4605
|
results.push(fileNode);
|
|
4482
4606
|
continue;
|
|
4483
4607
|
}
|
|
4484
4608
|
const directoryNode = await this.createDirectoryNode(fileName, filePath);
|
|
4609
|
+
if (directoryNode instanceof Error) {
|
|
4610
|
+
return directoryNode;
|
|
4611
|
+
}
|
|
4485
4612
|
results.push(directoryNode);
|
|
4486
4613
|
}
|
|
4487
4614
|
return results;
|
|
@@ -4520,6 +4647,9 @@ var DocFileTreeSystem = class {
|
|
|
4520
4647
|
const indexFile = this.createIndexFileReference(filePath);
|
|
4521
4648
|
if (await indexFile.exists()) {
|
|
4522
4649
|
const entity = await indexFile.read();
|
|
4650
|
+
if (entity instanceof Error) {
|
|
4651
|
+
return entity;
|
|
4652
|
+
}
|
|
4523
4653
|
title = entity.value.content.title || fileName;
|
|
4524
4654
|
const content = entity.content;
|
|
4525
4655
|
const frontMatter = content.meta();
|
|
@@ -4528,6 +4658,9 @@ var DocFileTreeSystem = class {
|
|
|
4528
4658
|
}
|
|
4529
4659
|
}
|
|
4530
4660
|
const children = await this.buildFileTree(filePath);
|
|
4661
|
+
if (children instanceof Error) {
|
|
4662
|
+
return children;
|
|
4663
|
+
}
|
|
4531
4664
|
return DocTreeDirectoryNodeValue.from({
|
|
4532
4665
|
name: fileName,
|
|
4533
4666
|
path: filePath,
|
|
@@ -4566,6 +4699,9 @@ var DocFileTreeSystem = class {
|
|
|
4566
4699
|
*/
|
|
4567
4700
|
async buildDirectoryTree(directoryPath = "") {
|
|
4568
4701
|
const fileNames = await this.props.fileSystem.readDirectoryFileNames(directoryPath);
|
|
4702
|
+
if (fileNames instanceof Error) {
|
|
4703
|
+
return fileNames;
|
|
4704
|
+
}
|
|
4569
4705
|
const results = [];
|
|
4570
4706
|
for (const fileName of fileNames) {
|
|
4571
4707
|
if (fileName === this.props.archiveDirectoryName) continue;
|
|
@@ -4577,6 +4713,9 @@ var DocFileTreeSystem = class {
|
|
|
4577
4713
|
fileName,
|
|
4578
4714
|
filePath
|
|
4579
4715
|
);
|
|
4716
|
+
if (directoryNode instanceof Error) {
|
|
4717
|
+
return directoryNode;
|
|
4718
|
+
}
|
|
4580
4719
|
results.push(directoryNode);
|
|
4581
4720
|
}
|
|
4582
4721
|
return results;
|
|
@@ -4590,6 +4729,9 @@ var DocFileTreeSystem = class {
|
|
|
4590
4729
|
const indexFile = this.createIndexFileReference(filePath);
|
|
4591
4730
|
if (await indexFile.exists()) {
|
|
4592
4731
|
const entity = await indexFile.read();
|
|
4732
|
+
if (entity instanceof Error) {
|
|
4733
|
+
return entity;
|
|
4734
|
+
}
|
|
4593
4735
|
title = entity.value.content.title || fileName;
|
|
4594
4736
|
const content = entity.content;
|
|
4595
4737
|
const frontMatter = content.meta();
|
|
@@ -4598,6 +4740,9 @@ var DocFileTreeSystem = class {
|
|
|
4598
4740
|
}
|
|
4599
4741
|
}
|
|
4600
4742
|
const children = await this.buildDirectoryTree(filePath);
|
|
4743
|
+
if (children instanceof Error) {
|
|
4744
|
+
return children;
|
|
4745
|
+
}
|
|
4601
4746
|
return DocTreeDirectoryNodeValue.from({
|
|
4602
4747
|
name: fileName,
|
|
4603
4748
|
path: filePath,
|
|
@@ -4852,10 +4997,16 @@ var DocClient = class {
|
|
|
4852
4997
|
}
|
|
4853
4998
|
async fileTree(directoryPath = "") {
|
|
4854
4999
|
const results = await this.fileTreeSystem.buildFileTree(directoryPath);
|
|
5000
|
+
if (results instanceof Error) {
|
|
5001
|
+
throw results;
|
|
5002
|
+
}
|
|
4855
5003
|
return results.map((node) => node.toJson());
|
|
4856
5004
|
}
|
|
4857
5005
|
async directoryTree(directoryPath = "") {
|
|
4858
5006
|
const results = await this.fileTreeSystem.buildDirectoryTree(directoryPath);
|
|
5007
|
+
if (results instanceof Error) {
|
|
5008
|
+
throw results;
|
|
5009
|
+
}
|
|
4859
5010
|
return results.map((node) => node.toJson());
|
|
4860
5011
|
}
|
|
4861
5012
|
};
|
|
@@ -4873,29 +5024,27 @@ var DocFileSystem = class {
|
|
|
4873
5024
|
* Read file content at the specified path
|
|
4874
5025
|
*/
|
|
4875
5026
|
async readFile(relativePath) {
|
|
4876
|
-
const exists = await this.exists(relativePath);
|
|
4877
|
-
if (!exists) return null;
|
|
4878
|
-
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
4879
5027
|
try {
|
|
5028
|
+
const exists = await this.exists(relativePath);
|
|
5029
|
+
if (!exists) return null;
|
|
5030
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
4880
5031
|
return await fs.readFile(fullPath, "utf-8");
|
|
4881
|
-
} catch {
|
|
4882
|
-
return
|
|
5032
|
+
} catch (error) {
|
|
5033
|
+
return error instanceof Error ? error : new Error(`Failed to read file at ${relativePath}`);
|
|
4883
5034
|
}
|
|
4884
5035
|
}
|
|
4885
5036
|
/**
|
|
4886
5037
|
* Write content to file at the specified path (creates directory if needed)
|
|
4887
5038
|
*/
|
|
4888
5039
|
async writeFile(relativePath, content) {
|
|
4889
|
-
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
4890
|
-
const dirPath = this.pathSystem.dirname(fullPath);
|
|
4891
5040
|
try {
|
|
5041
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
5042
|
+
const dirPath = this.pathSystem.dirname(fullPath);
|
|
4892
5043
|
await fs.mkdir(dirPath, { recursive: true });
|
|
4893
5044
|
await fs.writeFile(fullPath, content, "utf-8");
|
|
5045
|
+
return null;
|
|
4894
5046
|
} catch (error) {
|
|
4895
|
-
|
|
4896
|
-
throw error;
|
|
4897
|
-
}
|
|
4898
|
-
throw new Error(`Failed to write file at ${fullPath}`);
|
|
5047
|
+
return error instanceof Error ? error : new Error(`Failed to write file at ${relativePath}`);
|
|
4899
5048
|
}
|
|
4900
5049
|
}
|
|
4901
5050
|
/**
|
|
@@ -4932,18 +5081,25 @@ var DocFileSystem = class {
|
|
|
4932
5081
|
* Get list of entries in directory
|
|
4933
5082
|
*/
|
|
4934
5083
|
async readDirectoryFileNames(relativePath = "") {
|
|
4935
|
-
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
4936
5084
|
try {
|
|
5085
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
4937
5086
|
return await fs.readdir(fullPath);
|
|
4938
|
-
} catch {
|
|
4939
|
-
return
|
|
5087
|
+
} catch (error) {
|
|
5088
|
+
return error instanceof Error ? error : new Error(`Failed to read directory at ${relativePath}`);
|
|
4940
5089
|
}
|
|
4941
5090
|
}
|
|
4942
5091
|
async readDirectoryFilePaths(relativePath) {
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
(
|
|
4946
|
-
|
|
5092
|
+
try {
|
|
5093
|
+
const fileNames = await this.readDirectoryFileNames(relativePath);
|
|
5094
|
+
if (fileNames instanceof Error) {
|
|
5095
|
+
return fileNames;
|
|
5096
|
+
}
|
|
5097
|
+
return fileNames.map(
|
|
5098
|
+
(fileName) => this.pathSystem.join(relativePath, fileName)
|
|
5099
|
+
);
|
|
5100
|
+
} catch (error) {
|
|
5101
|
+
return error instanceof Error ? error : new Error(`Failed to read directory file paths at ${relativePath}`);
|
|
5102
|
+
}
|
|
4947
5103
|
}
|
|
4948
5104
|
/**
|
|
4949
5105
|
* Check if path is a directory
|
|
@@ -5009,56 +5165,95 @@ var DocFileSystem = class {
|
|
|
5009
5165
|
* Create directory
|
|
5010
5166
|
*/
|
|
5011
5167
|
async createDirectory(relativePath) {
|
|
5012
|
-
|
|
5013
|
-
|
|
5168
|
+
try {
|
|
5169
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
5170
|
+
await fs.mkdir(fullPath, { recursive: true });
|
|
5171
|
+
return null;
|
|
5172
|
+
} catch (error) {
|
|
5173
|
+
return error instanceof Error ? error : new Error(`Failed to create directory at ${relativePath}`);
|
|
5174
|
+
}
|
|
5014
5175
|
}
|
|
5015
5176
|
/**
|
|
5016
5177
|
* Get file size in bytes
|
|
5017
5178
|
*/
|
|
5018
5179
|
async getFileSize(relativePath) {
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5180
|
+
try {
|
|
5181
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
5182
|
+
const stats = await fs.stat(fullPath);
|
|
5183
|
+
return stats.size;
|
|
5184
|
+
} catch (error) {
|
|
5185
|
+
return error instanceof Error ? error : new Error(`Failed to get file size at ${relativePath}`);
|
|
5186
|
+
}
|
|
5022
5187
|
}
|
|
5023
5188
|
/**
|
|
5024
5189
|
* Create directory if it doesn't exist
|
|
5025
5190
|
*/
|
|
5026
5191
|
async ensureDirectoryExists(relativePath) {
|
|
5027
|
-
|
|
5028
|
-
await this.
|
|
5192
|
+
try {
|
|
5193
|
+
if (!await this.exists(relativePath)) {
|
|
5194
|
+
const result = await this.createDirectory(relativePath);
|
|
5195
|
+
if (result instanceof Error) {
|
|
5196
|
+
return result;
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
return null;
|
|
5200
|
+
} catch (error) {
|
|
5201
|
+
return error instanceof Error ? error : new Error(`Failed to ensure directory exists at ${relativePath}`);
|
|
5029
5202
|
}
|
|
5030
5203
|
}
|
|
5031
5204
|
/**
|
|
5032
5205
|
* Copy file
|
|
5033
5206
|
*/
|
|
5034
5207
|
async copyFile(sourcePath, destinationPath) {
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5208
|
+
try {
|
|
5209
|
+
const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
|
|
5210
|
+
const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
|
|
5211
|
+
await fs.copyFile(sourceFullPath, destFullPath);
|
|
5212
|
+
return null;
|
|
5213
|
+
} catch (error) {
|
|
5214
|
+
return error instanceof Error ? error : new Error(
|
|
5215
|
+
`Failed to copy file from ${sourcePath} to ${destinationPath}`
|
|
5216
|
+
);
|
|
5217
|
+
}
|
|
5038
5218
|
}
|
|
5039
5219
|
/**
|
|
5040
5220
|
* Move file
|
|
5041
5221
|
*/
|
|
5042
5222
|
async moveFile(sourcePath, destinationPath) {
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5223
|
+
try {
|
|
5224
|
+
const sourceFullPath = this.pathSystem.join(this.basePath, sourcePath);
|
|
5225
|
+
const destFullPath = this.pathSystem.join(this.basePath, destinationPath);
|
|
5226
|
+
await fs.rename(sourceFullPath, destFullPath);
|
|
5227
|
+
return null;
|
|
5228
|
+
} catch (error) {
|
|
5229
|
+
return error instanceof Error ? error : new Error(
|
|
5230
|
+
`Failed to move file from ${sourcePath} to ${destinationPath}`
|
|
5231
|
+
);
|
|
5232
|
+
}
|
|
5046
5233
|
}
|
|
5047
5234
|
/**
|
|
5048
5235
|
* Get file last modified time
|
|
5049
5236
|
*/
|
|
5050
5237
|
async getFileModifiedTime(relativePath) {
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5238
|
+
try {
|
|
5239
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
5240
|
+
const stats = await fs.stat(fullPath);
|
|
5241
|
+
return stats.mtime;
|
|
5242
|
+
} catch (error) {
|
|
5243
|
+
return error instanceof Error ? error : new Error(`Failed to get file modified time at ${relativePath}`);
|
|
5244
|
+
}
|
|
5054
5245
|
}
|
|
5055
5246
|
/**
|
|
5056
5247
|
* Get file creation time
|
|
5057
5248
|
*/
|
|
5058
5249
|
async getFileCreatedTime(relativePath) {
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5250
|
+
try {
|
|
5251
|
+
const fullPath = this.pathSystem.join(this.basePath, relativePath);
|
|
5252
|
+
const stats = await fs.stat(fullPath);
|
|
5253
|
+
return stats.birthtime;
|
|
5254
|
+
} catch (error) {
|
|
5255
|
+
return error instanceof Error ? error : new Error(`Failed to get file created time at ${relativePath}`);
|
|
5256
|
+
}
|
|
5062
5257
|
}
|
|
5063
5258
|
};
|
|
5064
5259
|
|
|
@@ -5098,10 +5293,14 @@ Complete API reference.`
|
|
|
5098
5293
|
var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
5099
5294
|
files = /* @__PURE__ */ new Map();
|
|
5100
5295
|
_pathSystem;
|
|
5296
|
+
_basePath;
|
|
5101
5297
|
constructor(props) {
|
|
5102
5298
|
super(props);
|
|
5103
5299
|
this._pathSystem = props.pathSystem;
|
|
5104
|
-
this.
|
|
5300
|
+
this._basePath = props.basePath.endsWith("/") ? props.basePath.slice(0, -1) : props.basePath;
|
|
5301
|
+
if (!props.skipDefaultFiles) {
|
|
5302
|
+
this.setupTestFiles(mockDirectoryData);
|
|
5303
|
+
}
|
|
5105
5304
|
Object.freeze(this);
|
|
5106
5305
|
}
|
|
5107
5306
|
/**
|
|
@@ -5110,6 +5309,16 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5110
5309
|
getPathSystem() {
|
|
5111
5310
|
return this._pathSystem;
|
|
5112
5311
|
}
|
|
5312
|
+
/**
|
|
5313
|
+
* Normalize path using basePath
|
|
5314
|
+
*/
|
|
5315
|
+
normalizePath(filePath) {
|
|
5316
|
+
if (filePath.startsWith(this._basePath)) {
|
|
5317
|
+
return filePath;
|
|
5318
|
+
}
|
|
5319
|
+
const cleanPath = filePath.startsWith("/") ? filePath.slice(1) : filePath;
|
|
5320
|
+
return `${this._basePath}/${cleanPath}`;
|
|
5321
|
+
}
|
|
5113
5322
|
/**
|
|
5114
5323
|
* Create instance (mock data is automatically loaded)
|
|
5115
5324
|
*/
|
|
@@ -5123,11 +5332,17 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5123
5332
|
static createWithFiles(props) {
|
|
5124
5333
|
const pathSystem = new DocPathSystem();
|
|
5125
5334
|
const basePath = props.basePath ?? "/test";
|
|
5126
|
-
const fileSystem = new _DocFileSystemMock({
|
|
5335
|
+
const fileSystem = new _DocFileSystemMock({
|
|
5336
|
+
basePath,
|
|
5337
|
+
pathSystem,
|
|
5338
|
+
skipDefaultFiles: true
|
|
5339
|
+
});
|
|
5127
5340
|
if (props.fileContents) {
|
|
5128
5341
|
const now = /* @__PURE__ */ new Date();
|
|
5129
5342
|
for (const [path, content] of Object.entries(props.fileContents)) {
|
|
5130
|
-
|
|
5343
|
+
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
5344
|
+
const normalizedPath = path.startsWith(basePath) ? path : `${basePath}/${cleanPath}`;
|
|
5345
|
+
fileSystem.files.set(normalizedPath, {
|
|
5131
5346
|
content,
|
|
5132
5347
|
modifiedTime: now,
|
|
5133
5348
|
createdTime: now,
|
|
@@ -5138,24 +5353,33 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5138
5353
|
return fileSystem;
|
|
5139
5354
|
}
|
|
5140
5355
|
async readFile(filePath) {
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5356
|
+
try {
|
|
5357
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5358
|
+
const file = this.files.get(normalizedPath);
|
|
5359
|
+
return file ? file.content : null;
|
|
5360
|
+
} catch (error) {
|
|
5361
|
+
return error instanceof Error ? error : new Error(`Failed to read file at ${filePath}`);
|
|
5362
|
+
}
|
|
5144
5363
|
}
|
|
5145
5364
|
async writeFile(filePath, content) {
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5365
|
+
try {
|
|
5366
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5367
|
+
const now = /* @__PURE__ */ new Date();
|
|
5368
|
+
const existing = this.files.get(normalizedPath);
|
|
5369
|
+
this.files.set(normalizedPath, {
|
|
5370
|
+
content,
|
|
5371
|
+
modifiedTime: now,
|
|
5372
|
+
createdTime: existing?.createdTime ?? now,
|
|
5373
|
+
size: new TextEncoder().encode(content).length
|
|
5374
|
+
});
|
|
5375
|
+
return null;
|
|
5376
|
+
} catch (error) {
|
|
5377
|
+
return error instanceof Error ? error : new Error(`Failed to write file at ${filePath}`);
|
|
5378
|
+
}
|
|
5155
5379
|
}
|
|
5156
5380
|
async deleteFile(filePath) {
|
|
5157
|
-
const normalizedPath = filePath.startsWith("docs/") ? filePath : `docs/${filePath}`;
|
|
5158
5381
|
try {
|
|
5382
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5159
5383
|
this.files.delete(normalizedPath);
|
|
5160
5384
|
return null;
|
|
5161
5385
|
} catch (error) {
|
|
@@ -5163,7 +5387,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5163
5387
|
}
|
|
5164
5388
|
}
|
|
5165
5389
|
async exists(filePath) {
|
|
5166
|
-
const normalizedPath =
|
|
5390
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5167
5391
|
if (this.files.has(normalizedPath)) {
|
|
5168
5392
|
return true;
|
|
5169
5393
|
}
|
|
@@ -5176,26 +5400,36 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5176
5400
|
return false;
|
|
5177
5401
|
}
|
|
5178
5402
|
async copyFile(source, destination) {
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5403
|
+
try {
|
|
5404
|
+
const normalizedSource = this.normalizePath(source);
|
|
5405
|
+
const normalizedDest = this.normalizePath(destination);
|
|
5406
|
+
const file = this.files.get(normalizedSource);
|
|
5407
|
+
if (!file) {
|
|
5408
|
+
return new Error(`Source file not found: ${normalizedSource}`);
|
|
5409
|
+
}
|
|
5410
|
+
this.files.set(normalizedDest, {
|
|
5411
|
+
...file,
|
|
5412
|
+
createdTime: /* @__PURE__ */ new Date()
|
|
5413
|
+
});
|
|
5414
|
+
return null;
|
|
5415
|
+
} catch (error) {
|
|
5416
|
+
return error instanceof Error ? error : new Error(`Failed to copy file from ${source} to ${destination}`);
|
|
5417
|
+
}
|
|
5189
5418
|
}
|
|
5190
5419
|
async moveFile(source, destination) {
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5420
|
+
try {
|
|
5421
|
+
const normalizedSource = this.normalizePath(source);
|
|
5422
|
+
const normalizedDest = this.normalizePath(destination);
|
|
5423
|
+
const file = this.files.get(normalizedSource);
|
|
5424
|
+
if (!file) {
|
|
5425
|
+
return new Error(`Source file not found: ${normalizedSource}`);
|
|
5426
|
+
}
|
|
5427
|
+
this.files.set(normalizedDest, file);
|
|
5428
|
+
this.files.delete(normalizedSource);
|
|
5429
|
+
return null;
|
|
5430
|
+
} catch (error) {
|
|
5431
|
+
return error instanceof Error ? error : new Error(`Failed to move file from ${source} to ${destination}`);
|
|
5196
5432
|
}
|
|
5197
|
-
this.files.set(normalizedDest, file);
|
|
5198
|
-
this.files.delete(normalizedSource);
|
|
5199
5433
|
}
|
|
5200
5434
|
async readDirectory(directoryPath) {
|
|
5201
5435
|
const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
|
|
@@ -5222,16 +5456,23 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5222
5456
|
return files.sort();
|
|
5223
5457
|
}
|
|
5224
5458
|
async readDirectoryFilePaths(directoryPath) {
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5459
|
+
try {
|
|
5460
|
+
const normalizedDir = this.normalizePath(directoryPath);
|
|
5461
|
+
const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
|
|
5462
|
+
const files = [];
|
|
5463
|
+
for (const path of this.files.keys()) {
|
|
5464
|
+
if (path.startsWith(dirPath) && !path.slice(dirPath.length).includes("/")) {
|
|
5465
|
+
const relativePath = path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
|
|
5466
|
+
files.push(relativePath);
|
|
5467
|
+
}
|
|
5230
5468
|
}
|
|
5469
|
+
return files.sort();
|
|
5470
|
+
} catch (error) {
|
|
5471
|
+
return error instanceof Error ? error : new Error(`Failed to read directory file paths at ${directoryPath}`);
|
|
5231
5472
|
}
|
|
5232
|
-
return files.sort();
|
|
5233
5473
|
}
|
|
5234
5474
|
async createDirectory(_directoryPath) {
|
|
5475
|
+
return null;
|
|
5235
5476
|
}
|
|
5236
5477
|
async deleteDirectory(directoryPath) {
|
|
5237
5478
|
const dirPath = directoryPath.endsWith("/") ? directoryPath : `${directoryPath}/`;
|
|
@@ -5242,31 +5483,43 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5242
5483
|
}
|
|
5243
5484
|
}
|
|
5244
5485
|
async getFileSize(filePath) {
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5486
|
+
try {
|
|
5487
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5488
|
+
const file = this.files.get(normalizedPath);
|
|
5489
|
+
if (!file) {
|
|
5490
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
5491
|
+
}
|
|
5492
|
+
return file.size;
|
|
5493
|
+
} catch (error) {
|
|
5494
|
+
return error instanceof Error ? error : new Error(`Failed to get file size at ${filePath}`);
|
|
5249
5495
|
}
|
|
5250
|
-
return file.size;
|
|
5251
5496
|
}
|
|
5252
5497
|
async getFileModifiedTime(filePath) {
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5498
|
+
try {
|
|
5499
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5500
|
+
const file = this.files.get(normalizedPath);
|
|
5501
|
+
if (!file) {
|
|
5502
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
5503
|
+
}
|
|
5504
|
+
return file.modifiedTime;
|
|
5505
|
+
} catch (error) {
|
|
5506
|
+
return error instanceof Error ? error : new Error(`Failed to get file modified time at ${filePath}`);
|
|
5257
5507
|
}
|
|
5258
|
-
return file.modifiedTime;
|
|
5259
5508
|
}
|
|
5260
5509
|
async getFileCreatedTime(filePath) {
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5510
|
+
try {
|
|
5511
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5512
|
+
const file = this.files.get(normalizedPath);
|
|
5513
|
+
if (!file) {
|
|
5514
|
+
return new Error(`File not found: ${normalizedPath}`);
|
|
5515
|
+
}
|
|
5516
|
+
return file.createdTime;
|
|
5517
|
+
} catch (error) {
|
|
5518
|
+
return error instanceof Error ? error : new Error(`Failed to get file created time at ${filePath}`);
|
|
5265
5519
|
}
|
|
5266
|
-
return file.createdTime;
|
|
5267
5520
|
}
|
|
5268
5521
|
async isDirectory(relativePath) {
|
|
5269
|
-
const normalizedPath =
|
|
5522
|
+
const normalizedPath = this.normalizePath(relativePath);
|
|
5270
5523
|
const dirPath = normalizedPath.endsWith("/") ? normalizedPath : `${normalizedPath}/`;
|
|
5271
5524
|
for (const path of this.files.keys()) {
|
|
5272
5525
|
if (path.startsWith(dirPath)) {
|
|
@@ -5276,26 +5529,30 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5276
5529
|
return false;
|
|
5277
5530
|
}
|
|
5278
5531
|
async isFile(relativePath) {
|
|
5279
|
-
const normalizedPath =
|
|
5532
|
+
const normalizedPath = this.normalizePath(relativePath);
|
|
5280
5533
|
return this.files.has(normalizedPath);
|
|
5281
5534
|
}
|
|
5282
5535
|
/**
|
|
5283
5536
|
* Get list of entries in directory
|
|
5284
5537
|
*/
|
|
5285
5538
|
async readDirectoryFileNames(directoryPath = "") {
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5539
|
+
try {
|
|
5540
|
+
const normalizedDir = directoryPath === "" ? this._basePath : this.normalizePath(directoryPath);
|
|
5541
|
+
const dirPath = normalizedDir.endsWith("/") ? normalizedDir : `${normalizedDir}/`;
|
|
5542
|
+
const entries = /* @__PURE__ */ new Set();
|
|
5543
|
+
for (const path of this.files.keys()) {
|
|
5544
|
+
if (path.startsWith(dirPath)) {
|
|
5545
|
+
const relativePath = path.slice(dirPath.length);
|
|
5546
|
+
const firstSegment = relativePath.split("/")[0];
|
|
5547
|
+
if (firstSegment) {
|
|
5548
|
+
entries.add(firstSegment);
|
|
5549
|
+
}
|
|
5295
5550
|
}
|
|
5296
5551
|
}
|
|
5552
|
+
return Array.from(entries).sort();
|
|
5553
|
+
} catch (error) {
|
|
5554
|
+
return error instanceof Error ? error : new Error(`Failed to read directory at ${directoryPath}`);
|
|
5297
5555
|
}
|
|
5298
|
-
return Array.from(entries).sort();
|
|
5299
5556
|
}
|
|
5300
5557
|
/**
|
|
5301
5558
|
* Check if directory exists
|
|
@@ -5313,6 +5570,7 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5313
5570
|
* Create directory if it doesn't exist
|
|
5314
5571
|
*/
|
|
5315
5572
|
async ensureDirectoryExists(_relativePath) {
|
|
5573
|
+
return null;
|
|
5316
5574
|
}
|
|
5317
5575
|
/**
|
|
5318
5576
|
* Clear all files
|
|
@@ -5324,19 +5582,23 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5324
5582
|
* Check file existence (for testing)
|
|
5325
5583
|
*/
|
|
5326
5584
|
hasFile(filePath) {
|
|
5327
|
-
|
|
5585
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5586
|
+
return this.files.has(normalizedPath);
|
|
5328
5587
|
}
|
|
5329
5588
|
/**
|
|
5330
5589
|
* Get file content (sync version, for testing)
|
|
5331
5590
|
*/
|
|
5332
5591
|
getFileContent(filePath) {
|
|
5333
|
-
|
|
5592
|
+
const normalizedPath = this.normalizePath(filePath);
|
|
5593
|
+
return this.files.get(normalizedPath)?.content;
|
|
5334
5594
|
}
|
|
5335
5595
|
/**
|
|
5336
5596
|
* Get all file paths (for testing)
|
|
5337
5597
|
*/
|
|
5338
5598
|
getAllFilePaths() {
|
|
5339
|
-
return Array.from(this.files.keys()).
|
|
5599
|
+
return Array.from(this.files.keys()).map((path) => {
|
|
5600
|
+
return path.startsWith(`${this._basePath}/`) ? path.slice(this._basePath.length + 1) : path;
|
|
5601
|
+
}).sort();
|
|
5340
5602
|
}
|
|
5341
5603
|
/**
|
|
5342
5604
|
* Get file count (for testing)
|
|
@@ -5350,7 +5612,8 @@ var DocFileSystemMock = class _DocFileSystemMock extends DocFileSystem {
|
|
|
5350
5612
|
setupTestFiles(files) {
|
|
5351
5613
|
const now = /* @__PURE__ */ new Date();
|
|
5352
5614
|
for (const [path, content] of Object.entries(files)) {
|
|
5353
|
-
this.
|
|
5615
|
+
const normalizedPath = this.normalizePath(path);
|
|
5616
|
+
this.files.set(normalizedPath, {
|
|
5354
5617
|
content,
|
|
5355
5618
|
modifiedTime: now,
|
|
5356
5619
|
createdTime: now,
|