@fgv/ts-json-base 5.1.0-0 → 5.1.0-10
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/dist/packlets/file-tree/directoryItem.js +78 -14
- package/dist/packlets/file-tree/fileItem.js +10 -0
- package/dist/packlets/file-tree/fileTreeAccessors.js +36 -1
- package/dist/packlets/file-tree/fsTree.js +34 -0
- package/dist/packlets/file-tree/in-memory/inMemoryTree.js +75 -0
- package/dist/packlets/file-tree/in-memory/treeBuilder.js +8 -0
- package/dist/ts-json-base.d.ts +190 -45
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/file-tree/directoryItem.d.ts +21 -6
- package/lib/packlets/file-tree/directoryItem.js +77 -13
- package/lib/packlets/file-tree/fileItem.d.ts +6 -2
- package/lib/packlets/file-tree/fileItem.js +10 -0
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +104 -10
- package/lib/packlets/file-tree/fileTreeAccessors.js +38 -1
- package/lib/packlets/file-tree/fsTree.d.ts +8 -0
- package/lib/packlets/file-tree/fsTree.js +34 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +8 -0
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +75 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +6 -0
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +8 -0
- package/package.json +9 -8
package/dist/ts-json-base.d.ts
CHANGED
|
@@ -9,6 +9,30 @@ import { Validation } from '@fgv/ts-utils';
|
|
|
9
9
|
import { Validator } from '@fgv/ts-utils';
|
|
10
10
|
import { Validators as Validators_3 } from '@fgv/ts-utils';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* A directory item that may or may not be mutable at runtime.
|
|
14
|
+
*
|
|
15
|
+
* Use this type for parameters or fields where the code checks for mutability
|
|
16
|
+
* and handles the read-only case gracefully. Use {@link FileTree.IMutableFileTreeDirectoryItem}
|
|
17
|
+
* when mutation is required.
|
|
18
|
+
*
|
|
19
|
+
* Narrow with {@link FileTree.isMutableDirectoryItem} to access mutation methods.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
declare type AnyFileTreeDirectoryItem<TCT extends string = string> = IFileTreeDirectoryItem<TCT> | IMutableFileTreeDirectoryItem<TCT>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A file item that may or may not be mutable at runtime.
|
|
26
|
+
*
|
|
27
|
+
* Use this type for parameters or fields where the code checks for mutability
|
|
28
|
+
* and handles the read-only case gracefully. Use {@link FileTree.IMutableFileTreeFileItem}
|
|
29
|
+
* when mutation is required.
|
|
30
|
+
*
|
|
31
|
+
* Narrow with {@link FileTree.isMutableFileItem} to access mutation methods.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
declare type AnyFileTreeFileItem<TCT extends string = string> = IFileTreeFileItem<TCT> | IMutableFileTreeFileItem<TCT>;
|
|
35
|
+
|
|
12
36
|
/**
|
|
13
37
|
* A converter which converts a supplied `unknown` value to a valid array of {@link JsonCompatibleType | JsonCompatible} values.
|
|
14
38
|
* @public
|
|
@@ -158,7 +182,7 @@ declare const DefaultJsonTreeHelper: JsonTreeHelper;
|
|
|
158
182
|
* Class representing a directory in a file tree.
|
|
159
183
|
* @public
|
|
160
184
|
*/
|
|
161
|
-
declare class DirectoryItem<TCT extends string = string> implements
|
|
185
|
+
declare class DirectoryItem<TCT extends string = string> implements IMutableFileTreeDirectoryItem<TCT> {
|
|
162
186
|
/**
|
|
163
187
|
* {@inheritDoc FileTree.IFileTreeDirectoryItem."type"}
|
|
164
188
|
*/
|
|
@@ -198,13 +222,28 @@ declare class DirectoryItem<TCT extends string = string> implements IFileTreeDir
|
|
|
198
222
|
*/
|
|
199
223
|
getChildren(): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
200
224
|
/**
|
|
201
|
-
* {@inheritDoc FileTree.
|
|
225
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildFile}
|
|
226
|
+
*/
|
|
227
|
+
createChildFile(name: string, contents: string): Result<IMutableFileTreeFileItem<TCT>>;
|
|
228
|
+
/**
|
|
229
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildDirectory}
|
|
230
|
+
*/
|
|
231
|
+
createChildDirectory(name: string): Result<IMutableFileTreeDirectoryItem<TCT>>;
|
|
232
|
+
/**
|
|
233
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.deleteChild}
|
|
202
234
|
*/
|
|
203
|
-
|
|
235
|
+
deleteChild(name: string, options?: IDeleteChildOptions): Result<boolean>;
|
|
204
236
|
/**
|
|
205
|
-
* {@inheritDoc FileTree.
|
|
237
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.delete}
|
|
206
238
|
*/
|
|
207
|
-
|
|
239
|
+
delete(): Result<boolean>;
|
|
240
|
+
/**
|
|
241
|
+
* Recursively deletes all children of a directory and then the directory itself.
|
|
242
|
+
* @param dirPath - The absolute path of the directory to delete.
|
|
243
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
244
|
+
* @internal
|
|
245
|
+
*/
|
|
246
|
+
private _deleteRecursive;
|
|
208
247
|
}
|
|
209
248
|
|
|
210
249
|
/**
|
|
@@ -254,7 +293,7 @@ declare function enumeratedValue_2<T>(values: ReadonlyArray<T>, message?: string
|
|
|
254
293
|
* Class representing a file in a file tree.
|
|
255
294
|
* @public
|
|
256
295
|
*/
|
|
257
|
-
declare class FileItem<TCT extends string = string> implements
|
|
296
|
+
declare class FileItem<TCT extends string = string> implements IMutableFileTreeFileItem<TCT> {
|
|
258
297
|
/**
|
|
259
298
|
* {@inheritDoc FileTree.IFileTreeFileItem."type"}
|
|
260
299
|
*/
|
|
@@ -334,6 +373,10 @@ declare class FileItem<TCT extends string = string> implements IFileTreeFileItem
|
|
|
334
373
|
* {@inheritDoc FileTree.IFileTreeFileItem.setRawContents}
|
|
335
374
|
*/
|
|
336
375
|
setRawContents(contents: string): Result<string>;
|
|
376
|
+
/**
|
|
377
|
+
* {@inheritDoc FileTree.IFileTreeFileItem.delete}
|
|
378
|
+
*/
|
|
379
|
+
delete(): Result<boolean>;
|
|
337
380
|
/**
|
|
338
381
|
* Default function to infer the content type of a file.
|
|
339
382
|
* @param filePath - The path of the file.
|
|
@@ -361,6 +404,8 @@ declare namespace FileTree {
|
|
|
361
404
|
inMemory,
|
|
362
405
|
isMutableAccessors,
|
|
363
406
|
isPersistentAccessors,
|
|
407
|
+
isMutableFileItem,
|
|
408
|
+
isMutableDirectoryItem,
|
|
364
409
|
SaveCapability,
|
|
365
410
|
SaveFailureReason,
|
|
366
411
|
SaveDetail,
|
|
@@ -368,9 +413,15 @@ declare namespace FileTree {
|
|
|
368
413
|
FileTreeItemType,
|
|
369
414
|
ContentTypeFactory,
|
|
370
415
|
IFileTreeInitParams,
|
|
416
|
+
IDeleteChildOptions,
|
|
371
417
|
IFileTreeFileItem,
|
|
418
|
+
IMutableFileTreeFileItem,
|
|
372
419
|
IFileTreeDirectoryItem,
|
|
420
|
+
IMutableFileTreeDirectoryItem,
|
|
373
421
|
FileTreeItem,
|
|
422
|
+
MutableFileTreeItem,
|
|
423
|
+
AnyFileTreeFileItem,
|
|
424
|
+
AnyFileTreeDirectoryItem,
|
|
374
425
|
IFileTreeAccessors,
|
|
375
426
|
IMutableFileTreeAccessors,
|
|
376
427
|
IPersistentFileTreeAccessors,
|
|
@@ -530,10 +581,30 @@ declare class FsFileTreeAccessors<TCT extends string = string> implements IMutab
|
|
|
530
581
|
* {@inheritDoc FileTree.IMutableFileTreeAccessors.saveFileContents}
|
|
531
582
|
*/
|
|
532
583
|
saveFileContents(path: string, contents: string): Result<string>;
|
|
584
|
+
/**
|
|
585
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteFile}
|
|
586
|
+
*/
|
|
587
|
+
deleteFile(path: string): Result<boolean>;
|
|
533
588
|
/**
|
|
534
589
|
* {@inheritDoc FileTree.IMutableFileTreeAccessors.createDirectory}
|
|
535
590
|
*/
|
|
536
591
|
createDirectory(dirPath: string): Result<string>;
|
|
592
|
+
/**
|
|
593
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteDirectory}
|
|
594
|
+
*/
|
|
595
|
+
deleteDirectory(dirPath: string): Result<boolean>;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Options for deleting a child item from a directory.
|
|
600
|
+
* @public
|
|
601
|
+
*/
|
|
602
|
+
declare interface IDeleteChildOptions {
|
|
603
|
+
/**
|
|
604
|
+
* If true, recursively delete directory children and their contents.
|
|
605
|
+
* Default: false (fail if directory is non-empty).
|
|
606
|
+
*/
|
|
607
|
+
recursive?: boolean;
|
|
537
608
|
}
|
|
538
609
|
|
|
539
610
|
/**
|
|
@@ -595,7 +666,7 @@ declare interface IFileTreeAccessors<TCT extends string = string> {
|
|
|
595
666
|
}
|
|
596
667
|
|
|
597
668
|
/**
|
|
598
|
-
* Interface for a directory in a file tree.
|
|
669
|
+
* Interface for a read-only directory in a file tree.
|
|
599
670
|
* @public
|
|
600
671
|
*/
|
|
601
672
|
declare interface IFileTreeDirectoryItem<TCT extends string = string> {
|
|
@@ -617,25 +688,10 @@ declare interface IFileTreeDirectoryItem<TCT extends string = string> {
|
|
|
617
688
|
* or `Failure` with an error message otherwise.
|
|
618
689
|
*/
|
|
619
690
|
getChildren(): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
620
|
-
/**
|
|
621
|
-
* Creates a new file as a child of this directory.
|
|
622
|
-
* @param name - The file name to create.
|
|
623
|
-
* @param contents - The string contents to write.
|
|
624
|
-
* @returns `Success` with the new file item, or `Failure` with an error message.
|
|
625
|
-
* @remarks This method is optional. Only available on mutable directory items.
|
|
626
|
-
*/
|
|
627
|
-
createChildFile?(name: string, contents: string): Result<IFileTreeFileItem<TCT>>;
|
|
628
|
-
/**
|
|
629
|
-
* Creates a new subdirectory as a child of this directory.
|
|
630
|
-
* @param name - The directory name to create.
|
|
631
|
-
* @returns `Success` with the new directory item, or `Failure` with an error message.
|
|
632
|
-
* @remarks This method is optional. Only available on mutable directory items.
|
|
633
|
-
*/
|
|
634
|
-
createChildDirectory?(name: string): Result<IFileTreeDirectoryItem<TCT>>;
|
|
635
691
|
}
|
|
636
692
|
|
|
637
693
|
/**
|
|
638
|
-
* Interface for a file in a file tree.
|
|
694
|
+
* Interface for a read-only file in a file tree.
|
|
639
695
|
* @public
|
|
640
696
|
*/
|
|
641
697
|
declare interface IFileTreeFileItem<TCT extends string = string> {
|
|
@@ -683,27 +739,6 @@ declare interface IFileTreeFileItem<TCT extends string = string> {
|
|
|
683
739
|
* `Failure` with an error message otherwise.
|
|
684
740
|
*/
|
|
685
741
|
getRawContents(): Result<string>;
|
|
686
|
-
/**
|
|
687
|
-
* Indicates whether this file can be saved.
|
|
688
|
-
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
689
|
-
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
690
|
-
* @remarks This property is optional. If not present, the file is not mutable.
|
|
691
|
-
*/
|
|
692
|
-
getIsMutable(): DetailedResult<boolean, SaveDetail>;
|
|
693
|
-
/**
|
|
694
|
-
* Sets the contents of the file from a JSON value.
|
|
695
|
-
* @param json - The JSON value to serialize and save.
|
|
696
|
-
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
697
|
-
* @remarks This method is optional. If not present, the file is not mutable.
|
|
698
|
-
*/
|
|
699
|
-
setContents(json: JsonValue): Result<JsonValue>;
|
|
700
|
-
/**
|
|
701
|
-
* Sets the raw contents of the file.
|
|
702
|
-
* @param contents - The string contents to save.
|
|
703
|
-
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
704
|
-
* @remarks This method is optional. If not present, the file is not mutable.
|
|
705
|
-
*/
|
|
706
|
-
setRawContents(contents: string): Result<string>;
|
|
707
742
|
}
|
|
708
743
|
|
|
709
744
|
/**
|
|
@@ -816,6 +851,8 @@ declare interface IJsonValidatorContext {
|
|
|
816
851
|
|
|
817
852
|
/**
|
|
818
853
|
* Extended accessors interface that supports mutation operations.
|
|
854
|
+
* All mutation methods are required — use {@link FileTree.isMutableAccessors | isMutableAccessors}
|
|
855
|
+
* type guard to check if an accessor supports mutation.
|
|
819
856
|
* @public
|
|
820
857
|
*/
|
|
821
858
|
declare interface IMutableFileTreeAccessors<TCT extends string = string> extends IFileTreeAccessors<TCT> {
|
|
@@ -833,12 +870,90 @@ declare interface IMutableFileTreeAccessors<TCT extends string = string> extends
|
|
|
833
870
|
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
834
871
|
*/
|
|
835
872
|
saveFileContents(path: string, contents: string): Result<string>;
|
|
873
|
+
/**
|
|
874
|
+
* Deletes a file at the given path.
|
|
875
|
+
* @param path - The path of the file to delete.
|
|
876
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
877
|
+
*/
|
|
878
|
+
deleteFile(path: string): Result<boolean>;
|
|
836
879
|
/**
|
|
837
880
|
* Creates a directory at the given path, including any missing parent directories.
|
|
838
881
|
* @param path - The path of the directory to create.
|
|
839
882
|
* @returns `Success` with the absolute path if created, or `Failure` with an error message.
|
|
840
883
|
*/
|
|
841
|
-
createDirectory
|
|
884
|
+
createDirectory(path: string): Result<string>;
|
|
885
|
+
/**
|
|
886
|
+
* Deletes a directory at the given path.
|
|
887
|
+
* The directory must be empty or the operation will fail.
|
|
888
|
+
* @param path - The path of the directory to delete.
|
|
889
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
890
|
+
*/
|
|
891
|
+
deleteDirectory(path: string): Result<boolean>;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Extended directory item interface that supports mutation operations.
|
|
896
|
+
* Use {@link FileTree.isMutableDirectoryItem | isMutableDirectoryItem} type guard to narrow.
|
|
897
|
+
* @public
|
|
898
|
+
*/
|
|
899
|
+
declare interface IMutableFileTreeDirectoryItem<TCT extends string = string> extends IFileTreeDirectoryItem<TCT> {
|
|
900
|
+
/**
|
|
901
|
+
* Creates a new file as a child of this directory.
|
|
902
|
+
* @param name - The file name to create.
|
|
903
|
+
* @param contents - The string contents to write.
|
|
904
|
+
* @returns `Success` with the new file item, or `Failure` with an error message.
|
|
905
|
+
*/
|
|
906
|
+
createChildFile(name: string, contents: string): Result<IMutableFileTreeFileItem<TCT>>;
|
|
907
|
+
/**
|
|
908
|
+
* Creates a new subdirectory as a child of this directory.
|
|
909
|
+
* @param name - The directory name to create.
|
|
910
|
+
* @returns `Success` with the new directory item, or `Failure` with an error message.
|
|
911
|
+
*/
|
|
912
|
+
createChildDirectory(name: string): Result<IMutableFileTreeDirectoryItem<TCT>>;
|
|
913
|
+
/**
|
|
914
|
+
* Deletes a child item from this directory.
|
|
915
|
+
* @param name - The name of the child to delete.
|
|
916
|
+
* @param options - Optional {@link FileTree.IDeleteChildOptions | options} controlling deletion behavior.
|
|
917
|
+
* @returns `Success` with `true` if the child was deleted, or `Failure` with an error message.
|
|
918
|
+
*/
|
|
919
|
+
deleteChild(name: string, options?: IDeleteChildOptions): Result<boolean>;
|
|
920
|
+
/**
|
|
921
|
+
* Deletes this directory from its backing store.
|
|
922
|
+
* The directory must be empty or the operation will fail.
|
|
923
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
924
|
+
*/
|
|
925
|
+
delete(): Result<boolean>;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Extended file item interface that supports mutation operations.
|
|
930
|
+
* Use {@link FileTree.isMutableFileItem | isMutableFileItem} type guard to narrow.
|
|
931
|
+
* @public
|
|
932
|
+
*/
|
|
933
|
+
declare interface IMutableFileTreeFileItem<TCT extends string = string> extends IFileTreeFileItem<TCT> {
|
|
934
|
+
/**
|
|
935
|
+
* Indicates whether this file can be saved.
|
|
936
|
+
* @returns `DetailedSuccess` with {@link FileTree.SaveCapability} if the file can be saved,
|
|
937
|
+
* or `DetailedFailure` with {@link FileTree.SaveFailureReason} if it cannot.
|
|
938
|
+
*/
|
|
939
|
+
getIsMutable(): DetailedResult<boolean, SaveDetail>;
|
|
940
|
+
/**
|
|
941
|
+
* Sets the contents of the file from a JSON value.
|
|
942
|
+
* @param json - The JSON value to serialize and save.
|
|
943
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
944
|
+
*/
|
|
945
|
+
setContents(json: JsonValue): Result<JsonValue>;
|
|
946
|
+
/**
|
|
947
|
+
* Sets the raw contents of the file.
|
|
948
|
+
* @param contents - The string contents to save.
|
|
949
|
+
* @returns `Success` if the file was saved, or `Failure` with an error message.
|
|
950
|
+
*/
|
|
951
|
+
setRawContents(contents: string): Result<string>;
|
|
952
|
+
/**
|
|
953
|
+
* Deletes this file from its backing store.
|
|
954
|
+
* @returns `Success` with `true` if the file was deleted, or `Failure` with an error message.
|
|
955
|
+
*/
|
|
956
|
+
delete(): Result<boolean>;
|
|
842
957
|
}
|
|
843
958
|
|
|
844
959
|
/**
|
|
@@ -936,6 +1051,14 @@ declare class InMemoryTreeAccessors<TCT extends string = string> implements IMut
|
|
|
936
1051
|
* {@inheritDoc FileTree.IMutableFileTreeAccessors.fileIsMutable}
|
|
937
1052
|
*/
|
|
938
1053
|
fileIsMutable(path: string): DetailedResult<boolean, SaveDetail>;
|
|
1054
|
+
/**
|
|
1055
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteFile}
|
|
1056
|
+
*/
|
|
1057
|
+
deleteFile(path: string): Result<boolean>;
|
|
1058
|
+
/**
|
|
1059
|
+
* {@inheritDoc FileTree.IMutableFileTreeAccessors.deleteDirectory}
|
|
1060
|
+
*/
|
|
1061
|
+
deleteDirectory(path: string): Result<boolean>;
|
|
939
1062
|
/**
|
|
940
1063
|
* {@inheritDoc FileTree.IMutableFileTreeAccessors.saveFileContents}
|
|
941
1064
|
*/
|
|
@@ -1014,6 +1137,22 @@ export declare function isJsonPrimitive(from: unknown): from is JsonPrimitive;
|
|
|
1014
1137
|
*/
|
|
1015
1138
|
declare function isMutableAccessors<TCT extends string = string>(accessors: IFileTreeAccessors<TCT>): accessors is IMutableFileTreeAccessors<TCT>;
|
|
1016
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Type guard to check if a directory item supports mutation.
|
|
1142
|
+
* @param item - The directory item to check.
|
|
1143
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeDirectoryItem}.
|
|
1144
|
+
* @public
|
|
1145
|
+
*/
|
|
1146
|
+
declare function isMutableDirectoryItem<TCT extends string = string>(item: AnyFileTreeDirectoryItem<TCT> | FileTreeItem<TCT>): item is IMutableFileTreeDirectoryItem<TCT>;
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Type guard to check if a file item supports mutation.
|
|
1150
|
+
* @param item - The file item to check.
|
|
1151
|
+
* @returns `true` if the item implements {@link FileTree.IMutableFileTreeFileItem}.
|
|
1152
|
+
* @public
|
|
1153
|
+
*/
|
|
1154
|
+
declare function isMutableFileItem<TCT extends string = string>(item: AnyFileTreeFileItem<TCT> | FileTreeItem<TCT>): item is IMutableFileTreeFileItem<TCT>;
|
|
1155
|
+
|
|
1017
1156
|
/**
|
|
1018
1157
|
* Checks if a path is allowed by a mutability configuration.
|
|
1019
1158
|
* @param path - The path to check.
|
|
@@ -1419,6 +1558,12 @@ declare function literal<T>(value: T): Converter<T, IJsonConverterContext>;
|
|
|
1419
1558
|
*/
|
|
1420
1559
|
declare function literal_2<T>(value: T): Validator<T, IJsonValidatorContext>;
|
|
1421
1560
|
|
|
1561
|
+
/**
|
|
1562
|
+
* Type for a mutable item in a file tree.
|
|
1563
|
+
* @public
|
|
1564
|
+
*/
|
|
1565
|
+
declare type MutableFileTreeItem<TCT extends string = string> = IMutableFileTreeFileItem<TCT> | IMutableFileTreeDirectoryItem<TCT>;
|
|
1566
|
+
|
|
1422
1567
|
/**
|
|
1423
1568
|
* A `Converter` which converts `unknown` to a `number`.
|
|
1424
1569
|
* Accepts `IJsonConverterContext` but ignores it.
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Result } from '@fgv/ts-utils';
|
|
2
|
-
import { FileTreeItem, IFileTreeAccessors,
|
|
2
|
+
import { FileTreeItem, IDeleteChildOptions, IFileTreeAccessors, IMutableFileTreeDirectoryItem, IMutableFileTreeFileItem } from './fileTreeAccessors';
|
|
3
3
|
/**
|
|
4
4
|
* Class representing a directory in a file tree.
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export declare class DirectoryItem<TCT extends string = string> implements
|
|
7
|
+
export declare class DirectoryItem<TCT extends string = string> implements IMutableFileTreeDirectoryItem<TCT> {
|
|
8
8
|
/**
|
|
9
9
|
* {@inheritDoc FileTree.IFileTreeDirectoryItem."type"}
|
|
10
10
|
*/
|
|
@@ -44,12 +44,27 @@ export declare class DirectoryItem<TCT extends string = string> implements IFile
|
|
|
44
44
|
*/
|
|
45
45
|
getChildren(): Result<ReadonlyArray<FileTreeItem<TCT>>>;
|
|
46
46
|
/**
|
|
47
|
-
* {@inheritDoc FileTree.
|
|
47
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildFile}
|
|
48
48
|
*/
|
|
49
|
-
createChildFile(name: string, contents: string): Result<
|
|
49
|
+
createChildFile(name: string, contents: string): Result<IMutableFileTreeFileItem<TCT>>;
|
|
50
50
|
/**
|
|
51
|
-
* {@inheritDoc FileTree.
|
|
51
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildDirectory}
|
|
52
52
|
*/
|
|
53
|
-
createChildDirectory(name: string): Result<
|
|
53
|
+
createChildDirectory(name: string): Result<IMutableFileTreeDirectoryItem<TCT>>;
|
|
54
|
+
/**
|
|
55
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.deleteChild}
|
|
56
|
+
*/
|
|
57
|
+
deleteChild(name: string, options?: IDeleteChildOptions): Result<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.delete}
|
|
60
|
+
*/
|
|
61
|
+
delete(): Result<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Recursively deletes all children of a directory and then the directory itself.
|
|
64
|
+
* @param dirPath - The absolute path of the directory to delete.
|
|
65
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
private _deleteRecursive;
|
|
54
69
|
}
|
|
55
70
|
//# sourceMappingURL=directoryItem.d.ts.map
|
|
@@ -68,34 +68,98 @@ class DirectoryItem {
|
|
|
68
68
|
return this._hal.getChildren(this.absolutePath);
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
* {@inheritDoc FileTree.
|
|
71
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildFile}
|
|
72
72
|
*/
|
|
73
73
|
createChildFile(name, contents) {
|
|
74
|
-
|
|
74
|
+
const hal = this._hal;
|
|
75
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(hal)) {
|
|
76
|
+
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
75
77
|
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
76
78
|
}
|
|
77
|
-
const filePath =
|
|
78
|
-
return
|
|
79
|
+
const filePath = hal.joinPaths(this.absolutePath, name);
|
|
80
|
+
return hal.saveFileContents(filePath, contents).onSuccess(() => hal.getItem(filePath).onSuccess((item) => {
|
|
79
81
|
/* c8 ignore next 3 - defensive: verifies accessor returned correct item type after save */
|
|
80
|
-
if (
|
|
81
|
-
return (0, ts_utils_1.fail)(`${filePath}: expected file but got ${item.type}`);
|
|
82
|
+
if (!(0, fileTreeAccessors_1.isMutableFileItem)(item)) {
|
|
83
|
+
return (0, ts_utils_1.fail)(`${filePath}: expected mutable file but got ${item.type}`);
|
|
82
84
|
}
|
|
83
85
|
return (0, ts_utils_1.succeed)(item);
|
|
84
86
|
}));
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
87
|
-
* {@inheritDoc FileTree.
|
|
89
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.createChildDirectory}
|
|
88
90
|
*/
|
|
89
91
|
createChildDirectory(name) {
|
|
90
|
-
|
|
92
|
+
const hal = this._hal;
|
|
93
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(hal)) {
|
|
94
|
+
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
91
95
|
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
92
96
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
const dirPath = hal.joinPaths(this.absolutePath, name);
|
|
98
|
+
return hal.createDirectory(dirPath).onSuccess(() => DirectoryItem.create(dirPath, hal));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.deleteChild}
|
|
102
|
+
*/
|
|
103
|
+
deleteChild(name, options) {
|
|
104
|
+
const hal = this._hal;
|
|
105
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(hal)) {
|
|
106
|
+
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
107
|
+
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
108
|
+
}
|
|
109
|
+
const childPath = hal.joinPaths(this.absolutePath, name);
|
|
110
|
+
return hal.getItem(childPath).onSuccess((item) => {
|
|
111
|
+
if (item.type === 'file') {
|
|
112
|
+
return hal.deleteFile(childPath);
|
|
113
|
+
}
|
|
114
|
+
// Directory child
|
|
115
|
+
if (options === null || options === void 0 ? void 0 : options.recursive) {
|
|
116
|
+
return this._deleteRecursive(childPath);
|
|
117
|
+
}
|
|
118
|
+
return hal.deleteDirectory(childPath);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* {@inheritDoc FileTree.IMutableFileTreeDirectoryItem.delete}
|
|
123
|
+
*/
|
|
124
|
+
delete() {
|
|
125
|
+
const hal = this._hal;
|
|
126
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(hal)) {
|
|
127
|
+
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
128
|
+
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
129
|
+
}
|
|
130
|
+
return hal.deleteDirectory(this.absolutePath);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Recursively deletes all children of a directory and then the directory itself.
|
|
134
|
+
* @param dirPath - The absolute path of the directory to delete.
|
|
135
|
+
* @returns `Success` with `true` if the directory was deleted, or `Failure` with an error message.
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
_deleteRecursive(dirPath) {
|
|
139
|
+
const hal = this._hal;
|
|
140
|
+
/* c8 ignore next 3 - defensive: caller already verified mutable */
|
|
141
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(hal)) {
|
|
142
|
+
return (0, ts_utils_1.fail)(`${dirPath}: mutation not supported`);
|
|
96
143
|
}
|
|
97
|
-
|
|
98
|
-
|
|
144
|
+
return hal.getChildren(dirPath).onSuccess((children) => {
|
|
145
|
+
for (const child of children) {
|
|
146
|
+
if (child.type === 'file') {
|
|
147
|
+
const result = hal.deleteFile(child.absolutePath);
|
|
148
|
+
/* c8 ignore next 3 - defensive: error propagation during recursive delete */
|
|
149
|
+
if (result.isFailure()) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const result = this._deleteRecursive(child.absolutePath);
|
|
155
|
+
/* c8 ignore next 3 - defensive: error propagation during recursive delete */
|
|
156
|
+
if (result.isFailure()) {
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return hal.deleteDirectory(dirPath);
|
|
162
|
+
});
|
|
99
163
|
}
|
|
100
164
|
}
|
|
101
165
|
exports.DirectoryItem = DirectoryItem;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DetailedResult, Result } from '@fgv/ts-utils';
|
|
2
2
|
import { Converter, Validator } from '@fgv/ts-utils';
|
|
3
3
|
import { JsonValue } from '../json';
|
|
4
|
-
import { IFileTreeAccessors,
|
|
4
|
+
import { IFileTreeAccessors, IMutableFileTreeFileItem, SaveDetail } from './fileTreeAccessors';
|
|
5
5
|
/**
|
|
6
6
|
* Class representing a file in a file tree.
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
export declare class FileItem<TCT extends string = string> implements
|
|
9
|
+
export declare class FileItem<TCT extends string = string> implements IMutableFileTreeFileItem<TCT> {
|
|
10
10
|
/**
|
|
11
11
|
* {@inheritDoc FileTree.IFileTreeFileItem."type"}
|
|
12
12
|
*/
|
|
@@ -86,6 +86,10 @@ export declare class FileItem<TCT extends string = string> implements IFileTreeF
|
|
|
86
86
|
* {@inheritDoc FileTree.IFileTreeFileItem.setRawContents}
|
|
87
87
|
*/
|
|
88
88
|
setRawContents(contents: string): Result<string>;
|
|
89
|
+
/**
|
|
90
|
+
* {@inheritDoc FileTree.IFileTreeFileItem.delete}
|
|
91
|
+
*/
|
|
92
|
+
delete(): Result<boolean>;
|
|
89
93
|
/**
|
|
90
94
|
* Default function to infer the content type of a file.
|
|
91
95
|
* @param filePath - The path of the file.
|
|
@@ -129,6 +129,16 @@ class FileItem {
|
|
|
129
129
|
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
130
130
|
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* {@inheritDoc FileTree.IFileTreeFileItem.delete}
|
|
134
|
+
*/
|
|
135
|
+
delete() {
|
|
136
|
+
if (!(0, fileTreeAccessors_1.isMutableAccessors)(this._hal)) {
|
|
137
|
+
/* c8 ignore next 2 - defensive: all current accessor implementations support mutation interface */
|
|
138
|
+
return (0, ts_utils_1.fail)(`${this.absolutePath}: mutation not supported`);
|
|
139
|
+
}
|
|
140
|
+
return this._hal.deleteFile(this.absolutePath);
|
|
141
|
+
}
|
|
132
142
|
/**
|
|
133
143
|
* Default function to infer the content type of a file.
|
|
134
144
|
* @param filePath - The path of the file.
|