@fgv/ts-utils 4.5.0-2 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.json +20 -0
  2. package/CHANGELOG.md +13 -1
  3. package/dist/ts-utils.d.ts +2594 -3081
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/index.d.ts +1 -2
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +1 -3
  8. package/lib/index.js.map +1 -1
  9. package/lib/packlets/base/mapResults.js +1 -1
  10. package/lib/packlets/base/mapResults.js.map +1 -1
  11. package/lib/packlets/base/result.d.ts +15 -78
  12. package/lib/packlets/base/result.d.ts.map +1 -1
  13. package/lib/packlets/base/result.js +19 -101
  14. package/lib/packlets/base/result.js.map +1 -1
  15. package/lib/packlets/base/utils.d.ts.map +1 -1
  16. package/lib/packlets/base/utils.js +1 -0
  17. package/lib/packlets/base/utils.js.map +1 -1
  18. package/lib/packlets/conversion/objectConverter.d.ts +0 -3
  19. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
  20. package/lib/packlets/conversion/objectConverter.js +43 -42
  21. package/lib/packlets/conversion/objectConverter.js.map +1 -1
  22. package/lib/packlets/hash/crcNormalizer.js +1 -1
  23. package/lib/packlets/hash/crcNormalizer.js.map +1 -1
  24. package/lib/packlets/validation/validators.d.ts +30 -0
  25. package/lib/packlets/validation/validators.d.ts.map +1 -1
  26. package/lib/packlets/validation/validators.js +53 -0
  27. package/lib/packlets/validation/validators.js.map +1 -1
  28. package/package.json +15 -15
  29. package/lib/packlets/file-tree/directoryItem.d.ts +0 -47
  30. package/lib/packlets/file-tree/directoryItem.d.ts.map +0 -1
  31. package/lib/packlets/file-tree/directoryItem.js +0 -71
  32. package/lib/packlets/file-tree/directoryItem.js.map +0 -1
  33. package/lib/packlets/file-tree/fileItem.d.ts +0 -64
  34. package/lib/packlets/file-tree/fileItem.d.ts.map +0 -1
  35. package/lib/packlets/file-tree/fileItem.js +0 -93
  36. package/lib/packlets/file-tree/fileItem.js.map +0 -1
  37. package/lib/packlets/file-tree/fileTree.d.ts +0 -84
  38. package/lib/packlets/file-tree/fileTree.d.ts.map +0 -1
  39. package/lib/packlets/file-tree/fileTree.js +0 -135
  40. package/lib/packlets/file-tree/fileTree.js.map +0 -1
  41. package/lib/packlets/file-tree/fileTreeAccessors.d.ts +0 -134
  42. package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +0 -1
  43. package/lib/packlets/file-tree/fileTreeAccessors.js +0 -24
  44. package/lib/packlets/file-tree/fileTreeAccessors.js.map +0 -1
  45. package/lib/packlets/file-tree/fsTree.d.ts +0 -45
  46. package/lib/packlets/file-tree/fsTree.d.ts.map +0 -1
  47. package/lib/packlets/file-tree/fsTree.js +0 -116
  48. package/lib/packlets/file-tree/fsTree.js.map +0 -1
  49. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +0 -67
  50. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +0 -1
  51. package/lib/packlets/file-tree/in-memory/inMemoryTree.js +0 -150
  52. package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +0 -1
  53. package/lib/packlets/file-tree/in-memory/index.d.ts +0 -2
  54. package/lib/packlets/file-tree/in-memory/index.d.ts.map +0 -1
  55. package/lib/packlets/file-tree/in-memory/index.js +0 -39
  56. package/lib/packlets/file-tree/in-memory/index.js.map +0 -1
  57. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +0 -106
  58. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +0 -1
  59. package/lib/packlets/file-tree/in-memory/treeBuilder.js +0 -170
  60. package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +0 -1
  61. package/lib/packlets/file-tree/index.d.ts +0 -8
  62. package/lib/packlets/file-tree/index.d.ts.map +0 -1
  63. package/lib/packlets/file-tree/index.js +0 -46
  64. package/lib/packlets/file-tree/index.js.map +0 -1
