@fgv/ts-utils 5.0.0-30 → 5.0.0-31

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.
Files changed (30) hide show
  1. package/dist/ts-utils.d.ts +3002 -3416
  2. package/lib/index.d.ts +1 -2
  3. package/lib/index.js +1 -3
  4. package/lib/packlets/base/mapResults.d.ts +8 -1
  5. package/lib/packlets/base/mapResults.js +19 -0
  6. package/lib/packlets/base/result.d.ts +20 -3
  7. package/lib/packlets/base/result.js +22 -3
  8. package/lib/packlets/collections/collector.js +10 -1
  9. package/lib/packlets/logging/logReporter.js +1 -10
  10. package/lib/packlets/logging/logger.d.ts +8 -0
  11. package/lib/packlets/logging/logger.js +24 -1
  12. package/package.json +1 -1
  13. package/lib/packlets/file-tree/directoryItem.d.ts +0 -47
  14. package/lib/packlets/file-tree/directoryItem.js +0 -71
  15. package/lib/packlets/file-tree/fileItem.d.ts +0 -64
  16. package/lib/packlets/file-tree/fileItem.js +0 -93
  17. package/lib/packlets/file-tree/fileTree.d.ts +0 -84
  18. package/lib/packlets/file-tree/fileTree.js +0 -135
  19. package/lib/packlets/file-tree/fileTreeAccessors.d.ts +0 -134
  20. package/lib/packlets/file-tree/fileTreeAccessors.js +0 -24
  21. package/lib/packlets/file-tree/fsTree.d.ts +0 -45
  22. package/lib/packlets/file-tree/fsTree.js +0 -116
  23. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +0 -67
  24. package/lib/packlets/file-tree/in-memory/inMemoryTree.js +0 -150
  25. package/lib/packlets/file-tree/in-memory/index.d.ts +0 -2
  26. package/lib/packlets/file-tree/in-memory/index.js +0 -39
  27. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +0 -106
  28. package/lib/packlets/file-tree/in-memory/treeBuilder.js +0 -170
  29. package/lib/packlets/file-tree/index.d.ts +0 -8
  30. package/lib/packlets/file-tree/index.js +0 -46
