@fgv/ts-utils 5.0.0-9 → 5.0.1-1
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/CHANGELOG.json +10 -7
- package/dist/ts-utils.d.ts +3042 -3133
- package/dist/tsdoc-metadata.json +1 -1
- package/eslint.config.js +37 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +3 -3
- package/lib/packlets/base/index.d.ts +0 -2
- package/lib/packlets/base/index.js +1 -25
- package/lib/packlets/base/mapResults.d.ts +8 -1
- package/lib/packlets/base/mapResults.js +19 -0
- package/lib/packlets/base/result.d.ts +81 -3
- package/lib/packlets/base/result.js +71 -3
- package/lib/packlets/collections/collector.d.ts +9 -0
- package/lib/packlets/collections/collector.js +16 -1
- package/lib/packlets/collections/validatingCollector.d.ts +5 -1
- package/lib/packlets/conversion/baseConverter.js +0 -1
- package/lib/packlets/conversion/converters.js +0 -2
- package/lib/packlets/conversion/objectConverter.js +1 -2
- package/lib/packlets/hash/hashingNormalizer.js +4 -3
- package/lib/packlets/logging/index.d.ts +3 -0
- package/lib/packlets/{file-tree/in-memory → logging}/index.js +3 -2
- package/lib/packlets/logging/logReporter.d.ts +88 -0
- package/lib/packlets/logging/logReporter.js +105 -0
- package/lib/packlets/logging/logger.d.ts +205 -0
- package/lib/packlets/logging/logger.js +267 -0
- package/lib/packlets/validation/array.d.ts +2 -1
- package/lib/packlets/validation/array.js +2 -1
- package/lib/packlets/validation/common.d.ts +0 -8
- package/lib/packlets/validation/field.d.ts +1 -1
- package/lib/packlets/validation/field.js +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +1 -6
- package/lib/packlets/validation/genericValidator.js +11 -11
- package/lib/packlets/validation/object.d.ts +1 -1
- package/lib/packlets/validation/object.js +1 -2
- package/lib/packlets/validation/oneOf.d.ts +2 -1
- package/lib/packlets/validation/oneOf.js +2 -1
- package/lib/packlets/validation/typeGuard.d.ts +3 -2
- package/lib/packlets/validation/typeGuard.js +2 -1
- package/lib/packlets/validation/validator.d.ts +7 -0
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/lib/packlets/validation/validatorBase.js +1 -1
- package/lib/packlets/validation/validators.d.ts +2 -2
- package/lib/packlets/validation/validators.js +3 -3
- package/package.json +16 -16
- package/CHANGELOG.md +0 -135
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/packlets/base/brand.d.ts.map +0 -1
- package/lib/packlets/base/brand.js.map +0 -1
- package/lib/packlets/base/index.d.ts.map +0 -1
- package/lib/packlets/base/index.js.map +0 -1
- package/lib/packlets/base/logger.d.ts +0 -52
- package/lib/packlets/base/logger.d.ts.map +0 -1
- package/lib/packlets/base/logger.js +0 -128
- package/lib/packlets/base/logger.js.map +0 -1
- package/lib/packlets/base/mapResults.d.ts.map +0 -1
- package/lib/packlets/base/mapResults.js.map +0 -1
- package/lib/packlets/base/messageAggregator.d.ts.map +0 -1
- package/lib/packlets/base/messageAggregator.js.map +0 -1
- package/lib/packlets/base/normalize.d.ts.map +0 -1
- package/lib/packlets/base/normalize.js.map +0 -1
- package/lib/packlets/base/result.d.ts.map +0 -1
- package/lib/packlets/base/result.js.map +0 -1
- package/lib/packlets/base/utils.d.ts.map +0 -1
- package/lib/packlets/base/utils.js.map +0 -1
- package/lib/packlets/collections/collectible.d.ts.map +0 -1
- package/lib/packlets/collections/collectible.js.map +0 -1
- package/lib/packlets/collections/collector.d.ts.map +0 -1
- package/lib/packlets/collections/collector.js.map +0 -1
- package/lib/packlets/collections/collectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/collectorValidator.js.map +0 -1
- package/lib/packlets/collections/common.d.ts.map +0 -1
- package/lib/packlets/collections/common.js.map +0 -1
- package/lib/packlets/collections/convertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollector.js.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +0 -1
- package/lib/packlets/collections/convertingCollectorValidator.js.map +0 -1
- package/lib/packlets/collections/index.d.ts.map +0 -1
- package/lib/packlets/collections/index.js.map +0 -1
- package/lib/packlets/collections/keyValueConverters.d.ts.map +0 -1
- package/lib/packlets/collections/keyValueConverters.js.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +0 -1
- package/lib/packlets/collections/resultMap.d.ts.map +0 -1
- package/lib/packlets/collections/resultMap.js.map +0 -1
- package/lib/packlets/collections/resultMapValidator.d.ts.map +0 -1
- package/lib/packlets/collections/resultMapValidator.js.map +0 -1
- package/lib/packlets/collections/utils.d.ts.map +0 -1
- package/lib/packlets/collections/utils.js.map +0 -1
- package/lib/packlets/collections/validatingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +0 -1
- package/lib/packlets/collections/validatingConvertingCollector.js.map +0 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/validatingResultMap.js.map +0 -1
- package/lib/packlets/conversion/baseConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/baseConverter.js.map +0 -1
- package/lib/packlets/conversion/converter.d.ts.map +0 -1
- package/lib/packlets/conversion/converter.js.map +0 -1
- package/lib/packlets/conversion/converters.d.ts.map +0 -1
- package/lib/packlets/conversion/converters.js.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/defaultingConverter.js.map +0 -1
- package/lib/packlets/conversion/index.d.ts.map +0 -1
- package/lib/packlets/conversion/index.js.map +0 -1
- package/lib/packlets/conversion/objectConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/objectConverter.js.map +0 -1
- package/lib/packlets/conversion/stringConverter.d.ts.map +0 -1
- package/lib/packlets/conversion/stringConverter.js.map +0 -1
- package/lib/packlets/file-tree/directoryItem.d.ts +0 -47
- package/lib/packlets/file-tree/directoryItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/directoryItem.js +0 -71
- package/lib/packlets/file-tree/directoryItem.js.map +0 -1
- package/lib/packlets/file-tree/fileItem.d.ts +0 -64
- package/lib/packlets/file-tree/fileItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileItem.js +0 -93
- package/lib/packlets/file-tree/fileItem.js.map +0 -1
- package/lib/packlets/file-tree/fileTree.d.ts +0 -84
- package/lib/packlets/file-tree/fileTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTree.js +0 -135
- package/lib/packlets/file-tree/fileTree.js.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts +0 -134
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.js +0 -24
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +0 -1
- package/lib/packlets/file-tree/fsTree.d.ts +0 -45
- package/lib/packlets/file-tree/fsTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fsTree.js +0 -116
- package/lib/packlets/file-tree/fsTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +0 -67
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js +0 -150
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.d.ts +0 -2
- package/lib/packlets/file-tree/in-memory/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/index.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +0 -106
- package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.js +0 -170
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +0 -1
- package/lib/packlets/file-tree/index.d.ts +0 -8
- package/lib/packlets/file-tree/index.d.ts.map +0 -1
- package/lib/packlets/file-tree/index.js +0 -46
- package/lib/packlets/file-tree/index.js.map +0 -1
- package/lib/packlets/hash/crcNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/crcNormalizer.js.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +0 -1
- package/lib/packlets/hash/hashingNormalizer.js.map +0 -1
- package/lib/packlets/hash/index.d.ts.map +0 -1
- package/lib/packlets/hash/index.js.map +0 -1
- package/lib/packlets/validation/array.d.ts.map +0 -1
- package/lib/packlets/validation/array.js.map +0 -1
- package/lib/packlets/validation/boolean.d.ts.map +0 -1
- package/lib/packlets/validation/boolean.js.map +0 -1
- package/lib/packlets/validation/classes.d.ts.map +0 -1
- package/lib/packlets/validation/classes.js.map +0 -1
- package/lib/packlets/validation/common.d.ts.map +0 -1
- package/lib/packlets/validation/common.js.map +0 -1
- package/lib/packlets/validation/field.d.ts.map +0 -1
- package/lib/packlets/validation/field.js.map +0 -1
- package/lib/packlets/validation/genericValidator.d.ts.map +0 -1
- package/lib/packlets/validation/genericValidator.js.map +0 -1
- package/lib/packlets/validation/index.d.ts.map +0 -1
- package/lib/packlets/validation/index.js.map +0 -1
- package/lib/packlets/validation/number.d.ts.map +0 -1
- package/lib/packlets/validation/number.js.map +0 -1
- package/lib/packlets/validation/object.d.ts.map +0 -1
- package/lib/packlets/validation/object.js.map +0 -1
- package/lib/packlets/validation/oneOf.d.ts.map +0 -1
- package/lib/packlets/validation/oneOf.js.map +0 -1
- package/lib/packlets/validation/string.d.ts.map +0 -1
- package/lib/packlets/validation/string.js.map +0 -1
- package/lib/packlets/validation/traits.d.ts.map +0 -1
- package/lib/packlets/validation/traits.js.map +0 -1
- package/lib/packlets/validation/typeGuard.d.ts.map +0 -1
- package/lib/packlets/validation/typeGuard.js.map +0 -1
- package/lib/packlets/validation/validator.d.ts.map +0 -1
- package/lib/packlets/validation/validator.js.map +0 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +0 -1
- package/lib/packlets/validation/validatorBase.js.map +0 -1
- package/lib/packlets/validation/validators.d.ts.map +0 -1
- package/lib/packlets/validation/validators.js.map +0 -1
package/dist/tsdoc-metadata.json
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// ESLint 9 flat config for ts-utils
|
|
2
|
+
const nodeProfile = require('@rushstack/eslint-config/flat/profile/node');
|
|
3
|
+
const packletsPlugin = require('@rushstack/eslint-config/flat/mixins/packlets');
|
|
4
|
+
const tsdocPlugin = require('@rushstack/eslint-config/flat/mixins/tsdoc');
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
...nodeProfile,
|
|
8
|
+
packletsPlugin,
|
|
9
|
+
...tsdocPlugin,
|
|
10
|
+
{
|
|
11
|
+
// Override specific rules if needed
|
|
12
|
+
rules: {
|
|
13
|
+
'@rushstack/packlets/mechanics': 'warn',
|
|
14
|
+
|
|
15
|
+
// Tighten naming conventions for interface properties
|
|
16
|
+
'@typescript-eslint/naming-convention': [
|
|
17
|
+
'warn',
|
|
18
|
+
// Keep all the base rules from rushstack but add stricter property rules
|
|
19
|
+
{
|
|
20
|
+
selector: 'property',
|
|
21
|
+
format: ['camelCase', 'UPPER_CASE'],
|
|
22
|
+
leadingUnderscore: 'allow',
|
|
23
|
+
filter: {
|
|
24
|
+
// Only allow quoted identifiers that truly need special chars (not just hyphens)
|
|
25
|
+
regex: '^__',
|
|
26
|
+
match: false
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
selector: 'method',
|
|
31
|
+
format: ['camelCase', 'PascalCase'],
|
|
32
|
+
leadingUnderscore: 'allow'
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
];
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +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
|
|
4
|
+
import * as Logging from './packlets/logging';
|
|
5
5
|
import * as Validation from './packlets/validation';
|
|
6
6
|
import { Collector, ICollectible, ConvertingCollector, IReadOnlyResultMap, ResultMap, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap } from './packlets/collections';
|
|
7
7
|
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
8
8
|
import { Validator, Validators } from './packlets/validation';
|
|
9
9
|
export * from './packlets/base';
|
|
10
|
-
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 };
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -57,15 +57,15 @@ 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.
|
|
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
|
|
68
|
-
exports.
|
|
67
|
+
const Logging = __importStar(require("./packlets/logging"));
|
|
68
|
+
exports.Logging = Logging;
|
|
69
69
|
const Validation = __importStar(require("./packlets/validation"));
|
|
70
70
|
exports.Validation = Validation;
|
|
71
71
|
const collections_1 = require("./packlets/collections");
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import * as Logging from './logger';
|
|
2
1
|
export * from './brand';
|
|
3
2
|
export * from './mapResults';
|
|
4
3
|
export * from './messageAggregator';
|
|
5
4
|
export { Normalizer } from './normalize';
|
|
6
5
|
export * from './result';
|
|
7
6
|
export * from './utils';
|
|
8
|
-
export { Logging };
|
|
9
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -31,35 +31,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
31
31
|
if (k2 === undefined) k2 = k;
|
|
32
32
|
o[k2] = m[k];
|
|
33
33
|
}));
|
|
34
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
-
}) : function(o, v) {
|
|
37
|
-
o["default"] = v;
|
|
38
|
-
});
|
|
39
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
-
var ownKeys = function(o) {
|
|
41
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
-
var ar = [];
|
|
43
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
-
return ar;
|
|
45
|
-
};
|
|
46
|
-
return ownKeys(o);
|
|
47
|
-
};
|
|
48
|
-
return function (mod) {
|
|
49
|
-
if (mod && mod.__esModule) return mod;
|
|
50
|
-
var result = {};
|
|
51
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
-
__setModuleDefault(result, mod);
|
|
53
|
-
return result;
|
|
54
|
-
};
|
|
55
|
-
})();
|
|
56
34
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
57
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
58
36
|
};
|
|
59
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
exports.
|
|
61
|
-
const Logging = __importStar(require("./logger"));
|
|
62
|
-
exports.Logging = Logging;
|
|
38
|
+
exports.Normalizer = void 0;
|
|
63
39
|
__exportStar(require("./brand"), exports);
|
|
64
40
|
__exportStar(require("./mapResults"), exports);
|
|
65
41
|
__exportStar(require("./messageAggregator"), exports);
|
|
@@ -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.
|
|
@@ -41,6 +53,37 @@ export interface IResultLogger<TD = unknown> {
|
|
|
41
53
|
*/
|
|
42
54
|
error(message: string, detail?: TD): void;
|
|
43
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The severity level at which a message should be logged.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';
|
|
61
|
+
/**
|
|
62
|
+
* Options for reporting a result.
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export interface IResultReportOptions<TD = unknown> {
|
|
66
|
+
/**
|
|
67
|
+
* The level of reporting to be used for failure results. Default is 'error'.
|
|
68
|
+
*/
|
|
69
|
+
failure?: MessageLogLevel;
|
|
70
|
+
/**
|
|
71
|
+
* The level of reporting to be used for success results. Default is 'quiet'.
|
|
72
|
+
*/
|
|
73
|
+
success?: MessageLogLevel;
|
|
74
|
+
/**
|
|
75
|
+
* The error formatter to be used for reporting an error result.
|
|
76
|
+
*/
|
|
77
|
+
message?: ErrorFormatter<TD>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Interface for reporting a result.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export interface IResultReporter<T, TD = unknown> {
|
|
84
|
+
reportSuccess(level: MessageLogLevel, value: T, detail?: TD): void;
|
|
85
|
+
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
86
|
+
}
|
|
44
87
|
/**
|
|
45
88
|
* Simple error aggregator to simplify collecting all errors in
|
|
46
89
|
* a flow.
|
|
@@ -235,8 +278,15 @@ export interface IResult<T> {
|
|
|
235
278
|
* supplied errors array.
|
|
236
279
|
* @param errors - {@link IMessageAggregator | Error aggregator} in which
|
|
237
280
|
* errors will be aggregated.
|
|
281
|
+
* @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.
|
|
282
|
+
*/
|
|
283
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;
|
|
284
|
+
/**
|
|
285
|
+
* Reports the result to the supplied reporter
|
|
286
|
+
* @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.
|
|
287
|
+
* @param options - The {@link IResultReportOptions | options} for reporting the result.
|
|
238
288
|
*/
|
|
239
|
-
|
|
289
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
240
290
|
}
|
|
241
291
|
/**
|
|
242
292
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
@@ -322,7 +372,11 @@ export declare class Success<T> implements IResult<T> {
|
|
|
322
372
|
/**
|
|
323
373
|
* {@inheritdoc IResult.aggregateError}
|
|
324
374
|
*/
|
|
325
|
-
aggregateError(__errors: IMessageAggregator): this;
|
|
375
|
+
aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this;
|
|
376
|
+
/**
|
|
377
|
+
* {@inheritdoc IResult.report}
|
|
378
|
+
*/
|
|
379
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
326
380
|
/**
|
|
327
381
|
* Creates a {@link Success | Success<T>} with the supplied value.
|
|
328
382
|
* @param value - The value to be returned.
|
|
@@ -414,7 +468,11 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
414
468
|
/**
|
|
415
469
|
* {@inheritdoc IResult.aggregateError}
|
|
416
470
|
*/
|
|
417
|
-
aggregateError(errors: IMessageAggregator): this;
|
|
471
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;
|
|
472
|
+
/**
|
|
473
|
+
* {@inheritdoc IResult.report}
|
|
474
|
+
*/
|
|
475
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
418
476
|
/**
|
|
419
477
|
* Get a 'friendly' string representation of this object.
|
|
420
478
|
* @remarks
|
|
@@ -458,6 +516,14 @@ export declare function fail<T>(message: string): Failure<T>;
|
|
|
458
516
|
* @public
|
|
459
517
|
*/
|
|
460
518
|
export declare function fails<T>(message: string): Failure<T>;
|
|
519
|
+
/**
|
|
520
|
+
* Uses a value or calls a supplied initializer if the supplied value is undefined.
|
|
521
|
+
* @param value - the value
|
|
522
|
+
* @param initializer - a function that initializes the value if it is undefined
|
|
523
|
+
* @returns `Success` with the value if it is defined, or the result of calling the initializer function.
|
|
524
|
+
* @public
|
|
525
|
+
*/
|
|
526
|
+
export declare function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T>;
|
|
461
527
|
/**
|
|
462
528
|
* Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.
|
|
463
529
|
* @remarks
|
|
@@ -529,6 +595,10 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
|
|
|
529
595
|
* {@inheritdoc Success.withErrorFormat}
|
|
530
596
|
*/
|
|
531
597
|
withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
|
|
598
|
+
/**
|
|
599
|
+
* {@inheritdoc IResult.report}
|
|
600
|
+
*/
|
|
601
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
532
602
|
/**
|
|
533
603
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
534
604
|
* optional detail.
|
|
@@ -591,6 +661,14 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
|
|
|
591
661
|
* {@inheritdoc IResult.withErrorFormat}
|
|
592
662
|
*/
|
|
593
663
|
withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
|
|
664
|
+
/**
|
|
665
|
+
* {@inheritdoc IResult.aggregateError}
|
|
666
|
+
*/
|
|
667
|
+
aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this;
|
|
668
|
+
/**
|
|
669
|
+
* {@inheritdoc IResult.report}
|
|
670
|
+
*/
|
|
671
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
594
672
|
orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;
|
|
595
673
|
orThrow(cb: ErrorFormatter): never;
|
|
596
674
|
/**
|
|
@@ -22,16 +22,27 @@
|
|
|
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;
|
|
28
29
|
exports.fails = fails;
|
|
30
|
+
exports.useOrInitialize = useOrInitialize;
|
|
29
31
|
exports.succeedWithDetail = succeedWithDetail;
|
|
30
32
|
exports.succeedsWithDetail = succeedsWithDetail;
|
|
31
33
|
exports.failWithDetail = failWithDetail;
|
|
32
34
|
exports.failsWithDetail = failsWithDetail;
|
|
33
35
|
exports.propagateWithDetail = propagateWithDetail;
|
|
34
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
|
+
}
|
|
35
46
|
/**
|
|
36
47
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
37
48
|
* corresponding value.
|
|
@@ -126,7 +137,16 @@ class Success {
|
|
|
126
137
|
/**
|
|
127
138
|
* {@inheritdoc IResult.aggregateError}
|
|
128
139
|
*/
|
|
129
|
-
aggregateError(__errors) {
|
|
140
|
+
aggregateError(__errors, __formatter) {
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* {@inheritdoc IResult.report}
|
|
145
|
+
*/
|
|
146
|
+
report(reporter, options) {
|
|
147
|
+
var _a;
|
|
148
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
149
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value);
|
|
130
150
|
return this;
|
|
131
151
|
}
|
|
132
152
|
/**
|
|
@@ -242,8 +262,19 @@ class Failure {
|
|
|
242
262
|
/**
|
|
243
263
|
* {@inheritdoc IResult.aggregateError}
|
|
244
264
|
*/
|
|
245
|
-
aggregateError(errors) {
|
|
246
|
-
|
|
265
|
+
aggregateError(errors, formatter) {
|
|
266
|
+
const message = formatter ? formatter(this._message) : this._message;
|
|
267
|
+
errors.addMessage(message);
|
|
268
|
+
return this;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* {@inheritdoc IResult.report}
|
|
272
|
+
*/
|
|
273
|
+
report(reporter, options) {
|
|
274
|
+
var _a, _b, _c;
|
|
275
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
276
|
+
const message = (_c = (_b = options === null || options === void 0 ? void 0 : options.message) === null || _b === void 0 ? void 0 : _b.call(options, this._message)) !== null && _c !== void 0 ? _c : this._message;
|
|
277
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message);
|
|
247
278
|
return this;
|
|
248
279
|
}
|
|
249
280
|
/**
|
|
@@ -302,6 +333,16 @@ function fail(message) {
|
|
|
302
333
|
function fails(message) {
|
|
303
334
|
return new Failure(message);
|
|
304
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Uses a value or calls a supplied initializer if the supplied value is undefined.
|
|
338
|
+
* @param value - the value
|
|
339
|
+
* @param initializer - a function that initializes the value if it is undefined
|
|
340
|
+
* @returns `Success` with the value if it is defined, or the result of calling the initializer function.
|
|
341
|
+
* @public
|
|
342
|
+
*/
|
|
343
|
+
function useOrInitialize(value, initializer) {
|
|
344
|
+
return value !== undefined ? succeed(value) : initializer();
|
|
345
|
+
}
|
|
305
346
|
/**
|
|
306
347
|
* A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
|
|
307
348
|
* details in addition to the error message.
|
|
@@ -365,6 +406,15 @@ class DetailedSuccess extends Success {
|
|
|
365
406
|
withErrorFormat(cb) {
|
|
366
407
|
return this;
|
|
367
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* {@inheritdoc IResult.report}
|
|
411
|
+
*/
|
|
412
|
+
report(reporter, options) {
|
|
413
|
+
var _a;
|
|
414
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
415
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value, this._detail);
|
|
416
|
+
return this;
|
|
417
|
+
}
|
|
368
418
|
/**
|
|
369
419
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
370
420
|
* optional detail.
|
|
@@ -441,6 +491,24 @@ class DetailedFailure extends Failure {
|
|
|
441
491
|
withErrorFormat(cb) {
|
|
442
492
|
return failWithDetail(cb(this._message, this._detail), this._detail);
|
|
443
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
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* {@inheritdoc IResult.report}
|
|
504
|
+
*/
|
|
505
|
+
report(reporter, options) {
|
|
506
|
+
var _a, _b, _c;
|
|
507
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
508
|
+
const message = (_c = (_b = options === null || options === void 0 ? void 0 : options.message) === null || _b === void 0 ? void 0 : _b.call(options, this._message, this._detail)) !== null && _c !== void 0 ? _c : this._message;
|
|
509
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message, this._detail);
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
444
512
|
orThrow(logOrFormat) {
|
|
445
513
|
if (logOrFormat !== undefined) {
|
|
446
514
|
if (typeof logOrFormat === 'function') {
|
|
@@ -19,6 +19,11 @@ export interface IReadOnlyCollector<TITEM extends ICollectible<any, any>> extend
|
|
|
19
19
|
* with an error if the index is out of range.
|
|
20
20
|
*/
|
|
21
21
|
getAt(index: number): Result<TITEM>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets all items in the collection, ordered by index.
|
|
24
|
+
* @returns An array of items in the collection, ordered by index.
|
|
25
|
+
*/
|
|
26
|
+
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
22
27
|
}
|
|
23
28
|
/**
|
|
24
29
|
* Parameters for constructing a {@link Collections.Collector | ICollector}.
|
|
@@ -115,6 +120,10 @@ export declare class Collector<TITEM extends ICollectible<any, any>> implements
|
|
|
115
120
|
* {@inheritdoc Collections.ResultMap.values}
|
|
116
121
|
*/
|
|
117
122
|
values(): IterableIterator<TITEM>;
|
|
123
|
+
/**
|
|
124
|
+
* {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
125
|
+
*/
|
|
126
|
+
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
118
127
|
/**
|
|
119
128
|
* Gets a read-only version of this collector.
|
|
120
129
|
*/
|
|
@@ -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
|
}
|
|
@@ -157,6 +166,12 @@ class Collector {
|
|
|
157
166
|
values() {
|
|
158
167
|
return this._byKey.values();
|
|
159
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
171
|
+
*/
|
|
172
|
+
valuesByIndex() {
|
|
173
|
+
return this._byIndex;
|
|
174
|
+
}
|
|
160
175
|
/**
|
|
161
176
|
* Gets a read-only version of this collector.
|
|
162
177
|
*/
|
|
@@ -18,7 +18,11 @@ export interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, an
|
|
|
18
18
|
/**
|
|
19
19
|
* {@inheritdoc Collections.IReadOnlyValidatingCollector.getAt}
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
getAt(index: number): Result<TITEM>;
|
|
22
|
+
/**
|
|
23
|
+
* {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
24
|
+
*/
|
|
25
|
+
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
22
26
|
}
|
|
23
27
|
/**
|
|
24
28
|
* Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.
|
|
@@ -580,7 +580,6 @@ function discriminatedObject(discriminatorProp, converters) {
|
|
|
580
580
|
function transform(properties) {
|
|
581
581
|
return new baseConverter_1.BaseConverter((from, __self, context) => {
|
|
582
582
|
// eslint bug thinks key is used before defined
|
|
583
|
-
// eslint-disable-next-line no-use-before-define
|
|
584
583
|
const converted = {};
|
|
585
584
|
const errors = [];
|
|
586
585
|
for (const key in properties) {
|
|
@@ -620,7 +619,6 @@ function transform(properties) {
|
|
|
620
619
|
function transformObject(destinationFields, options) {
|
|
621
620
|
return new baseConverter_1.BaseConverter((from, __self, context) => {
|
|
622
621
|
// eslint bug thinks key is used before defined
|
|
623
|
-
// eslint-disable-next-line no-use-before-define
|
|
624
622
|
const converted = {};
|
|
625
623
|
const errors = [];
|
|
626
624
|
const used = new Set(options === null || options === void 0 ? void 0 : options.ignore);
|
|
@@ -104,9 +104,8 @@ class ObjectConverter extends baseConverter_1.BaseConverter {
|
|
|
104
104
|
return new ObjectConverter(this.fields, options)._with(this._traits());
|
|
105
105
|
}
|
|
106
106
|
static _convert(from, context, fields, options) {
|
|
107
|
-
var _a;
|
|
108
107
|
// eslint bug thinks key is used before defined
|
|
109
|
-
|
|
108
|
+
var _a;
|
|
110
109
|
const converted = {};
|
|
111
110
|
const errors = [];
|
|
112
111
|
for (const key in fields) {
|
|
@@ -51,13 +51,14 @@ class HashingNormalizer extends base_1.Normalizer {
|
|
|
51
51
|
}
|
|
52
52
|
else if (Array.isArray(from)) {
|
|
53
53
|
return (0, base_1.mapResults)(from.map((e) => this.computeHash(e))).onSuccess((a) => {
|
|
54
|
-
return (0, base_1.captureResult)(() => this._hash(a));
|
|
54
|
+
return (0, base_1.captureResult)(() => this._hash(['array', ...a]));
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
else if (from instanceof Map || from instanceof Set) {
|
|
58
|
-
|
|
58
|
+
const type = from instanceof Map ? 'map' : 'set';
|
|
59
|
+
return this.computeHash([type, ...this.normalizeEntries(from.entries())]);
|
|
59
60
|
}
|
|
60
|
-
return this.computeHash(this.normalizeEntries(Object.entries(from)));
|
|
61
|
+
return this.computeHash(['object', ...this.normalizeEntries(Object.entries(from))]);
|
|
61
62
|
}
|
|
62
63
|
return (0, base_1.fail)(`computeHash: Unexpected type - cannot hash '${typeof from}'`);
|
|
63
64
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
4
4
|
*
|
|
5
5
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -35,5 +35,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
__exportStar(require("./
|
|
38
|
+
__exportStar(require("./logger"), exports);
|
|
39
|
+
__exportStar(require("./logReporter"), exports);
|
|
39
40
|
//# sourceMappingURL=index.js.map
|