@@ -1,93 +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.FileItem = void 0;
25
- const base_1 = require("../base");
26
- /**
27
- * Class representing a file in a file tree.
28
- * @public
29
- */
30
- class FileItem {
31
- /**
32
- * {@inheritdoc FileTree.IFileTreeFileItem.name}
33
- */
34
- get name() {
35
- return this._hal.getBaseName(this.absolutePath);
36
- }
37
- /**
38
- * {@inheritdoc FileTree.IFileTreeFileItem.baseName}
39
- */
40
- get baseName() {
41
- return this._hal.getBaseName(this.absolutePath, this.extension);
42
- }
43
- /**
44
- * {@inheritdoc FileTree.IFileTreeFileItem.extension}
45
- */
46
- get extension() {
47
- return this._hal.getExtension(this.absolutePath);
48
- }
49
- /**
50
- * Protected constructor for derived classes.
51
- * @param path - Relative path of the file.
52
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
53
- * file system operations.
54
- * @public
55
- */
56
- constructor(path, hal) {
57
- /**
58
- * {@inheritdoc FileTree.IFileTreeFileItem."type"}
59
- */
60
- this.type = 'file';
61
- this._hal = hal;
62
- this.absolutePath = hal.resolveAbsolutePath(path);
63
- }
64
- /**
65
- * Creates a new {@link FileTree.FileItem | FileItem} instance.
66
- * @param path - Relative path of the file.
67
- * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
68
- * file system operations.
69
- * @public
70
- */
71
- static create(path, hal) {
72
- return (0, base_1.captureResult)(() => new FileItem(path, hal));
73
- }
74
- getContents(converter) {
75
- return this._hal
76
- .getFileContents(this.absolutePath)
77
- .onSuccess((body) => (0, base_1.captureResult)(() => JSON.parse(body)).onFailure(() => (0, base_1.succeed)(body)))
78
- .onSuccess((parsed) => {
79
- if (converter !== undefined) {
80
- return converter.convert(parsed);
81
- }
82
- return (0, base_1.succeed)(parsed);
83
- });
84
- }
85
- /**
86
- * {@inheritdoc FileTree.IFileTreeFileItem.getRawContents}
87
- */
88
- getRawContents() {
89
- return this._hal.getFileContents(this.absolutePath);
90
- }
91
- }
92
- exports.FileItem = FileItem;
93
- //# sourceMappingURL=fileItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fileItem.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileItem.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyD;AAKzD;;;GAGG;AACH,MAAa,QAAQ;IAWnB;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAClB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aining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result, succeed } from '../base';\nimport { Converter } from '../conversion';\nimport { Validator } from '../validation';\nimport { IFileTreeAccessors, IFileTreeFileItem } from './fileTreeAccessors';\n\n/**\n * Class representing a file in a file tree.\n * @public\n */\nexport class FileItem implements IFileTreeFileItem {\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.\"type\"}\n */\n public readonly type: 'file' = 'file';\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.absolutePath}\n */\n public readonly absolutePath: string;\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.name}\n */\n public get name(): string {\n return this._hal.getBaseName(this.absolutePath);\n }\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.baseName}\n */\n public get baseName(): string {\n return this._hal.getBaseName(this.absolutePath, this.extension);\n }\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.extension}\n */\n public get extension(): string {\n return this._hal.getExtension(this.absolutePath);\n }\n\n /**\n * The {@link FileTree.IFileTreeAccessors | accessors} to use for file system operations.\n * @public\n */\n protected readonly _hal: IFileTreeAccessors;\n\n /**\n * Protected constructor for derived classes.\n * @param path - Relative path of the file.\n * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for\n * file system operations.\n * @public\n */\n protected constructor(path: string, hal: IFileTreeAccessors) {\n this._hal = hal;\n this.absolutePath = hal.resolveAbsolutePath(path);\n }\n\n /**\n * Creates a new {@link FileTree.FileItem | FileItem} instance.\n * @param path - Relative path of the file.\n * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for\n * file system operations.\n * @public\n */\n public static create(path: string, hal: IFileTreeAccessors): Result<FileItem> {\n return captureResult(() => new FileItem(path, hal));\n }\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.(getContents:1)}\n */\n public getContents(): Result<unknown>;\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.(getContents:2)}\n */\n public getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;\n public getContents<T>(converter?: Validator<T> | Converter<T>): Result<T | unknown> {\n return this._hal\n .getFileContents(this.absolutePath)\n .onSuccess((body) => captureResult(() => JSON.parse(body)).onFailure(() => succeed(body)))\n .onSuccess((parsed) => {\n if (converter !== undefined) {\n return converter.convert(parsed);\n }\n return succeed(parsed);\n });\n }\n\n /**\n * {@inheritdoc FileTree.IFileTreeFileItem.getRawContents}\n */\n public getRawContents(): Result<string> {\n return this._hal.getFileContents(this.absolutePath);\n }\n}\n"]}
@@ -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 +0,0 @@
1
- {"version":3,"file":"fileTree.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileTree.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,MAAM,EAAiB,MAAM,SAAS,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AAEnE;;;GAGG;AACH,qBAAa,QAAQ;IACnB;;;OAGG;IACI,GAAG,EAAE,kBAAkB,CAAC;IAE/B;;;;;OAKG;IACH,SAAS,aAAa,GAAG,EAAE,kBAAkB;IAI7C;;;;;OAKG;WACW,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAAC,QAAQ,CAAC;IAI/D;;;;;OAKG;WACW,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAI9D;;;;;;OAMG;WACW,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAMjF;;;;;OAKG;IACI,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;IAKtD;;;;;OAKG;IACI,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAS3D;;;;;OAKG;IACI,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,sBAAsB,CAAC;CAQ3E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAElF"}
@@ -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 +0,0 @@
1
- {"version":3,"file":"fileTree.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileTree.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;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OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;YACvB,CAAC;YACD,OAAO,IAAA,WAAI,EAAC,GAAG,QAAQ,cAAc,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,aAAqB;QACvC,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YACpD,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC9B,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;YACvB,CAAC;YACD,OAAO,IAAA,WAAI,EAAC,GAAG,aAAa,mBAAmB,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA1FD,4BA0FC;AAED;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAC,MAAe;IAC3C,OAAO,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CAAC,KAAsB,EAAE,MAAe;IAC9D,OAAO,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result, fail, succeed } from '../base';\nimport {\n FileTreeItem,\n IFileTreeAccessors,\n IFileTreeDirectoryItem,\n IFileTreeFileItem\n} from './fileTreeAccessors';\nimport { FsFileTreeAccessors } from './fsTree';\nimport { IInMemoryFile, InMemoryTreeAccessors } from './in-memory';\n\n/**\n * Represents a file tree.\n * @public\n */\nexport class FileTree {\n /**\n * The {@link FileTree.IFileTreeAccessors | accessors} to use for file system operations.\n * @public\n */\n public hal: IFileTreeAccessors;\n\n /**\n * Protected constructor for derived classes.\n * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for\n * file system operations.\n * @public\n */\n protected constructor(hal: IFileTreeAccessors) {\n this.hal = hal;\n }\n\n /**\n * Creates a new {@link FileTree.FileTree | FileTree} instance with the supplied\n * accessors.\n * @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for\n * file system operations.\n */\n public static create(hal: IFileTreeAccessors): Result<FileTree> {\n return captureResult(() => new FileTree(hal));\n }\n\n /**\n * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors\n * for the filesystem.\n * @param prefix - An optional prefix to prepended to supplied relative\n * paths.\n */\n public static forFilesystem(prefix?: string): Result<FileTree> {\n return captureResult(() => new FileTree(new FsFileTreeAccessors(prefix)));\n }\n\n /**\n * Creates a new {@link FileTree.FileTree | FileTree} instance with accessors\n * for an in-memory file tree.\n * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to\n * include in the tree.\n * @param prefix - An optional prefix to add to the paths of all files in the tree.\n */\n public static inMemory(files: IInMemoryFile[], prefix?: string): Result<FileTree> {\n return InMemoryTreeAccessors.create(files, prefix).onSuccess((hal) =>\n captureResult(() => new FileTree(hal))\n );\n }\n\n /**\n * Gets an item from the tree.\n * @param itemPath - The path to the item.\n * @returns {@link Success | Success} with the item if successful,\n * or {@link Failure | Failure} with an error message otherwise.\n */\n public getItem(itemPath: string): Result<FileTreeItem> {\n const absolutePath = this.hal.resolveAbsolutePath(itemPath);\n return this.hal.getItem(absolutePath);\n }\n\n /**\n * Gets a file item from the tree.\n * @param filePath - The path to the file.\n * @returns {@link Success | Success} with the {@link FileTree.IFileTreeFileItem | file item}\n * if successful, or {@link Failure | Failure} with an error message otherwise.\n */\n public getFile(filePath: string): Result<IFileTreeFileItem> {\n return this.getItem(filePath).onSuccess((item) => {\n if (item.type === 'file') {\n return succeed(item);\n }\n return fail(`${filePath}: not a file`);\n });\n }\n\n /**\n * Gets a directory item from the tree.\n * @param directoryPath - The path to the directory.\n * @returns {@link Success | Success} with the {@link FileTree.IFileTreeDirectoryItem | directory item}\n * if successful, or {@link Failure | Failure} with an error message otherwise.\n */\n public getDirectory(directoryPath: string): Result<IFileTreeDirectoryItem> {\n return this.getItem(directoryPath).onSuccess((item) => {\n if (item.type === 'directory') {\n return succeed(item);\n }\n return fail(`${directoryPath}: not a directory`);\n });\n }\n}\n\n/**\n * Helper function to create a new {@link FileTree.FileTree | FileTree} instance\n * with accessors for the filesystem.\n * @param prefix - An optional prefix to prepended to supplied relative paths.\n * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance\n * if successful, or {@link Failure | Failure} with an error message otherwise.\n * @public\n */\nexport function forFilesystem(prefix?: string): Result<FileTree> {\n return FileTree.forFilesystem(prefix);\n}\n\n/**\n * Helper function to create a new {@link FileTree.FileTree | FileTree} instance\n * with accessors for an in-memory file tree.\n * @param files - An array of {@link FileTree.IInMemoryFile | in-memory files} to include in the tree.\n * @param prefix - An optional prefix to add to the paths of all files in the tree.\n * @returns {@link Success | Success} with the new {@link FileTree.FileTree | FileTree} instance\n * if successful, or {@link Failure | Failure} with an error message otherwise.\n * @public\n */\nexport function inMemory(files: IInMemoryFile[], prefix?: string): Result<FileTree> {\n return FileTree.inMemory(files, prefix);\n}\n"]}
@@ -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 +0,0 @@
1
- {"version":3,"file":"fileTreeAccessors.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileTreeAccessors.ts"],"names":[],"mappings":"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IACjC;;;;OAIG;IACH,mBAAmB,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEhD;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAEnC;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEnD;;;;OAIG;IACH,SAAS,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEtC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;IAE5C;;;;OAIG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAE9C;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;CAChE"}
@@ -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 +0,0 @@
1
- {"version":3,"file":"fileTreeAccessors.js","sourceRoot":"","sources":["../../../src/packlets/file-tree/fileTreeAccessors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result } from '../base';\nimport { Converter } from '../conversion';\nimport { Validator } from '../validation';\n\n/**\n * Type of item in a file tree.\n * @public\n */\nexport type FileTreeItemType = 'directory' | 'file';\n\n/**\n * Interface for a file in a file tree.\n * @public\n */\nexport interface IFileTreeFileItem {\n /**\n * Indicates that this {@link FileTree.FileTreeItem | file tree item} is a file.\n */\n readonly type: 'file';\n\n /**\n * The absolute path of the file.\n */\n readonly absolutePath: string;\n\n /**\n * The name of the file\n */\n readonly name: string;\n\n /**\n * The base name of the file (without extension)\n */\n readonly baseName: string;\n\n /**\n * The extension of the file\n */\n readonly extension: string;\n\n /**\n * Gets the contents of the file as parsed JSON.\n * @returns {@link Success | Success} with the parsed contents if successful, or\n * {@link Failure | Failure}with an error message otherwise.\n */\n getContents(): Result<unknown>;\n\n /**\n * Gets the contents of the file as parsed JSON, converted to a specific type.\n * @param converter - A {@link Validation.Validator | Validator} or {@link Conversion.Converter | Converter}\n * to convert the parsed JSON contents to the desired type.\n * @returns {@link Success | Success} with the converted contents if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n */\n getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;\n\n /**\n * Gets the raw contents of the file as a string.\n * @returns {@link Success | Success} with the raw contents if successful, or\n * {@link Failure | Failure} with an error message otherwise.\n */\n getRawContents(): Result<string>;\n}\n\n/**\n * Interface for a directory in a file tree.\n * @public\n */\nexport interface IFileTreeDirectoryItem {\n /**\n * Indicates that this {@link FileTree.FileTreeItem | file tree item} is a directory\n */\n readonly type: 'directory';\n\n /**\n * The absolute path of the directory.\n */\n readonly absolutePath: string;\n\n /**\n * The name of the directory\n */\n readonly name: string;\n\n /**\n * Gets the children of the directory.\n * @returns {@link Success | Success} with the children of the directory if successful,\n * or {@link Failure | Failure} with an error message otherwise.\n */\n getChildren(): Result<ReadonlyArray<FileTreeItem>>;\n}\n\n/**\n * Type for an item in a file tree.\n * @public\n */\nexport type FileTreeItem = IFileTreeFileItem | IFileTreeDirectoryItem;\n\n/**\n * Common abstraction layer interface for a tree of files\n * (e.g. a file system or a zip file).\n * @public\n */\nexport interface IFileTreeAccessors {\n /**\n * Resolves paths to an absolute path.\n * @param paths - Paths to resolve.\n * @returns The resolved absolute path.\n */\n resolveAbsolutePath(...paths: string[]): string;\n\n /**\n * Gets the extension of a path.\n * @param path - Path to get the extension of.\n * @returns The extension of the path.\n */\n getExtension(path: string): string;\n\n /**\n * Gets the base name of a path.\n * @param path - Path to get the base name of.\n * @param suffix - Optional suffix to remove from the base name.\n * @returns The base name of the path.\n */\n getBaseName(path: string, suffix?: string): string;\n\n /**\n * Joins paths together.\n * @param paths - Paths to join.\n * @returns The joined paths.\n */\n joinPaths(...paths: string[]): string;\n\n /**\n * Gets an item from the file tree.\n * @param path - Path of the item to get.\n * @returns The item if it exists.\n */\n getItem(path: string): Result<FileTreeItem>;\n\n /**\n * Gets the contents of a file in the file tree.\n * @param path - Absolute path of the file.\n * @returns The contents of the file.\n */\n getFileContents(path: string): Result<string>;\n\n /**\n * Gets the children of a directory in the file tree.\n * @param path - Path of the directory.\n * @returns The children of the directory.\n */\n getChildren(path: string): Result<ReadonlyArray<FileTreeItem>>;\n}\n"]}
@@ -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 +0,0 @@
1
- {"version":3,"file":"fsTree.d.ts","sourceRoot":"","sources":["../../../src/packlets/file-tree/fsTree.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGvE,OAAO,EAAiB,MAAM,EAAE,MAAM,SAAS,CAAC;AAIhD;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAC5D,SAAgB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3C;;;;OAIG;gBACgB,MAAM,CAAC,EAAE,MAAM;IAIlC;;OAEG;IACI,mBAAmB,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAOtD;;OAEG;IACI,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI7C;;OAEG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAI7D;;OAEG;IACI,SAAS,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM;IAI5C;;OAEG;IACI,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;IAYtD;;OAEG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAIxD;;OAEG;IACI,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;CAezE"}