@fgv/ts-utils 5.0.1-9 → 5.0.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.
Files changed (89) hide show
  1. package/dist/index.js +32 -0
  2. package/dist/packlets/base/brand.js +23 -0
  3. package/dist/packlets/base/index.js +28 -0
  4. package/dist/packlets/base/mapResults.js +217 -0
  5. package/dist/packlets/base/messageAggregator.js +110 -0
  6. package/dist/packlets/base/normalize.js +132 -0
  7. package/dist/packlets/base/result.js +611 -0
  8. package/dist/packlets/base/utils.js +185 -0
  9. package/dist/packlets/collections/collectible.js +82 -0
  10. package/dist/packlets/collections/collector.js +189 -0
  11. package/dist/packlets/collections/collectorValidator.js +94 -0
  12. package/dist/packlets/collections/common.js +23 -0
  13. package/dist/packlets/collections/convertingCollector.js +118 -0
  14. package/dist/packlets/collections/convertingCollectorValidator.js +95 -0
  15. package/dist/packlets/collections/index.js +37 -0
  16. package/dist/packlets/collections/keyValueConverters.js +100 -0
  17. package/dist/packlets/collections/readonlyResultMap.js +23 -0
  18. package/dist/packlets/collections/resultMap.js +214 -0
  19. package/dist/packlets/collections/resultMapValidator.js +122 -0
  20. package/dist/packlets/collections/utils.js +31 -0
  21. package/dist/packlets/collections/validatingCollector.js +63 -0
  22. package/dist/packlets/collections/validatingConvertingCollector.js +64 -0
  23. package/dist/packlets/collections/validatingResultMap.js +57 -0
  24. package/dist/packlets/conversion/baseConverter.js +242 -0
  25. package/dist/packlets/conversion/converter.js +2 -0
  26. package/dist/packlets/conversion/converters.js +637 -0
  27. package/dist/packlets/conversion/defaultingConverter.js +149 -0
  28. package/dist/packlets/conversion/index.js +29 -0
  29. package/dist/packlets/conversion/objectConverter.js +141 -0
  30. package/dist/packlets/conversion/stringConverter.js +93 -0
  31. package/dist/packlets/hash/crcNormalizer.js +114 -0
  32. package/dist/packlets/hash/hashingNormalizer.js +92 -0
  33. package/dist/packlets/hash/index.js +24 -0
  34. package/dist/packlets/logging/index.js +24 -0
  35. package/dist/packlets/logging/logReporter.js +114 -0
  36. package/dist/packlets/logging/logger.js +258 -0
  37. package/dist/packlets/validation/array.js +64 -0
  38. package/dist/packlets/validation/boolean.js +52 -0
  39. package/dist/packlets/validation/classes.js +31 -0
  40. package/dist/packlets/validation/common.js +23 -0
  41. package/dist/packlets/validation/field.js +67 -0
  42. package/dist/packlets/validation/genericValidator.js +160 -0
  43. package/dist/packlets/validation/index.js +29 -0
  44. package/dist/packlets/validation/number.js +52 -0
  45. package/dist/packlets/validation/object.js +134 -0
  46. package/dist/packlets/validation/oneOf.js +58 -0
  47. package/dist/packlets/validation/string.js +52 -0
  48. package/dist/packlets/validation/traits.js +56 -0
  49. package/dist/packlets/validation/typeGuard.js +59 -0
  50. package/dist/packlets/validation/validator.js +23 -0
  51. package/dist/packlets/validation/validatorBase.js +37 -0
  52. package/dist/packlets/validation/validators.js +191 -0
  53. package/dist/test/helpers/jest/helpers/fsHelpers.js +139 -0
  54. package/dist/test/helpers/jest/helpers/index.js +2 -0
  55. package/dist/test/helpers/jest/index.js +17 -0
  56. package/dist/test/helpers/jest/matchers/index.js +14 -0
  57. package/dist/test/helpers/jest/matchers/toFail/index.js +23 -0
  58. package/dist/test/helpers/jest/matchers/toFail/predicate.js +5 -0
  59. package/dist/test/helpers/jest/matchers/toFailTest/index.js +28 -0
  60. package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +8 -0
  61. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +24 -0
  62. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +11 -0
  63. package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +29 -0
  64. package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +26 -0
  65. package/dist/test/helpers/jest/matchers/toFailWith/index.js +27 -0
  66. package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +16 -0
  67. package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +27 -0
  68. package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +22 -0
  69. package/dist/test/helpers/jest/matchers/toSucceed/index.js +23 -0
  70. package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +5 -0
  71. package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +24 -0
  72. package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +24 -0
  73. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +53 -0
  74. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +17 -0
  75. package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +27 -0
  76. package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +12 -0
  77. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +27 -0
  78. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +17 -0
  79. package/dist/test/helpers/jest/resolvers/cli.js +10 -0
  80. package/dist/test/helpers/jest/resolvers/ide.js +10 -0
  81. package/dist/test/helpers/jest/ts-utils.js +2 -0
  82. package/dist/test/helpers/jest/types/index.js +3 -0
  83. package/dist/test/helpers/jest/utils/matcherHelpers.js +47 -0
  84. package/dist/test/helpers/jest/utils/snapshotResolver.js +11 -0
  85. package/dist/test/unit/collections/helpers.js +106 -0
  86. package/dist/test/unit/hashTextEncodeCompat.js +23 -0
  87. package/dist/tsdoc-metadata.json +1 -1
  88. package/lib/packlets/hash/crcNormalizer.js +42 -2
  89. package/package.json +12 -2
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { captureResult } from '../base';
23
+ import { Collector } from './collector';
24
+ import { CollectorValidator } from './collectorValidator';
25
+ /**
26
+ * A {@link Collections.Collector | Collector} with a {@link Collections.CollectorValidator | CollectorValidator}
27
+ * property that enables validated use of the underlying map with weakly-typed keys and values.
28
+ * @public
29
+ */
30
+ export class ValidatingCollector extends Collector {
31
+ /**
32
+ * Constructs a new {@link Collections.ValidatingCollector | ValidatingConvertingCollector}
33
+ * from the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.
34
+ * @param params - Required parameters for constructing the collector.
35
+ */
36
+ constructor(params) {
37
+ var _a;
38
+ super();
39
+ this._converters = params.converters;
40
+ this.validating = new CollectorValidator({ collector: this, converters: params.converters });
41
+ for (const item of (_a = params.items) !== null && _a !== void 0 ? _a : []) {
42
+ this.validating.getOrAdd(item).orThrow();
43
+ }
44
+ }
45
+ /**
46
+ * Creates a new {@link Collections.ValidatingCollector | ValidatingCollector} instance from
47
+ * the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.
48
+ * @param params - Required parameters for constructing the collector.
49
+ * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.
50
+ */
51
+ static createValidatingCollector(params) {
52
+ return captureResult(() => new ValidatingCollector(params));
53
+ }
54
+ /**
55
+ * Gets a read-only version of this collector as a
56
+ * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.
57
+ * @returns
58
+ */
59
+ toReadOnly() {
60
+ return this;
61
+ }
62
+ }
63
+ //# sourceMappingURL=validatingCollector.js.map
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { captureResult } from '../base';
23
+ import { ConvertingCollector } from './convertingCollector';
24
+ import { ConvertingCollectorValidator } from './convertingCollectorValidator';
25
+ /**
26
+ * A {@link Collections.ConvertingCollector | ConvertingCollector} with a
27
+ * {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}
28
+ * property that enables validated use of the underlying map with weakly-typed keys and values.
29
+ * @public
30
+ */
31
+ export class ValidatingConvertingCollector extends ConvertingCollector {
32
+ /**
33
+ * Constructs a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector}
34
+ * from the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.
35
+ * @param params - Required parameters for constructing the collector.
36
+ */
37
+ constructor(params) {
38
+ var _a;
39
+ super({ factory: params.factory });
40
+ this._converters = params.converters;
41
+ this.validating = new ConvertingCollectorValidator({ collector: this, converters: params.converters });
42
+ for (const entry of (_a = params.entries) !== null && _a !== void 0 ? _a : []) {
43
+ this.getOrAdd(entry[0], entry[1]).orThrow();
44
+ }
45
+ }
46
+ /**
47
+ * Creates a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector} instance from
48
+ * the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.
49
+ * @param params - Required parameters for constructing the collector.
50
+ * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.
51
+ */
52
+ static createValidatingCollector(params) {
53
+ return captureResult(() => new ValidatingConvertingCollector(params));
54
+ }
55
+ /**
56
+ * Gets a read-only version of this collector as a
57
+ * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.
58
+ * @returns
59
+ */
60
+ toReadOnly() {
61
+ return this;
62
+ }
63
+ }
64
+ //# sourceMappingURL=validatingConvertingCollector.js.map
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright (c) 2025 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { captureResult } from '../base';
23
+ import { ResultMap } from './resultMap';
24
+ import { ResultMapValidator } from './resultMapValidator';
25
+ /**
26
+ * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapValidator | validator}
27
+ * property that enables validated use of the underlying map with weakly-typed keys and values.
28
+ * @public
29
+ */
30
+ export class ValidatingResultMap extends ResultMap {
31
+ /**
32
+ * Constructs a new {@link Collections.ValidatingResultMap | ValidatingResultMap}.
33
+ * @param params - Required parameters for constructing the map.
34
+ */
35
+ constructor(params) {
36
+ var _a;
37
+ const entries = params.converters.convertEntries([...((_a = params.entries) !== null && _a !== void 0 ? _a : [])]).orThrow();
38
+ super({ entries });
39
+ this.validating = new ResultMapValidator({ map: this, converters: params.converters });
40
+ }
41
+ /**
42
+ * Creates a new {@link Collections.ValidatingResultMap | ValidatingResultMap} instance.
43
+ * @param params - Required parameters for constructing the map.
44
+ * @returns `Success` with the new map if successful, `Failure` otherwise.
45
+ * @public
46
+ */
47
+ static createValidatingResultMap(params) {
48
+ return captureResult(() => new ValidatingResultMap(params));
49
+ }
50
+ /**
51
+ * Gets a read-only version of this map.
52
+ */
53
+ toReadOnly() {
54
+ return this;
55
+ }
56
+ }
57
+ //# sourceMappingURL=validatingResultMap.js.map
@@ -0,0 +1,242 @@
1
+ /*
2
+ * Copyright (c) 2020 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ import { fail, mapResults, succeed } from '../base';
23
+ import { GenericDefaultingConverter } from './defaultingConverter';
24
+ /**
25
+ * Base templated wrapper to simplify creation of new {@link Converter}s.
26
+ * @public
27
+ */
28
+ export class BaseConverter {
29
+ /**
30
+ * Constructs a new {@link Converter} which uses the supplied function to perform the conversion.
31
+ * @param converter - The conversion function to be applied.
32
+ * @param defaultContext - Optional conversion context to be used by default.
33
+ * @param traits - Optional {@link Conversion.ConverterTraits | traits} to be assigned to the resulting
34
+ * converter.
35
+ */
36
+ constructor(converter, defaultContext, traits) {
37
+ /**
38
+ * @internal
39
+ */
40
+ this._isOptional = false;
41
+ this._converter = converter;
42
+ this._defaultContext = defaultContext;
43
+ this._isOptional = (traits === null || traits === void 0 ? void 0 : traits.isOptional) === true;
44
+ this._brand = traits === null || traits === void 0 ? void 0 : traits.brand;
45
+ }
46
+ /**
47
+ * {@inheritdoc Converter.isOptional}
48
+ */
49
+ get isOptional() {
50
+ return this._isOptional;
51
+ }
52
+ /**
53
+ * {@inheritdoc Converter.brand}
54
+ */
55
+ get brand() {
56
+ return this._brand;
57
+ }
58
+ /**
59
+ * {@inheritdoc Converter.convert}
60
+ */
61
+ convert(from, context) {
62
+ return this._converter(from, this, context !== null && context !== void 0 ? context : this._defaultContext);
63
+ }
64
+ /**
65
+ * {@inheritdoc Converter.convertOptional}
66
+ */
67
+ convertOptional(from, context, onError) {
68
+ const result = this._converter(from, this, this._context(context));
69
+ if (result.isFailure()) {
70
+ onError = onError !== null && onError !== void 0 ? onError : 'ignoreErrors';
71
+ return from === undefined || onError === 'ignoreErrors' ? succeed(undefined) : result;
72
+ }
73
+ return result;
74
+ }
75
+ /**
76
+ * {@inheritdoc Converter.optional}
77
+ */
78
+ optional(onError) {
79
+ return new BaseConverter((from, __self, context) => {
80
+ onError = onError !== null && onError !== void 0 ? onError : 'failOnError';
81
+ return this.convertOptional(from, this._context(context), onError);
82
+ })._with(this._traits({ isOptional: true }));
83
+ }
84
+ /**
85
+ * {@inheritdoc Converter.map}
86
+ */
87
+ map(mapper) {
88
+ return new BaseConverter((from, __self, context) => {
89
+ const innerResult = this._converter(from, this, this._context(context));
90
+ if (innerResult.isSuccess()) {
91
+ return mapper(innerResult.value, this._context(context));
92
+ }
93
+ return fail(innerResult.message);
94
+ })._with(this._traits());
95
+ }
96
+ /**
97
+ * {@inheritdoc Converter.mapConvert}
98
+ */
99
+ mapConvert(mapConverter) {
100
+ return new BaseConverter((from, __self, context) => {
101
+ const innerResult = this._converter(from, this, this._context(context));
102
+ if (innerResult.isSuccess()) {
103
+ return mapConverter.convert(innerResult.value, this._context(context));
104
+ }
105
+ return fail(innerResult.message);
106
+ })._with(this._traits());
107
+ }
108
+ /**
109
+ * {@inheritdoc Converter.mapItems}
110
+ */
111
+ mapItems(mapper) {
112
+ return new BaseConverter((from, __self, context) => {
113
+ return this._converter(from, this, this._context(context)).onSuccess((items) => {
114
+ if (Array.isArray(items)) {
115
+ return mapResults(items.map((i) => mapper(i, this._context(context))));
116
+ }
117
+ return fail('Cannot map items - not an array');
118
+ });
119
+ });
120
+ }
121
+ /**
122
+ * {@inheritdoc Converter.mapConvertItems}
123
+ */
124
+ mapConvertItems(mapConverter) {
125
+ return new BaseConverter((from, __self, context) => {
126
+ return this._converter(from, this, this._context(context)).onSuccess((items) => {
127
+ if (Array.isArray(items)) {
128
+ return mapResults(items.map((i) => mapConverter.convert(i, this._context(context))));
129
+ }
130
+ return fail('Cannot map items - not an array');
131
+ });
132
+ });
133
+ }
134
+ /**
135
+ * {@inheritdoc Converter.withAction}
136
+ */
137
+ withAction(action) {
138
+ return new BaseConverter((from, __self, context) => {
139
+ return action(this._converter(from, this, this._context(context)), this._context(context));
140
+ })._with(this._traits());
141
+ }
142
+ /**
143
+ * {@inheritdoc Converter.withTypeGuard}
144
+ */
145
+ withTypeGuard(guard, message) {
146
+ return new BaseConverter((from, __self, context) => {
147
+ return this._converter(from, this, this._context(context)).onSuccess((inner) => {
148
+ message = message !== null && message !== void 0 ? message : 'invalid type';
149
+ return guard(inner, this._context(context))
150
+ ? succeed(inner)
151
+ : fail(`${message}: ${JSON.stringify(from)}`);
152
+ });
153
+ })._with(this._traits());
154
+ }
155
+ /**
156
+ * {@inheritdoc Converter.withItemTypeGuard}
157
+ */
158
+ withItemTypeGuard(guard, message) {
159
+ return new BaseConverter((from, __self, context) => {
160
+ return this._converter(from, this, this._context(context)).onSuccess((items) => {
161
+ if (Array.isArray(items)) {
162
+ return mapResults(items.map((i) => {
163
+ message = message !== null && message !== void 0 ? message : 'invalid type';
164
+ return guard(i, this._context(context))
165
+ ? succeed(i)
166
+ : fail(`${message}: ${JSON.stringify(from)}`);
167
+ }));
168
+ }
169
+ return fail('Cannot guard item type - not an array');
170
+ });
171
+ })._with(this._traits());
172
+ }
173
+ /**
174
+ * {@inheritdoc Converter.withConstraint}
175
+ */
176
+ withConstraint(constraint, options) {
177
+ return new BaseConverter((from, __self, context) => {
178
+ var _a;
179
+ const result = this._converter(from, this, this._context(context));
180
+ if (result.isSuccess()) {
181
+ const constraintResult = constraint(result.value, this._context(context));
182
+ if (typeof constraintResult === 'boolean') {
183
+ return constraintResult
184
+ ? result
185
+ : fail(`"${JSON.stringify(result.value)}": ${(_a = options === null || options === void 0 ? void 0 : options.description) !== null && _a !== void 0 ? _a : 'does not meet constraint'}`);
186
+ }
187
+ return constraintResult;
188
+ }
189
+ return result;
190
+ })._with(this._traits());
191
+ }
192
+ /**
193
+ * {@inheritdoc Converter.withBrand}
194
+ */
195
+ withBrand(brand) {
196
+ if (this._brand) {
197
+ throw new Error(`Cannot replace existing brand "${this._brand}" with "${brand}".`);
198
+ }
199
+ return new BaseConverter((from, __self, context) => {
200
+ return this._converter(from, this, this._context(context)).onSuccess((v) => {
201
+ return succeed(v);
202
+ });
203
+ })._with(this._traits({ brand }));
204
+ }
205
+ /**
206
+ * {@inheritdoc Converter.withDefault}
207
+ */
208
+ withDefault(defaultValue) {
209
+ return new GenericDefaultingConverter(this, defaultValue);
210
+ }
211
+ /**
212
+ * @internal
213
+ */
214
+ _context(supplied) {
215
+ return supplied !== null && supplied !== void 0 ? supplied : this._defaultContext;
216
+ }
217
+ /**
218
+ * {@inheritdoc Converter.withFormattedError}
219
+ */
220
+ withFormattedError(formatter) {
221
+ return new BaseConverter((from, __self, context) => {
222
+ return this._converter(from, this, this._context(context)).onFailure((msg) => {
223
+ return fail(formatter(from, msg, this._context(context)));
224
+ });
225
+ })._with(this._traits());
226
+ }
227
+ /**
228
+ * @internal
229
+ */
230
+ _traits(traits) {
231
+ return Object.assign({ isOptional: this.isOptional, brand: this.brand }, (traits !== null && traits !== void 0 ? traits : {}));
232
+ }
233
+ /**
234
+ * @internal
235
+ */
236
+ _with(traits) {
237
+ this._isOptional = traits.isOptional === true;
238
+ this._brand = traits.brand;
239
+ return this;
240
+ }
241
+ }
242
+ //# sourceMappingURL=baseConverter.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=converter.js.map