@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
|
@@ -59,7 +59,7 @@ class GenericValidator {
|
|
|
59
59
|
* {@inheritdoc Validation.Validator.validate}
|
|
60
60
|
*/
|
|
61
61
|
validate(from, context) {
|
|
62
|
-
const result = this._validator(from, this._context(context));
|
|
62
|
+
const result = this._validator(from, this._context(context), this);
|
|
63
63
|
if (typeof result === 'boolean') {
|
|
64
64
|
return result ? (0, base_1.succeed)(from) : (0, base_1.fail)('Invalid value');
|
|
65
65
|
}
|
|
@@ -69,7 +69,7 @@ class GenericValidator {
|
|
|
69
69
|
* {@inheritdoc Validation.Validator.convert}
|
|
70
70
|
*/
|
|
71
71
|
convert(from, context) {
|
|
72
|
-
const result = this._validator(from, this._context(context));
|
|
72
|
+
const result = this._validator(from, this._context(context), this);
|
|
73
73
|
if (typeof result === 'boolean') {
|
|
74
74
|
return result ? (0, base_1.succeed)(from) : (0, base_1.fail)('Invalid value');
|
|
75
75
|
}
|
|
@@ -85,15 +85,15 @@ class GenericValidator {
|
|
|
85
85
|
* {@inheritdoc Validation.Validator.guard}
|
|
86
86
|
*/
|
|
87
87
|
guard(from, context) {
|
|
88
|
-
return this._validator(from, this._context(context)) === true;
|
|
88
|
+
return this._validator(from, this._context(context), this) === true;
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* {@inheritdoc Validation.Validator.optional}
|
|
92
92
|
*/
|
|
93
93
|
optional() {
|
|
94
94
|
return new GenericValidator({
|
|
95
|
-
validator: (from, context) => {
|
|
96
|
-
return from === undefined || this._validator(from, this._context(context));
|
|
95
|
+
validator: (from, context, self) => {
|
|
96
|
+
return from === undefined || this._validator(from, this._context(context), this);
|
|
97
97
|
},
|
|
98
98
|
traits: { isOptional: true }
|
|
99
99
|
});
|
|
@@ -104,8 +104,8 @@ class GenericValidator {
|
|
|
104
104
|
withConstraint(constraint, trait) {
|
|
105
105
|
trait = trait !== null && trait !== void 0 ? trait : { type: 'function' };
|
|
106
106
|
return new GenericValidator({
|
|
107
|
-
validator: (from, context) => {
|
|
108
|
-
const result = this._validator(from, this._context(context));
|
|
107
|
+
validator: (from, context, self) => {
|
|
108
|
+
const result = this._validator(from, this._context(context), this);
|
|
109
109
|
if (result === true) {
|
|
110
110
|
const constraintResult = constraint(from);
|
|
111
111
|
if (typeof constraintResult === 'boolean') {
|
|
@@ -128,8 +128,8 @@ class GenericValidator {
|
|
|
128
128
|
throw new Error(`Cannot replace existing brand "${this.brand}" with "${brand}".`);
|
|
129
129
|
}
|
|
130
130
|
return new GenericValidator({
|
|
131
|
-
validator: (from, context) => {
|
|
132
|
-
return this._validator(from, this._context(context));
|
|
131
|
+
validator: (from, context, self) => {
|
|
132
|
+
return this._validator(from, this._context(context), this);
|
|
133
133
|
},
|
|
134
134
|
traits: { brand }
|
|
135
135
|
});
|
|
@@ -139,8 +139,8 @@ class GenericValidator {
|
|
|
139
139
|
*/
|
|
140
140
|
withFormattedError(formatter) {
|
|
141
141
|
return new GenericValidator({
|
|
142
|
-
validator: (from, context) => {
|
|
143
|
-
const result = this._validator(from, this._context(context));
|
|
142
|
+
validator: (from, context, self) => {
|
|
143
|
+
const result = this._validator(from, this._context(context), this);
|
|
144
144
|
if (result === true) {
|
|
145
145
|
return true;
|
|
146
146
|
}
|
|
@@ -110,6 +110,6 @@ export declare class ObjectValidator<T, TC = unknown> extends ValidatorBase<T, T
|
|
|
110
110
|
* {@inheritdoc Validation.ValidatorBase._validate}
|
|
111
111
|
* @internal
|
|
112
112
|
*/
|
|
113
|
-
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
113
|
+
protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
114
114
|
}
|
|
115
115
|
//# sourceMappingURL=object.d.ts.map
|
|
@@ -109,12 +109,11 @@ class ObjectValidator extends validatorBase_1.ValidatorBase {
|
|
|
109
109
|
* {@inheritdoc Validation.ValidatorBase._validate}
|
|
110
110
|
* @internal
|
|
111
111
|
*/
|
|
112
|
-
_validate(from, context) {
|
|
112
|
+
_validate(from, context, self) {
|
|
113
113
|
if (typeof from !== 'object' || from === null || Array.isArray(from)) {
|
|
114
114
|
return (0, base_1.fail)('source is not an object');
|
|
115
115
|
}
|
|
116
116
|
// eslint bug thinks key is used before defined
|
|
117
|
-
// eslint-disable-next-line no-use-before-define
|
|
118
117
|
const converted = {};
|
|
119
118
|
const errors = [];
|
|
120
119
|
for (const key in this._innerValidators) {
|
|
@@ -31,9 +31,10 @@ export declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC
|
|
|
31
31
|
* of the configured validators.
|
|
32
32
|
* @param from - The `unknown` value to be tested.
|
|
33
33
|
* @param context - Optional validation context will be propagated to element validator.
|
|
34
|
+
* @param self - Optional self-reference for recursive validation.
|
|
34
35
|
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
35
36
|
* {@link Failure} with an error message if not.
|
|
36
37
|
*/
|
|
37
|
-
protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
|
|
38
|
+
protected _validate<T>(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
38
39
|
}
|
|
39
40
|
//# sourceMappingURL=oneOf.d.ts.map
|
|
@@ -46,10 +46,11 @@ class OneOfValidator extends validatorBase_1.ValidatorBase {
|
|
|
46
46
|
* of the configured validators.
|
|
47
47
|
* @param from - The `unknown` value to be tested.
|
|
48
48
|
* @param context - Optional validation context will be propagated to element validator.
|
|
49
|
+
* @param self - Optional self-reference for recursive validation.
|
|
49
50
|
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
50
51
|
* {@link Failure} with an error message if not.
|
|
51
52
|
*/
|
|
52
|
-
_validate(from, context) {
|
|
53
|
+
_validate(from, context, self) {
|
|
53
54
|
const found = this._validators.some((v) => v.validate(from).success);
|
|
54
55
|
if (found) {
|
|
55
56
|
return true;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Failure } from '../base';
|
|
2
2
|
import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
|
|
3
3
|
import { TypeGuardWithContext } from './common';
|
|
4
|
-
import { ValidatorOptions } from './validator';
|
|
4
|
+
import { Validator, ValidatorOptions } from './validator';
|
|
5
5
|
/**
|
|
6
6
|
* Parameters used to construct a {@link Validation.Classes.TypeGuardValidator}.
|
|
7
7
|
* @public
|
|
@@ -34,10 +34,11 @@ export declare class TypeGuardValidator<T, TC = unknown> extends ValidatorBase<T
|
|
|
34
34
|
* type guard, returning a `Failure<T>` containing more information about a failure.
|
|
35
35
|
* @param from - Value to be converted.
|
|
36
36
|
* @param context - Optional validation context.
|
|
37
|
+
* @param self - Optional self-reference for recursive validation.
|
|
37
38
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
38
39
|
* with an error message if `from` is invalid.
|
|
39
40
|
* @internal
|
|
40
41
|
*/
|
|
41
|
-
protected _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
42
|
+
protected _validate(from: unknown, context?: TC, self?: Validator<T, TC>): boolean | Failure<T>;
|
|
42
43
|
}
|
|
43
44
|
//# sourceMappingURL=typeGuard.d.ts.map
|
|
@@ -47,11 +47,12 @@ class TypeGuardValidator extends validatorBase_1.ValidatorBase {
|
|
|
47
47
|
* type guard, returning a `Failure<T>` containing more information about a failure.
|
|
48
48
|
* @param from - Value to be converted.
|
|
49
49
|
* @param context - Optional validation context.
|
|
50
|
+
* @param self - Optional self-reference for recursive validation.
|
|
50
51
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
51
52
|
* with an error message if `from` is invalid.
|
|
52
53
|
* @internal
|
|
53
54
|
*/
|
|
54
|
-
_validate(from, context) {
|
|
55
|
+
_validate(from, context, self) {
|
|
55
56
|
if (this._guard(from, context)) {
|
|
56
57
|
return true;
|
|
57
58
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { Brand, Failure, Result } from '../base';
|
|
2
2
|
import { ConstraintTrait, ValidatorTraits } from './traits';
|
|
3
|
+
/**
|
|
4
|
+
* Type for a validation function, which validates that a supplied `unknown`
|
|
5
|
+
* value is a valid value of type `<T>`, possibly as influenced by
|
|
6
|
+
* an optionally-supplied validation context of type `<TC>`.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type ValidatorFunc<T, TC> = (from: unknown, context?: TC, self?: Validator<T, TC>) => boolean | Failure<T>;
|
|
3
10
|
/**
|
|
4
11
|
* Options that apply to any {@link Validation.Validator | Validator}.
|
|
5
12
|
* @public
|
|
@@ -19,10 +19,11 @@ export declare abstract class ValidatorBase<T, TC = unknown> extends GenericVali
|
|
|
19
19
|
* Abstract validation method to me implemented by derived classes.
|
|
20
20
|
* @param from - Value to be converted.
|
|
21
21
|
* @param context - Optional validation context.
|
|
22
|
+
* @param self - Optional self-reference for recursive validation.
|
|
22
23
|
* @returns `true` if `from` is valid, {@link Failure | Failure<T>}
|
|
23
24
|
* with an error message if `from` is invalid.
|
|
24
25
|
* @internal
|
|
25
26
|
*/
|
|
26
|
-
protected abstract _validate(from: unknown, context?: TC): boolean | Failure<T>;
|
|
27
|
+
protected abstract _validate(from: unknown, context?: TC, self?: import('./validator').Validator<T, TC>): boolean | Failure<T>;
|
|
27
28
|
}
|
|
28
29
|
//# sourceMappingURL=validatorBase.d.ts.map
|
|
@@ -34,7 +34,7 @@ class ValidatorBase extends genericValidator_1.GenericValidator {
|
|
|
34
34
|
* @internal
|
|
35
35
|
*/
|
|
36
36
|
constructor(params) {
|
|
37
|
-
super(Object.assign({ validator: (from, context) => this._validate(from, context) }, params));
|
|
37
|
+
super(Object.assign({ validator: (from, context, self) => this._validate(from, context, self) }, params));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
exports.ValidatorBase = ValidatorBase;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ArrayValidator, ArrayValidatorConstructorParams } from './array';
|
|
2
2
|
import { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';
|
|
3
3
|
import { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
|
|
4
|
-
import { TypeGuardWithContext
|
|
4
|
+
import { TypeGuardWithContext } from './common';
|
|
5
5
|
import { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';
|
|
6
|
-
import { Validator } from './validator';
|
|
6
|
+
import { Validator, ValidatorFunc } from './validator';
|
|
7
7
|
/**
|
|
8
8
|
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
9
9
|
* @public
|
|
@@ -94,7 +94,7 @@ function arrayOf(validateElement, params) {
|
|
|
94
94
|
function recordOf(validator, options) {
|
|
95
95
|
const opts = Object.assign({ onError: 'fail' }, options);
|
|
96
96
|
return new genericValidator_1.GenericValidator({
|
|
97
|
-
validator: (from, context) => {
|
|
97
|
+
validator: (from, context, self) => {
|
|
98
98
|
if (typeof from !== 'object' || from === null || Array.isArray(from)) {
|
|
99
99
|
return (0, base_1.fail)(`Not a string-keyed object: ${JSON.stringify(from)}`);
|
|
100
100
|
}
|
|
@@ -139,7 +139,7 @@ function recordOf(validator, options) {
|
|
|
139
139
|
*/
|
|
140
140
|
function enumeratedValue(values) {
|
|
141
141
|
return new genericValidator_1.GenericValidator({
|
|
142
|
-
validator: (from, context) => {
|
|
142
|
+
validator: (from, context, self) => {
|
|
143
143
|
if (typeof from === 'string') {
|
|
144
144
|
const v = context !== null && context !== void 0 ? context : values;
|
|
145
145
|
const index = v.indexOf(from);
|
|
@@ -156,7 +156,7 @@ function enumeratedValue(values) {
|
|
|
156
156
|
*/
|
|
157
157
|
function literal(value) {
|
|
158
158
|
return new genericValidator_1.GenericValidator({
|
|
159
|
-
validator: (from) => {
|
|
159
|
+
validator: (from, context, self) => {
|
|
160
160
|
return from === value
|
|
161
161
|
? true
|
|
162
162
|
: (0, base_1.fail)(`Expected literal ${String(value)}, found "${JSON.stringify(from, undefined, 2)}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-30",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-utils.d.ts",
|
|
@@ -17,32 +17,32 @@
|
|
|
17
17
|
"homepage": "https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#readme",
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@jest/expect-utils": "^29.7.0",
|
|
20
|
-
"@microsoft/api-documenter": "^7.26.
|
|
21
|
-
"@microsoft/api-extractor": "^7.
|
|
20
|
+
"@microsoft/api-documenter": "^7.26.31",
|
|
21
|
+
"@microsoft/api-extractor": "^7.52.10",
|
|
22
22
|
"@types/jest": "^29.5.14",
|
|
23
|
-
"@types/luxon": "^3.
|
|
23
|
+
"@types/luxon": "^3.7.1",
|
|
24
24
|
"@types/mustache": "^4.2.5",
|
|
25
25
|
"@types/node": "^20.14.9",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
27
|
-
"@typescript-eslint/parser": "^
|
|
28
|
-
"eslint": "^
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^8.42.0",
|
|
27
|
+
"@typescript-eslint/parser": "^8.42.0",
|
|
28
|
+
"eslint": "^9.35.0",
|
|
29
29
|
"eslint-plugin-import": "^2.32.0",
|
|
30
30
|
"eslint-plugin-node": "^11.1.0",
|
|
31
|
-
"eslint-plugin-promise": "^
|
|
31
|
+
"eslint-plugin-promise": "^7.2.1",
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
33
|
"jest-extended": "^4.0.2",
|
|
34
34
|
"jest-matcher-utils": "^29.7.0",
|
|
35
|
-
"rimraf": "^
|
|
36
|
-
"ts-jest": "^29.4.
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
|
+
"ts-jest": "^29.4.1",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "
|
|
39
|
-
"eslint-plugin-n": "^
|
|
38
|
+
"typescript": "5.8.3",
|
|
39
|
+
"eslint-plugin-n": "^17.21.3",
|
|
40
40
|
"jest-snapshot": "~29.7.0",
|
|
41
|
-
"@rushstack/heft": "
|
|
42
|
-
"@rushstack/heft-node-rig": "
|
|
43
|
-
"@rushstack/eslint-config": "
|
|
41
|
+
"@rushstack/heft": "0.74.4",
|
|
42
|
+
"@rushstack/heft-node-rig": "2.9.5",
|
|
43
|
+
"@rushstack/eslint-config": "4.4.0",
|
|
44
44
|
"@types/heft-jest": "1.0.6",
|
|
45
|
-
"@rushstack/heft-jest-plugin": "
|
|
45
|
+
"@rushstack/heft-jest-plugin": "0.16.13",
|
|
46
46
|
"eslint-plugin-tsdoc": "~0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
package/CHANGELOG.md
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
# Change Log - @fgv/ts-utils
|
|
2
|
-
|
|
3
|
-
This log was last generated on Thu, 17 Jul 2025 00:13:24 GMT and should not be manually modified.
|
|
4
|
-
|
|
5
|
-
## 5.0.0
|
|
6
|
-
Thu, 17 Jul 2025 00:13:24 GMT
|
|
7
|
-
|
|
8
|
-
### Updates
|
|
9
|
-
|
|
10
|
-
- add result helpers, clean up object converter
|
|
11
|
-
- object converter partial/required helpers
|
|
12
|
-
- add Result.withErrorFormat
|
|
13
|
-
- bump version
|
|
14
|
-
|
|
15
|
-
## 4.6.0
|
|
16
|
-
Wed, 02 Jul 2025 05:48:16 GMT
|
|
17
|
-
|
|
18
|
-
_Version update only_
|
|
19
|
-
|
|
20
|
-
## 4.5.1
|
|
21
|
-
Wed, 02 Jul 2025 05:47:11 GMT
|
|
22
|
-
|
|
23
|
-
### Updates
|
|
24
|
-
|
|
25
|
-
- use IterableIterator instead of MapIterator
|
|
26
|
-
- update rushstack
|
|
27
|
-
|
|
28
|
-
## 4.5.0
|
|
29
|
-
Tue, 01 Jul 2025 03:26:11 GMT
|
|
30
|
-
|
|
31
|
-
### Minor changes
|
|
32
|
-
|
|
33
|
-
- add recordOf validator for validating Record<string, T> objects
|
|
34
|
-
|
|
35
|
-
### Updates
|
|
36
|
-
|
|
37
|
-
- update collectors
|
|
38
|
-
- rework collections for better usability
|
|
39
|
-
|
|
40
|
-
## 4.4.0
|
|
41
|
-
Sat, 01 Feb 2025 17:13:10 GMT
|
|
42
|
-
|
|
43
|
-
_Version update only_
|
|
44
|
-
|
|
45
|
-
## 4.3.0
|
|
46
|
-
Thu, 30 Jan 2025 00:35:17 GMT
|
|
47
|
-
|
|
48
|
-
### Updates
|
|
49
|
-
|
|
50
|
-
- add collector, convertingResultMap, convertingCollector
|
|
51
|
-
|
|
52
|
-
## 4.2.2
|
|
53
|
-
Thu, 23 Jan 2025 06:19:32 GMT
|
|
54
|
-
|
|
55
|
-
### Updates
|
|
56
|
-
|
|
57
|
-
- QoL improvements to Success/Failure
|
|
58
|
-
|
|
59
|
-
## 4.2.1
|
|
60
|
-
Tue, 21 Jan 2025 04:19:21 GMT
|
|
61
|
-
|
|
62
|
-
### Updates
|
|
63
|
-
|
|
64
|
-
- allow factories in getOrAdd
|
|
65
|
-
|
|
66
|
-
## 4.2.0
|
|
67
|
-
Mon, 20 Jan 2025 09:46:53 GMT
|
|
68
|
-
|
|
69
|
-
### Updates
|
|
70
|
-
|
|
71
|
-
- add collections packlet and ResultMap class
|
|
72
|
-
- add withFormattedError on validator and converter
|
|
73
|
-
- clean up type inconsistencies, relax some constraints
|
|
74
|
-
|
|
75
|
-
## 4.1.0
|
|
76
|
-
Thu, 09 Jan 2025 05:33:39 GMT
|
|
77
|
-
|
|
78
|
-
### Updates
|
|
79
|
-
|
|
80
|
-
- update dependencies
|
|
81
|
-
|
|
82
|
-
## 4.0.2
|
|
83
|
-
Tue, 14 May 2024 14:45:53 GMT
|
|
84
|
-
|
|
85
|
-
_Version update only_
|
|
86
|
-
|
|
87
|
-
## 4.0.1
|
|
88
|
-
Tue, 14 May 2024 05:02:20 GMT
|
|
89
|
-
|
|
90
|
-
### Updates
|
|
91
|
-
|
|
92
|
-
- publish
|
|
93
|
-
- import TextEncoder to avoid globals race
|
|
94
|
-
|
|
95
|
-
## 4.0.0
|
|
96
|
-
Tue, 14 May 2024 03:09:27 GMT
|
|
97
|
-
|
|
98
|
-
### Updates
|
|
99
|
-
|
|
100
|
-
- rework validation/converter compatibility a bit
|
|
101
|
-
- QoL improvement to simplify error aggregation
|
|
102
|
-
- factor optional converters out to ts-extras package to eliminate large dependencies
|
|
103
|
-
- update generated api docs
|
|
104
|
-
- add convalidate helper
|
|
105
|
-
- add defaulting converter
|
|
106
|
-
- extend conversion to accept validators
|
|
107
|
-
- export StringConverter at top level
|
|
108
|
-
|
|
109
|
-
## 3.0.0
|
|
110
|
-
Mon, 22 Jan 2024 07:00:18 GMT
|
|
111
|
-
|
|
112
|
-
### Updates
|
|
113
|
-
|
|
114
|
-
- gitignore tweaks
|
|
115
|
-
- refactor hash implementation
|
|
116
|
-
- bump versions
|
|
117
|
-
- refactor and cleanup
|
|
118
|
-
- build changes
|
|
119
|
-
- Factor out extras, enable shaking
|
|
120
|
-
- bump dependencies
|
|
121
|
-
- version upgrades
|
|
122
|
-
- relax mapToRecord from Map to ReadonlyMap
|
|
123
|
-
- bump version
|
|
124
|
-
- add oneOf validator
|
|
125
|
-
|
|
126
|
-
## 2.0.0
|
|
127
|
-
Mon, 10 Apr 2023 03:33:11 GMT
|
|
128
|
-
|
|
129
|
-
### Breaking changes
|
|
130
|
-
|
|
131
|
-
- refactor and cleanup
|
|
132
|
-
- reorganization and cleanup
|
|
133
|
-
- more refactoring
|
|
134
|
-
- refactor
|
|
135
|
-
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,EACT,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,UAAU,EACX,CAAC"}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oEAAsD;AAqBpD,kCAAW;AApBb,kEAAoD;AAuBlD,gCAAU;AAtBZ,sDAAwC;AA0BtC,oBAAI;AAzBN,+DAAiD;AAwB/C,4BAAQ;AAvBV,kEAAoD;AAiClD,gCAAU;AA/BZ,wDASgC;AAO9B,0FAfA,uBAAS,OAeA;AACT,oGAdA,iCAAmB,OAcA;AASnB,0FArBA,uBAAS,OAqBA;AAET,oGAtBA,iCAAmB,OAsBA;AACnB,8GAtBA,2CAA6B,OAsBA;AAC7B,oGAtBA,iCAAmB,OAsBA;AApBrB,sDAAgG;AAU9F,2FAVkB,uBAAU,OAUlB;AAKV,gGAf8B,4BAAe,OAe9B;AAEf,gGAjB+C,4BAAe,OAiB/C;AAhBjB,sDAA8D;AAsB5D,2FAtBkB,uBAAU,OAsBlB;AApBZ,kDAAgC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Collections from './packlets/collections';\nimport * as Conversion from './packlets/conversion';\nimport * as Hash from './packlets/hash';\nimport * as FileTree from './packlets/file-tree';\nimport * as Validation from './packlets/validation';\n\nimport {\n Collector,\n ICollectible,\n ConvertingCollector,\n IReadOnlyResultMap,\n ResultMap,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap\n} from './packlets/collections';\nimport { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport {\n Collections,\n Collector,\n ConvertingCollector,\n Conversion,\n Converter,\n Converters,\n FileTree,\n Hash,\n ICollectible,\n IReadOnlyResultMap,\n ObjectConverter,\n ResultMap,\n StringConverter,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap,\n Validation,\n Validator,\n Validators\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/brand.ts"],"names":[],"mappings":"AAsBA;;;GAGG;AAEH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../src/packlets/base/brand.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Helper type to brand a simple type to prevent inappropriate use\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport type Brand<T, B> = T & { __brand: B };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAoC;AAQ3B,0BAAO;AANhB,0CAAwB;AACxB,+CAA6B;AAC7B,sDAAoC;AACpC,yCAAyC;AAAhC,uGAAA,UAAU,OAAA;AACnB,2CAAyB;AACzB,0CAAwB","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Logging from './logger';\n\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\nexport { Logging };\n"]}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Failure, Success } from './result';
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface Logger {
|
|
10
|
-
log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
11
|
-
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
12
|
-
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
13
|
-
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
14
|
-
warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
15
|
-
error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export declare abstract class LoggerBase {
|
|
21
|
-
logLevel: LogLevel;
|
|
22
|
-
constructor(logLevel?: LogLevel);
|
|
23
|
-
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
24
|
-
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
25
|
-
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
26
|
-
warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
27
|
-
error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
28
|
-
log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
29
|
-
protected _format(message?: unknown, ...parameters: unknown[]): string;
|
|
30
|
-
protected _innerSilent(__message: string): Success<string | undefined>;
|
|
31
|
-
protected abstract _innerLog(message: string): Success<string | undefined>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export declare class InMemoryLogger extends LoggerBase {
|
|
37
|
-
protected _messages: string[];
|
|
38
|
-
protected _silent: string[];
|
|
39
|
-
constructor(logLevel?: LogLevel);
|
|
40
|
-
get messages(): string[];
|
|
41
|
-
get silent(): string[];
|
|
42
|
-
clear(): void;
|
|
43
|
-
protected _innerLog(message: string): Success<string | undefined>;
|
|
44
|
-
protected _innerSilent(message: string): Success<string | undefined>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export declare class NoOpLogger extends LoggerBase {
|
|
50
|
-
protected _innerLog(message: string): Success<string | undefined>;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoOpLogger = exports.InMemoryLogger = exports.LoggerBase = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright (c) 2020 Erik Fortune
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
const result_1 = require("./result");
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
class LoggerBase {
|
|
30
|
-
constructor(logLevel) {
|
|
31
|
-
this.logLevel = 'info';
|
|
32
|
-
this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
|
|
33
|
-
}
|
|
34
|
-
detail(message, ...parameters) {
|
|
35
|
-
if (this.logLevel === 'detail') {
|
|
36
|
-
return this.log(message, parameters);
|
|
37
|
-
}
|
|
38
|
-
return (0, result_1.succeed)(undefined);
|
|
39
|
-
}
|
|
40
|
-
info(message, ...parameters) {
|
|
41
|
-
if (this.logLevel === 'detail' || this.logLevel === 'info') {
|
|
42
|
-
return this.log(message, parameters);
|
|
43
|
-
}
|
|
44
|
-
return (0, result_1.succeed)(undefined);
|
|
45
|
-
}
|
|
46
|
-
warn(message, ...parameters) {
|
|
47
|
-
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
48
|
-
return this.log(message, parameters);
|
|
49
|
-
}
|
|
50
|
-
return (0, result_1.succeed)(undefined);
|
|
51
|
-
}
|
|
52
|
-
warnAndFail(message, ...parameters) {
|
|
53
|
-
var _a;
|
|
54
|
-
const formatted = this._format(message, ...parameters);
|
|
55
|
-
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
56
|
-
const result = this.log(formatted);
|
|
57
|
-
return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
|
|
58
|
-
}
|
|
59
|
-
return (0, result_1.fail)(formatted);
|
|
60
|
-
}
|
|
61
|
-
error(message, ...parameters) {
|
|
62
|
-
var _a;
|
|
63
|
-
const formatted = this._format(message, ...parameters);
|
|
64
|
-
if (this.logLevel !== 'silent') {
|
|
65
|
-
const result = this.log(formatted);
|
|
66
|
-
return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
|
|
67
|
-
}
|
|
68
|
-
return (0, result_1.fail)(formatted);
|
|
69
|
-
}
|
|
70
|
-
log(message, ...parameters) {
|
|
71
|
-
const messageString = this._format(message, ...parameters);
|
|
72
|
-
if (this.logLevel === 'silent') {
|
|
73
|
-
return this._innerSilent(messageString);
|
|
74
|
-
}
|
|
75
|
-
return this._innerLog(messageString);
|
|
76
|
-
}
|
|
77
|
-
_format(message, ...parameters) {
|
|
78
|
-
const raw = [message, ...parameters];
|
|
79
|
-
const filtered = raw.filter((m) => m !== undefined);
|
|
80
|
-
const strings = filtered.map((m) => m.toString());
|
|
81
|
-
const joined = strings.join('');
|
|
82
|
-
return joined;
|
|
83
|
-
}
|
|
84
|
-
_innerSilent(__message) {
|
|
85
|
-
return (0, result_1.succeed)(undefined);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.LoggerBase = LoggerBase;
|
|
89
|
-
/**
|
|
90
|
-
* @public
|
|
91
|
-
*/
|
|
92
|
-
class InMemoryLogger extends LoggerBase {
|
|
93
|
-
constructor(logLevel) {
|
|
94
|
-
super(logLevel);
|
|
95
|
-
this._messages = [];
|
|
96
|
-
this._silent = [];
|
|
97
|
-
}
|
|
98
|
-
get messages() {
|
|
99
|
-
return this._messages;
|
|
100
|
-
}
|
|
101
|
-
get silent() {
|
|
102
|
-
return this._silent;
|
|
103
|
-
}
|
|
104
|
-
clear() {
|
|
105
|
-
this._messages = [];
|
|
106
|
-
this._silent = [];
|
|
107
|
-
}
|
|
108
|
-
_innerLog(message) {
|
|
109
|
-
this._messages.push(message);
|
|
110
|
-
return (0, result_1.succeed)(message);
|
|
111
|
-
}
|
|
112
|
-
_innerSilent(message) {
|
|
113
|
-
this._silent.push(message);
|
|
114
|
-
return (0, result_1.succeed)(undefined);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.InMemoryLogger = InMemoryLogger;
|
|
118
|
-
/**
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
|
-
class NoOpLogger extends LoggerBase {
|
|
122
|
-
_innerLog(message) {
|
|
123
|
-
// no-op
|
|
124
|
-
return (0, result_1.succeed)(message);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.NoOpLogger = NoOpLogger;
|
|
128
|
-
//# sourceMappingURL=logger.js.map
|