@fgv/ts-utils 5.1.0-3 → 5.1.0-31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/index.js.map +1 -0
- package/dist/packlets/base/brand.js.map +1 -0
- package/dist/packlets/base/index.js +2 -0
- package/dist/packlets/base/index.js.map +1 -0
- package/dist/packlets/base/mapResults.js.map +1 -0
- package/dist/packlets/base/messageAggregator.js.map +1 -0
- package/dist/packlets/base/normalize.js +54 -1
- package/dist/packlets/base/normalize.js.map +1 -0
- package/dist/packlets/base/result.js +299 -2
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/shouldNotFail.js +123 -0
- package/dist/packlets/base/shouldNotFail.js.map +1 -0
- package/dist/packlets/base/utils.js.map +1 -0
- package/dist/packlets/base/uuid.js +55 -0
- package/dist/packlets/base/uuid.js.map +1 -0
- package/dist/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/dist/packlets/collections/collectible.js.map +1 -0
- package/dist/packlets/collections/collector.js +23 -9
- package/dist/packlets/collections/collector.js.map +1 -0
- package/dist/packlets/collections/collectorValidator.js +6 -1
- package/dist/packlets/collections/collectorValidator.js.map +1 -0
- package/dist/packlets/collections/common.js.map +1 -0
- package/dist/packlets/collections/converters.js.map +1 -0
- package/dist/packlets/collections/convertingCollector.js.map +1 -0
- package/dist/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/dist/packlets/collections/convertingResultMap.js.map +1 -0
- package/dist/packlets/collections/index.js.map +1 -0
- package/dist/packlets/collections/keyValueConverters.js.map +1 -0
- package/dist/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/readonlyResultMap.js.map +1 -0
- package/dist/packlets/collections/resultMap.js.map +1 -0
- package/dist/packlets/collections/resultMapValidator.js.map +1 -0
- package/dist/packlets/collections/utils.js.map +1 -0
- package/dist/packlets/collections/validatingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/dist/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/dist/packlets/collections/validatingResultMap.js.map +1 -0
- package/dist/packlets/conversion/advancedConverters.js.map +1 -0
- package/dist/packlets/conversion/baseConverter.js +102 -16
- package/dist/packlets/conversion/baseConverter.js.map +1 -0
- package/dist/packlets/conversion/basicConverters.js.map +1 -0
- package/dist/packlets/conversion/converter.js.map +1 -0
- package/dist/packlets/conversion/converters.js.map +1 -0
- package/dist/packlets/conversion/defaultingConverter.js.map +1 -0
- package/dist/packlets/conversion/index.js.map +1 -0
- package/dist/packlets/conversion/objectConverter.js.map +1 -0
- package/dist/packlets/conversion/stringConverter.js.map +1 -0
- package/dist/packlets/hash/crcNormalizer.js.map +1 -0
- package/dist/packlets/hash/hashingNormalizer.js.map +1 -0
- package/dist/packlets/hash/index.js.map +1 -0
- package/dist/packlets/logging/bootLogger.js.map +1 -0
- package/dist/packlets/logging/index.js +2 -0
- package/dist/packlets/logging/index.js.map +1 -0
- package/dist/packlets/logging/logReporter.js.map +1 -0
- package/dist/packlets/logging/logger.js +49 -8
- package/dist/packlets/logging/logger.js.map +1 -0
- package/dist/packlets/logging/multiLogger.js +104 -0
- package/dist/packlets/logging/multiLogger.js.map +1 -0
- package/dist/packlets/logging/retainingLogger.js +161 -0
- package/dist/packlets/logging/retainingLogger.js.map +1 -0
- package/dist/packlets/validation/array.js.map +1 -0
- package/dist/packlets/validation/boolean.js.map +1 -0
- package/dist/packlets/validation/classes.js.map +1 -0
- package/dist/packlets/validation/common.js.map +1 -0
- package/dist/packlets/validation/compositeId.js.map +1 -0
- package/dist/packlets/validation/field.js.map +1 -0
- package/dist/packlets/validation/genericValidator.js.map +1 -0
- package/dist/packlets/validation/index.js.map +1 -0
- package/dist/packlets/validation/number.js.map +1 -0
- package/dist/packlets/validation/object.js.map +1 -0
- package/dist/packlets/validation/oneOf.js.map +1 -0
- package/dist/packlets/validation/string.js.map +1 -0
- package/dist/packlets/validation/traits.js.map +1 -0
- package/dist/packlets/validation/typeGuard.js.map +1 -0
- package/dist/packlets/validation/validator.js.map +1 -0
- package/dist/packlets/validation/validatorBase.js.map +1 -0
- package/dist/packlets/validation/validators.js.map +1 -0
- package/dist/ts-utils.d.ts +861 -57
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/base/brand.d.ts.map +1 -0
- package/lib/packlets/base/brand.js.map +1 -0
- package/lib/packlets/base/index.d.ts +2 -0
- package/lib/packlets/base/index.d.ts.map +1 -0
- package/lib/packlets/base/index.js +2 -0
- package/lib/packlets/base/index.js.map +1 -0
- package/lib/packlets/base/mapResults.d.ts.map +1 -0
- package/lib/packlets/base/mapResults.js.map +1 -0
- package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
- package/lib/packlets/base/messageAggregator.js.map +1 -0
- package/lib/packlets/base/normalize.d.ts +24 -0
- package/lib/packlets/base/normalize.d.ts.map +1 -0
- package/lib/packlets/base/normalize.js +53 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts +263 -1
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js +303 -3
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/shouldNotFail.d.ts +53 -0
- package/lib/packlets/base/shouldNotFail.d.ts.map +1 -0
- package/lib/packlets/base/shouldNotFail.js +129 -0
- package/lib/packlets/base/shouldNotFail.js.map +1 -0
- package/lib/packlets/base/utils.d.ts +12 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.js.map +1 -0
- package/lib/packlets/base/uuid.d.ts +27 -0
- package/lib/packlets/base/uuid.d.ts.map +1 -0
- package/lib/packlets/base/uuid.js +59 -0
- package/lib/packlets/base/uuid.js.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/aggregatedResultMap.js.map +1 -0
- package/lib/packlets/collections/collectible.d.ts.map +1 -0
- package/lib/packlets/collections/collectible.js.map +1 -0
- package/lib/packlets/collections/collector.d.ts +23 -9
- package/lib/packlets/collections/collector.d.ts.map +1 -0
- package/lib/packlets/collections/collector.js +23 -9
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorValidator.d.ts +29 -5
- package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/collectorValidator.js +6 -1
- package/lib/packlets/collections/collectorValidator.js.map +1 -0
- package/lib/packlets/collections/common.d.ts.map +1 -0
- package/lib/packlets/collections/common.js.map +1 -0
- package/lib/packlets/collections/converters.d.ts.map +1 -0
- package/lib/packlets/collections/converters.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +21 -3
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +22 -3
- package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
- package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/convertingResultMap.js.map +1 -0
- package/lib/packlets/collections/index.d.ts.map +1 -0
- package/lib/packlets/collections/index.js.map +1 -0
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
- package/lib/packlets/collections/keyValueConverters.js.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +18 -7
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
- package/lib/packlets/collections/resultMap.d.ts.map +1 -0
- package/lib/packlets/collections/resultMap.js.map +1 -0
- package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
- package/lib/packlets/collections/resultMapValidator.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts.map +1 -0
- package/lib/packlets/collections/utils.js.map +1 -0
- package/lib/packlets/collections/validatingCollector.d.ts +7 -3
- package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingConvertingResultMap.js.map +1 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +2 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/validatingResultMap.js.map +1 -0
- package/lib/packlets/conversion/advancedConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/advancedConverters.js.map +1 -0
- package/lib/packlets/conversion/baseConverter.d.ts +102 -16
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/baseConverter.js +102 -16
- package/lib/packlets/conversion/baseConverter.js.map +1 -0
- package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
- package/lib/packlets/conversion/basicConverters.js.map +1 -0
- package/lib/packlets/conversion/converter.d.ts.map +1 -0
- package/lib/packlets/conversion/converter.js.map +1 -0
- package/lib/packlets/conversion/converters.d.ts.map +1 -0
- package/lib/packlets/conversion/converters.js.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
- package/lib/packlets/conversion/index.d.ts.map +1 -0
- package/lib/packlets/conversion/index.js.map +1 -0
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/objectConverter.js.map +1 -0
- package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
- package/lib/packlets/conversion/stringConverter.js.map +1 -0
- package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/crcNormalizer.js.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.d.ts.map +1 -0
- package/lib/packlets/hash/hashingNormalizer.js.map +1 -0
- package/lib/packlets/hash/index.d.ts.map +1 -0
- package/lib/packlets/hash/index.js.map +1 -0
- package/lib/packlets/logging/bootLogger.d.ts.map +1 -0
- package/lib/packlets/logging/bootLogger.js.map +1 -0
- package/lib/packlets/logging/index.d.ts +2 -0
- package/lib/packlets/logging/index.d.ts.map +1 -0
- package/lib/packlets/logging/index.js +2 -0
- package/lib/packlets/logging/index.js.map +1 -0
- package/lib/packlets/logging/logReporter.d.ts.map +1 -0
- package/lib/packlets/logging/logReporter.js.map +1 -0
- package/lib/packlets/logging/logger.d.ts +46 -8
- package/lib/packlets/logging/logger.d.ts.map +1 -0
- package/lib/packlets/logging/logger.js +49 -8
- package/lib/packlets/logging/logger.js.map +1 -0
- package/lib/packlets/logging/multiLogger.d.ts +54 -0
- package/lib/packlets/logging/multiLogger.d.ts.map +1 -0
- package/lib/packlets/logging/multiLogger.js +108 -0
- package/lib/packlets/logging/multiLogger.js.map +1 -0
- package/lib/packlets/logging/retainingLogger.d.ts +143 -0
- package/lib/packlets/logging/retainingLogger.d.ts.map +1 -0
- package/lib/packlets/logging/retainingLogger.js +165 -0
- package/lib/packlets/logging/retainingLogger.js.map +1 -0
- package/lib/packlets/validation/array.d.ts.map +1 -0
- package/lib/packlets/validation/array.js.map +1 -0
- package/lib/packlets/validation/boolean.d.ts.map +1 -0
- package/lib/packlets/validation/boolean.js.map +1 -0
- package/lib/packlets/validation/classes.d.ts.map +1 -0
- package/lib/packlets/validation/classes.js.map +1 -0
- package/lib/packlets/validation/common.d.ts.map +1 -0
- package/lib/packlets/validation/common.js.map +1 -0
- package/lib/packlets/validation/compositeId.d.ts.map +1 -0
- package/lib/packlets/validation/compositeId.js.map +1 -0
- package/lib/packlets/validation/field.d.ts.map +1 -0
- package/lib/packlets/validation/field.js.map +1 -0
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
- package/lib/packlets/validation/genericValidator.js.map +1 -0
- package/lib/packlets/validation/index.d.ts.map +1 -0
- package/lib/packlets/validation/index.js.map +1 -0
- package/lib/packlets/validation/number.d.ts.map +1 -0
- package/lib/packlets/validation/number.js.map +1 -0
- package/lib/packlets/validation/object.d.ts.map +1 -0
- package/lib/packlets/validation/object.js.map +1 -0
- package/lib/packlets/validation/oneOf.d.ts.map +1 -0
- package/lib/packlets/validation/oneOf.js.map +1 -0
- package/lib/packlets/validation/string.d.ts.map +1 -0
- package/lib/packlets/validation/string.js.map +1 -0
- package/lib/packlets/validation/traits.d.ts.map +1 -0
- package/lib/packlets/validation/traits.js.map +1 -0
- package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
- package/lib/packlets/validation/typeGuard.js.map +1 -0
- package/lib/packlets/validation/validator.d.ts.map +1 -0
- package/lib/packlets/validation/validator.js.map +1 -0
- package/lib/packlets/validation/validatorBase.d.ts +2 -1
- package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
- package/lib/packlets/validation/validatorBase.js.map +1 -0
- package/lib/packlets/validation/validators.d.ts.map +1 -0
- package/lib/packlets/validation/validators.js.map +1 -0
- package/package.json +6 -4
- package/dist/test/helpers/jest/helpers/fsHelpers.js +0 -139
- package/dist/test/helpers/jest/helpers/index.js +0 -2
- package/dist/test/helpers/jest/index.js +0 -17
- package/dist/test/helpers/jest/matchers/index.js +0 -14
- package/dist/test/helpers/jest/matchers/toFail/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toFail/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toFailTest/index.js +0 -28
- package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +0 -8
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +0 -11
- package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +0 -29
- package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +0 -26
- package/dist/test/helpers/jest/matchers/toFailWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +0 -16
- package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +0 -22
- package/dist/test/helpers/jest/matchers/toSucceed/index.js +0 -23
- package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +0 -5
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +0 -24
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +0 -53
- package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +0 -17
- package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +0 -12
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +0 -27
- package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +0 -17
- package/dist/test/helpers/jest/resolvers/cli.js +0 -10
- package/dist/test/helpers/jest/resolvers/ide.js +0 -10
- package/dist/test/helpers/jest/ts-utils.js +0 -2
- package/dist/test/helpers/jest/types/index.js +0 -3
- package/dist/test/helpers/jest/utils/matcherHelpers.js +0 -47
- package/dist/test/helpers/jest/utils/snapshotResolver.js +0 -11
- package/dist/test/unit/collections/helpers.js +0 -106
- package/dist/test/unit/hashTextEncodeCompat.js +0 -23
|
@@ -31,7 +31,7 @@ import { captureResult, failWithDetail, fail, succeed, succeedWithDetail } from
|
|
|
31
31
|
*/
|
|
32
32
|
export class Collector {
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Returns the number of entries in the map.
|
|
35
35
|
*/
|
|
36
36
|
get size() {
|
|
37
37
|
return this._byIndex.length;
|
|
@@ -87,13 +87,16 @@ export class Collector {
|
|
|
87
87
|
return succeedWithDetail(item, 'added');
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
90
|
+
* Returns an iterator over the map entries.
|
|
91
|
+
* @returns An iterator over the map entries.
|
|
91
92
|
*/
|
|
92
93
|
entries() {
|
|
93
94
|
return this._byKey.entries();
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
|
-
*
|
|
97
|
+
* Calls a function for each entry in the map.
|
|
98
|
+
* @param callback - The function to call for each entry.
|
|
99
|
+
* @param arg - An optional argument to pass to the callback.
|
|
97
100
|
*/
|
|
98
101
|
forEach(callback, arg) {
|
|
99
102
|
for (const [key, value] of this._byKey.entries()) {
|
|
@@ -101,14 +104,20 @@ export class Collector {
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
/**
|
|
104
|
-
*
|
|
107
|
+
* Gets a value by key.
|
|
108
|
+
* @param key - The key to look up.
|
|
109
|
+
* @returns Returns {@link DetailedSuccess | Success} with the value and detail `exists` if found,
|
|
110
|
+
* or {@link DetailedFailure | Failure} with detail `not-found` if the key does not exist.
|
|
105
111
|
*/
|
|
106
112
|
get(key) {
|
|
107
113
|
const item = this._byKey.get(key);
|
|
108
114
|
return item ? succeedWithDetail(item, 'exists') : failWithDetail(`${key}: not found`, 'not-found');
|
|
109
115
|
}
|
|
110
116
|
/**
|
|
111
|
-
*
|
|
117
|
+
* Gets the item at a specified index.
|
|
118
|
+
* @param index - The index of the item to retrieve.
|
|
119
|
+
* @returns Returns {@link Success | Success} with the item if it exists, or {@link Failure | Failure}
|
|
120
|
+
* with an error if the index is out of range.
|
|
112
121
|
*/
|
|
113
122
|
getAt(index) {
|
|
114
123
|
if (typeof index !== 'number') {
|
|
@@ -146,25 +155,30 @@ export class Collector {
|
|
|
146
155
|
});
|
|
147
156
|
}
|
|
148
157
|
/**
|
|
149
|
-
*
|
|
158
|
+
* Returns true if the map contains an entry with the given key.
|
|
159
|
+
* @param key - The key to check for.
|
|
160
|
+
* @returns `true` if the key exists, `false` otherwise.
|
|
150
161
|
*/
|
|
151
162
|
has(key) {
|
|
152
163
|
return this._byKey.has(key);
|
|
153
164
|
}
|
|
154
165
|
/**
|
|
155
|
-
*
|
|
166
|
+
* Returns an iterator over the map keys.
|
|
167
|
+
* @returns An iterator over the map keys.
|
|
156
168
|
*/
|
|
157
169
|
keys() {
|
|
158
170
|
return this._byKey.keys();
|
|
159
171
|
}
|
|
160
172
|
/**
|
|
161
|
-
*
|
|
173
|
+
* Returns an iterator over the map values.
|
|
174
|
+
* @returns An iterator over the map values.
|
|
162
175
|
*/
|
|
163
176
|
values() {
|
|
164
177
|
return this._byKey.values();
|
|
165
178
|
}
|
|
166
179
|
/**
|
|
167
|
-
*
|
|
180
|
+
* Gets all items in the collection, ordered by index.
|
|
181
|
+
* @returns An array of items in the collection, ordered by index.
|
|
168
182
|
*/
|
|
169
183
|
valuesByIndex() {
|
|
170
184
|
return this._byIndex;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collector.js","sourceRoot":"","sources":["../../../src/packlets/collections/collector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,aAAa,EAEb,cAAc,EAEd,IAAI,EACJ,OAAO,EACP,iBAAiB,EAClB,MAAM,SAAS,CAAC;AA8CjB;;;;;;;;GAQG;AACH,MAAM,OAAO,SAAS;IAQpB;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,YAAmB,MAA2C;;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAgC,CAAC;QACtD,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,KAAK,MAAM,IAAI,IAAI,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,mCAAI,EAAE,EAAE,CAAC;YACvC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;IACH,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nC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACI,MAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;IAES,OAAO,CAAC,SAAwC;QACxD,OAAO,OAAO,SAAS,KAAK,QAAQ,CAAC;IACvC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 {\n captureResult,\n DetailedResult,\n failWithDetail,\n Result,\n fail,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { CollectibleFactoryCallback, CollectibleKey, ICollectible } from './collectible';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Additional success or failure details for mutating collector calls.\n * @public\n */\nexport type CollectorResultDetail = ResultMapResultDetail | 'invalid-index';\n\n/**\n * A read-only interface exposing only the non-mutating methods of a {@link Collections.Collector | ICollector}.\n * @public\n */\nexport interface IReadOnlyCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM> {\n /**\n * Gets the item at a specified index.\n * @param index - The index of the item to retrieve.\n * @returns Returns {@link Success | Success} with the item if it exists, or {@link Failure | Failure}\n * with an error if the index is out of range.\n */\n getAt(index: number): Result<TITEM>;\n\n /**\n * Gets all items in the collection, ordered by index.\n * @returns An array of items in the collection, ordered by index.\n */\n valuesByIndex(): ReadonlyArray<TITEM>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.Collector | ICollector}.\n * @public\n */\nexport interface ICollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> {\n /** Optional initial items to populate the collector. */\n items?: TITEM[];\n}\n\n/**\n * A {@link Collections.Collector | Collector} that is a specialized collection\n * which contains items of type {@link Collections.ICollectible | ICollectible},\n * which have a unique key and a write-once index.\n *\n * Items are assigned an index sequentially as they are added to the collection.\n * Once added, items are immutable - they cannot be removed or replaced.\n * @public\n */\nexport class Collector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> implements IReadOnlyCollector<TITEM>\n{\n private readonly _byKey: Map<CollectibleKey<TITEM>, TITEM>;\n private readonly _byIndex: TITEM[];\n\n /**\n * Returns the number of entries in the map.\n */\n public get size(): number {\n return this._byIndex.length;\n }\n\n /**\n * Constructs a new {@link Collections.Collector | Collector}.\n * @param params - Optional {@link Collections.ICollectorConstructorParams | initialization parameters} used\n * to construct the collector.\n */\n public constructor(params?: ICollectorConstructorParams<TITEM>) {\n this._byKey = new Map<CollectibleKey<TITEM>, TITEM>();\n this._byIndex = [];\n for (const item of params?.items ?? []) {\n this.add(item).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.Collector | Collector} instance.\n * @param params - Optional {@link Collections.ICollectorConstructorParams | initialization parameters} used\n * to create the collector.\n * @returns Returns {@link Success | Success} with the new collector if it was created successfully,\n * or {@link Failure | Failure} with an error if the collector could not be created.\n */\n public static createCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n >(params?: ICollectorConstructorParams<TITEM>): Result<Collector<TITEM>> {\n return captureResult(() => new Collector(params));\n }\n\n /**\n * Adds an item to the collection, failing if a different item with the same key already exists. Note\n * that adding an object that is already in the collection again will succeed without updating the collection.\n * @param item - The item to add.\n * @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added\n * or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with\n * an error message and appropriate detail if the item could not be added.\n */\n public add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail> {\n const existing = this._byKey.get(item.key);\n if (existing === item) {\n return succeedWithDetail(item, 'exists');\n } else if (existing) {\n return failWithDetail(`${item.key}: already exists`, 'exists');\n }\n const indexResult = item.setIndex(this._byIndex.length);\n if (indexResult.isFailure()) {\n return failWithDetail(`${item.key}: ${indexResult.message}`, 'invalid-index');\n } else if (item.index !== this._byIndex.length) {\n return failWithDetail(`${item.key}: index mismatch - built item has ${item.index}`, 'invalid-index');\n }\n this._byKey.set(item.key, item);\n this._byIndex.push(item);\n return succeedWithDetail(item, 'added');\n }\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public entries(): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>> {\n return this._byKey.entries();\n }\n\n /**\n * Calls a function for each entry in the map.\n * @param callback - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n public forEach(callback: ResultMapForEachCb<CollectibleKey<TITEM>, TITEM>, arg?: unknown): void {\n for (const [key, value] of this._byKey.entries()) {\n callback(value, key, this, arg);\n }\n }\n\n /**\n * Gets a value by key.\n * @param key - The key to look up.\n * @returns Returns {@link DetailedSuccess | Success} with the value and detail `exists` if found,\n * or {@link DetailedFailure | Failure} with detail `not-found` if the key does not exist.\n */\n public get(key: CollectibleKey<TITEM>): DetailedResult<TITEM, ResultMapResultDetail> {\n const item = this._byKey.get(key);\n return item ? succeedWithDetail(item, 'exists') : failWithDetail(`${key}: not found`, 'not-found');\n }\n\n /**\n * Gets the item at a specified index.\n * @param index - The index of the item to retrieve.\n * @returns Returns {@link Success | Success} with the item if it exists, or {@link Failure | Failure}\n * with an error if the index is out of range.\n */\n public getAt(index: number): Result<TITEM> {\n if (typeof index !== 'number') {\n // Handle Symbol conversion safely\n const indexStr = typeof index === 'symbol' ? (index as symbol).toString() : String(index);\n return fail(`${indexStr}: collector index must be a number.`);\n }\n\n // Check that the number is a finite integer (handles NaN, Infinity, and non-integers)\n if (!Number.isFinite(index) || !Number.isInteger(index)) {\n return fail(`${index}: collector index must be a finite integer.`);\n }\n\n if (index < 0 || index >= this._byIndex.length) {\n return fail(`${index}: collector index out of range.`);\n }\n\n return succeed(this._byIndex[index]);\n }\n\n /**\n * Gets an existing item with a key matching that of a supplied item, or adds the supplied\n * item to the collector if no item with that key exists.\n * @param item - The item to get or add.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item return and detail `added` indicates that the\n * item was added. Returns {@link DetailedFailure | Failure} with an error and appropriate\n * detail if the item could not be added.\n */\n public getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The key of the item to add.\n * @param factory - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item return and detail `added` indicates that the\n * item was added. Returns {@link DetailedFailure | Failure} with an error and appropriate\n * detail if the item could not be added.\n */\n public getOrAdd(\n key: CollectibleKey<TITEM>,\n factory: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n factory?: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n const key = !this._isItem(keyOrItem) ? keyOrItem : keyOrItem.key;\n const existing = this._byKey.get(key);\n if (existing) {\n return succeedWithDetail(existing, 'exists');\n }\n\n const itemResult = !this._isItem(keyOrItem)\n ? factory!(keyOrItem, this._byIndex.length)\n : succeed(keyOrItem);\n if (itemResult.isFailure()) {\n return failWithDetail(`${key}: ${itemResult.message}`, 'invalid-value');\n }\n const item = itemResult.value;\n\n if (item.key !== key) {\n return failWithDetail(`${key}: key mismatch - built item has ${key}`, 'invalid-key');\n }\n\n return itemResult.withFailureDetail<CollectorResultDetail>('invalid-index').onSuccess((item) => {\n return this.add(item);\n });\n }\n\n /**\n * Returns true if the map contains an entry with the given key.\n * @param key - The key to check for.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: CollectibleKey<TITEM>): boolean {\n return this._byKey.has(key);\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<CollectibleKey<TITEM>> {\n return this._byKey.keys();\n }\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n public values(): IterableIterator<TITEM> {\n return this._byKey.values();\n }\n\n /**\n * Gets all items in the collection, ordered by index.\n * @returns An array of items in the collection, ordered by index.\n */\n public valuesByIndex(): ReadonlyArray<TITEM> {\n return this._byIndex;\n }\n\n /**\n * Gets a read-only version of this collector.\n */\n public toReadOnly(): IReadOnlyCollector<TITEM> {\n return this;\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<CollectibleKey<TITEM>, TITEM>> {\n return this._byKey[Symbol.iterator]();\n }\n\n protected _isItem(keyOrItem: CollectibleKey<TITEM> | TITEM): keyOrItem is TITEM {\n return typeof keyOrItem !== 'string';\n }\n}\n"]}
|
|
@@ -37,7 +37,12 @@ export class CollectorValidator {
|
|
|
37
37
|
this.converters = params.converters;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Adds an item to the collection, failing if a different item with the same key already exists. Note
|
|
41
|
+
* that adding an object that is already in the collection again will succeed without updating the collection.
|
|
42
|
+
* @param item - The item to add.
|
|
43
|
+
* @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added
|
|
44
|
+
* or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with
|
|
45
|
+
* an error message and appropriate detail if the item could not be added.
|
|
41
46
|
*/
|
|
42
47
|
add(item) {
|
|
43
48
|
return this._convertValue(item).onSuccess((i) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectorValidator.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectorValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAgEH;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAO7B,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAID;;;OAGG;IACH,YAAmB,MAA8C;QAC/D,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACI,GA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K,CAAC;aACnB,eAAe,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,OAAO,EAAE,CAAC;aACxD,UAAU,CAAwB,eAAe,EAAE,SAAS,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { DetailedResult } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { Collector, CollectorResultDetail } from './collector';\nimport { IReadOnlyResultMapValidator } from './resultMapValidator';\nimport { CollectibleKey, ICollectible } from './collectible';\n\n/**\n * A read-only interface exposing non-mutating methods of a\n * {@link Collections.CollectorValidator | CollectorValidator}.\n * @public\n */\nexport interface IReadOnlyCollectorValidator<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends IReadOnlyResultMapValidator<CollectibleKey<TITEM>, TITEM> {\n /**\n * {@inheritDoc Collections.ReadOnlyResultMapValidator.map}\n */\n readonly map: IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM>;\n\n /**\n * {@inheritDoc Collections.Collector.get}\n */\n get(key: string): DetailedResult<TITEM, ResultMapResultDetail>;\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n has(key: string): boolean;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param factory - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n getOrAdd(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.CollectorValidator | CollectorValidator}.\n * @public\n */\nexport interface ICollectorValidatorCreateParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> {\n /** The collector to validate access to. */\n readonly collector: Collector<TITEM>;\n /** The key-value converters for validation. */\n readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n}\n\n/**\n * A {@link Collections.Collector | Collector} wrapper which validates weakly-typed keys\n * and values before calling the wrapped collector.\n * @public\n */\nexport class CollectorValidator<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> implements IReadOnlyCollectorValidator<TITEM>\n{\n public readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n\n public get map(): IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM> {\n return this._collector.toReadOnly();\n }\n\n protected _collector: Collector<TITEM>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}.\n * @param params - Required parameters for constructing the collector validator.\n */\n public constructor(params: ICollectorValidatorCreateParams<TITEM>) {\n this._collector = params.collector;\n this.converters = params.converters;\n }\n\n /**\n * Adds an item to the collection, failing if a different item with the same key already exists. Note\n * that adding an object that is already in the collection again will succeed without updating the collection.\n * @param item - The item to add.\n * @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added\n * or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with\n * an error message and appropriate detail if the item could not be added.\n */\n public add(item: unknown): DetailedResult<TITEM, CollectorResultDetail> {\n return this._convertValue(item).onSuccess((i) => {\n return this._collector.add(i);\n });\n }\n\n /**\n * {@inheritDoc Collections.Collector.get}\n */\n public get(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._collector.get(k);\n });\n }\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param factory - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching that of the supplied item, or adds the supplied\n * item to the collector if no item with that key exists.\n * @param item - The weakly-typed item to get or add.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(item: unknown): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n keyOrItem: string | unknown,\n factoryCb?: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (factoryCb === undefined) {\n return this._convertValue(keyOrItem).onSuccess((item) => this._collector.getOrAdd(item));\n } else {\n return this.converters\n .convertKey(keyOrItem)\n .withDetail<CollectorResultDetail>('invalid-key', 'success')\n .onSuccess((key) => this._collector.getOrAdd(key, factoryCb));\n }\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n public has(key: string): boolean {\n return this._collector.has(key as CollectibleKey<TITEM>);\n }\n\n /**\n * {@inheritDoc Collections.Collector.toReadOnly}\n */\n public toReadOnly(): IReadOnlyCollectorValidator<TITEM> {\n return this;\n }\n\n /**\n * Helper to convert a value, returning a {@link DetailedResult | DetailedResult}\n * and formatting the error message.\n * @param value - The value to convert.\n * @returns {@link DetailedSuccess | DetailedSuccess} with the converted value\n * and detail `success` if conversion is successful, or\n * {@link DetailedFailure | DetailedFailure} with the error message and detail `invalid-value`\n * if conversion fails.\n */\n protected _convertValue(value: unknown): DetailedResult<TITEM, CollectorResultDetail> {\n return this.converters\n .convertValue(value)\n .withErrorFormat((message) => `invalid item: ${message}`)\n .withDetail<CollectorResultDetail>('invalid-value', 'success');\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/collections/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 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 * Generic key-value entry.\n * @public\n */\nexport type KeyValueEntry<TK extends string = string, TV = unknown> = [TK, TV];\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converters.js","sourceRoot":"","sources":["../../../src/packlets/collections/converters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,OAAO,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AAYtD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA6C;IAE7C,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,IAAa,EAAiC,EAAE;QACzE,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,GAAO,EAAE,EAAE;YACpD,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,KAAS,EAAE,EAAE;gBACxD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 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 { Result, Success } from '../base';\nimport { Converter, Converters } from '../conversion';\nimport { KeyValueEntry } from './common';\n\n/**\n * Initialization parameters for the {@link Collections.Converters.keyValueEntry | keyValueEntry} converter.\n * @public\n */\nexport interface IKeyValueEntryConverterParams<TK extends string, TV> {\n key: Converter<TK, unknown>;\n value: Converter<TV, unknown>;\n}\n\n/**\n * A {@link Converter | Converter} for {@link Collections.KeyValueEntry | KeyValueEntry} instances.\n * @param params - Conversion parameters.\n * @returns A converter for which validates key value entries using the supplied validators.\n * @public\n */\nexport function keyValueEntry<TK extends string, TV>(\n params: IKeyValueEntryConverterParams<TK, TV>\n): Converter<KeyValueEntry<TK, TV>, unknown> {\n return Converters.generic((from: unknown): Result<KeyValueEntry<TK, TV>> => {\n return params.key.convert(from).onSuccess((key: TK) => {\n return params.value.convert(from).onSuccess((value: TV) => {\n return Success.with([key, value]);\n });\n });\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollector.ts"],"names":[],"mappings":"AAAA;;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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 { captureResult, DetailedResult, failWithDetail, Result, succeedWithDetail } from '../base';\nimport { ICollectible, CollectibleFactoryCallback, CollectibleFactory, CollectibleKey } from './collectible';\nimport { Collector, CollectorResultDetail } from './collector';\nimport { KeyValueEntry } from './common';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @public\n */\nexport interface IConvertingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /**\n * The default {@link Collections.CollectibleFactory | factory} to create items.\n */\n factory: CollectibleFactory<TITEM, TSRC>;\n /**\n * An optional array of entries to add to the collector.\n */\n entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];\n}\n\n/**\n * A {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible} items,\n * optionally converting them from a source representation to the target representation using a factory\n * supplied at default or at the time of collection.\n * @public\n */\nexport class ConvertingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> extends Collector<TITEM> {\n private _factory: CollectibleFactory<TITEM, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @param params - Parameters for constructing the collector.\n */\n public constructor(params: IConvertingCollectorConstructorParams<TITEM, TSRC>) {\n super();\n this._factory = params.factory;\n params.entries?.forEach((entry) => {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n });\n }\n\n /**\n * Creates a new {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @param params - Required parameters for constructing the collector.\n * @returns Returns {@link Success | Success} with the new collector if it is created, or {@link Failure | Failure}\n * with an error if the collector cannot be created.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(\n params: IConvertingCollectorConstructorParams<TITEM, TSRC>\n ): Result<ConvertingCollector<TITEM, TSRC>> {\n return captureResult(() => new ConvertingCollector(params));\n }\n\n /**\n * Adds an item to the collection, failing if a different item with the same key already exists. Note\n * that adding an object that is already in the collection again will succeed without updating the collection.\n * @param item - The item to add.\n * @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added\n * or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with\n * an error message and appropriate detail if the item could not be added.\n */\n public add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using the default {@link Collections.CollectibleFactory | factory}\n * at a specified key, failing if an item with that key already exists.\n * @param key - The key of the item to add.\n * @param item - The source representation of the item to be added.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n * @public\n */\n public add(key: CollectibleKey<TITEM>, item: TSRC): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using a supplied {@link Collections.CollectibleFactoryCallback | factory callback}\n * at a specified key, failing if an item with that key already exists or if the created item is invalid.\n * @param key - The key of the item to add.\n * @param cb - The factory callback to create the item.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n */\n public add(\n key: CollectibleKey<TITEM>,\n cb: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n public add(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this._overloadIsItem(keyOrItem, itemOrCb)) {\n return super.add(keyOrItem);\n }\n return this._buildItem(keyOrItem, itemOrCb!)\n .withFailureDetail<CollectorResultDetail>('invalid-value')\n .onSuccess((item) => {\n return super.add(item);\n });\n }\n\n /**\n * Gets an existing item with a key matching that of the supplied item, or adds the supplied\n * item to the collector if no item with that key exists.\n * @param item - The item to get or add.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The key of the item to get or add.\n * @param callback - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(\n key: CollectibleKey<TITEM>,\n callback: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an item by key if it exists, or creates a new item and adds it using the default {@link Collections.CollectibleFactory | factory} if not.\n * @param key - The key of the item to retrieve.\n * @param item - The source representation of the item to be added if it does not exist.\n * @returns Returns {@link Success | Success} with the item if it exists or could be created, or {@link Failure | Failure} with an error if the\n * item cannot be created and indexed.\n */\n public getOrAdd(key: CollectibleKey<TITEM>, item: TSRC): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this._overloadIsItem(keyOrItem, itemOrCb)) {\n return super.getOrAdd(keyOrItem);\n }\n\n if (this.has(keyOrItem)) {\n return this.get(keyOrItem);\n }\n\n return this._buildItem(keyOrItem, itemOrCb!)\n .withFailureDetail<CollectorResultDetail>('invalid-value')\n .onSuccess((item) => {\n if (item.key !== keyOrItem) {\n return failWithDetail<TITEM, CollectorResultDetail>(\n `${keyOrItem}: key mismatch - item has unexpected key ${item.key}`,\n 'invalid-key'\n );\n }\n return succeedWithDetail(item, 'success');\n })\n .onSuccess((item) => {\n return super.add(item);\n });\n }\n\n /**\n * Helper method for derived classes to determine if a supplied\n * itemOrCb parameter is a factory callback.\n * @param itemOrCb - Overloaded parameter is either `CollectibleKey<TITEM>` or\n * a {@link Collections.CollectibleFactoryCallback | factory callback}.\n * @returns Returns `true` if the parameter is a factory callback, `false` otherwise.\n * @public\n */\n protected _isFactoryCB(\n itemOrCb: TSRC | CollectibleFactoryCallback<TITEM>\n ): itemOrCb is CollectibleFactoryCallback<TITEM> {\n return typeof itemOrCb === 'function';\n }\n\n /**\n * Helper method for derived classes to determine if a supplied\n * keyOrItem parameter is an item.\n * @param keyOrItem - Overloaded parameter is either `CollectibleKey<TITEM>` or `TITEM`.\n * @param itemOrCb - Overloaded parameter is either `TSRC`, a {@link Collections.CollectibleFactoryCallback | factory callback}\n * or `undefined`.\n * @returns Returns `true` if the parameter is an item, `false` otherwise.\n * @public\n */\n protected _overloadIsItem(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): keyOrItem is TITEM {\n return itemOrCb === undefined;\n }\n\n /**\n * Helper method for derived classes to build an item from a key and a source representation using\n * a default or supplied factory.\n * @param key - The key of the item to build.\n * @param itemOrCb - The source representation of the item to build, or a factory callback to create it.\n * @returns Returns {@link Success | Success} with the item if it is built, or {@link Failure | Failure}\n * with an error if the item cannot be built.\n * @public\n */\n protected _buildItem(\n key: CollectibleKey<TITEM>,\n itemOrCb: TSRC | CollectibleFactoryCallback<TITEM>\n ): Result<TITEM> {\n return this._isFactoryCB(itemOrCb) ? itemOrCb(key, this.size) : this._factory(key, this.size, itemOrCb);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertingCollectorValidator.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollectorValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,cAAc,EAAE,MAAM,SAAS,CAAC;AAwBzD;;;;;GAKG;AACH,MAAM,OAAO,4BAA4B;IAQvC,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAID;;;OAGG;IACH,YAAmB,MAA8D;QAC/E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAoBM,GAAG,CACR,GAAW,EACX,cAA6E;QAE7E,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,cAAc,CAAC,GAAG,GAAG,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,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AK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { DetailedResult, failWithDetail } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { CollectibleFactoryCallback, CollectibleKey, ICollectible } from './collectible';\nimport { CollectorResultDetail } from './collector';\nimport { ConvertingCollector } from './convertingCollector';\nimport { IReadOnlyCollectorValidator } from './collectorValidator';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}.\n * @public\n */\nexport interface IConvertingCollectorValidatorCreateParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /** The converting collector to validate access to. */\n collector: ConvertingCollector<TITEM, TSRC>;\n /** The key-value converters for validation. */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n}\n\n/**\n * A {@link Collections.ConvertingCollector | ConvertingCollector} wrapper which validates weakly-typed keys\n * and values before calling the wrapped collector. Unlike the basic {@link Collections.CollectorValidator | CollectorValidator},\n * the converting collector expects the items to be in the source type of the converting collector, not the target type.\n * @public\n */\nexport class ConvertingCollectorValidator<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> implements IReadOnlyCollectorValidator<TITEM>\n{\n public readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n public get map(): IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM> {\n return this._collector.toReadOnly();\n }\n\n protected _collector: ConvertingCollector<TITEM, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}.\n * @param params - Required parameters for constructing the collector validator.\n */\n public constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>) {\n this._collector = params.collector;\n this.converters = params.converters;\n }\n\n /**\n * Adds an item to the collector using the default factory at a specified key,\n * failing if an item with that key already exists.\n * @param key - The weakly-typed key of the item to add.\n * @param value - The source representation of the item to be added.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n */\n public add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using a supplied factory callback\n * at a specified key, validating the key first.\n */\n public add(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n public add(\n key: string,\n valueOrFactory: unknown | ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this.has(key)) {\n return failWithDetail(`${key}: already exists`, 'exists');\n }\n return this.getOrAdd(key, valueOrFactory);\n }\n\n /**\n * {@inheritDoc Collections.Collector.get}\n */\n public get(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._collector.get(k);\n });\n }\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * by converting the supplied weakly-typed value if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param value - The weakly-typed source value to convert and add if the key does not exist.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param factory - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n key: string,\n valueOrFactory: unknown | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (!this._isCollectibleFactoryCallback(valueOrFactory)) {\n const converted = this.converters.convertEntry([key, valueOrFactory]);\n if (converted.isFailure()) {\n return failWithDetail(converted.message, converted.detail);\n }\n const [vk, vs] = converted.value;\n return this._collector.getOrAdd(vk, vs);\n } else {\n const converted = this.converters.convertKey(key);\n if (converted.isFailure()) {\n return failWithDetail(converted.message, converted.detail);\n }\n return this._collector.getOrAdd(converted.value, valueOrFactory);\n }\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n public has(key: string): boolean {\n return this._collector.has(key as CollectibleKey<TITEM>);\n }\n\n /**\n * {@inheritDoc Collections.Collector.toReadOnly}\n */\n public toReadOnly(): IReadOnlyCollectorValidator<TITEM> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback},\n * `false` otherwise.\n * @public\n */\n protected _isCollectibleFactoryCallback(\n value: unknown | CollectibleFactoryCallback<TITEM>\n ): value is CollectibleFactoryCallback<TITEM> {\n return typeof value === 'function';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAA0B,MAAM,SAAS,CAAC;AAGhE,OAAO,EACL,2BAA2B,EAG5B,MAAM,+BAA+B,CAAC;AAwBvC;;;;GAIG;AACH,MAAM,OAAO,iCAAiC;IAU5C;;;;OAIG;IACH,YAAmB,KAAc,EAAE,MAAuD;QACxF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,GAAO,EAAE,KAAW;QAC7B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,GAAO,EAAE,KAAW;QAC7B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,GA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KAAK,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, DetailedResult, Result } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\nimport {\n ReadOnlyConvertingResultMap,\n ConvertingResultMapValueConverter,\n IReadOnlyConvertingResultMapConstructorParams\n} from './readOnlyConvertingResultMap';\nimport { IResultMap, ResultMapValueFactory } from './resultMap';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @public\n */\nexport interface IConvertingResultMapConstructorParams<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> {\n /**\n * The inner map containing source values.\n */\n inner: TSRCMAP;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n}\n\n/**\n * A wrapper around a mutable result map that invalidates cache entries\n * in the parent {@link Collections.ConvertingResultMap | ConvertingResultMap} when mutations occur.\n * @public\n */\nexport class CacheInvalidatingResultMapWrapper<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> implements IResultMap<TK, TSRC>\n{\n private readonly _inner: TSRCMAP;\n private readonly _parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>;\n\n /**\n * Constructs a new cache-invalidating wrapper.\n * @param inner - The inner map to wrap.\n * @param parent - The parent converting map whose cache should be invalidated.\n */\n public constructor(inner: TSRCMAP, parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>) {\n this._inner = inner;\n this._parent = parent;\n }\n\n /**\n * The number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Adds a key/value pair to the map if the key does not already exist.\n * Invalidates the cache entry for the key.\n * @param key - The key to add.\n * @param value - The value to add.\n * @returns The result of the add operation.\n */\n public add(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.add(key, value);\n }\n\n /**\n * Sets a key/value pair in the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns The result of the set operation.\n */\n public set(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.set(key, value);\n }\n\n /**\n * Updates an existing key in the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to update.\n * @param value - The new value.\n * @returns The result of the update operation.\n */\n public update(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.update(key, value);\n }\n\n /**\n * Deletes a key from the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to delete.\n * @returns The result of the delete operation.\n */\n public delete(key: TK): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.delete(key);\n }\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns The result of the get operation.\n */\n public get(key: TK): DetailedResult<TSRC, ResultMapResultDetail> {\n return this._inner.get(key);\n }\n\n /**\n * Gets a value from the map, or adds a supplied value if it does not exist.\n * Invalidates the cache entry for the key if a new value is added.\n * @param key - The key to retrieve or add.\n * @param value - The value to add if the key does not exist.\n * @returns The result of the operation.\n */\n public getOrAdd(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory if it does not exist.\n * Invalidates the cache entry for the key if a new value is added.\n * @param key - The key to retrieve or add.\n * @param factory - A factory function to create the value if the key does not exist.\n * @returns The result of the operation.\n */\n public getOrAdd(\n key: TK,\n factory: ResultMapValueFactory<TK, TSRC>\n ): DetailedResult<TSRC, ResultMapResultDetail>;\n\n public getOrAdd(\n key: TK,\n valueOrFactory: TSRC | ResultMapValueFactory<TK, TSRC>\n ): DetailedResult<TSRC, ResultMapResultDetail> {\n const result =\n typeof valueOrFactory === 'function'\n ? this._inner.getOrAdd(key, valueOrFactory as ResultMapValueFactory<TK, TSRC>)\n : this._inner.getOrAdd(key, valueOrFactory);\n\n if (result.isSuccess() && result.detail === 'added') {\n this._parent._clearCacheEntry(key);\n }\n return result;\n }\n\n /**\n * Checks if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Clears all entries from the map.\n * Clears the entire cache.\n */\n public clear(): void {\n this._parent._clearCache();\n this._inner.clear();\n }\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public entries(): IterableIterator<KeyValueEntry<TK, TSRC>> {\n return this._inner.entries();\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n public values(): IterableIterator<TSRC> {\n return this._inner.values();\n }\n\n /**\n * Calls a callback for each entry in the map.\n * @param cb - The callback to call for each entry.\n * @param thisArg - Optional `this` argument for the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TSRC>, thisArg?: unknown): void {\n this._inner.forEach(cb, thisArg);\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TSRC>> {\n return this._inner[Symbol.iterator]();\n }\n\n /**\n * Gets a read-only version of this map.\n * @returns A read-only version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TSRC> {\n return this._inner.toReadOnly();\n }\n}\n\n/**\n * A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type\n * and returns lazily-converted, cached values of a target type. Exposes the inner map\n * via a {@link Collections.CacheInvalidatingResultMapWrapper | source} property that\n * invalidates cache entries when mutations occur.\n * @public\n */\nexport class ConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {\n /**\n * A wrapper around the inner map that invalidates cache entries when mutations occur.\n * Use this property to add, update, or delete source values.\n */\n public readonly source: CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>;\n\n /**\n * The inner map, typed as the specific source map type.\n */\n protected readonly _typedInner: TSRCMAP;\n\n /**\n * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>) {\n super(params as IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>);\n this._typedInner = params.inner;\n this.source = new CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>(params.inner, this);\n }\n\n /**\n * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n >(\n params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>\n ): Result<ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>> {\n return captureResult(() => new ConvertingResultMap(params));\n }\n\n /**\n * Clears a single entry from the cache.\n * This method is public to allow the cache-invalidating wrapper to call it.\n * @param key - The key to clear from the cache.\n * @internal\n */\n public override _clearCacheEntry(key: TK): void {\n super._clearCacheEntry(key);\n }\n\n /**\n * Clears all entries from the cache.\n * This method is public to allow the cache-invalidating wrapper to call it.\n * @internal\n */\n public override _clearCache(): void {\n super._clearCache();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 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 Utils from './utils';\n\nexport * from './collectible';\nexport * from './convertingCollector';\nexport * from './convertingResultMap';\nexport * from './collector';\nexport * from './collectorValidator';\nexport * from './convertingCollectorValidator';\nexport * from './validatingConvertingCollector';\nexport * from './common';\nexport * from './keyValueConverters';\nexport * from './readonlyResultMap';\nexport * from './readOnlyConvertingResultMap';\nexport * from './resultMap';\nexport * from './resultMapValidator';\nexport * from './validatingCollector';\nexport * from './validatingConvertingResultMap';\nexport * from './validatingResultMap';\nexport * from './aggregatedResultMap';\n\nexport { Utils };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueConverters.js","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAEL,cAAc,EACd,iBAAiB,EAEjB,OAAO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C;YAC7E,IAAI,GAAG,IAAI,KAAK,EAAE,CAAC;gBACjB,OAAO,iBAAiB,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;YACrD,OAAO,cAAc,CAAC,kBAAkB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QACvE,CAAC;QACD,sBAAsB;QACtB,OAAO,cAAc,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACxF,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,OAA0B;QAC9C,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAA4B,EAAE,CAAC;QAC9C,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;iBACvB,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;gBACf,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAClB,OAAO,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC,CAAC;iBACD,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 {\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.\n * @public\n */\nexport interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;\n\n /**\n * Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;\n}\n\n/**\n * Helper class for converting strongly-typed keys, values, or entries\n * from unknown values.\n * @public\n */\nexport class KeyValueConverters<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly key: Validator<TK, unknown> | Converter<TK, unknown>;\n /**\n * Required value {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly value: Validator<TV, unknown> | Converter<TV, unknown>;\n\n /**\n * Constructs a new key-value validator.\n * @param params - Key and value converters or validators.\n */\n public constructor({ key, value }: IKeyValueConverterConstructorParams<TK, TV>) {\n this.key = typeof key === 'function' ? Converters.generic(key) : key;\n this.value = typeof value === 'function' ? Converters.generic(value) : value;\n }\n\n /**\n * Converts a supplied unknown to a valid key value of type `<TK>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted key value and 'success' detail if the key is valid,\n * or `Failure` with an error message and 'invalid-key' detail if the key is invalid.\n */\n public convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail> {\n return this.key.convert(key).withFailureDetail('invalid-key');\n }\n\n /**\n * Converts a supplied unknown to a valid value of type `<TV>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted value and 'success' detail if the value is valid,\n * or `Failure` with an error message and 'invalid-value' detail if the value is invalid.\n */\n public convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.value.convert(key).withFailureDetail('invalid-value');\n }\n\n /**\n * Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.\n * @param entry - The unknown to be converted.\n * @returns `Success` with the converted entry and 'success' detail if the entry\n * is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if\n * the entry is invalid\n */\n public convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail> {\n if (Array.isArray(entry) && entry.length === 2) {\n const errors = new MessageAggregator();\n const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();\n const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();\n if (key && value) {\n return succeedWithDetail([key, value], 'success');\n }\n const detail = key ? 'invalid-value' : 'invalid-key';\n return failWithDetail(`invalid entry: ${errors.toString()}`, detail);\n }\n /* c8 ignore next 2 */\n return failWithDetail(`malformed entry: \"${JSON.stringify(entry)}\"`, 'invalid-value');\n }\n\n /**\n * Converts a supplied iterable of unknowns to valid key-value pairs.\n * @param entries - The iterable of unknowns to be converted.\n * @returns `Success` with an array of converted key-value pairs if all entries are valid,\n * or `Failure` with an error message if any entry is invalid.\n */\n public convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]> {\n const errors = new MessageAggregator();\n const converted: KeyValueEntry<TK, TV>[] = [];\n for (const element of entries) {\n this.convertEntry(element)\n .onSuccess((e) => {\n converted.push(e);\n return succeedWithDetail(e, 'success');\n })\n .aggregateError(errors);\n }\n return errors.returnOrReport(succeed(converted));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readOnlyConvertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/readOnlyConvertingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAkB,cAAc,EAAU,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAkDnG;;;;GAIG;AACH,MAAM,OAAO,2BAA2B;IA4BtC;;;OAGG;IACH,YAAmB,MAAwE;;QACzF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAe,CAAC;QACrC,IAAI,CAAC,kBAAkB,GAAG,MAAA,MAAM,CAAC,iBAAiB,mCAAI,QAAQ,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAClB,MAAwE;QAExE,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,2BAA2B,CAAC,MAAM,CAAC,CAAC,CAAC;IACtE,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,GAAO;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,G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C,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC;QAED,QAAQ,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAChC,KAAK,MAAM;gBACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YAC3E,KAAK,MAAM;gBACT,MAAA,IAAI,CAAC,OAAO,0CAAE,GAAG,CAAC,SAAS,EAAE,8BAA8B,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;gBACtF,MAAM;QACV,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;OAGG;IACO,gBAAgB,CAAC,GAAO;QAChC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACO,WAAW;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 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 { captureResult, DetailedResult, failWithDetail, Result, succeedWithDetail } from '../base';\nimport { ILogger } from '../logging';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * A function that converts a source value to a target value.\n * @public\n */\nexport type ConvertingResultMapValueConverter<TK extends string, TSRC, TTARGET> = (\n src: TSRC,\n key: TK\n) => Result<TTARGET>;\n\n/**\n * Error handling behavior for conversion failures during iteration.\n * - `'ignore'`: Silently skip failed conversions (default behavior)\n * - `'warn'`: Log warning and skip failed conversions\n * - `'fail'`: Throw error on first conversion failure\n * @public\n */\nexport type ConversionErrorHandling = 'ignore' | 'warn' | 'fail';\n\n/**\n * Parameters for constructing a {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @public\n */\nexport interface IReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {\n /**\n * The inner map containing source values.\n */\n inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * Error handling behavior for conversion failures during iteration.\n * Defaults to `'ignore'` (silently skip failed conversions).\n */\n onConversionError?: ConversionErrorHandling;\n\n /**\n * Optional logger for warnings when `onConversionError` is `'warn'`.\n */\n logger?: ILogger;\n}\n\n/**\n * A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * of source type and returns lazily-converted, cached values of a target type.\n * @public\n */\nexport class ReadOnlyConvertingResultMap<TK extends string, TSRC, TTARGET>\n implements IReadOnlyResultMap<TK, TTARGET>\n{\n /**\n * The inner map containing source values.\n */\n protected readonly _inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n protected readonly _converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * Cache of converted target values.\n */\n protected readonly _cache: Map<TK, TTARGET>;\n\n /**\n * Error handling behavior for conversion failures during iteration.\n */\n protected readonly _onConversionError: ConversionErrorHandling;\n\n /**\n * Optional logger for warnings.\n */\n protected readonly _logger?: ILogger;\n\n /**\n * Constructs a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>) {\n this._inner = params.inner;\n this._converter = params.converter;\n this._cache = new Map<TK, TTARGET>();\n this._onConversionError = params.onConversionError ?? 'ignore';\n this._logger = params.logger;\n }\n\n /**\n * Creates a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static create<TK extends string, TSRC, TTARGET>(\n params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>\n ): Result<ReadOnlyConvertingResultMap<TK, TSRC, TTARGET>> {\n return captureResult(() => new ReadOnlyConvertingResultMap(params));\n }\n\n /**\n * The number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Gets a converted value from the map by key.\n * @param key - The key to retrieve.\n * @returns `Success` with the converted value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found, or `Failure` with\n * detail `invalid-value` if conversion failed.\n */\n public get(key: TK): DetailedResult<TTARGET, ResultMapResultDetail> {\n const cached = this._cache.get(key);\n if (cached !== undefined) {\n return succeedWithDetail(cached, 'exists');\n }\n\n return this._inner.get(key).onSuccess((src) => {\n return this._convertAndCache(key, src);\n });\n }\n\n /**\n * Checks if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Returns an iterator over the map entries with converted values.\n * @returns An iterator over the map entries.\n */\n public *entries(): IterableIterator<KeyValueEntry<TK, TTARGET>> {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n yield [key, target];\n }\n }\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Returns an iterator over the converted map values.\n * @returns An iterator over the map values.\n */\n public *values(): IterableIterator<TTARGET> {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n yield target;\n }\n }\n }\n\n /**\n * Calls a callback for each entry in the map with converted values.\n * @param cb - The callback to call for each entry.\n * @param thisArg - Optional `this` argument for the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TTARGET>, thisArg?: unknown): void {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n cb.call(thisArg, target, key, this);\n }\n }\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TTARGET>> {\n return this.entries();\n }\n\n /**\n * Gets a read-only version of this map.\n * @returns A read-only version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TTARGET> {\n return this;\n }\n\n /**\n * Converts a source value to a target value and caches the result.\n * @param key - The key of the value.\n * @param src - The source value to convert.\n * @returns `Success` with the converted value if successful, `Failure` otherwise.\n */\n protected _convertAndCache(key: TK, src: TSRC): DetailedResult<TTARGET, ResultMapResultDetail> {\n const result = this._converter(src, key);\n if (result.isFailure()) {\n return failWithDetail(result.message, 'invalid-value');\n }\n this._cache.set(key, result.value);\n return succeedWithDetail(result.value, 'exists');\n }\n\n /**\n * Gets a cached value or converts and caches a source value.\n * Used by iterators. Handles conversion failures according to `_onConversionError`.\n * @param key - The key of the value.\n * @param src - The source value to convert if not cached.\n * @returns The converted value, or `undefined` if conversion failed.\n * @throws Error if `_onConversionError` is `'fail'` and conversion fails.\n */\n protected _getOrConvert(key: TK, src: TSRC): TTARGET | undefined {\n const cached = this._cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n\n const result = this._converter(src, key);\n if (result.isSuccess()) {\n this._cache.set(key, result.value);\n return result.value;\n }\n\n switch (this._onConversionError) {\n case 'fail':\n throw new Error(`Conversion failed for key '${key}': ${result.message}`);\n case 'warn':\n this._logger?.log('warning', `Conversion failed for key '${key}': ${result.message}`);\n break;\n }\n return undefined;\n }\n\n /**\n * Clears a single entry from the cache.\n * @param key - The key to clear from the cache.\n */\n protected _clearCacheEntry(key: TK): void {\n this._cache.delete(key);\n }\n\n /**\n * Clears all entries from the cache.\n */\n protected _clearCache(): void {\n this._cache.clear();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readonlyResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/readonlyResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 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 { DetailedResult } from '../base';\nimport { KeyValueEntry } from './common';\n\n/**\n * Additional success or failure details for {@link Collections.ResultMap | ResultMap} calls.\n * @public\n */\nexport type ResultMapResultDetail =\n | 'added'\n | 'deleted'\n | 'exists'\n | 'failure'\n | 'invalid-key'\n | 'invalid-value'\n | 'not-found'\n | 'success'\n | 'updated';\n\n/**\n * Callback for {@link Collections.ResultMap | ResultMap} `forEach` method.\n * @public\n */\nexport type ResultMapForEachCb<TK extends string = string, TE = unknown> = (\n value: TE,\n key: TK,\n map: IReadOnlyResultMap<TK, TE>,\n thisArg?: unknown\n) => void;\n\n/**\n * A readonly `ReadonlyMap<TK, TV>`-like object which reports success or failure\n * with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {\n /**\n * Returns the number of entries in the map.\n */\n readonly size: number;\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n entries(): IterableIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n forEach(cb: ResultMapForEachCb, arg?: unknown): void;\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Returns `true` if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has(key: TK): boolean;\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n keys(): IterableIterator<TK>;\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n values(): IterableIterator<TV>;\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/resultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAkB,cAAc,EAAU,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG5G,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAwIrC;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IAmBpB;;;;OAIG;IACH,YACE,gBAAwF;QAExF,MAAM,MAAM,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,EAAE,CAAC;QACrG,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAwBD;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAClB,gBAAwF;QAExF,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,gBAAuD,CAAC,CAAC,CAAC;IACrG,CAAC;IAED;;;;;;;OAOG;IACI,GAAG,CAAC,GAAO,EAAE,KAAS;QAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,cAAc,CAAC,GAAG,GAAG,mBAAmB,EAAE,QAAQ,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,MAAM,CAA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;IAED;;;;;;;;;OASG;IACI,MAAM,CAAC,GAAO,EAAE,KAAS;QAC9B,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAC5B,OAAO,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,cAAc,CAAC,GAAG,GAAG,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED;;;OAGG;IACI,MAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,wBAAwB,CAChC,KAAyC;QAEzC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, DetailedResult, failWithDetail, Result, succeed, succeedWithDetail } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\nimport { isIterable } from './utils';\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<TK, TV>>;\n}\n\n/**\n * Deferred constructor for the {@link Collections.ResultMap.getOrAdd | getOrAdd} method.\n * @public\n */\nexport type ResultMapValueFactory<TK extends string = string, TV = unknown> = (key: TK) => Result<TV>;\n\n/**\n * Interface for a mutable {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {\n /**\n * Sets a key/value pair in the map if the key does not already exist.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the value and detail `added` if the key was added,\n * `Failure` with detail `exists` if the key already exists. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Sets a key/value pair in the map regardless of whether the key already exists.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the new value and the detail `updated` if the\n * key was found and updated, `Success` with the new value and detail\n * `added` if the key was not found and added. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Updates the value associated with a key in the map.\n * @param key - The key to update.\n * @param value - The value to set.\n * @returns `Success` with the value and detail 'updated' if the key was found\n * and the value updated, `Failure` an error message and with detail `not-found`\n * if the key was not found, or with detail 'invalid-key' or 'invalid-value'\n * if either is invalid.\n */\n update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Deletes a key from the map.\n * @param key - The key to delete.\n * @returns `Success` with the previous value and the detail 'deleted'\n * if the key was found and deleted, `Failure` with detail 'not-found'\n * if the key was not found, or with detail 'invalid-key' if the key is invalid.\n */\n delete(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a supplied value if it does not exist.\n * @param key - The key to be retrieved or created.\n * @param value - The value to add if the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Success` with the value and detail `added` if the key was not found and added.\n * Fails with detail 'invalid-key' or 'invalid-value' and an error message if either\n * is invalid.\n * {@label WITH_VALUE}\n */\n getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory function if it does not exist.\n * @param key - The key of the element to be retrieved or created.\n * @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if\n * the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found, `Success` with\n * the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'\n * or 'invalid-value' and an error message if either is invalid.\n * {@label WITH_FACTORY}\n */\n getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n entries(): IterableIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * Returns the number of entries in the map.\n */\n readonly size: number;\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n keys(): IterableIterator<TK>;\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n values(): IterableIterator<TV>;\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void;\n\n /**\n * Clears all entries from the map.\n */\n clear(): void;\n\n /**\n * Gets a readonly version of this map.\n */\n toReadOnly(): IReadOnlyResultMap<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} class as a `Map<TK, TV>`-like object which\n * reports success or failure with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport class ResultMap<TK extends string = string, TV = unknown> implements IResultMap<TK, TV> {\n /**\n * Protected raw access to the inner `Map<TK, TV>` object.\n * @public\n */\n protected readonly _inner: Map<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param iterable - An iterable to initialize the map.\n */\n public constructor(iterable?: Iterable<KeyValueEntry<TK, TV>>);\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param params - An optional set of parameters to configure the map.\n */\n public constructor(params: IResultMapConstructorParams);\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param iterableOrParams - An iterable to initialize the map, or a set of parameters\n * to configure the map.\n */\n public constructor(\n iterableOrParams?: Iterable<KeyValueEntry<TK, TV>> | IResultMapConstructorParams<TK, TV>\n ) {\n const params = isIterable(iterableOrParams) ? { entries: iterableOrParams } : iterableOrParams ?? {};\n this._inner = new Map(params.entries);\n }\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param elements - An optional iterable to initialize the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n elements: Iterable<KeyValueEntry<TK, TV>>\n ): Result<ResultMap<TK, TV>>;\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param params - An optional set of parameters to configure the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n params?: IResultMapConstructorParams<TK, TV>\n ): Result<ResultMap<TK, TV>>;\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param elementsOrParams - An optional iterable to initialize the map, or a set of parameters\n * to configure the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n elementsOrParams?: Iterable<KeyValueEntry<TK, TV>> | IResultMapConstructorParams<TK, TV>\n ): Result<ResultMap<TK, TV>> {\n return captureResult(() => new ResultMap(elementsOrParams as IResultMapConstructorParams<TK, TV>));\n }\n\n /**\n * Sets a key/value pair in the map if the key does not already exist.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the value and detail `added` if the key was added,\n * `Failure` with detail `exists` if the key already exists. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n public add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return failWithDetail(`${key}: already exists.`, 'exists');\n }\n this._inner.set(key, value);\n return succeedWithDetail(value, 'added');\n }\n\n /**\n * Clears the map.\n */\n public clear(): void {\n this._inner.clear();\n }\n\n /**\n * Deletes a key from the map.\n * @param key - The key to delete.\n * @returns `Success` with the previous value and the detail 'deleted'\n * if the key was found and deleted, `Failure` with detail 'not-found'\n * if the key was not found, or with detail 'invalid-key' if the key is invalid.\n */\n public delete(key: TK): DetailedResult<TV, ResultMapResultDetail> {\n const was = this._inner.get(key);\n if (this._inner.delete(key)) {\n return succeedWithDetail(was!, 'deleted');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public entries(): IterableIterator<KeyValueEntry<TK, TV>> {\n return this._inner.entries();\n }\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void {\n for (const [key, value] of this._inner.entries()) {\n cb(value, key as TK, this, arg);\n }\n }\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n public get(key: TK): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return succeedWithDetail(this._inner.get(key)!, 'exists');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Gets a value from the map, or adds a supplied value it if it does not exist.\n * @param key - The key to be retrieved or created.\n * @param value - The value to add if the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Success` with the value and detail `added` if the key was not found and added.\n * Fails with detail 'invalid-key' or 'invalid-value' and an error message if either\n * is invalid.\n * {@label WITH_VALUE}\n */\n public getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory function if it does not exist.\n * @param key - The key of the element to be retrieved or created.\n * @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if\n * the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found, `Success` with\n * the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'\n * or 'invalid-value' and an error message if either is invalid.\n * {@label WITH_FACTORY}\n */\n public getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: TK,\n valueOrFactory: TV | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return succeedWithDetail(this._inner.get(key)!, 'exists');\n }\n\n const factory: ResultMapValueFactory<TK, TV> = this._isResultMapValueFactory(valueOrFactory)\n ? valueOrFactory\n : () => succeed(valueOrFactory);\n\n return factory(key)\n .onSuccess((val) => {\n this._inner.set(key, val);\n return succeedWithDetail(val, 'added');\n })\n .withDetail('invalid-value', 'added');\n }\n\n /**\n * Returns `true` if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Sets a key/value pair in the map.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the new value and the detail `updated` if the\n * key was found and updated, `Success` with the new value and detail\n * `added` if the key was not found and added. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n public set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n const detail: ResultMapResultDetail = this._inner.has(key) ? 'updated' : 'added';\n this._inner.set(key, value);\n return succeedWithDetail(value, detail);\n }\n\n /**\n * Returns the number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Updates an existing key in the map - the map is not updated if the key does\n * not exist.\n * @param key - The key to update.\n * @param value - The value to set.\n * @returns `Success` with the value and detail 'exists' if the key was found\n * and the value updated, `Failure` an error message and with detail `not-found`\n * if the key was not found, or with detail 'invalid-key' or 'invalid-value'\n * if either is invalid.\n */\n public update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n this._inner.set(key, value);\n return succeedWithDetail(value, 'updated');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n public values(): IterableIterator<TV> {\n return this._inner.values();\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>> {\n return this._inner[Symbol.iterator]();\n }\n\n /**\n * Gets a readonly version of this map.\n * @returns A readonly version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TV> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory},\n * `false` otherwise.\n * @public\n */\n protected _isResultMapValueFactory<TK extends string, TV>(\n value: TV | ResultMapValueFactory<TK, TV>\n ): value is ResultMapValueFactory<TK, TV> {\n return typeof value === 'function';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resultMapValidator.js","sourceRoot":"","sources":["../../../src/packlets/collections/resultMapValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAmC5E;;;;GAIG;AACH,MAAM,OAAO,0BAA0B;IAQrC;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAID;;;;OAIG;IACH,YAAmB,GAA+B,EAAE,UAAsC;QACxF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAW;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,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GAAG,CAAC,GAAW,EAAE,KAAc;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;YACvE,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAW,EAAE,KAAc;QACvC,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;YACvE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,wBAAwB,CAChC,KAAyC;QAEzC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { DetailedResult, failWithDetail, succeedWithDetail } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMap, ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @public\n */\nexport interface IReadOnlyResultMapValidator<TK extends string = string, TV = unknown> {\n /**\n * {@inheritDoc Collections.ReadOnlyResultMapValidator.map}\n */\n readonly map: IReadOnlyResultMap<TK, TV>;\n\n /**\n * {@inheritDoc Collections.ResultMap.get}\n */\n get(key: string): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n has(key: string): boolean;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @public\n */\nexport interface IResultMapValidatorCreateParams<TK extends string = string, TV = unknown> {\n map: ResultMap<TK, TV>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A read-only validator for any {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * that validates weakly-typed keys before accessing values.\n * @public\n */\nexport class ReadOnlyResultMapValidator<TK extends string = string, TV = unknown>\n implements IReadOnlyResultMapValidator<TK, TV>\n{\n /**\n * The key-value converters used for validation.\n */\n public readonly converters: KeyValueConverters<TK, TV>;\n\n /**\n * The underlying map.\n */\n public get map(): IReadOnlyResultMap<TK, TV> {\n return this._map;\n }\n\n private readonly _map: IReadOnlyResultMap<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ReadOnlyResultMapValidator | ReadOnlyResultMapValidator}.\n * @param map - The map to validate access to.\n * @param converters - The key-value converters for validation.\n */\n public constructor(map: IReadOnlyResultMap<TK, TV>, converters: KeyValueConverters<TK, TV>) {\n this._map = map;\n this.converters = converters;\n }\n\n /**\n * Gets a value from the map by key, validating the key first.\n * @param key - The key to retrieve (will be validated).\n * @returns `Success` with the value if found, `Failure` otherwise.\n */\n public get(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((validKey) => {\n return this._map.get(validKey);\n });\n }\n\n /**\n * Checks if the map contains a key, validating the key first.\n * @param key - The key to check (will be validated).\n * @returns `true` if the key exists and is valid, `false` otherwise.\n */\n public has(key: string): boolean {\n const result = this.converters.convertKey(key);\n if (result.isFailure()) {\n return false;\n }\n return this._map.has(result.value);\n }\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} wrapper which validates weakly-typed keys\n * before calling the wrapped result map.\n * @public\n */\nexport class ResultMapValidator<TK extends string = string, TV = unknown>\n implements IReadOnlyResultMapValidator<TK, TV>\n{\n public readonly converters: KeyValueConverters<TK, TV>;\n public get map(): IReadOnlyResultMap<TK, TV> {\n return this._map;\n }\n\n protected _map: ResultMap<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @param params - Required parameters for constructing the result map validator.\n */\n public constructor(params: IResultMapValidatorCreateParams<TK, TV>) {\n this._map = params.map;\n this.converters = params.converters;\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.add}\n */\n public add(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.add(vk, vv);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.delete}\n */\n public delete(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.delete(k);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.get}\n */\n public get(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.get(k);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.getOrAdd}\n */\n public getOrAdd(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritDoc Collections.ResultMap.getOrAdd}\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: string,\n valueOrFactory: unknown | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (!this._isResultMapValueFactory(valueOrFactory)) {\n return this.converters.convertEntry([key, valueOrFactory]).onSuccess(([vk, vv]) => {\n return this._map.getOrAdd(vk, vv);\n });\n } else {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.get(k).onFailure(() => {\n const value = valueOrFactory(k)\n .onSuccess((value) => this.converters.convertEntry([k, value]))\n .onSuccess(([__key, value]) => succeedWithDetail(value, 'added'));\n\n return value.success\n ? this._map.add(k, value.value)\n : failWithDetail<TV, ResultMapResultDetail>(value.message, 'invalid-value');\n });\n });\n }\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n public has(key: string): boolean {\n return this._map.has(key as TK);\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.set}\n */\n public set(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.set(vk, vv);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.update}\n */\n public update(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.update(vk, vv);\n });\n }\n\n /**\n * Gets a read-only version of this validator.\n */\n public toReadOnly(): IReadOnlyResultMapValidator<TK, TV> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory},\n * `false` otherwise.\n * @public\n */\n protected _isResultMapValueFactory<TK extends string, TV>(\n value: TV | ResultMapValueFactory<TK, TV>\n ): value is ResultMapValueFactory<TK, TV> {\n return typeof value === 'function';\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/collections/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,KAAc;IAEd,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC;AACnF,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 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 * Determines if a supplied value is an iterable object or some other type.\n * @param value - The value to be tested.\n * @returns `true` if the value is an iterable object, `false` otherwise.\n * @public\n */\nexport function isIterable<TE = unknown, TI extends Iterable<TE> = Iterable<TE>, TO = unknown>(\n value: TI | TO\n): value is TI {\n return (value && typeof value === 'object' && Symbol.iterator in value) === true;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingCollector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAKhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAmD1D;;;;GAIG;AACH,MAAM,OAAO,mBAGX,SAAQ,SAAgB;IASxB;;;;OAIG;IACH,YAAmB,MAAoD;;QACrE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7F,KAAK,MAAM,IAAI,IAAI,MAAA,MAAM,CAAC,KAAK,mCAAI,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAGrC,MAAoD;QACpD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, Result } from '../base';\nimport { CollectibleKey, ICollectible } from './collectible';\nimport { IReadOnlyCollectorValidator } from './collectorValidator';\nimport { IReadOnlyValidatingResultMap } from './validatingResultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { Collector } from './collector';\nimport { CollectorValidator } from './collectorValidator';\n\n/**\n * A read-only interface exposing non-mutating methods of a\n * {@link Collections.ValidatingCollector | ValidatingCollector}.\n * @public\n */\n\nexport interface IReadOnlyValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {\n /**\n * A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n readonly validating: IReadOnlyCollectorValidator<TITEM>;\n\n /**\n * Gets the item at a specified index.\n * @param index - The index of the item to retrieve.\n * @returns `Success` with the item if it exists, or `Failure` with an error if the index is out of range.\n */\n getAt(index: number): Result<TITEM>;\n\n /**\n * Gets all items in the collection, ordered by index.\n * @returns An array of items in the collection, ordered by index.\n */\n valuesByIndex(): ReadonlyArray<TITEM>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.\n * @public\n */\nexport interface IValidatingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> {\n /**\n * {@inheritDoc Collections.ICollectorValidatorCreateParams.converters}\n */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n\n /**\n * {@inheritDoc Collections.ICollectorConstructorParams.items}\n */\n items?: unknown[];\n}\n\n/**\n * A {@link Collections.Collector | Collector} with a {@link Collections.CollectorValidator | CollectorValidator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends Collector<TITEM> {\n /**\n * A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly validating: CollectorValidator<TITEM>;\n\n protected readonly _converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n\n /**\n * Constructs a new {@link Collections.ValidatingCollector | ValidatingConvertingCollector}\n * from the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IValidatingCollectorConstructorParams<TITEM>) {\n super();\n this._converters = params.converters;\n this.validating = new CollectorValidator({ collector: this, converters: params.converters });\n for (const item of params.items ?? []) {\n this.validating.getOrAdd(item).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ValidatingCollector | ValidatingCollector} instance from\n * the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n >(params: IValidatingCollectorConstructorParams<TITEM>): Result<ValidatingCollector<TITEM>> {\n return captureResult(() => new ValidatingCollector(params));\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyValidatingCollector<TITEM> {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatingConvertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingConvertingCollector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AA8B9E;;;;;GAKG;AACH,MAAM,OAAO,6BAIX,SAAQ,mBAAgC;IASxC;;;;OAIG;IACH,YAAmB,MAAoE;;QACrF,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,4BAA4B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACvG,KAAK,MAAM,KAAK,IAAI,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAKrC,MAAoE;QAEpE,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,6BAA6B,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, Result } from '../base';\nimport { CollectibleFactory, CollectibleKey, ICollectible } from './collectible';\nimport { ConvertingCollector } from './convertingCollector';\nimport { ConvertingCollectorValidator } from './convertingCollectorValidator';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyValidatingCollector } from './validatingCollector';\n\n/**\n * Parameters for constructing a {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector}.\n * @public\n */\nexport interface IValidatingConvertingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /**\n * {@inheritDoc Collections.IConvertingCollectorConstructorParams.factory}\n */\n factory: CollectibleFactory<TITEM, TSRC>;\n\n /**\n * {@inheritDoc Collections.IConvertingCollectorValidatorCreateParams.converters}\n */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n /**\n * {@inheritDoc Collections.IConvertingCollectorConstructorParams.entries}\n */\n entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];\n}\n\n/**\n * A {@link Collections.ConvertingCollector | ConvertingCollector} with a\n * {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingConvertingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> extends ConvertingCollector<TITEM, TSRC> {\n /**\n * A {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly validating: ConvertingCollectorValidator<TITEM, TSRC>;\n\n protected readonly _converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector}\n * from the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IValidatingConvertingCollectorConstructorParams<TITEM, TSRC>) {\n super({ factory: params.factory });\n this._converters = params.converters;\n this.validating = new ConvertingCollectorValidator({ collector: this, converters: params.converters });\n for (const entry of params.entries ?? []) {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector} instance from\n * the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n >(\n params: IValidatingConvertingCollectorConstructorParams<TITEM, TSRC>\n ): Result<ValidatingConvertingCollector<TITEM, TSRC>> {\n return captureResult(() => new ValidatingConvertingCollector(params));\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyValidatingCollector<TITEM> {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatingConvertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingConvertingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAGhD,OAAO,EACL,2BAA2B,EAE5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAwBlE;;;;;GAKG;AACH,MAAM,OAAO,qCAIX,SAAQ,2BAA8C;IAWtD;;;OAGG;IACH,YAAmB,MAAkF;QACnG,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,0BAA0B,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAU,MAAM,CAC3B,MAAkF;QAElF,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,qCAAqC,CAAC,MAAM,CAAC,CAAC,CAAC;IAChF,CAAC;CACF;AA6BD;;;;;;;GAOG;AACH,MAAM,OAAO,6BAKX,SAAQ,mBAA+C;IAWvD;;;OAGG;IACH,YAAmB,MAAmF;QACpG,KAAK,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,0BAA0B,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAU,MAAM,CAM3B,MAAmF;QAEnF,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,6BAA6B,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, Result } from '../base';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMap } from './readonlyResultMap';\nimport {\n ReadOnlyConvertingResultMap,\n ConvertingResultMapValueConverter\n} from './readOnlyConvertingResultMap';\nimport { ConvertingResultMap } from './convertingResultMap';\nimport { IResultMap } from './resultMap';\nimport { ReadOnlyResultMapValidator } from './resultMapValidator';\n\n/**\n * Parameters for constructing a\n * {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @public\n */\nexport interface IValidatingReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {\n /**\n * The inner map containing source values.\n */\n inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * The key-value converters for validating weakly-typed access.\n */\n converters: KeyValueConverters<TK, TTARGET>;\n}\n\n/**\n * A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * of source type and returns lazily-converted, cached values of a target type, with a\n * {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access.\n * @public\n */\nexport class ValidatingReadOnlyConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET\n> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {\n /**\n * A validator for weakly-typed access to the map.\n */\n public readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;\n\n /**\n * The key-value converters used for validation.\n */\n protected readonly _converters: KeyValueConverters<TK, TTARGET>;\n\n /**\n * Constructs a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>) {\n super({ inner: params.inner, converter: params.converter });\n this._converters = params.converters;\n this.validating = new ReadOnlyResultMapValidator(this, params.converters);\n }\n\n /**\n * Creates a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<TK extends string, TSRC, TTARGET>(\n params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>\n ): Result<ValidatingReadOnlyConvertingResultMap<TK, TSRC, TTARGET>> {\n return captureResult(() => new ValidatingReadOnlyConvertingResultMap(params));\n }\n}\n\n/**\n * Parameters for constructing a\n * {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @public\n */\nexport interface IValidatingConvertingResultMapConstructorParams<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> {\n /**\n * The inner map containing source values.\n */\n inner: TSRCMAP;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * The key-value converters for validating weakly-typed access.\n */\n converters: KeyValueConverters<TK, TTARGET>;\n}\n\n/**\n * A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type\n * and returns lazily-converted, cached values of a target type, with a\n * {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access\n * and a {@link Collections.CacheInvalidatingResultMapWrapper | source} property for mutable access\n * to the underlying source map.\n * @public\n */\nexport class ValidatingConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> extends ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP> {\n /**\n * A validator for weakly-typed access to the map.\n */\n public readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;\n\n /**\n * The key-value converters used for validation.\n */\n protected readonly _converters: KeyValueConverters<TK, TTARGET>;\n\n /**\n * Constructs a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>) {\n super({ inner: params.inner, converter: params.converter });\n this._converters = params.converters;\n this.validating = new ReadOnlyResultMapValidator(this, params.converters);\n }\n\n /**\n * Creates a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n >(\n params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>\n ): Result<ValidatingConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>> {\n return captureResult(() => new ValidatingConvertingResultMap(params));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validatingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAIhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAA+B,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwBvF;;;;GAIG;AACH,MAAM,OAAO,mBACX,SAAQ,SAAiB;IASzB;;;OAGG;IACH,YAAmB,MAAqD;;QACtE,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAS,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjG,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CACrC,MAAqD;QAErD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 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 { captureResult, Result } from '../base';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMap } from './readonlyResultMap';\nimport { ResultMap } from './resultMap';\nimport { IReadOnlyResultMapValidator, ResultMapValidator } from './resultMapValidator';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ValidatingResultMap | ValidatingResultMap}.\n * @public\n */\nexport interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown>\n extends IReadOnlyResultMap<TK, TV> {\n /**\n * A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values\n * before inserting them into this collection.\n */\n readonly validating: IReadOnlyResultMapValidator<TK, TV>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IValidatingResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<string, unknown>>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapValidator | validator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingResultMap<TK extends string = string, TV = unknown>\n extends ResultMap<TK, TV>\n implements IReadOnlyValidatingResultMap<TK, TV>\n{\n /**\n * A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values\n * before inserting them into this collection.\n */\n public readonly validating: ResultMapValidator<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ValidatingResultMap | ValidatingResultMap}.\n * @param params - Required parameters for constructing the map.\n */\n public constructor(params: IValidatingResultMapConstructorParams<TK, TV>) {\n const entries = params.converters.convertEntries([...(params.entries ?? [])]).orThrow();\n super({ entries });\n this.validating = new ResultMapValidator<TK, TV>({ map: this, converters: params.converters });\n }\n\n /**\n * Creates a new {@link Collections.ValidatingResultMap | ValidatingResultMap} instance.\n * @param params - Required parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n * @public\n */\n public static createValidatingResultMap<TK extends string = string, TV = unknown>(\n params: IValidatingResultMapConstructorParams<TK, TV>\n ): Result<ValidatingResultMap<TK, TV>> {\n return captureResult(() => new ValidatingResultMap(params));\n }\n\n /**\n * Gets a read-only version of this map.\n */\n public toReadOnly(): IReadOnlyValidatingResultMap<TK, TV> {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advancedConverters.js","sourceRoot":"","sources":["../../../src/packlets/conversion/advancedConverters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CA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AC,MAAM,EAAE,CAAC;YACtC,OAAO,IAAI,CACT,4BAA4B,UAAU,CAAC,MAAM,SAAS,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC7F,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAClD,OAAO,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC,OAAO,CAAkE,CAAC;IAC9F,CAAC,CACF,CAAC;AACJ,CAAC","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 { fail, isKeyOf, mapResults, succeed, Success } from '../base';\nimport { Validator } from '../validation';\nimport { BaseConverter, ConverterResultTypes } from './baseConverter';\nimport { Converter } from './converter';\nimport { literal } from './basicConverters';\nimport { FieldConverters, ObjectConverter } from './objectConverter';\n\n/**\n * Represents a composite ID constructed of two strongly-typed string IDs\n * separated by a delimiter.\n * @public\n */\nexport interface ICompositeId<TCOLLECTIONID extends string, TITEMID extends string> {\n readonly collectionId: TCOLLECTIONID;\n readonly separator: string;\n readonly itemId: TITEMID;\n}\n\n/**\n * Represents a partial composite ID, where separator is optional.\n * @public\n */\nexport interface IPartialCompositeId<TCOLLECTIONID extends string, TITEMID extends string> {\n readonly collectionId: TCOLLECTIONID;\n readonly separator?: string;\n readonly itemId: TITEMID;\n}\n\n/**\n * Creates an {@link ObjectConverter | ObjectConverter} for a strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @param collectionIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns An {@link ObjectConverter | ObjectConverter} for the strongly-typed composite ICompositeId.\n * @public\n */\nexport function compositeIdFromObject<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdValidator: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdValidator: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return new ObjectConverter<IPartialCompositeId<TCOLLECTIONID, TITEMID>, TC>({\n collectionId: collectionIdValidator,\n separator: literal(separator).optional(),\n itemId: itemIdValidator\n }).map<ICompositeId<TCOLLECTIONID, TITEMID>>((obj) =>\n Success.with({\n collectionId: obj.collectionId,\n separator: obj.separator ?? separator,\n itemId: obj.itemId\n })\n );\n}\n\n/**\n * Converts a composite ID string into a strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @public\n */\nexport function compositeIdFromString<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return new BaseConverter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>(\n (from: unknown, __self?: Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>, context?: TC) => {\n if (typeof from !== 'string') {\n return fail(`${from}: invalid non-string composite ID.`);\n }\n const parts = from.split(separator);\n if (parts.length < 2) {\n return fail(`${from}: invalid composite ID - separator '${separator}' not found.`);\n } else if (parts.length > 2) {\n return fail(`${from}: invalid composite ID - multiple separators '${separator}.' found.`);\n }\n return collectionIdConverter.convert(parts[0], context).onSuccess((collectionId) => {\n return itemIdConverter.convert(parts[1], context).onSuccess((itemId) => {\n return succeed({\n collectionId,\n separator,\n itemId\n });\n });\n });\n }\n );\n}\n\n/**\n * Creates a {@link Converter | Converter} for a strongly-typed {@link Converters.ICompositeId | CompositeId} from\n * either a string or an object representation.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @public\n */\nexport function compositeId<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return compositeIdFromObject(collectionIdConverter, separator, itemIdConverter).or(\n compositeIdFromString(collectionIdConverter, separator, itemIdConverter)\n );\n}\n\n/**\n * Converts a strongly-typed {@link Converters.ICompositeId | CompositeId} into a string.\n * @param compositeIdConverter - {@link Converter | Converter} or {@link Validator | Validator} that validates/converts the composite ID string.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} which produces a composite ID string.\n * @public\n */\nexport function compositeIdString<\n T extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TC = unknown\n>(\n compositeIdConverter: Validator<T, TC> | Converter<T, TC>,\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<T, TC> {\n const objectConverter = compositeIdFromObject(collectionIdConverter, separator, itemIdConverter);\n return new BaseConverter<T, TC>((from: unknown, __self?: Converter<T, TC>, context?: TC) => {\n if (typeof from === 'string') {\n return compositeIdConverter.convert(from, context);\n }\n return objectConverter.convert(from, context).onSuccess((compositeId) => {\n return compositeIdConverter.convert(`${compositeId.collectionId}${separator}${compositeId.itemId}`);\n });\n });\n}\n\n/**\n * Helper to create a {@link Converter | Converter} which converts a source object to a new object with a\n * different shape.\n *\n * @remarks\n * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new\n * object, which contains the converted values under the key names specified at initialization time.\n * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist\n * or cannot be converted.\n *\n * Fields that succeed but convert to undefined are omitted from the result object but do not\n * fail the conversion.\n *\n * @param properties - An object with key names that correspond to the target object and an\n * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts\n * a single filed from the source object.\n * @returns A {@link Converter | Converter} with the specified conversion behavior.\n * @public\n */\nexport function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC> {\n return new BaseConverter((from: unknown, __self, context?: TC) => {\n // eslint bug thinks key is used before defined\n\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n\n for (const key in properties) {\n if (properties[key]) {\n const result = properties[key].convert(from, context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n return errors.length === 0 ? succeed(converted) : fail(errors.join('\\n'));\n });\n}\n\n/**\n * Per-property converters and configuration for each field in the destination object of\n * a {@link Converters.transformObject} call.\n * @public\n */\nexport type FieldTransformers<TSRC, TDEST, TC = unknown> = {\n [key in keyof TDEST]: {\n /**\n * The name of the property in the source object to be converted.\n */\n from: keyof TSRC;\n /**\n * The converter or validator used to convert the property.\n */\n converter: Converter<TDEST[key], TC> | Validator<TDEST[key], TC>;\n /**\n * If `true` then a missing source property is ignored. If `false` or omitted\n * then a missing source property causes an error.\n */\n optional?: boolean;\n };\n};\n\n/**\n * Options for a {@link Converters.transformObject} call.\n * @public\n */\n\nexport interface TransformObjectOptions<TSRC> {\n /**\n * If `strict` is `true` then unused properties in the source object cause\n * an error, otherwise they are ignored.\n */\n strict: true;\n\n /**\n * An optional list of source properties to be ignored when strict mode\n * is enabled.\n */\n ignore?: (keyof TSRC)[];\n\n /**\n * An optional description of this transform to be used for error messages.\n */\n description?: string;\n}\n\n/**\n * Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a\n * new object with a different shape.\n *\n * @remarks\n * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new\n * object, which contains the converted values under the key names specified at initialization time.\n *\n * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist\n * or cannot be converted.\n *\n * @param destinationFields - An object with key names that correspond to the target object and an\n * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name\n * of the corresponding property in the source object, the converter or validator used for each source\n * property and any other configuration to guide the conversion.\n * @param options - Options which affect the transformation.\n *\n * @returns A {@link Converter | Converter} with the specified conversion behavior.\n * @public\n */\nexport function transformObject<TSRC, TDEST, TC = unknown>(\n destinationFields: FieldTransformers<TSRC, TDEST, TC>,\n options?: TransformObjectOptions<TSRC>\n): Converter<TDEST, TC> {\n return new BaseConverter((from: unknown, __self, context?: TC) => {\n // eslint bug thinks key is used before defined\n\n const converted = {} as { [key in keyof TDEST]: TDEST[key] };\n const errors: string[] = [];\n const used: Set<keyof TSRC> = new Set(options?.ignore);\n\n if (typeof from === 'object' && !Array.isArray(from) && from !== null) {\n for (const destinationKey in destinationFields) {\n if (destinationFields[destinationKey]) {\n const srcKey = destinationFields[destinationKey].from;\n const converter = destinationFields[destinationKey].converter;\n\n if (isKeyOf(srcKey, from)) {\n const result = converter.convert(from[srcKey], context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[destinationKey] = result.value;\n } else if (result.isFailure()) {\n errors.push(`${srcKey}->${destinationKey}: ${result.message}`);\n }\n used.add(srcKey);\n } else if (destinationFields[destinationKey].optional !== true) {\n errors.push(`${String(srcKey)}: required property missing in source object.`);\n }\n }\n }\n\n if (options?.strict === true) {\n for (const key in from) {\n if (isKeyOf(key, from) && !used.has(key as keyof TSRC)) {\n errors.push(`${key}: unexpected property in source object`);\n }\n }\n }\n } else {\n errors.push('source is not an object');\n }\n\n return errors.length === 0\n ? succeed(converted)\n : fail(options?.description ? `${options.description}:\\n ${errors.join('\\n ')}` : errors.join('\\n'));\n });\n}\n\n/**\n * Creates a {@link Converter | Converter} that converts an array to a strongly-typed tuple,\n * using the supplied tuple of {@link Converter | Converters} to convert each element.\n *\n * @remarks\n * The resulting {@link Converter | Converter} returns {@link Success | Success} with a tuple\n * containing the converted values if all conversions succeed. Returns {@link Failure | Failure}\n * with an error message if the source is not an array, has the wrong number of elements, or\n * any element conversion fails.\n *\n * @example\n * ```typescript\n * const converter = tuple([Converters.string, Converters.number, Converters.boolean]);\n * // Type is Converter<[string, number, boolean]>\n *\n * converter.convert(['hello', 42, true]);\n * // Returns Success with ['hello', 42, true]\n * ```\n *\n * @param converters - A tuple of {@link Converter | Converters} defining the expected types\n * for each element of the tuple.\n * @returns A {@link Converter | Converter} that returns a strongly-typed tuple.\n * @public\n */\nexport function tuple<T extends readonly Converter<unknown, TC>[], TC = unknown>(\n converters: [...T]\n): Converter<ConverterResultTypes<T>, TC> {\n return new BaseConverter<ConverterResultTypes<T>, TC>(\n (from: unknown, __self: Converter<ConverterResultTypes<T>, TC>, context?: TC) => {\n if (!Array.isArray(from)) {\n return fail(`Not an array: ${JSON.stringify(from)}`);\n }\n\n if (from.length !== converters.length) {\n return fail(\n `Expected array of length ${converters.length}, got ${from.length}: ${JSON.stringify(from)}`\n );\n }\n\n const results = converters.map((converter, index) => {\n return converter.convert(from[index], context);\n });\n\n return mapResults(results) as ReturnType<Converter<ConverterResultTypes<T>, TC>['convert']>;\n }\n );\n}\n"]}
|