@fgv/ts-utils 5.1.0-19 → 5.1.0-20
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/dist/index.js.map +1 -0
- package/dist/packlets/base/brand.js.map +1 -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.map +1 -0
- package/dist/packlets/base/result.js.map +1 -0
- package/dist/packlets/base/utils.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.map +1 -0
- 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.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.map +1 -0
- package/dist/packlets/logging/logReporter.js.map +1 -0
- package/dist/packlets/logging/logger.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/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.map +1 -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.map +1 -0
- package/lib/packlets/base/normalize.js.map +1 -0
- package/lib/packlets/base/result.d.ts.map +1 -0
- package/lib/packlets/base/result.js.map +1 -0
- package/lib/packlets/base/utils.d.ts.map +1 -0
- package/lib/packlets/base/utils.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.map +1 -0
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
- 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.map +1 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- 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.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.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.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.map +1 -0
- 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.map +1 -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.map +1 -0
- package/lib/packlets/logging/logger.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.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 +3 -3
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EACL,mBAAmB,EACnB,SAAS,EAET,mBAAmB,EAEnB,SAAS,EACT,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAa,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAa,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,UAAU,EAEV,UAAU,EACV,IAAI,EAGJ,OAAO,EACP,eAAe,EACf,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,6BAA6B,EAC7B,mBAAmB,EACnB,UAAU,EAEV,UAAU,EACX,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 * as Collections from './packlets/collections';\nimport * as Conversion from './packlets/conversion';\nimport * as Hash from './packlets/hash';\nimport * as Logging from './packlets/logging';\nimport * as Validation from './packlets/validation';\n\nimport {\n AggregatedResultMap,\n Collector,\n ICollectible,\n ConvertingCollector,\n IReadOnlyResultMap,\n ResultMap,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap\n} from './packlets/collections';\nimport { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport {\n AggregatedResultMap,\n Collections,\n Collector,\n ConvertingCollector,\n Conversion,\n Converter,\n Converters,\n Hash,\n ICollectible,\n IReadOnlyResultMap,\n Logging,\n ObjectConverter,\n ResultMap,\n StringConverter,\n ValidatingCollector,\n ValidatingConvertingCollector,\n ValidatingResultMap,\n Validation,\n Validator,\n Validators\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brand.js","sourceRoot":"","sources":["../../../src/packlets/base/brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2021 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Helper type to brand a simple type to prevent inappropriate use\n * @public\n */\n\nexport type Brand<T, B> = T & { __brand: B };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC","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\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapResults.js","sourceRoot":"","sources":["../../../src/packlets/base/mapResults.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAKL,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACR,MAAM,UAAU,CAAC;AAElB;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,OAA4B,EAC5B,gBAAqC;IAErC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAQ,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,C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,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC,KAAU,CAAC,CAAC;AAC7B,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 { MessageAggregator } from './messageAggregator';\nimport {\n DeferredResult,\n DetailedResult,\n IMessageAggregator,\n Result,\n fail,\n isDeferredResult,\n succeed\n} from './result';\n\n/**\n * Aggregates successful result values from a collection of {@link Result | Result<T>}.\n * @param results - The collection of {@link Result | Result<T>} to be mapped.\n * @param aggregatedErrors - Optional string array to which any error messages will be\n * appended. Each error is appended as an individual string.\n * @returns If all {@link Result | results} are successful, returns {@link Success} with an\n * array containing all returned values. If any {@link Result | results} failed, returns\n * {@link Failure} with a concatenated summary of all error messages.\n * @public\n */\nexport function mapResults<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},\n * optionally ignoring certain error details.\n * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.\n * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.\n * @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array containing all successful results if all results either\n * succeeded or returned error details listed in `ignore`. If any results failed with details\n * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable\n * error messages.\n * @public\n */\nexport function mapDetailedResults<T, TD>(\n results: Iterable<DetailedResult<T, TD>>,\n ignore: TD[],\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else if (result.detail && !ignore.includes(result.detail)) {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a a collection of {@link Result | Result<T>}.\n * @param results - An `Iterable` of {@link Result | Result<T>} from which success\n * results are to be aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array of `<T>` if any results were successful. If\n * all {@link Result | results} failed, returns {@link Failure} with a concatenated\n * summary of all error messages.\n * @public\n */\nexport function mapSuccess<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (elements.length === 0 && errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates error messages from a collection of {@link Result | Result<T>}.\n * @param results - An iterable collection of {@link Result | Result<T>} for which\n * error messages are aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns An array of strings consisting of all error messages returned by\n * {@link Result | results} in the source collection. Ignores {@link Success}\n * results and returns an empty array if there were no errors.\n * @public\n */\nexport function mapFailures<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): string[] {\n const errors: string[] = [];\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n aggregatedErrors?.addMessage(result.message);\n }\n }\n return errors;\n}\n\n/**\n * Determines if an iterable collection of {@link Result | Result<T>} were all successful.\n * @param results - The collection of {@link Result | Result<T>} to be tested.\n * @param successValue - The value to be returned if results are successful.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.\n * If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error\n * messages from all failed elements.\n * @public\n */\nexport function allSucceed<T>(\n results: Iterable<Result<unknown>>,\n successValue: T,\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const errors: string[] = [];\n\n if (results !== undefined) {\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(successValue);\n}\n\n/**\n * Returns the first successful result from a collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>}.\n * @param results - The collection of {@link Result | Result<T>} or {@link DeferredResult | DeferredResult<T>} to be tested.\n * @returns The first successful result, or {@link Failure} with a concatenated summary of all error messages.\n * @public\n */\nexport function firstSuccess<T>(results: Iterable<Result<T> | DeferredResult<T>>): Result<T> {\n const errors: MessageAggregator = new MessageAggregator();\n for (const r of results) {\n const result = isDeferredResult(r) ? r() : r;\n if (result.isSuccess()) {\n return result;\n }\n errors.addMessage(result.message);\n }\n return errors.returnOrReport(fail('no results found'));\n}\n\n/**\n * String-keyed record of initialization functions to be passed to {@link populateObject}\n * or {@link populateObject}.\n * @public\n */\nexport type FieldInitializers<T> = { [key in keyof T]: (state: Partial<T>) => Result<T[key]> };\n\n/**\n * Options for the {@link populateObject} function.\n * @public\n */\n\nexport interface PopulateObjectOptions<T> {\n /**\n * If present, specifies the order in which property values should\n * be evaluated. Any keys not listed are evaluated after all listed\n * keys in indeterminate order. If 'order' is not present, keys\n * are evaluated in indeterminate order.\n */\n order?: (keyof T)[];\n\n /**\n * Specify handling of `undefined` values. By default, successful\n * `undefined` results are written to the result object. If this value\n * is `true` then `undefined` results are suppressed for all properties.\n * If this value is an array of property keys then `undefined` results\n * are suppressed for those properties only.\n */\n suppressUndefined?: boolean | (keyof T)[];\n}\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param options - An optional {@link PopulateObjectOptions | set of options} which\n * modify the behavior of this call.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * {@label WITH_OPTIONS}\n * @public\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n options?: PopulateObjectOptions<T>,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param order - Optional order in which keys should be written.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @public\n * {@label WITH_ORDER}\n * @deprecated Pass {@link PopulateObjectOptions} instead.\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n order: (keyof T)[] | undefined,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n optionsOrOrder?: PopulateObjectOptions<T> | (keyof T)[],\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const options: PopulateObjectOptions<T> = optionsOrOrder\n ? Array.isArray(optionsOrOrder)\n ? { order: optionsOrOrder }\n : optionsOrOrder\n : {};\n const state = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n const keys: (keyof T)[] = Array.from(options.order ?? []);\n const foundKeys = new Set<keyof T>(options.order);\n\n // start with the supplied order then append anything else we find\n for (const key in initializers) {\n if (!foundKeys.has(key)) {\n keys.push(key);\n foundKeys.add(key);\n }\n }\n\n for (const key of keys) {\n if (initializers[key]) {\n const result = initializers[key](state);\n if (result.isSuccess()) {\n if (result.value === undefined) {\n if (\n options.suppressUndefined === true ||\n (Array.isArray(options.suppressUndefined) && options.suppressUndefined.includes(key))\n ) {\n continue;\n }\n }\n state[key] = result.value;\n } else {\n errors.push(result.message);\n }\n } else {\n errors.push(`populateObject: Key ${String(key)} is present but has no initializer`);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(state as T);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageAggregator.js","sourceRoot":"","sources":["../../../src/packlets/base/messageAggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAA8B,IAAI,EAAE,MAAM,UAAU,CAAC;AAE5D;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAG5B;;;;;OAKG;IACH,YAAmB,MAAiB;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,CAAC;IAED;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAW,WAAW;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,UAAU,CAAC,OAA2B;QAC3C,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,WAAW,CAAC,QAA8B;QAC/C,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,SAAkB;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACI,cAAc,CAAI,MAAiB,EAAE,SAAkB;QAC5D,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACtD,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAI,CAAC,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2024 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 { IMessageAggregator, Result, fail } from './result';\n\n/**\n * A simple error aggregator to simplify collecting and reporting all errors in\n * a flow.\n * @public\n */\nexport class MessageAggregator implements IMessageAggregator {\n private readonly _messages: string[];\n\n /**\n * Constructs a new {@link MessageAggregator | ErrorAggregator} with an\n * optionally specified initial set of error messages.\n * @param errors - optional array of errors to be included\n * in the aggregation.\n */\n public constructor(errors?: string[]) {\n this._messages = errors ? Array.from(errors) : [];\n }\n\n /**\n * {@inheritDoc IMessageAggregator.hasMessages}\n */\n public get hasMessages(): boolean {\n return this._messages.length > 0;\n }\n\n /**\n * {@inheritDoc IMessageAggregator.numMessages}\n */\n public get numMessages(): number {\n return this._messages.length;\n }\n\n /**\n * {@inheritDoc IMessageAggregator.messages}\n */\n public get messages(): string[] {\n return this._messages;\n }\n\n /**\n * {@inheritDoc IMessageAggregator.addMessage}\n */\n public addMessage(message: string | undefined): this {\n if (message) {\n this._messages.push(message);\n }\n return this;\n }\n\n /**\n * {@inheritDoc IMessageAggregator.addMessages}\n */\n public addMessages(messages: string[] | undefined): this {\n if (messages && messages.length > 0) {\n this._messages.push(...messages);\n }\n return this;\n }\n\n /**\n * {@inheritDoc IMessageAggregator.toString}\n */\n public toString(separator?: string): string {\n return this._messages.join(separator ?? '\\n');\n }\n\n /**\n * If any error messages have been aggregated, returns\n * {@link Failure | Failure<T>} with the aggregated\n * messages concatenated using the optionally-supplied\n * separator, or newline. If the supplied {@link Result | Result<T>}\n * contains an error message that has not already been aggregated,\n * it will be included in the aggregated messages.\n *\n * If no error messages have been aggregated, returns\n * the supplied {@link Result | Result<T>}.\n * @param result - The {@link Result | Result<T>} to be returned\n * if no messages have been aggregated.\n * @param separator - Optional string separator used to construct\n * the error message.\n * @returns {@link Failure | Failure<T>} with an aggregated message\n * if any error messages were collected, the supplied\n * {@link Result | Result<T>} otherwise.\n */\n public returnOrReport<T>(result: Result<T>, separator?: string): Result<T> {\n if (!this.hasMessages) {\n return result;\n }\n if (!result.success) {\n if (!this._messages.find((s) => s === result.message)) {\n return fail([...this._messages, result.message].join(separator ?? '\\n'));\n }\n }\n return fail(this.toString(separator));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAYjD;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAI,IAAO;QACzB,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACrC,KAAK,QAAQ;gBACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;oBACpE,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACrC,CAAC;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAyB,CAAC;gBAC5D,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAiB,CAAC,CAAC;gBACjF,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,OAAO,CAAC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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 { mapResults } from './mapResults';\nimport { Result, fail, succeed } from './result';\n\n/**\n * @internal\n */\nexport type Entry<T> = [string | number | symbol, T];\n\n/**\n * @internal\n */\nexport type ResultEntry<T> = [string | number | symbol, Result<T>];\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class Normalizer {\n /**\n * Normalizes the supplied value\n *\n * @param from - The value to be normalized\n * @returns A normalized version of the value\n */\n public normalize<T>(from: T): Result<T> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this.normalizeLiteral(from);\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this.normalizeLiteral(from);\n } else if (Array.isArray(from)) {\n return this._normalizeArray(from) as unknown as Result<T>;\n } else if (from instanceof Map) {\n return succeed(new Map(this.normalizeEntries(from.entries())) as unknown as T);\n } else if (from instanceof Set) {\n return succeed(new Set(this.normalizeEntries(from.entries())) as unknown as T);\n }\n const obj: { [key in number | string | symbol]: unknown } = {};\n for (const e of this.normalizeEntries(Object.entries(from as unknown as object))) {\n obj[e[0]] = e[1];\n }\n return succeed(obj as T);\n }\n return fail(`normalize: Unexpected type - cannot normalize '${typeof from}'`);\n }\n\n /**\n * Compares two property names from some object being normalized.\n * @param k1 - First key to be compared.\n * @param k2 - Second key to be compared.\n * @returns `1` if `k1` is greater, `-1` if `k2` is greater and\n * `0` if they are equal.\n * @internal\n */\n protected _compareKeys(k1: unknown, k2: unknown): number {\n const cs1 = String(k1);\n const cs2 = String(k2);\n if (cs1 > cs2) {\n return 1;\n }\n if (cs2 > cs1) {\n return -1;\n }\n /* c8 ignore next 2 */\n return 0;\n }\n\n /**\n * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).\n * @remarks\n * Converts property names (entry key) to string and then sorts as string.\n * @param entries - The entries to be normalized.\n * @returns A normalized sorted array of entries.\n */\n public normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[] {\n return Array.from(entries)\n .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))\n .map((e) => [e[0], this.normalize(e[1])] as ResultEntry<T>)\n .filter((e) => e[1].isSuccess())\n .map((e) => [e[0], e[1].orThrow()]);\n }\n\n protected _normalizeArray(from: unknown[]): Result<unknown[]> {\n return mapResults(from.map((v) => this.normalize(v)));\n }\n\n /**\n * Normalizes the supplied literal value\n * @param from - The literal value to be normalized.\n * @returns A normalized value for the literal.\n */\n public normalizeLiteral<T>(from: T): Result<T> {\n // TODO: Apply configurable normalization rules\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(from);\n }\n if (from === null) {\n return succeed(from);\n }\n if (from instanceof Date) {\n return succeed(from);\n }\n if (from instanceof RegExp) {\n return succeed(from);\n }\n /* c8 ignore next 2 */\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,MAA0B,EAAE,SAA0B;QAC1E,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAA6B,EAAE,OAAuC;QAClF,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,IAAsB;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,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\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this._message;\n }\n\n /**\n * Creates a {@link Failure | Failure<T>} with the supplied error message.\n * @param message - The error message to be returned.\n * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.\n */\n public static with<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @remarks\n * A `succeeds` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added\n * to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * {@inheritDoc succeed}\n * @public\n */\nexport function succeeds<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @remarks\n * A `fails` alias was added in release 5.0 due to\n * issues with the name `fail` being used test frameworks and libraries.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * {@inheritDoc fail}\n * @public\n */\nexport function fails<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Uses a value or calls a supplied initializer if the supplied value is undefined.\n * @param value - the value\n * @param initializer - a function that initializes the value if it is undefined\n * @returns `Success` with the value if it is defined, or the result of calling the initializer function.\n * @public\n */\nexport function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T> {\n return value !== undefined ? succeed(value) : initializer();\n}\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to\n * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success\n * details in addition to the error message.\n * @public\n */\nexport class DetailedSuccess<out T, out TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this._value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param __cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedSuccess<T, TD> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n // Cast reporter to preserve detail type when calling reportSuccess\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportSuccess(level, this._value, this._detail, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and\n * optional detail.\n */\n public static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n }\n\n /**\n * Returns this {@link DetailedSuccess} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional\n * failure details in addition to the error message.\n * @public\n */\nexport class DetailedFailure<out T, out TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail?: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param __cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this._message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this._message, this._detail);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this._message, this._detail), this._detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this {\n const message = formatter ? formatter(this._message, this._detail) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedFailure<T, TD> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n // Cast formatter to handle detail type properly\n const formatter = failureOptions.message as ErrorFormatter<TD> | undefined;\n const message = formatter?.(this._message, this._detail) ?? this._message;\n // Cast reporter to preserve detail type when calling reportFailure\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportFailure(level, message, this._detail);\n return this;\n }\n\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message, this._detail));\n } else {\n logOrFormat.error(this._message, this._detail);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * Returns this {@link DetailedFailure} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message\n * and optional detail.\n * @param message - The error message to be returned.\n * @param detail - The error detail to be returned.\n * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * error message and detail.\n * @public\n */\n public static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n }\n}\n\n/**\n * Represents a result with additional detail.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResultValueType<T> = T extends DetailedResult<infer TV, unknown> ? TV : never;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @remarks\n * The `succeedsWithDetail` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added to avoid conflicts\n * with test frameworks and libraries.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * {@inheritDoc succeedWithDetail}\n * @public\n */\nexport function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @remarks\n * The `failsWithDetail` alias was added in release 5.0 for naming consistency\n * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * {@inheritDoc failWithDetail}\n * @public\n */\nexport function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Extracts a message string from an unknown thrown/rejected value.\n * @param err - The caught error value.\n * @returns The error message string.\n * @internal\n */\nexport function _errorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n return String(err);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error` or string.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail(_errorMessage(err));\n }\n}\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} is successful, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise.\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` that resolves to a {@link Result}.\n */\n public constructor(promise: Promise<Result<T>>) {\n this._promise = promise.catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The async function to be captured.\n * @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on\n * success, or {@link Failure} with the thrown error message if `func` throws or rejects.\n * @public\n */\nexport async function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>> {\n try {\n return succeed(await func());\n } catch (err: unknown) {\n return fail(_errorMessage(err));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CA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C,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregatedResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/aggregatedResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EACL,aAAa,EAGb,IAAI,EACJ,cAAc,EACd,OAAO,EACP,iBAAiB,EACjB,OAAO,EACR,MAAM,SAAS,CAAC;AACjB,OAAO,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAa,UAAU,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAgC,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;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iB,EACjB,iBAAiB,CAClB;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAMX,SAAQ,uBAA+E;IACvF;;;OAGG;IACH,YACE,MAAqG;QAErG,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,CAOlB,MAAqG;QAErG,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,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 {\n captureResult,\n DetailedResult,\n Result,\n fail,\n failWithDetail,\n succeed,\n succeedWithDetail,\n Success\n} from '../base';\nimport { Converter, Converters } from '../conversion';\nimport { Validator, Validators } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMapValidator } from './resultMapValidator';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\nimport { IResultMap, ResultMapValueFactory } from './resultMap';\nimport { IReadOnlyValidatingResultMap, ValidatingResultMap } from './validatingResultMap';\n\n/**\n * A read-only collection entry in an {@link AggregatedResultMap | aggregated result map}.\n * @public\n */\nexport interface IReadonlyAggregatedResultMapEntry<\n TCOLLECTIONID extends string = string,\n TITEMID extends string = string,\n TITEM = unknown,\n TMETADATA = unknown\n> {\n readonly isMutable: false;\n readonly id: TCOLLECTIONID;\n readonly items: IReadOnlyValidatingResultMap<TITEMID, TITEM>;\n readonly metadata?: TMETADATA;\n}\n\n/**\n * A mutable collection entry in an {@link AggregatedResultMap | aggregated result map}.\n * @public\n */\nexport interface IMutableAggregatedResultMapEntry<\n TCOLLECTIONID extends string = string,\n TITEMID extends string = string,\n TITEM = unknown,\n TMETADATA = unknown\n> {\n readonly isMutable: true;\n readonly id: TCOLLECTIONID;\n readonly items: ValidatingResultMap<TITEMID, TITEM>;\n metadata?: TMETADATA;\n}\n\n/**\n * A collection entry in an {@link AggregatedResultMap | aggregated result map}, either mutable or read-only.\n * @public\n */\nexport type AggregatedResultMapEntry<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> =\n | IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n | IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>;\n\n/**\n * JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using an entries array.\n * @public\n */\nexport interface IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID extends string = string> {\n readonly isMutable: boolean;\n readonly id: TCOLLECTIONID;\n readonly entries: ReadonlyArray<KeyValueEntry<string, unknown>>;\n readonly metadata?: unknown;\n}\n\n/**\n * JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry using a string-keyed items object.\n * @public\n */\nexport interface IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID extends string = string> {\n readonly isMutable: boolean;\n readonly id: TCOLLECTIONID;\n readonly items: Record<string, unknown>;\n readonly metadata?: unknown;\n}\n\n/**\n * JSON format for an {@link AggregatedResultMap | aggregated result map} collection entry - supports both entries array and items object.\n * @public\n */\nexport type AggregatedResultMapJsonEntry<TCOLLECTIONID extends string = string> =\n | IAggregatedResultMapJsonEntryWithEntries<TCOLLECTIONID>\n | IAggregatedResultMapJsonEntryWithItems<TCOLLECTIONID>;\n\n/**\n * Any valid input format for an {@link AggregatedResultMap | aggregated result map} collection entry.\n * @public\n */\nexport type AggregatedResultMapEntryInit<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> =\n | AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n | AggregatedResultMapJsonEntry<TCOLLECTIONID>;\n\n/**\n * Options for {@link Collections.AggregatedResultMapBase.addCollectionWithItems | addCollectionWithItems}.\n * @public\n */\nexport interface IAddCollectionWithItemsOptions<TMETADATA = unknown> {\n /**\n * If true, the collection will be immutable (read-only).\n * Defaults to false (mutable).\n */\n readonly isImmutable?: boolean;\n\n /**\n * Optional metadata to attach to the collection.\n */\n readonly metadata?: TMETADATA;\n}\n\n/**\n * Parameters for constructing an {@link AggregatedResultMap | aggregated result map}.\n * @public\n */\nexport interface IAggregatedResultMapConstructorParams<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> {\n /**\n * Validator for composite IDs.\n */\n readonly compositeIdValidator?: Validator<TCOMPOSITEID, unknown>;\n /**\n * Converter or validator for collection IDs.\n */\n readonly collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>;\n /**\n * Converter or validator for item IDs.\n */\n readonly itemIdConverter: Converter<TITEMID, unknown> | Validator<TITEMID, unknown>;\n /**\n * Converter or validator for individual items in each collection.\n */\n readonly itemConverter: Converter<TITEM, unknown> | Validator<TITEM, unknown>;\n /**\n * Optional converter or validator for collection metadata. If not provided, a metadata field\n * in the input will cause a validation failure.\n */\n readonly metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>;\n\n /**\n * Optional separator string for composite IDs. Defaults to `.`.\n */\n readonly separator?: string;\n\n /**\n * Initial collections to populate the map.\n * @remarks Each entry may be mutable or read-only.\n */\n readonly collections?: ReadonlyArray<\n AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n >;\n}\n\n/**\n * A validator for weakly-typed access to an {@link AggregatedResultMap | aggregated result map}.\n * @public\n */\nexport class AggregatedResultMapValidator<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> implements IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM>\n{\n private readonly _map: AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>;\n\n /**\n * The key-value converters used for validating weakly-typed access.\n */\n public readonly converters: KeyValueConverters<TCOMPOSITEID, TITEM>;\n\n /**\n * Constructs a new {@link AggregatedResultMapValidator | aggregated result map validator}.\n * @param map - The {@link AggregatedResultMap | aggregated result map} being validated.\n * @param converters - The key-value converters for weakly-typed access.\n */\n public constructor(\n map: AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>,\n converters: KeyValueConverters<TCOMPOSITEID, TITEM>\n ) {\n this._map = map;\n this.converters = converters;\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.map} */\n public get map(): IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM> {\n return this._map;\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.get} */\n public get(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.get(k);\n });\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.has} */\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 /** {@inheritDoc Collections.ResultMapValidator.add} */\n public add(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.add(vk, vv);\n });\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.set} */\n public set(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.set(vk, vv);\n });\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.update} */\n public update(key: string, value: unknown): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.update(vk, vv);\n });\n }\n\n /** {@inheritDoc Collections.ResultMapValidator.delete} */\n public delete(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.delete(k);\n });\n }\n}\n\n/**\n * Type guard to check if an {@link AggregatedResultMapEntry | aggregated result map entry} is mutable.\n */\nfunction isMutableEntry<TCOLLECTIONID extends string, TITEMID extends string, TITEM, TMETADATA>(\n entry: AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n): entry is IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> {\n return entry.isMutable === true;\n}\n\n/**\n * Base class for an aggregated result map that wraps a collection of {@link ValidatingResultMap} instances,\n * keyed by collection ID. Items are accessed via composite IDs that combine the collection ID\n * and item ID with a delimiter.\n * @remarks Consumers should inherit from this class or use {@link AggregatedResultMap | AggregatedResultMap}\n * for fully generic.\n * @public\n */\nexport class AggregatedResultMapBase<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> implements IResultMap<TCOMPOSITEID, TITEM>, IReadOnlyValidatingResultMap<TCOMPOSITEID, TITEM>\n{\n private readonly _childKvConverters: KeyValueConverters<TITEMID, TITEM>;\n private readonly _collections: ValidatingResultMap<\n TCOLLECTIONID,\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n >;\n private readonly _collectionKvConverters: KeyValueConverters<\n TCOLLECTIONID,\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n >;\n private readonly _compositeIdValidator: Validator<TCOMPOSITEID, unknown>;\n private readonly _collectionIdConverter:\n | Converter<TCOLLECTIONID, unknown>\n | Validator<TCOLLECTIONID, unknown>;\n private readonly _itemIdConverter: Converter<TITEMID, unknown> | Validator<TITEMID, unknown>;\n private readonly _itemConverter: Converter<TITEM, unknown> | Validator<TITEM, unknown>;\n private readonly _metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>;\n private readonly _delimiter: string;\n private readonly _compositeIdConverter: Converter<Converters.ICompositeId<TCOLLECTIONID, TITEMID>, unknown>;\n private readonly _kvConverters: KeyValueConverters<TCOMPOSITEID, TITEM>;\n private readonly _validating: AggregatedResultMapValidator<\n TCOMPOSITEID,\n TCOLLECTIONID,\n TITEMID,\n TITEM,\n TMETADATA\n >;\n\n /**\n * Protected constructor for derived classes.\n * Use the {@link AggregatedResultMap.create | create static method} for safe construction with error handling.\n * @param params - {@link IAggregatedResultMapConstructorParams | Parameters} for constructing the map.\n * @throws If initialization fails (e.g., invalid collections).\n * @public\n */\n protected constructor(\n params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n ) {\n this._compositeIdValidator =\n params.compositeIdValidator ?? AggregatedResultMapBase._compositeIdValidator(params);\n this._collectionIdConverter = params.collectionIdConverter;\n this._itemIdConverter = params.itemIdConverter;\n this._itemConverter = params.itemConverter;\n this._metadataConverter = params.metadataConverter;\n this._delimiter = params.separator ?? '.';\n\n // Build child key-value converters for item ID/value pairs\n this._childKvConverters = new KeyValueConverters<TITEMID, TITEM>({\n key: params.itemIdConverter,\n value: params.itemConverter\n });\n\n // Build composite ID converter for parsing composite IDs\n this._compositeIdConverter = Converters.compositeId(\n params.collectionIdConverter,\n this._delimiter,\n params.itemIdConverter\n );\n\n // Build key-value converters for composite ID/item pairs\n this._kvConverters = new KeyValueConverters<TCOMPOSITEID, TITEM>({\n key: this._compositeIdValidator,\n value: params.itemConverter\n });\n\n // Build entry converter for collection entries\n const entryConverter = AggregatedResultMapBase._entryConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n params.collectionIdConverter,\n this._childKvConverters,\n params.metadataConverter\n );\n\n // Build key-value converters for the collections map\n this._collectionKvConverters = new KeyValueConverters<\n TCOLLECTIONID,\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n >({\n key: params.collectionIdConverter,\n value: entryConverter\n });\n\n // Convert all input collections to [id, entry] pairs for ValidatingResultMap\n const initCollections = params.collections ?? [];\n const initEntries: KeyValueEntry<string, unknown>[] = initCollections.map((entry) => {\n return [entry.id, entry];\n });\n\n // Build the inner ValidatingResultMap - throws on error\n this._collections = new ValidatingResultMap<\n TCOLLECTIONID,\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n >({\n converters: this._collectionKvConverters,\n entries: initEntries\n });\n\n // Build the validator\n this._validating = new AggregatedResultMapValidator<\n TCOMPOSITEID,\n TCOLLECTIONID,\n TITEMID,\n TITEM,\n TMETADATA\n >(this, this._kvConverters);\n }\n\n // ==================== IReadOnlyValidatingResultMap implementation ====================\n\n /**\n * A validator for weakly-typed access to the map.\n */\n public get validating(): IReadOnlyResultMapValidator<TCOMPOSITEID, TITEM> {\n return this._validating;\n }\n\n /**\n * The total number of items across all collections.\n */\n public get size(): number {\n let total = 0;\n for (const entry of Array.from(this._collections.values())) {\n total += entry.items.size;\n }\n return total;\n }\n\n /**\n * Gets an item by its composite ID.\n * @param key - The composite ID of the item.\n * @returns `Success` with the item if found, `Failure` otherwise.\n */\n public get(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitAndLookup(key).onSuccess(({ entry, itemId }) => {\n return entry.items.get(itemId);\n });\n }\n\n /**\n * Checks if an item exists by its composite ID.\n * @param key - The composite ID of the item.\n * @returns `true` if the item exists, `false` otherwise.\n */\n public has(key: TCOMPOSITEID): boolean {\n const result = this._splitAndLookup(key);\n if (result.isFailure()) {\n return false;\n }\n return result.value.entry.items.has(result.value.itemId);\n }\n\n /**\n * Iterates over all entries in all collections.\n */\n public *entries(): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>> {\n for (const collectionEntry of Array.from(this._collections.values())) {\n for (const [itemId, item] of Array.from(collectionEntry.items.entries())) {\n // Validate the composite ID through the converter\n const compositeId = this._compositeIdValidator\n .convert(`${collectionEntry.id}${this._delimiter}${itemId}`)\n .orThrow();\n yield [compositeId, item];\n }\n }\n }\n\n /**\n * Iterates over all composite keys.\n */\n public *keys(): IterableIterator<TCOMPOSITEID> {\n for (const [key] of Array.from(this.entries())) {\n yield key;\n }\n }\n\n /**\n * Iterates over all values.\n */\n public *values(): IterableIterator<TITEM> {\n for (const collectionEntry of Array.from(this._collections.values())) {\n for (const value of Array.from(collectionEntry.items.values())) {\n yield value;\n }\n }\n }\n\n /**\n * Calls a callback for each entry.\n * @param cb - The callback to call.\n * @param thisArg - Optional `this` argument for the callback.\n */\n public forEach(cb: ResultMapForEachCb<TCOMPOSITEID, TITEM>, thisArg?: unknown): void {\n for (const [key, value] of Array.from(this.entries())) {\n cb.call(thisArg, value, key, this);\n }\n }\n\n /**\n * Gets an iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TCOMPOSITEID, TITEM>> {\n return this.entries();\n }\n\n // ==================== Mutating methods ====================\n\n /**\n * Sets an item by its composite ID. Creates the collection if it doesn't exist and is mutable.\n * @param key - The composite ID of the item.\n * @param value - The value to set.\n * @returns `Success` with the value if set, `Failure` otherwise.\n */\n public set(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitCompositeId(key).onSuccess(({ collectionId, itemId }) => {\n return this._getOrCreateMutableCollection(collectionId).onSuccess((collection) => {\n return collection.set(itemId, value);\n });\n });\n }\n\n /**\n * Adds an item by its composite ID. Fails if the item already exists.\n * @param key - The composite ID of the item.\n * @param value - The value to add.\n * @returns `Success` with the value if added, `Failure` otherwise.\n */\n public add(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitCompositeId(key).onSuccess(({ collectionId, itemId }) => {\n return this._getOrCreateMutableCollection(collectionId).onSuccess((collection) => {\n return collection.add(itemId, value);\n });\n });\n }\n\n /**\n * Updates an existing item by its composite ID. Fails if the item doesn't exist.\n * @param key - The composite ID of the item.\n * @param value - The new value.\n * @returns `Success` with the value if updated, `Failure` otherwise.\n */\n public update(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitAndLookupMutable(key).onSuccess(({ entry, itemId }) => {\n return entry.items.update(itemId, value);\n });\n }\n\n /**\n * Deletes an item by its composite ID.\n * @param key - The composite ID of the item.\n * @returns `Success` with the deleted value, `Failure` otherwise.\n */\n public delete(key: TCOMPOSITEID): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitAndLookupMutable(key).onSuccess(({ entry, itemId }) => {\n return entry.items.delete(itemId);\n });\n }\n\n /**\n * Gets an existing item or adds a new one.\n * @param key - The composite ID of the item.\n * @param value - The value to add if not found.\n * @returns `Success` with the existing or new value.\n */\n public getOrAdd(key: TCOMPOSITEID, value: TITEM): DetailedResult<TITEM, ResultMapResultDetail>;\n\n /**\n * Gets an existing item or adds a new one using a factory.\n * @param key - The composite ID of the item.\n * @param factory - A factory function to create the value if not found. Receives the composite ID.\n * @returns `Success` with the existing or new value.\n */\n public getOrAdd(\n key: TCOMPOSITEID,\n factory: ResultMapValueFactory<TCOMPOSITEID, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail>;\n\n public getOrAdd(\n key: TCOMPOSITEID,\n valueOrFactory: TITEM | ResultMapValueFactory<TCOMPOSITEID, TITEM>\n ): DetailedResult<TITEM, ResultMapResultDetail> {\n return this._splitCompositeId(key).onSuccess(({ collectionId, itemId }) => {\n return this._getOrCreateMutableCollection(collectionId).onSuccess((collection) => {\n // Use type guard to check if valueOrFactory is a factory function\n if (this._isFactory(valueOrFactory)) {\n return collection.getOrAdd(itemId, () => valueOrFactory(key));\n }\n return collection.getOrAdd(itemId, valueOrFactory);\n });\n });\n }\n\n /**\n * Clears all items from all mutable collections.\n * Immutable collections are not affected.\n */\n public clear(): void {\n for (const entry of Array.from(this._collections.values())) {\n if (isMutableEntry(entry)) {\n entry.items.clear();\n }\n }\n }\n\n /**\n * Returns a read-only view of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TCOMPOSITEID, TITEM> {\n return this;\n }\n\n // ==================== Convenience methods for split IDs ====================\n\n /**\n * Composes a collection ID and item ID into a composite ID.\n * @param collectionId - The collection ID.\n * @param itemId - The item ID.\n * @returns `Success` with the composite ID if valid, `Failure` otherwise.\n */\n public composeId(collectionId: TCOLLECTIONID, itemId: TITEMID): Result<TCOMPOSITEID> {\n const rawId = `${collectionId}${this._delimiter}${itemId}`;\n return this._compositeIdValidator.convert(rawId);\n }\n\n /**\n * Adds an item using separate collection and item IDs.\n * @param collectionId - The collection ID.\n * @param itemId - The item ID.\n * @param value - The value to add.\n * @returns `Success` with the composite ID if added, `Failure` otherwise.\n */\n public addToCollection(\n collectionId: TCOLLECTIONID,\n itemId: TITEMID,\n value: TITEM\n ): DetailedResult<TCOMPOSITEID, ResultMapResultDetail> {\n return this._getOrCreateMutableCollection(collectionId).onSuccess((collection) => {\n return collection.add(itemId, value).onSuccess(() => {\n return this.composeId(collectionId, itemId).withDetail('invalid-key', 'added');\n });\n });\n }\n\n /**\n * Sets an item using separate collection and item IDs.\n * @param collectionId - The collection ID.\n * @param itemId - The item ID.\n * @param value - The value to set.\n * @returns `Success` with the composite ID if set, `Failure` otherwise.\n */\n public setInCollection(\n collectionId: TCOLLECTIONID,\n itemId: TITEMID,\n value: TITEM\n ): DetailedResult<TCOMPOSITEID, ResultMapResultDetail> {\n return this._getOrCreateMutableCollection(collectionId).onSuccess((collection) => {\n return collection.set(itemId, value).onSuccess((_, detail) => {\n return this.composeId(collectionId, itemId).withDetail('invalid-key', detail);\n });\n });\n }\n\n /**\n * Updates an item using separate collection and item IDs.\n * @param collectionId - The collection ID.\n * @param itemId - The item ID.\n * @param value - The new value.\n * @returns `Success` with the composite ID if updated, `Failure` otherwise.\n */\n public updateInCollection(\n collectionId: TCOLLECTIONID,\n itemId: TITEMID,\n value: TITEM\n ): DetailedResult<TCOMPOSITEID, ResultMapResultDetail> {\n return this._getMutableCollection(collectionId).onSuccess((collection) => {\n return collection.update(itemId, value).onSuccess(() => {\n return this.composeId(collectionId, itemId).withDetail('invalid-key', 'updated');\n });\n });\n }\n\n /**\n * Deletes an item using separate collection and item IDs.\n * @param collectionId - The collection ID.\n * @param itemId - The item ID.\n * @returns `Success` with the composite ID if deleted, `Failure` otherwise.\n */\n public deleteFromCollection(\n collectionId: TCOLLECTIONID,\n itemId: TITEMID\n ): DetailedResult<TCOMPOSITEID, ResultMapResultDetail> {\n return this._getMutableCollection(collectionId).onSuccess((collection) => {\n return collection.delete(itemId).onSuccess(() => {\n return this.composeId(collectionId, itemId).withDetail('invalid-key', 'deleted');\n });\n });\n }\n\n // ==================== Collection-level methods ====================\n\n /**\n * Provides read-only access to the underlying collections map.\n * Use `collections.has(id)` and `collections.get(id)` to check existence and retrieve collections.\n */\n public get collections(): IReadOnlyValidatingResultMap<\n TCOLLECTIONID,\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n > {\n return this._collections;\n }\n\n /**\n * The number of collections.\n */\n public get collectionCount(): number {\n return this._collections.size;\n }\n\n /**\n * Gets the metadata for a specific collection.\n * @param collectionId - The collection ID.\n * @returns `Success` with the metadata if found, `Failure` otherwise.\n */\n public getCollectionMetadata(collectionId: TCOLLECTIONID): Result<TMETADATA | undefined> {\n return this._collections.get(collectionId).asResult.onSuccess((entry) => {\n return succeed(entry.metadata);\n });\n }\n\n /**\n * Sets the metadata for a mutable collection.\n * @param collectionId - The collection ID.\n * @param metadata - The metadata to set.\n * @returns `Success` if set, `Failure` otherwise.\n */\n public setCollectionMetadata(collectionId: TCOLLECTIONID, metadata: TMETADATA): Result<TMETADATA> {\n return this._collections.get(collectionId).asResult.onSuccess((entry) => {\n if (!isMutableEntry(entry)) {\n return fail(`Cannot modify metadata of immutable collection '${collectionId}'`);\n }\n entry.metadata = metadata;\n return succeed(metadata);\n });\n }\n\n /**\n * Adds a new collection from a pre-built entry object.\n * @param entry - The collection entry to add (JSON with items/entries, or pre-instantiated).\n * @returns `Success` with the entry if added, `Failure` otherwise.\n */\n public addCollectionEntry(\n entry: AggregatedResultMapEntryInit<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n ): DetailedResult<\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>,\n ResultMapResultDetail\n > {\n return AggregatedResultMapBase._entryConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n this._collectionIdConverter,\n this._childKvConverters,\n this._metadataConverter\n )\n .convert(entry)\n .withFailureDetail<ResultMapResultDetail>('invalid-value')\n .onSuccess((c) => this._collections.add(c.id, c));\n }\n\n /**\n * Adds a new collection with the specified ID and optional initial entries.\n * @param collectionId - The collection ID as a string (will be validated).\n * @param items - Optional initial entries for the collection.\n * @param options - Optional settings (isImmutable defaults to false).\n * @returns `Success` with the validated collection ID if added, `Failure` otherwise.\n */\n public addCollectionWithItems(\n collectionId: string,\n items?: Iterable<KeyValueEntry<string, unknown>>,\n options?: IAddCollectionWithItemsOptions<TMETADATA>\n ): Result<TCOLLECTIONID> {\n const isMutable = options?.isImmutable !== true;\n const entries = items ? Array.from(items) : [];\n return this._collectionIdConverter\n .convert(collectionId)\n .onSuccess((id) =>\n this.addCollectionEntry({ isMutable, id, entries, metadata: options?.metadata }).asResult.onSuccess(\n () => Success.with(id)\n )\n );\n }\n\n // ==================== Protected helpers ====================\n\n /**\n * Deletes a collection from the internal collections map.\n * This is a protected method for use by derived classes that need to implement\n * collection deletion functionality.\n *\n * @param collectionId - The collection ID to delete.\n * @returns `Success` with the deleted entry if found, `Failure` otherwise.\n * @remarks\n * - Does NOT check if the collection is mutable - callers should validate this first.\n * - Use `collections.get(id)` to check if a collection exists and its mutability before calling.\n */\n protected _deleteCollection(\n collectionId: TCOLLECTIONID\n ): DetailedResult<\n AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>,\n ResultMapResultDetail\n > {\n // ValidatingResultMap extends ResultMap which has delete method\n return this._collections.delete(collectionId);\n }\n\n // ==================== Private helpers ====================\n\n /**\n * Type guard to check if a value is a factory function.\n */\n private _isFactory(\n valueOrFactory: TITEM | ResultMapValueFactory<TCOMPOSITEID, TITEM>\n ): valueOrFactory is ResultMapValueFactory<TCOMPOSITEID, TITEM> {\n return typeof valueOrFactory === 'function';\n }\n\n private _splitCompositeId(\n key: TCOMPOSITEID\n ): DetailedResult<Converters.ICompositeId<TCOLLECTIONID, TITEMID>, ResultMapResultDetail> {\n return this._compositeIdConverter.convert(key).withDetail('invalid-key', 'success');\n }\n\n private _splitAndLookup(\n key: TCOMPOSITEID\n ): DetailedResult<\n { entry: AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>; itemId: TITEMID },\n ResultMapResultDetail\n > {\n return this._splitCompositeId(key).onSuccess(({ collectionId, itemId }) => {\n return this._collections.get(collectionId).onSuccess((entry) => {\n return succeedWithDetail({ entry, itemId }, 'success');\n });\n });\n }\n\n private _splitAndLookupMutable(\n key: TCOMPOSITEID\n ): DetailedResult<\n { entry: IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>; itemId: TITEMID },\n ResultMapResultDetail\n > {\n return this._splitAndLookup(key).onSuccess(({ entry, itemId }) => {\n if (!isMutableEntry(entry)) {\n return failWithDetail(`Cannot modify immutable collection '${entry.id}'`, 'failure');\n }\n return succeedWithDetail({ entry, itemId }, 'success');\n });\n }\n\n /**\n * Gets an existing mutable collection by ID.\n * Returns failure if the collection doesn't exist or is immutable.\n */\n private _getMutableCollection(\n collectionId: TCOLLECTIONID\n ): DetailedResult<ValidatingResultMap<TITEMID, TITEM>, ResultMapResultDetail> {\n return this._collections.get(collectionId).onSuccess((entry) => {\n if (!isMutableEntry(entry)) {\n return failWithDetail(`Cannot modify immutable collection '${collectionId}'`, 'failure');\n }\n return succeedWithDetail(entry.items, 'exists');\n });\n }\n\n /**\n * Gets an existing mutable collection or creates a new one.\n */\n private _getOrCreateMutableCollection(\n collectionId: TCOLLECTIONID\n ): DetailedResult<ValidatingResultMap<TITEMID, TITEM>, ResultMapResultDetail> {\n const existing = this._collections.get(collectionId);\n if (existing.isSuccess()) {\n if (!isMutableEntry(existing.value)) {\n return failWithDetail(`Cannot modify immutable collection '${collectionId}'`, 'failure');\n }\n return succeedWithDetail(existing.value.items, 'exists');\n }\n\n // Create a new mutable collection\n const newItems = new ValidatingResultMap<TITEMID, TITEM>({\n converters: this._childKvConverters\n });\n const newEntry: IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> = {\n isMutable: true,\n id: collectionId,\n items: newItems\n };\n return this._collections.add(collectionId, newEntry).onSuccess(() => {\n return succeedWithDetail(newItems, 'added');\n });\n }\n\n // ==================== Static converter factories ====================\n\n /**\n * Constructs a composite id validator using other converters/validators and separator supplied in params.\n * @param params - Constructor params.\n * @returns The composite ID validator.\n */\n private static _compositeIdValidator<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n ): Validator<TCOMPOSITEID, unknown> {\n return Validators.compositeId<TCOMPOSITEID, TCOLLECTIONID, TITEMID>({\n collectionId: Converters.asValidator(params.collectionIdConverter),\n separator: params.separator ?? '.',\n itemId: Converters.asValidator(params.itemIdConverter)\n });\n }\n\n /**\n * Converts metadata from source, failing fast if metadata is present but no converter is configured.\n * @param sourceMetadata - The metadata from the source (may be undefined).\n * @param metadataConverter - Optional converter for metadata.\n * @returns Success with converted metadata (or undefined), or Failure if metadata is present but disallowed.\n */\n private static _convertMetadata<TMETADATA>(\n sourceMetadata: unknown,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Result<TMETADATA | undefined> {\n if (sourceMetadata === undefined) {\n return succeed(undefined);\n }\n if (!metadataConverter) {\n return fail('metadata is not allowed when no metadataConverter is configured');\n }\n return metadataConverter.convert(sourceMetadata);\n }\n\n /**\n * Extracts metadata from a source object if present.\n */\n private static _extractSourceMetadata(from: unknown): unknown {\n return typeof from === 'object' && from !== null && 'metadata' in from ? from.metadata : undefined;\n }\n\n /**\n * Creates a converter for pre-instantiated mutable entries.\n * These are entries that already have a ValidatingResultMap as their items property.\n */\n private static _instantiatedMutableConverter<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Converter<IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown> {\n const baseConverter = Converters.strictObject<{\n isMutable: true;\n id: TCOLLECTIONID;\n items: ValidatingResultMap<TITEMID, TITEM>;\n }>({\n isMutable: Converters.literal(true),\n id: collectionIdConverter,\n items: Converters.isA<ValidatingResultMap<TITEMID, TITEM>>(\n 'ValidatingResultMap',\n (t) => t instanceof ValidatingResultMap\n )\n });\n\n return Converters.generic<\n IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>,\n unknown\n >((from) => {\n return baseConverter.convert(from).onSuccess((base) => {\n const sourceMetadata = AggregatedResultMapBase._extractSourceMetadata(from);\n return AggregatedResultMapBase._convertMetadata(sourceMetadata, metadataConverter).onSuccess(\n (metadata) => {\n const entry: IMutableAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> = {\n isMutable: true,\n id: base.id,\n items: base.items,\n metadata\n };\n return succeed(entry);\n }\n );\n });\n });\n }\n\n /**\n * Creates a converter for pre-instantiated read-only entries.\n * These are entries that already have an IReadOnlyValidatingResultMap as their items property.\n */\n private static _instantiatedReadonlyConverter<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Converter<IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown> {\n const baseConverter = Converters.strictObject<{\n isMutable: false;\n id: TCOLLECTIONID;\n items: IReadOnlyValidatingResultMap<TITEMID, TITEM>;\n }>({\n isMutable: Converters.literal(false),\n id: collectionIdConverter,\n items: Converters.isA<IReadOnlyValidatingResultMap<TITEMID, TITEM>>(\n 'IReadOnlyValidatingResultMap',\n (t) => t instanceof ValidatingResultMap\n )\n });\n\n return Converters.generic<\n IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>,\n unknown\n >((from) => {\n return baseConverter.convert(from).onSuccess((base) => {\n const sourceMetadata = AggregatedResultMapBase._extractSourceMetadata(from);\n return AggregatedResultMapBase._convertMetadata(sourceMetadata, metadataConverter).onSuccess(\n (metadata) => {\n const entry: IReadonlyAggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA> = {\n isMutable: false,\n id: base.id,\n items: base.items,\n metadata\n };\n return succeed(entry);\n }\n );\n });\n });\n }\n\n /**\n * Creates a converter for JSON entries with an entries array.\n * Converts the entries array to a ValidatingResultMap.\n */\n private static _jsonWithEntriesConverter<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>,\n childKvConverters: KeyValueConverters<TITEMID, TITEM>,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Converter<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown> {\n const entriesArrayConverter = Converters.isA<KeyValueEntry<string, unknown>[]>(\n 'entries array',\n (t): t is KeyValueEntry<string, unknown>[] =>\n Array.isArray(t) && t.every((item) => Array.isArray(item) && item.length === 2)\n );\n\n const baseConverter = Converters.object<{\n isMutable: boolean;\n id: TCOLLECTIONID;\n entries: KeyValueEntry<string, unknown>[];\n }>({\n isMutable: Converters.boolean,\n id: collectionIdConverter,\n entries: entriesArrayConverter\n });\n\n return Converters.generic<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>((from) => {\n return baseConverter.convert(from).onSuccess((json) => {\n const sourceMetadata = AggregatedResultMapBase._extractSourceMetadata(from);\n\n return childKvConverters.convertEntries(json.entries).onSuccess((convertedEntries) => {\n const items = new ValidatingResultMap<TITEMID, TITEM>({\n converters: childKvConverters,\n entries: convertedEntries\n });\n return AggregatedResultMapBase._convertMetadata(sourceMetadata, metadataConverter).onSuccess(\n (metadata) => {\n if (json.isMutable) {\n return succeed<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>({\n isMutable: true,\n id: json.id,\n items,\n metadata\n });\n }\n return succeed<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>({\n isMutable: false,\n id: json.id,\n items: items.toReadOnly(),\n metadata\n });\n }\n );\n });\n });\n });\n }\n\n /**\n * Creates a converter for JSON entries with an items object.\n * Converts the items object to a ValidatingResultMap.\n */\n private static _jsonWithItemsConverter<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>,\n childKvConverters: KeyValueConverters<TITEMID, TITEM>,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Converter<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown> {\n const baseConverter = Converters.object<{\n isMutable: boolean;\n id: TCOLLECTIONID;\n items: Record<string, unknown>;\n }>({\n isMutable: Converters.boolean,\n id: collectionIdConverter,\n items: Converters.generic<Record<string, unknown>>((from) => {\n if (typeof from === 'object' && from !== null && !Array.isArray(from)) {\n return succeed(from as Record<string, unknown>);\n }\n return fail('expected an object');\n })\n });\n\n return Converters.generic<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>((from) => {\n return baseConverter.convert(from).onSuccess((json) => {\n const sourceMetadata = AggregatedResultMapBase._extractSourceMetadata(from);\n const entries = Object.entries(json.items) as KeyValueEntry<string, unknown>[];\n\n return childKvConverters.convertEntries(entries).onSuccess((convertedEntries) => {\n const items = new ValidatingResultMap<TITEMID, TITEM>({\n converters: childKvConverters,\n entries: convertedEntries\n });\n return AggregatedResultMapBase._convertMetadata(sourceMetadata, metadataConverter).onSuccess(\n (metadata) => {\n if (json.isMutable) {\n return succeed<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>({\n isMutable: true,\n id: json.id,\n items,\n metadata\n });\n }\n return succeed<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>>({\n isMutable: false,\n id: json.id,\n items: items.toReadOnly(),\n metadata\n });\n }\n );\n });\n });\n });\n }\n\n /**\n * Creates a unified entry converter that handles all entry formats.\n * Tries each format in order: instantiated mutable, instantiated readonly,\n * JSON with entries array, JSON with items object.\n */\n private static _entryConverter<\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n collectionIdConverter: Converter<TCOLLECTIONID, unknown> | Validator<TCOLLECTIONID, unknown>,\n childKvConverters: KeyValueConverters<TITEMID, TITEM>,\n metadataConverter?: Converter<TMETADATA, unknown> | Validator<TMETADATA, unknown>\n ): Converter<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown> {\n return Converters.oneOf<AggregatedResultMapEntry<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>, unknown>([\n AggregatedResultMapBase._instantiatedMutableConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n collectionIdConverter,\n metadataConverter\n ),\n AggregatedResultMapBase._instantiatedReadonlyConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n collectionIdConverter,\n metadataConverter\n ),\n AggregatedResultMapBase._jsonWithEntriesConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n collectionIdConverter,\n childKvConverters,\n metadataConverter\n ),\n AggregatedResultMapBase._jsonWithItemsConverter<TCOLLECTIONID, TITEMID, TITEM, TMETADATA>(\n collectionIdConverter,\n childKvConverters,\n metadataConverter\n )\n ]);\n }\n}\n\n/**\n * An aggregated result map that wraps a collection of {@link ValidatingResultMap | ValidatingResultMap} instances,\n * keyed by collection ID. Items are accessed via composite IDs that combine the collection ID\n * and item ID with a delimiter.\n * @public\n */\nexport class AggregatedResultMap<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n> extends AggregatedResultMapBase<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA> {\n /**\n * Constructs a new {@link AggregatedResultMap | AggregatedResultMap}.\n * @param params -\n */\n public constructor(\n params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n ) {\n super(params);\n }\n\n /**\n * Creates a new {@link AggregatedResultMap | AggregatedResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n */\n public static create<\n TCOMPOSITEID extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TITEM,\n TMETADATA = unknown\n >(\n params: IAggregatedResultMapConstructorParams<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>\n ): Result<AggregatedResultMap<TCOMPOSITEID, TCOLLECTIONID, TITEMID, TITEM, TMETADATA>> {\n return captureResult(() => new AggregatedResultMap(params));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectible.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAA4B,UAAU,EAAE,MAAM,eAAe,CAAC;AAuFrE;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAQtB;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IA2BD,YAAmB,MAAmD;QACpE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe;gBAClB,OAAO,MAAM,CAAC,cAAc,KAAK,UAAU;oBACzC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;oBAC3C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YACrE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,qDAAqD;YACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAkCM,MAAM,CAAC,iBAAiB,CAC7B,MAAmD;QAEnD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC/D,iFAAiF;YACjF,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,6CAA6C;QAC7C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,SAAS,KAAK,4DAA4D,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5B,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 { Result, captureResult, fail, succeed } from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\n\n/**\n * An item that can be collected by some {@link ConvertingCollector | Collector}.\n * @public\n */\nexport interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {\n readonly key: TKEY;\n readonly index: TINDEX | undefined;\n setIndex(index: number): Result<TINDEX>;\n}\n\n/**\n * Infer the key type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\nexport type CollectibleKey<TITEM extends ICollectible> = TITEM extends ICollectible<infer TKEY>\n ? TKEY\n : never;\n\n/**\n * Infer the index type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleIndex<TITEM extends ICollectible> = TITEM extends ICollectible<any, infer TINDEX>\n ? TINDEX\n : never;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation\n * of the item to be added.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactory<TITEM extends ICollectible<any, any>, TSRC> = (\n key: CollectibleKey<TITEM>,\n index: number,\n item: TSRC\n) => Result<TITEM>;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactoryCallback<TITEM extends ICollectible<any, any>> = (\n key: CollectibleKey<TITEM>,\n index: number\n) => Result<TITEM>;\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with\n * a defined, strongly-typed index.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithIndex<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index: TINDEX;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an\n * index converter.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithConverter<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index?: number;\n indexConverter: Validator<TINDEX, unknown> | Converter<TINDEX, unknown> | ConverterFunc<TINDEX, undefined>;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance.\n * @public\n */\nexport type ICollectibleConstructorParams<TKEY extends string = string, TINDEX extends number = number> =\n | ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n | ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>;\n\n/**\n * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be\n * changed once set.\n * @public\n */\nexport class Collectible<TKEY extends string = string, TINDEX extends number = number>\n implements ICollectible<TKEY, TINDEX>\n{\n /**\n * {@link Collections.ICollectible.key}\n */\n public readonly key: TKEY;\n\n /**\n * {@link Collections.ICollectible.index}\n */\n public get index(): TINDEX | undefined {\n return this._index;\n }\n\n protected _index: TINDEX | undefined;\n protected readonly _indexConverter?: Validator<TINDEX, unknown> | Converter<TINDEX, unknown>;\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance\n * with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance with\n * an undefined index and an index converter to validate te index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>);\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>) {\n this.key = params.key;\n if ('indexConverter' in params) {\n this._indexConverter =\n typeof params.indexConverter === 'function'\n ? Converters.generic(params.indexConverter)\n : params.indexConverter;\n if (params.index !== undefined) {\n this._index = this._indexConverter.convert(params.index).orThrow();\n }\n } else {\n /* c8 ignore next 3 - coverage is having a bad day */\n this._index = params.index;\n }\n }\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index\n * converter to validate the index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise\n * @public\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>> {\n return captureResult(() => new Collectible(params));\n }\n\n /**\n * {@link Collections.ICollectible.setIndex}\n */\n public setIndex(index: number): Result<TINDEX> {\n let converted: TINDEX | undefined;\n if (this._indexConverter) {\n const { value, message } = this._indexConverter.convert(index);\n /* c8 ignore next 3 - there's a test for this but coverage is having a bad day */\n if (message) {\n return fail(message);\n }\n converted = value;\n }\n\n if (index === this.index) {\n return succeed(this.index);\n } else if (this._index !== undefined) {\n return fail(`index ${this.index} is immutable and cannot be changed to ${index}`);\n }\n\n /* c8 ignore next 3 - should be impossible */\n if (converted === undefined) {\n return fail(`index ${index} cannot be set on a Collectible without an index converter`);\n }\n\n this._index = converted;\n return succeed(converted);\n }\n}\n"]}
|
|
@@ -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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AmC,GAAG,EAAE,EAAE,aAAa,CAAC,CAAC;QACvF,CAAC;QAED,OAAO,UAAU,CAAC,iBAAiB,CAAwB,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7F,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAA0B;QACnC,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"]}
|
|
@@ -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,GAAG,CAAC,IAAa;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,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yright (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"]}
|