@fgv/ts-utils 5.0.0-3 → 5.0.0-30
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 +0 -21
- package/dist/ts-utils.d.ts +364 -41
- package/dist/tsdoc-metadata.json +1 -1
- package/eslint.config.js +37 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/packlets/base/index.d.ts +0 -2
- package/lib/packlets/base/index.js +1 -25
- package/lib/packlets/base/result.d.ts +61 -0
- package/lib/packlets/base/result.js +49 -0
- package/lib/packlets/collections/collector.d.ts +9 -0
- package/lib/packlets/collections/collector.js +6 -0
- 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/crcNormalizer.js +3 -1
- package/lib/packlets/hash/hashingNormalizer.js +4 -3
- package/lib/packlets/logging/index.d.ts +3 -0
- package/lib/packlets/logging/index.js +40 -0
- package/lib/packlets/logging/logReporter.d.ts +88 -0
- package/lib/packlets/logging/logReporter.js +114 -0
- package/lib/packlets/logging/logger.d.ts +197 -0
- package/lib/packlets/logging/logger.js +244 -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.map +0 -1
- package/lib/packlets/file-tree/directoryItem.js.map +0 -1
- package/lib/packlets/file-tree/fileItem.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileItem.js.map +0 -1
- package/lib/packlets/file-tree/fileTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTree.js.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +0 -1
- package/lib/packlets/file-tree/fileTreeAccessors.js.map +0 -1
- package/lib/packlets/file-tree/fsTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/fsTree.js.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +0 -1
- package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +0 -1
- 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.map +0 -1
- package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +0 -1
- package/lib/packlets/file-tree/index.d.ts.map +0 -1
- 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
|
@@ -2,10 +2,11 @@ import * as Collections from './packlets/collections';
|
|
|
2
2
|
import * as Conversion from './packlets/conversion';
|
|
3
3
|
import * as Hash from './packlets/hash';
|
|
4
4
|
import * as FileTree from './packlets/file-tree';
|
|
5
|
+
import * as Logging from './packlets/logging';
|
|
5
6
|
import * as Validation from './packlets/validation';
|
|
6
7
|
import { Collector, ICollectible, ConvertingCollector, IReadOnlyResultMap, ResultMap, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap } from './packlets/collections';
|
|
7
8
|
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
8
9
|
import { Validator, Validators } from './packlets/validation';
|
|
9
10
|
export * from './packlets/base';
|
|
10
|
-
export { Collections, Collector, ConvertingCollector, Conversion, Converter, Converters, FileTree, Hash, ICollectible, IReadOnlyResultMap, ObjectConverter, ResultMap, StringConverter, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap, Validation, Validator, Validators };
|
|
11
|
+
export { Collections, Collector, ConvertingCollector, Conversion, Converter, Converters, FileTree, Hash, ICollectible, IReadOnlyResultMap, Logging, ObjectConverter, ResultMap, StringConverter, ValidatingCollector, ValidatingConvertingCollector, ValidatingResultMap, Validation, Validator, Validators };
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -57,7 +57,7 @@ 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.Hash = exports.FileTree = exports.Converters = exports.Conversion = exports.ConvertingCollector = exports.Collector = exports.Collections = void 0;
|
|
60
|
+
exports.Validators = exports.Validation = exports.ValidatingResultMap = exports.ValidatingConvertingCollector = exports.ValidatingCollector = exports.StringConverter = exports.ResultMap = exports.ObjectConverter = exports.Logging = exports.Hash = exports.FileTree = 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"));
|
|
@@ -66,6 +66,8 @@ const Hash = __importStar(require("./packlets/hash"));
|
|
|
66
66
|
exports.Hash = Hash;
|
|
67
67
|
const FileTree = __importStar(require("./packlets/file-tree"));
|
|
68
68
|
exports.FileTree = FileTree;
|
|
69
|
+
const Logging = __importStar(require("./packlets/logging"));
|
|
70
|
+
exports.Logging = Logging;
|
|
69
71
|
const Validation = __importStar(require("./packlets/validation"));
|
|
70
72
|
exports.Validation = Validation;
|
|
71
73
|
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);
|
|
@@ -41,6 +41,37 @@ export interface IResultLogger<TD = unknown> {
|
|
|
41
41
|
*/
|
|
42
42
|
error(message: string, detail?: TD): void;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* The severity level at which a message should be logged.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';
|
|
49
|
+
/**
|
|
50
|
+
* Options for reporting a result.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface IResultReportOptions<TD = unknown> {
|
|
54
|
+
/**
|
|
55
|
+
* The level of reporting to be used for failure results. Default is 'error'.
|
|
56
|
+
*/
|
|
57
|
+
failure?: MessageLogLevel;
|
|
58
|
+
/**
|
|
59
|
+
* The level of reporting to be used for success results. Default is 'quiet'.
|
|
60
|
+
*/
|
|
61
|
+
success?: MessageLogLevel;
|
|
62
|
+
/**
|
|
63
|
+
* The error formatter to be used for reporting an error result.
|
|
64
|
+
*/
|
|
65
|
+
message?: ErrorFormatter<TD>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Interface for reporting a result.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface IResultReporter<T, TD = unknown> {
|
|
72
|
+
reportSuccess(level: MessageLogLevel, value: T, detail?: TD): void;
|
|
73
|
+
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
74
|
+
}
|
|
44
75
|
/**
|
|
45
76
|
* Simple error aggregator to simplify collecting all errors in
|
|
46
77
|
* a flow.
|
|
@@ -237,6 +268,12 @@ export interface IResult<T> {
|
|
|
237
268
|
* errors will be aggregated.
|
|
238
269
|
*/
|
|
239
270
|
aggregateError(errors: IMessageAggregator): this;
|
|
271
|
+
/**
|
|
272
|
+
* Reports the result to the supplied reporter
|
|
273
|
+
* @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.
|
|
274
|
+
* @param options - The {@link IResultReportOptions | options} for reporting the result.
|
|
275
|
+
*/
|
|
276
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
240
277
|
}
|
|
241
278
|
/**
|
|
242
279
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
@@ -323,6 +360,10 @@ export declare class Success<T> implements IResult<T> {
|
|
|
323
360
|
* {@inheritdoc IResult.aggregateError}
|
|
324
361
|
*/
|
|
325
362
|
aggregateError(__errors: IMessageAggregator): this;
|
|
363
|
+
/**
|
|
364
|
+
* {@inheritdoc IResult.report}
|
|
365
|
+
*/
|
|
366
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
326
367
|
/**
|
|
327
368
|
* Creates a {@link Success | Success<T>} with the supplied value.
|
|
328
369
|
* @param value - The value to be returned.
|
|
@@ -415,6 +456,10 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
415
456
|
* {@inheritdoc IResult.aggregateError}
|
|
416
457
|
*/
|
|
417
458
|
aggregateError(errors: IMessageAggregator): this;
|
|
459
|
+
/**
|
|
460
|
+
* {@inheritdoc IResult.report}
|
|
461
|
+
*/
|
|
462
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
418
463
|
/**
|
|
419
464
|
* Get a 'friendly' string representation of this object.
|
|
420
465
|
* @remarks
|
|
@@ -458,6 +503,14 @@ export declare function fail<T>(message: string): Failure<T>;
|
|
|
458
503
|
* @public
|
|
459
504
|
*/
|
|
460
505
|
export declare function fails<T>(message: string): Failure<T>;
|
|
506
|
+
/**
|
|
507
|
+
* Uses a value or calls a supplied initializer if the supplied value is undefined.
|
|
508
|
+
* @param value - the value
|
|
509
|
+
* @param initializer - a function that initializes the value if it is undefined
|
|
510
|
+
* @returns `Success` with the value if it is defined, or the result of calling the initializer function.
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
export declare function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T>;
|
|
461
514
|
/**
|
|
462
515
|
* Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.
|
|
463
516
|
* @remarks
|
|
@@ -529,6 +582,10 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
|
|
|
529
582
|
* {@inheritdoc Success.withErrorFormat}
|
|
530
583
|
*/
|
|
531
584
|
withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
|
|
585
|
+
/**
|
|
586
|
+
* {@inheritdoc IResult.report}
|
|
587
|
+
*/
|
|
588
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
532
589
|
/**
|
|
533
590
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
534
591
|
* optional detail.
|
|
@@ -591,6 +648,10 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
|
|
|
591
648
|
* {@inheritdoc IResult.withErrorFormat}
|
|
592
649
|
*/
|
|
593
650
|
withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
|
|
651
|
+
/**
|
|
652
|
+
* {@inheritdoc IResult.report}
|
|
653
|
+
*/
|
|
654
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
594
655
|
orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;
|
|
595
656
|
orThrow(cb: ErrorFormatter): never;
|
|
596
657
|
/**
|
|
@@ -26,6 +26,7 @@ exports.succeed = succeed;
|
|
|
26
26
|
exports.succeeds = succeeds;
|
|
27
27
|
exports.fail = fail;
|
|
28
28
|
exports.fails = fails;
|
|
29
|
+
exports.useOrInitialize = useOrInitialize;
|
|
29
30
|
exports.succeedWithDetail = succeedWithDetail;
|
|
30
31
|
exports.succeedsWithDetail = succeedsWithDetail;
|
|
31
32
|
exports.failWithDetail = failWithDetail;
|
|
@@ -129,6 +130,15 @@ class Success {
|
|
|
129
130
|
aggregateError(__errors) {
|
|
130
131
|
return this;
|
|
131
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* {@inheritdoc IResult.report}
|
|
135
|
+
*/
|
|
136
|
+
report(reporter, options) {
|
|
137
|
+
var _a;
|
|
138
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
139
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
132
142
|
/**
|
|
133
143
|
* Creates a {@link Success | Success<T>} with the supplied value.
|
|
134
144
|
* @param value - The value to be returned.
|
|
@@ -246,6 +256,16 @@ class Failure {
|
|
|
246
256
|
errors.addMessage(this._message);
|
|
247
257
|
return this;
|
|
248
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* {@inheritdoc IResult.report}
|
|
261
|
+
*/
|
|
262
|
+
report(reporter, options) {
|
|
263
|
+
var _a, _b, _c;
|
|
264
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
265
|
+
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;
|
|
266
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message);
|
|
267
|
+
return this;
|
|
268
|
+
}
|
|
249
269
|
/**
|
|
250
270
|
* Get a 'friendly' string representation of this object.
|
|
251
271
|
* @remarks
|
|
@@ -302,6 +322,16 @@ function fail(message) {
|
|
|
302
322
|
function fails(message) {
|
|
303
323
|
return new Failure(message);
|
|
304
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Uses a value or calls a supplied initializer if the supplied value is undefined.
|
|
327
|
+
* @param value - the value
|
|
328
|
+
* @param initializer - a function that initializes the value if it is undefined
|
|
329
|
+
* @returns `Success` with the value if it is defined, or the result of calling the initializer function.
|
|
330
|
+
* @public
|
|
331
|
+
*/
|
|
332
|
+
function useOrInitialize(value, initializer) {
|
|
333
|
+
return value !== undefined ? succeed(value) : initializer();
|
|
334
|
+
}
|
|
305
335
|
/**
|
|
306
336
|
* A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
|
|
307
337
|
* details in addition to the error message.
|
|
@@ -365,6 +395,15 @@ class DetailedSuccess extends Success {
|
|
|
365
395
|
withErrorFormat(cb) {
|
|
366
396
|
return this;
|
|
367
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* {@inheritdoc IResult.report}
|
|
400
|
+
*/
|
|
401
|
+
report(reporter, options) {
|
|
402
|
+
var _a;
|
|
403
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
404
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value, this._detail);
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
368
407
|
/**
|
|
369
408
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
370
409
|
* optional detail.
|
|
@@ -441,6 +480,16 @@ class DetailedFailure extends Failure {
|
|
|
441
480
|
withErrorFormat(cb) {
|
|
442
481
|
return failWithDetail(cb(this._message, this._detail), this._detail);
|
|
443
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* {@inheritdoc IResult.report}
|
|
485
|
+
*/
|
|
486
|
+
report(reporter, options) {
|
|
487
|
+
var _a, _b, _c;
|
|
488
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
489
|
+
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;
|
|
490
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message, this._detail);
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
444
493
|
orThrow(logOrFormat) {
|
|
445
494
|
if (logOrFormat !== undefined) {
|
|
446
495
|
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
|
*/
|
|
@@ -157,6 +157,12 @@ class Collector {
|
|
|
157
157
|
values() {
|
|
158
158
|
return this._byKey.values();
|
|
159
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* {@inheritdoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
162
|
+
*/
|
|
163
|
+
valuesByIndex() {
|
|
164
|
+
return this._byIndex;
|
|
165
|
+
}
|
|
160
166
|
/**
|
|
161
167
|
* Gets a read-only version of this collector.
|
|
162
168
|
*/
|
|
@@ -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) {
|
|
@@ -69,7 +69,9 @@ class Crc32Normalizer extends hashingNormalizer_1.HashingNormalizer {
|
|
|
69
69
|
super(Crc32Normalizer.crc32Hash);
|
|
70
70
|
}
|
|
71
71
|
static crc32Hash(parts) {
|
|
72
|
-
return crc32(textEncoder.encode(parts.join('|')))
|
|
72
|
+
return crc32(textEncoder.encode(parts.join('|')))
|
|
73
|
+
.toString(16)
|
|
74
|
+
.padStart(8, '0');
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
exports.Crc32Normalizer = Crc32Normalizer;
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
__exportStar(require("./logger"), exports);
|
|
39
|
+
__exportStar(require("./logReporter"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ILogger, ReporterLogLevel } from './logger';
|
|
2
|
+
import { IResultReporter, MessageLogLevel, Success } from '../base';
|
|
3
|
+
/**
|
|
4
|
+
* A function that formats a value for logging.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export type LogValueFormatter<T, TD = unknown> = (value: T, detail?: TD) => string;
|
|
8
|
+
/**
|
|
9
|
+
* A function that formats a message for logging.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export type LogMessageFormatter<TD = unknown> = (message: string, detail?: TD) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for creating a {@link Logging.LogReporter | LogReporter}.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface ILogReporterCreateParams<T, TD = unknown> {
|
|
18
|
+
logger?: ILogger;
|
|
19
|
+
valueFormatter?: LogValueFormatter<T, TD>;
|
|
20
|
+
messageFormatter?: LogMessageFormatter<TD>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Abstract base class which wraps an existing {@link Logging.ILogger | ILogger} to implement
|
|
24
|
+
* both {@link Logging.ILogger | ILogger} and {@link IResultReporter | IResultReporter}.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare class LogReporter<T, TD = unknown> implements ILogger, IResultReporter<T, TD> {
|
|
28
|
+
/**
|
|
29
|
+
* The logger to wrap.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
protected readonly _logger: ILogger;
|
|
33
|
+
/**
|
|
34
|
+
* The formatter to use for values.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
protected readonly _valueFormatter: LogValueFormatter<T, TD>;
|
|
38
|
+
/**
|
|
39
|
+
* The formatter to use for messages.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
protected readonly _messageFormatter: LogMessageFormatter<TD>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new {@link Logging.LogReporter | LogReporter}.
|
|
45
|
+
* @param params - The parameters for creating the {@link Logging.LogReporter | LogReporter}.
|
|
46
|
+
*/
|
|
47
|
+
constructor(params?: ILogReporterCreateParams<T, TD>);
|
|
48
|
+
/**
|
|
49
|
+
* {@inheritDoc Logging.ILogger.logLevel}
|
|
50
|
+
*/
|
|
51
|
+
get logLevel(): ReporterLogLevel;
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritDoc Logging.ILogger.detail}
|
|
54
|
+
*/
|
|
55
|
+
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritDoc Logging.ILogger.info}
|
|
58
|
+
*/
|
|
59
|
+
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* {@inheritDoc Logging.ILogger.warn}
|
|
62
|
+
*/
|
|
63
|
+
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* {@inheritDoc Logging.ILogger.error}
|
|
66
|
+
*/
|
|
67
|
+
error(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
68
|
+
/**
|
|
69
|
+
* {@inheritDoc Logging.ILogger.log}
|
|
70
|
+
*/
|
|
71
|
+
log(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc IResultReporter.reportSuccess}
|
|
74
|
+
*/
|
|
75
|
+
reportSuccess(level: MessageLogLevel, value: T, detail?: TD): void;
|
|
76
|
+
/**
|
|
77
|
+
* {@inheritDoc IResultReporter.reportFailure}
|
|
78
|
+
*/
|
|
79
|
+
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
80
|
+
/**
|
|
81
|
+
* Generic method to try to format an object for logging.
|
|
82
|
+
* @param value - The value to format.
|
|
83
|
+
* @param detail - The detail to format.
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
static tryFormatObject<T = unknown, TD = unknown>(value: T, detail?: TD): string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=logReporter.d.ts.map
|