@@ -1,84 +0,0 @@
1
- import { Result } from '../base';
2
- import { FileTreeItem, IFileTreeAccessors, IFileTreeDirectoryItem, IFileTreeFileItem } from './fileTreeAccessors';
3
- import { IInMemoryFile } from './in-memory';
4
- /**
5
- * Represents a file tree.
6
- * @public
7
- */
8
- export declare class FileTree {
9
- /**
10
- * The {@link FileTree.IFileTreeAccessors | accessors} to use for file system operations.
11
- * @public
12
- */
13
- hal: IFileTreeAccessors;
14
- /**
15
- * Protected constructor for derived classes.
16
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
17
- * file system operations.
18
- * @public
19
- */
20
- protected constructor(hal: IFileTreeAccessors);
21
- /**
22
- * Creates a new {@link FileTree.FileTree | FileTree} instance with the supplied
23
- * accessors.
24
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
25
- * file system operations.
26
- */
27
- static create(hal: IFileTreeAccessors): Result<FileTree>;
28
- /**
29
- * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors
30
- * for the filesystem.
31
- * @param prefix - An optional prefix to prepended to supplied relative
32
- * paths.
33
- */
34
- static forFilesystem(prefix?: string): Result<FileTree>;
35
- /**
36
- * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors
37
- * for an in-memory file tree.
38
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to
39
- * include in the tree.
40
- * @param prefix - An optional prefix to add to the paths of all files in the tree.
41
- */
42
- static inMemory(files: IInMemoryFile[], prefix?: string): Result<FileTree>;
43
- /**
44
- * Gets an item from the tree.
45
- * @param itemPath - The path to the item.
46
- * @returns {@link Success | Success} with the item if successful,
47
- * or {@link Failure | Failure} with an error message otherwise.
48
- */
49
- getItem(itemPath: string): Result<FileTreeItem>;
50
- /**
51
- * Gets a file item from the tree.
52
- * @param filePath - The path to the file.
53
- * @returns {@link Success | Success} with the {@link FileTree.IFileTreeFileItem | file item}
54
- * if successful, or {@link Failure | Failure} with an error message otherwise.
55
- */
56
- getFile(filePath: string): Result<IFileTreeFileItem>;
57
- /**
58
- * Gets a directory item from the tree.
59
- * @param directoryPath - The path to the directory.
60
- * @returns {@link Success | Success} with the {@link FileTree.IFileTreeDirectoryItem | directory item}
61
- * if successful, or {@link Failure | Failure} with an error message otherwise.
62
- */
63
- getDirectory(directoryPath: string): Result<IFileTreeDirectoryItem>;
64
- }
65
- /**
66
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
67
- * with accessors for the filesystem.
68
- * @param prefix - An optional prefix to prepended to supplied relative paths.
69
- * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance
70
- * if successful, or {@link Failure | Failure} with an error message otherwise.
71
- * @public
72
- */
73
- export declare function forFilesystem(prefix?: string): Result<FileTree>;
74
- /**
75
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
76
- * with accessors for an in-memory file tree.
77
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
78
- * @param prefix - An optional prefix to add to the paths of all files in the tree.
79
- * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance
80
- * if successful, or {@link Failure | Failure} with an error message otherwise.
81
- * @public
82
- */
83
- export declare function inMemory(files: IInMemoryFile[], prefix?: string): Result<FileTree>;
84
- //# sourceMappingURL=fileTree.d.ts.map
@@ -1,135 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2025 Erik Fortune
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining a copy
6
- * of this software and associated documentation files (the "Software"), to deal
7
- * in the Software without restriction, including without limitation the rights
8
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- * copies of the Software, and to permit persons to whom the Software is
10
- * furnished to do so, subject to the following conditions:
11
- *
12
- * The above copyright notice and this permission notice shall be included in all
13
- * copies or substantial portions of the Software.
14
- *
15
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- * SOFTWARE.
22
- */
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.FileTree = void 0;
25
- exports.forFilesystem = forFilesystem;
26
- exports.inMemory = inMemory;
27
- const base_1 = require("../base");
28
- const fsTree_1 = require("./fsTree");
29
- const in_memory_1 = require("./in-memory");
30
- /**
31
- * Represents a file tree.
32
- * @public
33
- */
34
- class FileTree {
35
- /**
36
- * Protected constructor for derived classes.
37
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
38
- * file system operations.
39
- * @public
40
- */
41
- constructor(hal) {
42
- this.hal = hal;
43
- }
44
- /**
45
- * Creates a new {@link FileTree.FileTree | FileTree} instance with the supplied
46
- * accessors.
47
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
48
- * file system operations.
49
- */
50
- static create(hal) {
51
- return (0, base_1.captureResult)(() => new FileTree(hal));
52
- }
53
- /**
54
- * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors
55
- * for the filesystem.
56
- * @param prefix - An optional prefix to prepended to supplied relative
57
- * paths.
58
- */
59
- static forFilesystem(prefix) {
60
- return (0, base_1.captureResult)(() => new FileTree(new fsTree_1.FsFileTreeAccessors(prefix)));
61
- }
62
- /**
63
- * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors
64
- * for an in-memory file tree.
65
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to
66
- * include in the tree.
67
- * @param prefix - An optional prefix to add to the paths of all files in the tree.
68
- */
69
- static inMemory(files, prefix) {
70
- return in_memory_1.InMemoryTreeAccessors.create(files, prefix).onSuccess((hal) => (0, base_1.captureResult)(() => new FileTree(hal)));
71
- }
72
- /**
73
- * Gets an item from the tree.
74
- * @param itemPath - The path to the item.
75
- * @returns {@link Success | Success} with the item if successful,
76
- * or {@link Failure | Failure} with an error message otherwise.
77
- */
78
- getItem(itemPath) {
79
- const absolutePath = this.hal.resolveAbsolutePath(itemPath);
80
- return this.hal.getItem(absolutePath);
81
- }
82
- /**
83
- * Gets a file item from the tree.
84
- * @param filePath - The path to the file.
85
- * @returns {@link Success | Success} with the {@link FileTree.IFileTreeFileItem | file item}
86
- * if successful, or {@link Failure | Failure} with an error message otherwise.
87
- */
88
- getFile(filePath) {
89
- return this.getItem(filePath).onSuccess((item) => {
90
- if (item.type === 'file') {
91
- return (0, base_1.succeed)(item);
92
- }
93
- return (0, base_1.fail)(`${filePath}: not a file`);
94
- });
95
- }
96
- /**
97
- * Gets a directory item from the tree.
98
- * @param directoryPath - The path to the directory.
99
- * @returns {@link Success | Success} with the {@link FileTree.IFileTreeDirectoryItem | directory item}
100
- * if successful, or {@link Failure | Failure} with an error message otherwise.
101
- */
102
- getDirectory(directoryPath) {
103
- return this.getItem(directoryPath).onSuccess((item) => {
104
- if (item.type === 'directory') {
105
- return (0, base_1.succeed)(item);
106
- }
107
- return (0, base_1.fail)(`${directoryPath}: not a directory`);
108
- });
109
- }
110
- }
111
- exports.FileTree = FileTree;
112
- /**
113
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
114
- * with accessors for the filesystem.
115
- * @param prefix - An optional prefix to prepended to supplied relative paths.
116
- * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance
117
- * if successful, or {@link Failure | Failure} with an error message otherwise.
118
- * @public
119
- */
120
- function forFilesystem(prefix) {
121
- return FileTree.forFilesystem(prefix);
122
- }
123
- /**
124
- * Helper function to create a new {@link FileTree.FileTree | FileTree} instance
125
- * with accessors for an in-memory file tree.
126
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
127
- * @param prefix - An optional prefix to add to the paths of all files in the tree.
128
- * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance
129
- * if successful, or {@link Failure | Failure} with an error message otherwise.
130
- * @public
131
- */
132
- function inMemory(files, prefix) {
133
- return FileTree.inMemory(files, prefix);
134
- }
135
- //# sourceMappingURL=fileTree.js.map
@@ -1,134 +0,0 @@
1
- import { Result } from '../base';
2
- import { Converter } from '../conversion';
3
- import { Validator } from '../validation';
4
- /**
5
- * Type of item in a file tree.
6
- * @public
7
- */
8
- export type FileTreeItemType = 'directory' | 'file';
9
- /**
10
- * Interface for a file in a file tree.
11
- * @public
12
- */
13
- export interface IFileTreeFileItem {
14
- /**
15
- * Indicates that this {@link FileTree.FileTreeItem | file tree item} is a file.
16
- */
17
- readonly type: 'file';
18
- /**
19
- * The absolute path of the file.
20
- */
21
- readonly absolutePath: string;
22
- /**
23
- * The name of the file
24
- */
25
- readonly name: string;
26
- /**
27
- * The base name of the file (without extension)
28
- */
29
- readonly baseName: string;
30
- /**
31
- * The extension of the file
32
- */
33
- readonly extension: string;
34
- /**
35
- * Gets the contents of the file as parsed JSON.
36
- * @returns {@link Success | Success} with the parsed contents if successful, or
37
- * {@link Failure | Failure}with an error message otherwise.
38
- */
39
- getContents(): Result<unknown>;
40
- /**
41
- * Gets the contents of the file as parsed JSON, converted to a specific type.
42
- * @param converter - A {@link Validation.Validator | Validator} or {@link Conversion.Converter | Converter}
43
- * to convert the parsed JSON contents to the desired type.
44
- * @returns {@link Success | Success} with the converted contents if successful, or
45
- * {@link Failure | Failure} with an error message otherwise.
46
- */
47
- getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;
48
- /**
49
- * Gets the raw contents of the file as a string.
50
- * @returns {@link Success | Success} with the raw contents if successful, or
51
- * {@link Failure | Failure} with an error message otherwise.
52
- */
53
- getRawContents(): Result<string>;
54
- }
55
- /**
56
- * Interface for a directory in a file tree.
57
- * @public
58
- */
59
- export interface IFileTreeDirectoryItem {
60
- /**
61
- * Indicates that this {@link FileTree.FileTreeItem | file tree item} is a directory
62
- */
63
- readonly type: 'directory';
64
- /**
65
- * The absolute path of the directory.
66
- */
67
- readonly absolutePath: string;
68
- /**
69
- * The name of the directory
70
- */
71
- readonly name: string;
72
- /**
73
- * Gets the children of the directory.
74
- * @returns {@link Success | Success} with the children of the directory if successful,
75
- * or {@link Failure | Failure} with an error message otherwise.
76
- */
77
- getChildren(): Result<ReadonlyArray<FileTreeItem>>;
78
- }
79
- /**
80
- * Type for an item in a file tree.
81
- * @public
82
- */
83
- export type FileTreeItem = IFileTreeFileItem | IFileTreeDirectoryItem;
84
- /**
85
- * Common abstraction layer interface for a tree of files
86
- * (e.g. a file system or a zip file).
87
- * @public
88
- */
89
- export interface IFileTreeAccessors {
90
- /**
91
- * Resolves paths to an absolute path.
92
- * @param paths - Paths to resolve.
93
- * @returns The resolved absolute path.
94
- */
95
- resolveAbsolutePath(...paths: string[]): string;
96
- /**
97
- * Gets the extension of a path.
98
- * @param path - Path to get the extension of.
99
- * @returns The extension of the path.
100
- */
101
- getExtension(path: string): string;
102
- /**
103
- * Gets the base name of a path.
104
- * @param path - Path to get the base name of.
105
- * @param suffix - Optional suffix to remove from the base name.
106
- * @returns The base name of the path.
107
- */
108
- getBaseName(path: string, suffix?: string): string;
109
- /**
110
- * Joins paths together.
111
- * @param paths - Paths to join.
112
- * @returns The joined paths.
113
- */
114
- joinPaths(...paths: string[]): string;
115
- /**
116
- * Gets an item from the file tree.
117
- * @param path - Path of the item to get.
118
- * @returns The item if it exists.
119
- */
120
- getItem(path: string): Result<FileTreeItem>;
121
- /**
122
- * Gets the contents of a file in the file tree.
123
- * @param path - Absolute path of the file.
124
- * @returns The contents of the file.
125
- */
126
- getFileContents(path: string): Result<string>;
127
- /**
128
- * Gets the children of a directory in the file tree.
129
- * @param path - Path of the directory.
130
- * @returns The children of the directory.
131
- */
132
- getChildren(path: string): Result<ReadonlyArray<FileTreeItem>>;
133
- }
134
- //# sourceMappingURL=fileTreeAccessors.d.ts.map
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2025 Erik Fortune
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining a copy
6
- * of this software and associated documentation files (the "Software"), to deal
7
- * in the Software without restriction, including without limitation the rights
8
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- * copies of the Software, and to permit persons to whom the Software is
10
- * furnished to do so, subject to the following conditions:
11
- *
12
- * The above copyright notice and this permission notice shall be included in all
13
- * copies or substantial portions of the Software.
14
- *
15
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- * SOFTWARE.
22
- */
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- //# sourceMappingURL=fileTreeAccessors.js.map
@@ -1,45 +0,0 @@
1
- import { FileTreeItem, IFileTreeAccessors } from './fileTreeAccessors';
2
- import { Result } from '../base';
3
- /**
4
- * Implementation of {@link FileTree.IFileTreeAccessors | IFileTreeAccessors} that uses the
5
- * file system to access files and directories.
6
- * @public
7
- */
8
- export declare class FsFileTreeAccessors implements IFileTreeAccessors {
9
- readonly prefix: string | undefined;
10
- /**
11
- * Protected constructor for derived classes.
12
- * @param prefix - Optional prefix for the tree.
13
- * @public
14
- */
15
- constructor(prefix?: string);
16
- /**
17
- * {@inheritDoc FileTree.IFileTreeAccessors.resolveAbsolutePath}
18
- */
19
- resolveAbsolutePath(...paths: string[]): string;
20
- /**
21
- * {@inheritDoc FileTree.IFileTreeAccessors.getExtension}
22
- */
23
- getExtension(itemPath: string): string;
24
- /**
25
- * {@inheritDoc FileTree.IFileTreeAccessors.getBaseName}
26
- */
27
- getBaseName(itemPath: string, suffix?: string): string;
28
- /**
29
- * {@inheritDoc FileTree.IFileTreeAccessors.joinPaths}
30
- */
31
- joinPaths(...paths: string[]): string;
32
- /**
33
- * {@inheritDoc FileTree.IFileTreeAccessors.getItem}
34
- */
35
- getItem(itemPath: string): Result<FileTreeItem>;
36
- /**
37
- * {@inheritDoc FileTree.IFileTreeAccessors.getFileContents}
38
- */
39
- getFileContents(filePath: string): Result<string>;
40
- /**
41
- * {@inheritDoc FileTree.IFileTreeAccessors.getChildren}
42
- */
43
- getChildren(dirPath: string): Result<ReadonlyArray<FileTreeItem>>;
44
- }
45
- //# sourceMappingURL=fsTree.d.ts.map
@@ -1,116 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2025 Erik Fortune
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining a copy
6
- * of this software and associated documentation files (the "Software"), to deal
7
- * in the Software without restriction, including without limitation the rights
8
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- * copies of the Software, and to permit persons to whom the Software is
10
- * furnished to do so, subject to the following conditions:
11
- *
12
- * The above copyright notice and this permission notice shall be included in all
13
- * copies or substantial portions of the Software.
14
- *
15
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- * SOFTWARE.
22
- */
23
- var __importDefault = (this && this.__importDefault) || function (mod) {
24
- return (mod && mod.__esModule) ? mod : { "default": mod };
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.FsFileTreeAccessors = void 0;
28
- const path_1 = __importDefault(require("path"));
29
- const fs_1 = __importDefault(require("fs"));
30
- const base_1 = require("../base");
31
- const directoryItem_1 = require("./directoryItem");
32
- const fileItem_1 = require("./fileItem");
33
- /**
34
- * Implementation of {@link FileTree.IFileTreeAccessors | IFileTreeAccessors} that uses the
35
- * file system to access files and directories.
36
- * @public
37
- */
38
- class FsFileTreeAccessors {
39
- /**
40
- * Protected constructor for derived classes.
41
- * @param prefix - Optional prefix for the tree.
42
- * @public
43
- */
44
- constructor(prefix) {
45
- this.prefix = prefix;
46
- }
47
- /**
48
- * {@inheritDoc FileTree.IFileTreeAccessors.resolveAbsolutePath}
49
- */
50
- resolveAbsolutePath(...paths) {
51
- if (this.prefix && !path_1.default.isAbsolute(paths[0])) {
52
- return path_1.default.resolve(this.prefix, ...paths);
53
- }
54
- return path_1.default.resolve(...paths);
55
- }
56
- /**
57
- * {@inheritDoc FileTree.IFileTreeAccessors.getExtension}
58
- */
59
- getExtension(itemPath) {
60
- return path_1.default.extname(itemPath);
61
- }
62
- /**
63
- * {@inheritDoc FileTree.IFileTreeAccessors.getBaseName}
64
- */
65
- getBaseName(itemPath, suffix) {
66
- return path_1.default.basename(itemPath, suffix);
67
- }
68
- /**
69
- * {@inheritDoc FileTree.IFileTreeAccessors.joinPaths}
70
- */
71
- joinPaths(...paths) {
72
- return path_1.default.join(...paths);
73
- }
74
- /**
75
- * {@inheritDoc FileTree.IFileTreeAccessors.getItem}
76
- */
77
- getItem(itemPath) {
78
- return (0, base_1.captureResult)(() => {
79
- const stat = fs_1.default.statSync(this.resolveAbsolutePath(itemPath));
80
- if (stat.isDirectory()) {
81
- return directoryItem_1.DirectoryItem.create(itemPath, this).orThrow();
82
- }
83
- else if (stat.isFile()) {
84
- return fileItem_1.FileItem.create(itemPath, this).orThrow();
85
- }
86
- throw new Error(`${itemPath}: not a file or directory`);
87
- });
88
- }
89
- /**
90
- * {@inheritDoc FileTree.IFileTreeAccessors.getFileContents}
91
- */
92
- getFileContents(filePath) {
93
- return (0, base_1.captureResult)(() => fs_1.default.readFileSync(this.resolveAbsolutePath(filePath), 'utf8'));
94
- }
95
- /**
96
- * {@inheritDoc FileTree.IFileTreeAccessors.getChildren}
97
- */
98
- getChildren(dirPath) {
99
- return (0, base_1.captureResult)(() => {
100
- const children = [];
101
- const files = fs_1.default.readdirSync(this.resolveAbsolutePath(dirPath), { withFileTypes: true });
102
- files.forEach((file) => {
103
- const fullPath = this.resolveAbsolutePath(dirPath, file.name);
104
- if (file.isDirectory()) {
105
- children.push(directoryItem_1.DirectoryItem.create(fullPath, this).orThrow());
106
- }
107
- else if (file.isFile()) {
108
- children.push(fileItem_1.FileItem.create(fullPath, this).orThrow());
109
- }
110
- });
111
- return children;
112
- });
113
- }
114
- }
115
- exports.FsFileTreeAccessors = FsFileTreeAccessors;
116
- //# sourceMappingURL=fsTree.js.map
@@ -1,67 +0,0 @@
1
- import { Result } from '../../base';
2
- import { FileTreeItem, IFileTreeAccessors } from '../fileTreeAccessors';
3
- /**
4
- * Represents a single file in an in-memory {@link FileTree.FileTree | file tree}.
5
- * @public
6
- */
7
- export interface IInMemoryFile {
8
- /**
9
- * The absolute path of the file in the tree.
10
- */
11
- readonly path: string;
12
- /**
13
- * The contents of the file
14
- */
15
- readonly contents: unknown;
16
- }
17
- /**
18
- * Implementation of {@link FileTree.IFileTreeAccessors | IFileTreeAccessors} that uses an in-memory
19
- * tree to access files and directories.
20
- * @public
21
- */
22
- export declare class InMemoryTreeAccessors implements IFileTreeAccessors {
23
- private readonly _tree;
24
- /**
25
- * Protected constructor for derived classes.
26
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
27
- * @param prefix - Optional prefix for the tree.
28
- * @public
29
- */
30
- protected constructor(files: IInMemoryFile[], prefix?: string);
31
- /**
32
- * Creates a new {@link FileTree.InMemoryTreeAccessors | InMemoryTreeAccessors} instance with the supplied
33
- * in-memory files.
34
- * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to include in the tree.
35
- * @param prefix - Optional prefix for the tree.
36
- */
37
- static create(files: IInMemoryFile[], prefix?: string): Result<InMemoryTreeAccessors>;
38
- /**
39
- * {@inheritDoc FileTree.IFileTreeAccessors.resolveAbsolutePath}
40
- */
41
- resolveAbsolutePath(...paths: string[]): string;
42
- /**
43
- * {@inheritdoc FileTree.IFileTreeAccessors.getExtension}
44
- */
45
- getExtension(path: string): string;
46
- /**
47
- * {@inheritdoc FileTree.IFileTreeAccessors.getBaseName}
48
- */
49
- getBaseName(path: string, suffix?: string): string;
50
- /**
51
- * {@inheritdoc FileTree.IFileTreeAccessors.joinPaths}
52
- */
53
- joinPaths(...paths: string[]): string;
54
- /**
55
- * {@inheritDoc FileTree.IFileTreeAccessors.getItem}
56
- */
57
- getItem(itemPath: string): Result<FileTreeItem>;
58
- /**
59
- * {@inheritDoc FileTree.IFileTreeAccessors.getFileContents}
60
- */
61
- getFileContents(path: string): Result<string>;
62
- /**
63
- * {@inheritDoc FileTree.IFileTreeAccessors.getChildren}
64
- */
65
- getChildren(path: string): Result<ReadonlyArray<FileTreeItem>>;
66
- }
67
- //# sourceMappingURL=inMemoryTree.d.ts.map