@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.
- package/dist/ts-utils.d.ts +3002 -3416
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -3
- package/lib/packlets/base/mapResults.d.ts +8 -1
- package/lib/packlets/base/mapResults.js +19 -0
- package/lib/packlets/base/result.d.ts +20 -3
- package/lib/packlets/base/result.js +22 -3
- package/lib/packlets/collections/collector.js +10 -1
- package/lib/packlets/logging/logReporter.js +1 -10
- package/lib/packlets/logging/logger.d.ts +8 -0
- package/lib/packlets/logging/logger.js +24 -1
- package/package.json +1 -1
- package/lib/packlets/file-tree/directoryItem.d.ts +0 -47
- package/lib/packlets/file-tree/directoryItem.js +0 -71
- package/lib/packlets/file-tree/fileItem.d.ts +0 -64
- package/lib/packlets/file-tree/fileItem.js +0 -93
- package/lib/packlets/file-tree/fileTree.d.ts +0 -84
- package/lib/packlets/file-tree/fileTree.js +0 -135
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +0 -134
- package/lib/packlets/file-tree/fileTreeAccessors.js +0 -24
- package/lib/packlets/file-tree/fsTree.d.ts +0 -45
- package/lib/packlets/file-tree/fsTree.js +0 -116
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +0 -67
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +0 -150
- package/lib/packlets/file-tree/in-memory/index.d.ts +0 -2
- package/lib/packlets/file-tree/in-memory/index.js +0 -39
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +0 -106
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +0 -170
- package/lib/packlets/file-tree/index.d.ts +0 -8
- package/lib/packlets/file-tree/index.js +0 -46
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import * as Collections from './packlets/collections';
|
|
2
2
|
import * as Conversion from './packlets/conversion';
|
|
3
3
|
import * as Hash from './packlets/hash';
|
|
4
|
-
import * as FileTree from './packlets/file-tree';
|
|
5
4
|
import * as Logging from './packlets/logging';
|
|
6
5
|
import * as Validation from './packlets/validation';
|
|
7
6
|
import { Collector, ICollectible, ConvertingCollector, IReadOnlyResultMap, ResultMap, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap } from './packlets/collections';
|
|
8
7
|
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
9
8
|
import { Validator, Validators } from './packlets/validation';
|
|
10
9
|
export * from './packlets/base';
|
|
11
|
-
export { Collections, Collector, ConvertingCollector, Conversion, Converter, Converters,
|
|
10
|
+
export { Collections, Collector, ConvertingCollector, Conversion, Converter, Converters, Hash, ICollectible, IReadOnlyResultMap, Logging, ObjectConverter, ResultMap, StringConverter, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap, Validation, Validator, Validators };
|
|
12
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -57,15 +57,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
57
57
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
58
58
|
};
|
|
59
59
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
exports.Validators = exports.Validation = exports.ValidatingResultMap = exports.ValidatingConvertingCollector = exports.ValidatingCollector = exports.StringConverter = exports.ResultMap = exports.ObjectConverter = exports.Logging = exports.Hash = exports.
|
|
60
|
+
exports.Validators = exports.Validation = exports.ValidatingResultMap = exports.ValidatingConvertingCollector = exports.ValidatingCollector = exports.StringConverter = exports.ResultMap = exports.ObjectConverter = exports.Logging = exports.Hash = exports.Converters = exports.Conversion = exports.ConvertingCollector = exports.Collector = exports.Collections = void 0;
|
|
61
61
|
const Collections = __importStar(require("./packlets/collections"));
|
|
62
62
|
exports.Collections = Collections;
|
|
63
63
|
const Conversion = __importStar(require("./packlets/conversion"));
|
|
64
64
|
exports.Conversion = Conversion;
|
|
65
65
|
const Hash = __importStar(require("./packlets/hash"));
|
|
66
66
|
exports.Hash = Hash;
|
|
67
|
-
const FileTree = __importStar(require("./packlets/file-tree"));
|
|
68
|
-
exports.FileTree = FileTree;
|
|
69
67
|
const Logging = __importStar(require("./packlets/logging"));
|
|
70
68
|
exports.Logging = Logging;
|
|
71
69
|
const Validation = __importStar(require("./packlets/validation"));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DetailedResult, IMessageAggregator, Result } from './result';
|
|
1
|
+
import { DeferredResult, DetailedResult, IMessageAggregator, Result } from './result';
|
|
2
2
|
/**
|
|
3
3
|
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
4
4
|
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
@@ -60,6 +60,13 @@ export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedE
|
|
|
60
60
|
* @public
|
|
61
61
|
*/
|
|
62
62
|
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: IMessageAggregator): Result<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the first successful result from a collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>}.
|
|
65
|
+
* @param results - The collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>} to be tested.
|
|
66
|
+
* @returns The first successful result, or {@link Failure} with a concatenated summary of all error messages.
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
export declare function firstSuccess<T>(results: Iterable<Result<T> | DeferredResult<T>>): Result<T>;
|
|
63
70
|
/**
|
|
64
71
|
* String-keyed record of initialization functions to be passed to {@link (populateObject:1)}
|
|
65
72
|
* or {@link (populateObject:2)}.
|
|
@@ -26,7 +26,9 @@ exports.mapDetailedResults = mapDetailedResults;
|
|
|
26
26
|
exports.mapSuccess = mapSuccess;
|
|
27
27
|
exports.mapFailures = mapFailures;
|
|
28
28
|
exports.allSucceed = allSucceed;
|
|
29
|
+
exports.firstSuccess = firstSuccess;
|
|
29
30
|
exports.populateObject = populateObject;
|
|
31
|
+
const messageAggregator_1 = require("./messageAggregator");
|
|
30
32
|
const result_1 = require("./result");
|
|
31
33
|
/**
|
|
32
34
|
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
@@ -160,6 +162,23 @@ function allSucceed(results, successValue, aggregatedErrors) {
|
|
|
160
162
|
}
|
|
161
163
|
return (0, result_1.succeed)(successValue);
|
|
162
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the first successful result from a collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>}.
|
|
167
|
+
* @param results - The collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>} to be tested.
|
|
168
|
+
* @returns The first successful result, or {@link Failure} with a concatenated summary of all error messages.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
function firstSuccess(results) {
|
|
172
|
+
const errors = new messageAggregator_1.MessageAggregator();
|
|
173
|
+
for (const r of results) {
|
|
174
|
+
const result = (0, result_1.isDeferredResult)(r) ? r() : r;
|
|
175
|
+
if (result.isSuccess()) {
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
errors.addMessage(result.message);
|
|
179
|
+
}
|
|
180
|
+
return errors.returnOrReport((0, result_1.fail)('no results found'));
|
|
181
|
+
}
|
|
163
182
|
function populateObject(initializers, optionsOrOrder, aggregatedErrors) {
|
|
164
183
|
var _a;
|
|
165
184
|
const options = optionsOrOrder
|
|
@@ -6,6 +6,18 @@
|
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
8
|
export type Result<T> = Success<T> | Failure<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Represents a deferred result that will be evaluated if needed.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export type DeferredResult<T> = () => Result<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a result is a deferred result.
|
|
16
|
+
* @param result - The result to check.
|
|
17
|
+
* @returns `true` if the result is a deferred result, `false` otherwise.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T>;
|
|
9
21
|
/**
|
|
10
22
|
* Continuation callback to be called in the event that an
|
|
11
23
|
* {@link Result} is successful.
|
|
@@ -266,8 +278,9 @@ export interface IResult<T> {
|
|
|
266
278
|
* supplied errors array.
|
|
267
279
|
* @param errors - {@link IMessageAggregator | Error aggregator} in which
|
|
268
280
|
* errors will be aggregated.
|
|
281
|
+
* @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.
|
|
269
282
|
*/
|
|
270
|
-
aggregateError(errors: IMessageAggregator): this;
|
|
283
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;
|
|
271
284
|
/**
|
|
272
285
|
* Reports the result to the supplied reporter
|
|
273
286
|
* @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.
|
|
@@ -359,7 +372,7 @@ export declare class Success<T> implements IResult<T> {
|
|
|
359
372
|
/**
|
|
360
373
|
* {@inheritdoc IResult.aggregateError}
|
|
361
374
|
*/
|
|
362
|
-
aggregateError(__errors: IMessageAggregator): this;
|
|
375
|
+
aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this;
|
|
363
376
|
/**
|
|
364
377
|
* {@inheritdoc IResult.report}
|
|
365
378
|
*/
|
|
@@ -455,7 +468,7 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
455
468
|
/**
|
|
456
469
|
* {@inheritdoc IResult.aggregateError}
|
|
457
470
|
*/
|
|
458
|
-
aggregateError(errors: IMessageAggregator): this;
|
|
471
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;
|
|
459
472
|
/**
|
|
460
473
|
* {@inheritdoc IResult.report}
|
|
461
474
|
*/
|
|
@@ -648,6 +661,10 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
|
|
|
648
661
|
* {@inheritdoc IResult.withErrorFormat}
|
|
649
662
|
*/
|
|
650
663
|
withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
|
|
664
|
+
/**
|
|
665
|
+
* {@inheritdoc IResult.aggregateError}
|
|
666
|
+
*/
|
|
667
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this;
|
|
651
668
|
/**
|
|
652
669
|
* {@inheritdoc IResult.report}
|
|
653
670
|
*/
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.DetailedFailure = exports.DetailedSuccess = exports.Failure = exports.Success = void 0;
|
|
25
|
+
exports.isDeferredResult = isDeferredResult;
|
|
25
26
|
exports.succeed = succeed;
|
|
26
27
|
exports.succeeds = succeeds;
|
|
27
28
|
exports.fail = fail;
|
|
@@ -33,6 +34,15 @@ exports.failWithDetail = failWithDetail;
|
|
|
33
34
|
exports.failsWithDetail = failsWithDetail;
|
|
34
35
|
exports.propagateWithDetail = propagateWithDetail;
|
|
35
36
|
exports.captureResult = captureResult;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a result is a deferred result.
|
|
39
|
+
* @param result - The result to check.
|
|
40
|
+
* @returns `true` if the result is a deferred result, `false` otherwise.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
function isDeferredResult(result) {
|
|
44
|
+
return typeof result === 'function';
|
|
45
|
+
}
|
|
36
46
|
/**
|
|
37
47
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
38
48
|
* corresponding value.
|
|
@@ -127,7 +137,7 @@ class Success {
|
|
|
127
137
|
/**
|
|
128
138
|
* {@inheritdoc IResult.aggregateError}
|
|
129
139
|
*/
|
|
130
|
-
aggregateError(__errors) {
|
|
140
|
+
aggregateError(__errors, __formatter) {
|
|
131
141
|
return this;
|
|
132
142
|
}
|
|
133
143
|
/**
|
|
@@ -252,8 +262,9 @@ class Failure {
|
|
|
252
262
|
/**
|
|
253
263
|
* {@inheritdoc IResult.aggregateError}
|
|
254
264
|
*/
|
|
255
|
-
aggregateError(errors) {
|
|
256
|
-
|
|
265
|
+
aggregateError(errors, formatter) {
|
|
266
|
+
const message = formatter ? formatter(this._message) : this._message;
|
|
267
|
+
errors.addMessage(message);
|
|
257
268
|
return this;
|
|
258
269
|
}
|
|
259
270
|
/**
|
|
@@ -480,6 +491,14 @@ class DetailedFailure extends Failure {
|
|
|
480
491
|
withErrorFormat(cb) {
|
|
481
492
|
return failWithDetail(cb(this._message, this._detail), this._detail);
|
|
482
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* {@inheritdoc IResult.aggregateError}
|
|
496
|
+
*/
|
|
497
|
+
aggregateError(errors, formatter) {
|
|
498
|
+
const message = formatter ? formatter(this._message, this._detail) : this._message;
|
|
499
|
+
errors.addMessage(message);
|
|
500
|
+
return this;
|
|
501
|
+
}
|
|
483
502
|
/**
|
|
484
503
|
* {@inheritdoc IResult.report}
|
|
485
504
|
*/
|
|
@@ -114,8 +114,17 @@ class Collector {
|
|
|
114
114
|
* {@inheritdoc Collections.IReadOnlyCollector.getAt}
|
|
115
115
|
*/
|
|
116
116
|
getAt(index) {
|
|
117
|
+
if (typeof index !== 'number') {
|
|
118
|
+
// Handle Symbol conversion safely
|
|
119
|
+
const indexStr = typeof index === 'symbol' ? index.toString() : String(index);
|
|
120
|
+
return (0, base_1.fail)(`${indexStr}: collector index must be a number.`);
|
|
121
|
+
}
|
|
122
|
+
// Check that the number is a finite integer (handles NaN, Infinity, and non-integers)
|
|
123
|
+
if (!Number.isFinite(index) || !Number.isInteger(index)) {
|
|
124
|
+
return (0, base_1.fail)(`${index}: collector index must be a finite integer.`);
|
|
125
|
+
}
|
|
117
126
|
if (index < 0 || index >= this._byIndex.length) {
|
|
118
|
-
return (0, base_1.fail)(`${index}: out of range.`);
|
|
127
|
+
return (0, base_1.fail)(`${index}: collector index out of range.`);
|
|
119
128
|
}
|
|
120
129
|
return (0, base_1.succeed)(this._byIndex[index]);
|
|
121
130
|
}
|
|
@@ -98,16 +98,7 @@ class LogReporter {
|
|
|
98
98
|
* @returns
|
|
99
99
|
*/
|
|
100
100
|
static tryFormatObject(value, detail) {
|
|
101
|
-
|
|
102
|
-
if (message === '[object Object]') {
|
|
103
|
-
try {
|
|
104
|
-
return JSON.stringify(value);
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
return message;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return message;
|
|
101
|
+
return (0, logger_1.stringifyLogValue)(value);
|
|
111
102
|
}
|
|
112
103
|
}
|
|
113
104
|
exports.LogReporter = LogReporter;
|
|
@@ -12,6 +12,14 @@ export type ReporterLogLevel = 'all' | 'detail' | 'info' | 'warning' | 'error' |
|
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
14
|
export declare function shouldLog(message: MessageLogLevel, reporter: ReporterLogLevel): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Stringifies an arbitrary value for logging.
|
|
17
|
+
* @param value - The value to stringify.
|
|
18
|
+
* @returns The stringified value.
|
|
19
|
+
* @param maxLength - The maximum length of the stringified value.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function stringifyLogValue(value: unknown, maxLength?: number): string;
|
|
15
23
|
/**
|
|
16
24
|
* Generic Result-aware logger interface with multiple levels of logging.
|
|
17
25
|
* @public
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoOpLogger = exports.ConsoleLogger = exports.InMemoryLogger = exports.LoggerBase = void 0;
|
|
4
4
|
exports.shouldLog = shouldLog;
|
|
5
|
+
exports.stringifyLogValue = stringifyLogValue;
|
|
5
6
|
/*
|
|
6
7
|
* Copyright (c) 2020 Erik Fortune
|
|
7
8
|
*
|
|
@@ -51,6 +52,28 @@ function shouldLog(message, reporter) {
|
|
|
51
52
|
}
|
|
52
53
|
return true;
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Stringifies an arbitrary value for logging.
|
|
57
|
+
* @param value - The value to stringify.
|
|
58
|
+
* @returns The stringified value.
|
|
59
|
+
* @param maxLength - The maximum length of the stringified value.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
function stringifyLogValue(value, maxLength) {
|
|
63
|
+
maxLength = maxLength !== null && maxLength !== void 0 ? maxLength : 40;
|
|
64
|
+
if (typeof value === 'string') {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
const str = String(value);
|
|
68
|
+
if (str === '[object Object]') {
|
|
69
|
+
return (0, base_1.captureResult)(() => JSON.stringify(value))
|
|
70
|
+
.onSuccess((s) => {
|
|
71
|
+
return (0, base_1.succeed)(s.length < maxLength ? s : s.substring(0, maxLength - 3) + '...');
|
|
72
|
+
})
|
|
73
|
+
.orDefault(str);
|
|
74
|
+
}
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
54
77
|
/**
|
|
55
78
|
* Abstract base class which implements {@link Logging.ILogger | ILogger}.
|
|
56
79
|
* @public
|
|
@@ -107,7 +130,7 @@ class LoggerBase {
|
|
|
107
130
|
_format(message, ...parameters) {
|
|
108
131
|
const raw = [message, ...parameters];
|
|
109
132
|
const filtered = raw.filter((m) => m !== undefined);
|
|
110
|
-
const strings = filtered.map((m) => m
|
|
133
|
+
const strings = filtered.map((m) => stringifyLogValue(m));
|
|
111
134
|
const joined = strings.join('');
|
|
112
135
|
return joined;
|
|
113
136
|
}
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
import { FileTreeItem, IFileTreeAccessors, IFileTreeDirectoryItem } from './fileTreeAccessors';
|
|
3
|
-
/**
|
|
4
|
-
* Class representing a directory in a file tree.
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export declare class DirectoryItem implements IFileTreeDirectoryItem {
|
|
8
|
-
/**
|
|
9
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem."type"}
|
|
10
|
-
*/
|
|
11
|
-
readonly type: 'directory';
|
|
12
|
-
/**
|
|
13
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem.absolutePath}
|
|
14
|
-
*/
|
|
15
|
-
readonly absolutePath: string;
|
|
16
|
-
/**
|
|
17
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem.name}
|
|
18
|
-
*/
|
|
19
|
-
get name(): string;
|
|
20
|
-
/**
|
|
21
|
-
* The {@link FileTree.IFileTreeAccessors | accessors} to use for file system operations.
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
protected readonly _hal: IFileTreeAccessors;
|
|
25
|
-
/**
|
|
26
|
-
* Protected constructor for derived classes.
|
|
27
|
-
* @param path - Relative path of the directory.
|
|
28
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
29
|
-
* file system operations.
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
protected constructor(path: string, hal: IFileTreeAccessors);
|
|
33
|
-
/**
|
|
34
|
-
* Creates a new DirectoryItem instance.
|
|
35
|
-
* @param path - Relative path of the directory.
|
|
36
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
37
|
-
* file system operations.
|
|
38
|
-
* @returns A {@link Result | result} containing the new DirectoryItem instance if successful,
|
|
39
|
-
* or a failure if an error occurs.
|
|
40
|
-
*/
|
|
41
|
-
static create(path: string, hal: IFileTreeAccessors): Result<DirectoryItem>;
|
|
42
|
-
/**
|
|
43
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem.getChildren}
|
|
44
|
-
*/
|
|
45
|
-
getChildren(): Result<ReadonlyArray<FileTreeItem>>;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=directoryItem.d.ts.map
|
|
@@ -1,71 +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.DirectoryItem = void 0;
|
|
25
|
-
const base_1 = require("../base");
|
|
26
|
-
/**
|
|
27
|
-
* Class representing a directory in a file tree.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
class DirectoryItem {
|
|
31
|
-
/**
|
|
32
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem.name}
|
|
33
|
-
*/
|
|
34
|
-
get name() {
|
|
35
|
-
return this._hal.getBaseName(this.absolutePath);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Protected constructor for derived classes.
|
|
39
|
-
* @param path - Relative path of the directory.
|
|
40
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
41
|
-
* file system operations.
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
constructor(path, hal) {
|
|
45
|
-
/**
|
|
46
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem."type"}
|
|
47
|
-
*/
|
|
48
|
-
this.type = 'directory';
|
|
49
|
-
this._hal = hal;
|
|
50
|
-
this.absolutePath = hal.resolveAbsolutePath(path);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new DirectoryItem instance.
|
|
54
|
-
* @param path - Relative path of the directory.
|
|
55
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
56
|
-
* file system operations.
|
|
57
|
-
* @returns A {@link Result | result} containing the new DirectoryItem instance if successful,
|
|
58
|
-
* or a failure if an error occurs.
|
|
59
|
-
*/
|
|
60
|
-
static create(path, hal) {
|
|
61
|
-
return (0, base_1.captureResult)(() => new DirectoryItem(path, hal));
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* {@inheritdoc FileTree.IFileTreeDirectoryItem.getChildren}
|
|
65
|
-
*/
|
|
66
|
-
getChildren() {
|
|
67
|
-
return this._hal.getChildren(this.absolutePath);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.DirectoryItem = DirectoryItem;
|
|
71
|
-
//# sourceMappingURL=directoryItem.js.map
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Result } from '../base';
|
|
2
|
-
import { Converter } from '../conversion';
|
|
3
|
-
import { Validator } from '../validation';
|
|
4
|
-
import { IFileTreeAccessors, IFileTreeFileItem } from './fileTreeAccessors';
|
|
5
|
-
/**
|
|
6
|
-
* Class representing a file in a file tree.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export declare class FileItem implements IFileTreeFileItem {
|
|
10
|
-
/**
|
|
11
|
-
* {@inheritdoc FileTree.IFileTreeFileItem."type"}
|
|
12
|
-
*/
|
|
13
|
-
readonly type: 'file';
|
|
14
|
-
/**
|
|
15
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.absolutePath}
|
|
16
|
-
*/
|
|
17
|
-
readonly absolutePath: string;
|
|
18
|
-
/**
|
|
19
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.name}
|
|
20
|
-
*/
|
|
21
|
-
get name(): string;
|
|
22
|
-
/**
|
|
23
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.baseName}
|
|
24
|
-
*/
|
|
25
|
-
get baseName(): string;
|
|
26
|
-
/**
|
|
27
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.extension}
|
|
28
|
-
*/
|
|
29
|
-
get extension(): string;
|
|
30
|
-
/**
|
|
31
|
-
* The {@link FileTree.IFileTreeAccessors | accessors} to use for file system operations.
|
|
32
|
-
* @public
|
|
33
|
-
*/
|
|
34
|
-
protected readonly _hal: IFileTreeAccessors;
|
|
35
|
-
/**
|
|
36
|
-
* Protected constructor for derived classes.
|
|
37
|
-
* @param path - Relative path of the file.
|
|
38
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
39
|
-
* file system operations.
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
protected constructor(path: string, hal: IFileTreeAccessors);
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new {@link FileTree.FileItem | FileItem} instance.
|
|
45
|
-
* @param path - Relative path of the file.
|
|
46
|
-
* @param hal - The {@link FileTree.IFileTreeAccessors | accessors} to use for
|
|
47
|
-
* file system operations.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
static create(path: string, hal: IFileTreeAccessors): Result<FileItem>;
|
|
51
|
-
/**
|
|
52
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.(getContents:1)}
|
|
53
|
-
*/
|
|
54
|
-
getContents(): Result<unknown>;
|
|
55
|
-
/**
|
|
56
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.(getContents:2)}
|
|
57
|
-
*/
|
|
58
|
-
getContents<T>(converter: Validator<T> | Converter<T>): Result<T>;
|
|
59
|
-
/**
|
|
60
|
-
* {@inheritdoc FileTree.IFileTreeFileItem.getRawContents}
|
|
61
|
-
*/
|
|
62
|
-
getRawContents(): Result<string>;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=fileItem.d.ts.map
|
|
@@ -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
|