@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.
Files changed (218) hide show
  1. package/dist/index.js.map +1 -0
  2. package/dist/packlets/base/brand.js.map +1 -0
  3. package/dist/packlets/base/index.js.map +1 -0
  4. package/dist/packlets/base/mapResults.js.map +1 -0
  5. package/dist/packlets/base/messageAggregator.js.map +1 -0
  6. package/dist/packlets/base/normalize.js.map +1 -0
  7. package/dist/packlets/base/result.js.map +1 -0
  8. package/dist/packlets/base/utils.js.map +1 -0
  9. package/dist/packlets/collections/aggregatedResultMap.js.map +1 -0
  10. package/dist/packlets/collections/collectible.js.map +1 -0
  11. package/dist/packlets/collections/collector.js.map +1 -0
  12. package/dist/packlets/collections/collectorValidator.js.map +1 -0
  13. package/dist/packlets/collections/common.js.map +1 -0
  14. package/dist/packlets/collections/converters.js.map +1 -0
  15. package/dist/packlets/collections/convertingCollector.js.map +1 -0
  16. package/dist/packlets/collections/convertingCollectorValidator.js.map +1 -0
  17. package/dist/packlets/collections/convertingResultMap.js.map +1 -0
  18. package/dist/packlets/collections/index.js.map +1 -0
  19. package/dist/packlets/collections/keyValueConverters.js.map +1 -0
  20. package/dist/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
  21. package/dist/packlets/collections/readonlyResultMap.js.map +1 -0
  22. package/dist/packlets/collections/resultMap.js.map +1 -0
  23. package/dist/packlets/collections/resultMapValidator.js.map +1 -0
  24. package/dist/packlets/collections/utils.js.map +1 -0
  25. package/dist/packlets/collections/validatingCollector.js.map +1 -0
  26. package/dist/packlets/collections/validatingConvertingCollector.js.map +1 -0
  27. package/dist/packlets/collections/validatingConvertingResultMap.js.map +1 -0
  28. package/dist/packlets/collections/validatingResultMap.js.map +1 -0
  29. package/dist/packlets/conversion/advancedConverters.js.map +1 -0
  30. package/dist/packlets/conversion/baseConverter.js.map +1 -0
  31. package/dist/packlets/conversion/basicConverters.js.map +1 -0
  32. package/dist/packlets/conversion/converter.js.map +1 -0
  33. package/dist/packlets/conversion/converters.js.map +1 -0
  34. package/dist/packlets/conversion/defaultingConverter.js.map +1 -0
  35. package/dist/packlets/conversion/index.js.map +1 -0
  36. package/dist/packlets/conversion/objectConverter.js.map +1 -0
  37. package/dist/packlets/conversion/stringConverter.js.map +1 -0
  38. package/dist/packlets/hash/crcNormalizer.js.map +1 -0
  39. package/dist/packlets/hash/hashingNormalizer.js.map +1 -0
  40. package/dist/packlets/hash/index.js.map +1 -0
  41. package/dist/packlets/logging/bootLogger.js.map +1 -0
  42. package/dist/packlets/logging/index.js.map +1 -0
  43. package/dist/packlets/logging/logReporter.js.map +1 -0
  44. package/dist/packlets/logging/logger.js.map +1 -0
  45. package/dist/packlets/validation/array.js.map +1 -0
  46. package/dist/packlets/validation/boolean.js.map +1 -0
  47. package/dist/packlets/validation/classes.js.map +1 -0
  48. package/dist/packlets/validation/common.js.map +1 -0
  49. package/dist/packlets/validation/compositeId.js.map +1 -0
  50. package/dist/packlets/validation/field.js.map +1 -0
  51. package/dist/packlets/validation/genericValidator.js.map +1 -0
  52. package/dist/packlets/validation/index.js.map +1 -0
  53. package/dist/packlets/validation/number.js.map +1 -0
  54. package/dist/packlets/validation/object.js.map +1 -0
  55. package/dist/packlets/validation/oneOf.js.map +1 -0
  56. package/dist/packlets/validation/string.js.map +1 -0
  57. package/dist/packlets/validation/traits.js.map +1 -0
  58. package/dist/packlets/validation/typeGuard.js.map +1 -0
  59. package/dist/packlets/validation/validator.js.map +1 -0
  60. package/dist/packlets/validation/validatorBase.js.map +1 -0
  61. package/dist/packlets/validation/validators.js.map +1 -0
  62. package/lib/index.d.ts.map +1 -0
  63. package/lib/index.js.map +1 -0
  64. package/lib/packlets/base/brand.d.ts.map +1 -0
  65. package/lib/packlets/base/brand.js.map +1 -0
  66. package/lib/packlets/base/index.d.ts.map +1 -0
  67. package/lib/packlets/base/index.js.map +1 -0
  68. package/lib/packlets/base/mapResults.d.ts.map +1 -0
  69. package/lib/packlets/base/mapResults.js.map +1 -0
  70. package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
  71. package/lib/packlets/base/messageAggregator.js.map +1 -0
  72. package/lib/packlets/base/normalize.d.ts.map +1 -0
  73. package/lib/packlets/base/normalize.js.map +1 -0
  74. package/lib/packlets/base/result.d.ts.map +1 -0
  75. package/lib/packlets/base/result.js.map +1 -0
  76. package/lib/packlets/base/utils.d.ts.map +1 -0
  77. package/lib/packlets/base/utils.js.map +1 -0
  78. package/lib/packlets/collections/aggregatedResultMap.d.ts.map +1 -0
  79. package/lib/packlets/collections/aggregatedResultMap.js.map +1 -0
  80. package/lib/packlets/collections/collectible.d.ts.map +1 -0
  81. package/lib/packlets/collections/collectible.js.map +1 -0
  82. package/lib/packlets/collections/collector.d.ts.map +1 -0
  83. package/lib/packlets/collections/collector.js.map +1 -0
  84. package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
  85. package/lib/packlets/collections/collectorValidator.js.map +1 -0
  86. package/lib/packlets/collections/common.d.ts.map +1 -0
  87. package/lib/packlets/collections/common.js.map +1 -0
  88. package/lib/packlets/collections/converters.d.ts.map +1 -0
  89. package/lib/packlets/collections/converters.js.map +1 -0
  90. package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
  91. package/lib/packlets/collections/convertingCollector.js.map +1 -0
  92. package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
  93. package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
  94. package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
  95. package/lib/packlets/collections/convertingResultMap.js.map +1 -0
  96. package/lib/packlets/collections/index.d.ts.map +1 -0
  97. package/lib/packlets/collections/index.js.map +1 -0
  98. package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
  99. package/lib/packlets/collections/keyValueConverters.js.map +1 -0
  100. package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts.map +1 -0
  101. package/lib/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
  102. package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
  103. package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
  104. package/lib/packlets/collections/resultMap.d.ts.map +1 -0
  105. package/lib/packlets/collections/resultMap.js.map +1 -0
  106. package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
  107. package/lib/packlets/collections/resultMapValidator.js.map +1 -0
  108. package/lib/packlets/collections/utils.d.ts.map +1 -0
  109. package/lib/packlets/collections/utils.js.map +1 -0
  110. package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
  111. package/lib/packlets/collections/validatingCollector.js.map +1 -0
  112. package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
  113. package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
  114. package/lib/packlets/collections/validatingConvertingResultMap.d.ts.map +1 -0
  115. package/lib/packlets/collections/validatingConvertingResultMap.js.map +1 -0
  116. package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
  117. package/lib/packlets/collections/validatingResultMap.js.map +1 -0
  118. package/lib/packlets/conversion/advancedConverters.d.ts.map +1 -0
  119. package/lib/packlets/conversion/advancedConverters.js.map +1 -0
  120. package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
  121. package/lib/packlets/conversion/baseConverter.js.map +1 -0
  122. package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
  123. package/lib/packlets/conversion/basicConverters.js.map +1 -0
  124. package/lib/packlets/conversion/converter.d.ts.map +1 -0
  125. package/lib/packlets/conversion/converter.js.map +1 -0
  126. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  127. package/lib/packlets/conversion/converters.js.map +1 -0
  128. package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
  129. package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
  130. package/lib/packlets/conversion/index.d.ts.map +1 -0
  131. package/lib/packlets/conversion/index.js.map +1 -0
  132. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
  133. package/lib/packlets/conversion/objectConverter.js.map +1 -0
  134. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
  135. package/lib/packlets/conversion/stringConverter.js.map +1 -0
  136. package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -0
  137. package/lib/packlets/hash/crcNormalizer.js.map +1 -0
  138. package/lib/packlets/hash/hashingNormalizer.d.ts.map +1 -0
  139. package/lib/packlets/hash/hashingNormalizer.js.map +1 -0
  140. package/lib/packlets/hash/index.d.ts.map +1 -0
  141. package/lib/packlets/hash/index.js.map +1 -0
  142. package/lib/packlets/logging/bootLogger.d.ts.map +1 -0
  143. package/lib/packlets/logging/bootLogger.js.map +1 -0
  144. package/lib/packlets/logging/index.d.ts.map +1 -0
  145. package/lib/packlets/logging/index.js.map +1 -0
  146. package/lib/packlets/logging/logReporter.d.ts.map +1 -0
  147. package/lib/packlets/logging/logReporter.js.map +1 -0
  148. package/lib/packlets/logging/logger.d.ts.map +1 -0
  149. package/lib/packlets/logging/logger.js.map +1 -0
  150. package/lib/packlets/validation/array.d.ts.map +1 -0
  151. package/lib/packlets/validation/array.js.map +1 -0
  152. package/lib/packlets/validation/boolean.d.ts.map +1 -0
  153. package/lib/packlets/validation/boolean.js.map +1 -0
  154. package/lib/packlets/validation/classes.d.ts.map +1 -0
  155. package/lib/packlets/validation/classes.js.map +1 -0
  156. package/lib/packlets/validation/common.d.ts.map +1 -0
  157. package/lib/packlets/validation/common.js.map +1 -0
  158. package/lib/packlets/validation/compositeId.d.ts.map +1 -0
  159. package/lib/packlets/validation/compositeId.js.map +1 -0
  160. package/lib/packlets/validation/field.d.ts.map +1 -0
  161. package/lib/packlets/validation/field.js.map +1 -0
  162. package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
  163. package/lib/packlets/validation/genericValidator.js.map +1 -0
  164. package/lib/packlets/validation/index.d.ts.map +1 -0
  165. package/lib/packlets/validation/index.js.map +1 -0
  166. package/lib/packlets/validation/number.d.ts.map +1 -0
  167. package/lib/packlets/validation/number.js.map +1 -0
  168. package/lib/packlets/validation/object.d.ts.map +1 -0
  169. package/lib/packlets/validation/object.js.map +1 -0
  170. package/lib/packlets/validation/oneOf.d.ts.map +1 -0
  171. package/lib/packlets/validation/oneOf.js.map +1 -0
  172. package/lib/packlets/validation/string.d.ts.map +1 -0
  173. package/lib/packlets/validation/string.js.map +1 -0
  174. package/lib/packlets/validation/traits.d.ts.map +1 -0
  175. package/lib/packlets/validation/traits.js.map +1 -0
  176. package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
  177. package/lib/packlets/validation/typeGuard.js.map +1 -0
  178. package/lib/packlets/validation/validator.d.ts.map +1 -0
  179. package/lib/packlets/validation/validator.js.map +1 -0
  180. package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
  181. package/lib/packlets/validation/validatorBase.js.map +1 -0
  182. package/lib/packlets/validation/validators.d.ts.map +1 -0
  183. package/lib/packlets/validation/validators.js.map +1 -0
  184. package/package.json +3 -3
  185. package/dist/test/helpers/jest/helpers/fsHelpers.js +0 -139
  186. package/dist/test/helpers/jest/helpers/index.js +0 -2
  187. package/dist/test/helpers/jest/index.js +0 -17
  188. package/dist/test/helpers/jest/matchers/index.js +0 -14
  189. package/dist/test/helpers/jest/matchers/toFail/index.js +0 -23
  190. package/dist/test/helpers/jest/matchers/toFail/predicate.js +0 -5
  191. package/dist/test/helpers/jest/matchers/toFailTest/index.js +0 -28
  192. package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +0 -8
  193. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +0 -24
  194. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +0 -11
  195. package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +0 -29
  196. package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +0 -26
  197. package/dist/test/helpers/jest/matchers/toFailWith/index.js +0 -27
  198. package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +0 -16
  199. package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +0 -27
  200. package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +0 -22
  201. package/dist/test/helpers/jest/matchers/toSucceed/index.js +0 -23
  202. package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +0 -5
  203. package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +0 -24
  204. package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +0 -24
  205. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +0 -53
  206. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +0 -17
  207. package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +0 -27
  208. package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +0 -12
  209. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +0 -27
  210. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +0 -17
  211. package/dist/test/helpers/jest/resolvers/cli.js +0 -10
  212. package/dist/test/helpers/jest/resolvers/ide.js +0 -10
  213. package/dist/test/helpers/jest/ts-utils.js +0 -2
  214. package/dist/test/helpers/jest/types/index.js +0 -3
  215. package/dist/test/helpers/jest/utils/matcherHelpers.js +0 -47
  216. package/dist/test/helpers/jest/utils/snapshotResolver.js +0 -11
  217. package/dist/test/unit/collections/helpers.js +0 -106
  218. package/dist/test/unit/hashTextEncodeCompat.js +0 -23
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAkB,cAAc,EAAU,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEnG,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAsB/D;;;;;GAKG;AACH,MAAM,OAAO,mBAIX,SAAQ,SAAgB;IAGxB;;;OAGG;IACH,YAAmB,MAA0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S,EAAE,QAAS,CAAC;aACzC,iBAAiB,CAAwB,eAAe,CAAC;aACzD,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,cAAc,CACnB,GAAG,SAAS,4CAA4C,IAAI,CAAC,GAAG,EAAE,EAClE,aAAa,CACd,CAAC;YACJ,CAAC;YACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC5C,CAAC,CAAC;aACD,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;OAOG;IACO,YAAY,CACpB,QAAkD;QAElD,OAAO,OAAO,QAAQ,KAAK,UAAU,CAAC;IACxC,CAAC;IAED;;;;;;;;OAQG;IACO,eAAe,CACvB,SAAwC,EACxC,QAAmD;QAEnD,OAAO,QAAQ,KAAK,SAAS,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACO,UAAU,CAClB,GAA0B,EAC1B,QAAkD;QAElD,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1G,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, failWithDetail, Result, succeedWithDetail } from '../base';\nimport { ICollectible, CollectibleFactoryCallback, CollectibleFactory, CollectibleKey } from './collectible';\nimport { Collector, CollectorResultDetail } from './collector';\nimport { KeyValueEntry } from './common';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @public\n */\nexport interface IConvertingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /**\n * The default {@link Collections.CollectibleFactory | factory} to create items.\n */\n factory: CollectibleFactory<TITEM, TSRC>;\n /**\n * An optional array of entries to add to the collector.\n */\n entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];\n}\n\n/**\n * A {@link Collector | collector} that collects {@link Collections.ICollectible | ICollectible} items,\n * optionally converting them from a source representation to the target representation using a factory\n * supplied at default or at the time of collection.\n * @public\n */\nexport class ConvertingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> extends Collector<TITEM> {\n private _factory: CollectibleFactory<TITEM, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @param params - Parameters for constructing the collector.\n */\n public constructor(params: IConvertingCollectorConstructorParams<TITEM, TSRC>) {\n super();\n this._factory = params.factory;\n params.entries?.forEach((entry) => {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n });\n }\n\n /**\n * Creates a new {@link Collections.ConvertingCollector | ConvertingCollector}.\n * @param params - Required parameters for constructing the collector.\n * @returns Returns {@link Success | Success} with the new collector if it is created, or {@link Failure | Failure}\n * with an error if the collector cannot be created.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public static createConvertingCollector<TITEM extends ICollectible<any, any>, TSRC = TITEM>(\n params: IConvertingCollectorConstructorParams<TITEM, TSRC>\n ): Result<ConvertingCollector<TITEM, TSRC>> {\n return captureResult(() => new ConvertingCollector(params));\n }\n\n /**\n * Adds an item to the collection, failing if a different item with the same key already exists. Note\n * that adding an object that is already in the collection again will succeed without updating the collection.\n * @param item - The item to add.\n * @returns Returns {@link DetailedSuccess | Success} with the item and detail `added` if it was added\n * or detail `exists` if the item was already in the map. Returns {@link DetailedFailure | Failure} with\n * an error message and appropriate detail if the item could not be added.\n */\n public add(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using the default {@link Collections.CollectibleFactory | factory}\n * at a specified key, failing if an item with that key already exists.\n * @param key - The key of the item to add.\n * @param item - The source representation of the item to be added.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n * @public\n */\n public add(key: CollectibleKey<TITEM>, item: TSRC): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using a supplied {@link Collections.CollectibleFactoryCallback | factory callback}\n * at a specified key, failing if an item with that key already exists or if the created item is invalid.\n * @param key - The key of the item to add.\n * @param cb - The factory callback to create the item.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n */\n public add(\n key: CollectibleKey<TITEM>,\n cb: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n public add(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this._overloadIsItem(keyOrItem, itemOrCb)) {\n return super.add(keyOrItem);\n }\n return this._buildItem(keyOrItem, itemOrCb!)\n .withFailureDetail<CollectorResultDetail>('invalid-value')\n .onSuccess((item) => {\n return super.add(item);\n });\n }\n\n /**\n * Gets an existing item with a key matching that of the supplied item, or adds the supplied\n * item to the collector if no item with that key exists.\n * @param item - The item to get or add.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(item: TITEM): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The key of the item to get or add.\n * @param callback - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(\n key: CollectibleKey<TITEM>,\n callback: CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an item by key if it exists, or creates a new item and adds it using the default {@link Collections.CollectibleFactory | factory} if not.\n * @param key - The key of the item to retrieve.\n * @param item - The source representation of the item to be added if it does not exist.\n * @returns Returns {@link Success | Success} with the item if it exists or could be created, or {@link Failure | Failure} with an error if the\n * item cannot be created and indexed.\n */\n public getOrAdd(key: CollectibleKey<TITEM>, item: TSRC): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this._overloadIsItem(keyOrItem, itemOrCb)) {\n return super.getOrAdd(keyOrItem);\n }\n\n if (this.has(keyOrItem)) {\n return this.get(keyOrItem);\n }\n\n return this._buildItem(keyOrItem, itemOrCb!)\n .withFailureDetail<CollectorResultDetail>('invalid-value')\n .onSuccess((item) => {\n if (item.key !== keyOrItem) {\n return failWithDetail<TITEM, CollectorResultDetail>(\n `${keyOrItem}: key mismatch - item has unexpected key ${item.key}`,\n 'invalid-key'\n );\n }\n return succeedWithDetail(item, 'success');\n })\n .onSuccess((item) => {\n return super.add(item);\n });\n }\n\n /**\n * Helper method for derived classes to determine if a supplied\n * itemOrCb parameter is a factory callback.\n * @param itemOrCb - Overloaded parameter is either `CollectibleKey<TITEM>` or\n * a {@link Collections.CollectibleFactoryCallback | factory callback}.\n * @returns Returns `true` if the parameter is a factory callback, `false` otherwise.\n * @public\n */\n protected _isFactoryCB(\n itemOrCb: TSRC | CollectibleFactoryCallback<TITEM>\n ): itemOrCb is CollectibleFactoryCallback<TITEM> {\n return typeof itemOrCb === 'function';\n }\n\n /**\n * Helper method for derived classes to determine if a supplied\n * keyOrItem parameter is an item.\n * @param keyOrItem - Overloaded parameter is either `CollectibleKey<TITEM>` or `TITEM`.\n * @param itemOrCb - Overloaded parameter is either `TSRC`, a {@link Collections.CollectibleFactoryCallback | factory callback}\n * or `undefined`.\n * @returns Returns `true` if the parameter is an item, `false` otherwise.\n * @public\n */\n protected _overloadIsItem(\n keyOrItem: CollectibleKey<TITEM> | TITEM,\n itemOrCb?: TSRC | CollectibleFactoryCallback<TITEM>\n ): keyOrItem is TITEM {\n return itemOrCb === undefined;\n }\n\n /**\n * Helper method for derived classes to build an item from a key and a source representation using\n * a default or supplied factory.\n * @param key - The key of the item to build.\n * @param itemOrCb - The source representation of the item to build, or a factory callback to create it.\n * @returns Returns {@link Success | Success} with the item if it is built, or {@link Failure | Failure}\n * with an error if the item cannot be built.\n * @public\n */\n protected _buildItem(\n key: CollectibleKey<TITEM>,\n itemOrCb: TSRC | CollectibleFactoryCallback<TITEM>\n ): Result<TITEM> {\n return this._isFactoryCB(itemOrCb) ? itemOrCb(key, this.size) : this._factory(key, this.size, itemOrCb);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertingCollectorValidator.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingCollectorValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,cAAc,EAAE,MAAM,SAAS,CAAC;AAwBzD;;;;;GAKG;AACH,MAAM,OAAO,4BAA4B;IAQvC,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;IACtC,CAAC;IAID;;;OAGG;IACH,YAAmB,MAA8D;QAC/E,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;IACtC,CAAC;IAoBM,GAAG,CACR,GAAW,EACX,cAA6E;QAE7E,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,cAAc,CAAC,GAAG,GAAG,kBAAkB,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC;IA6BM,QAAQ,CACb,GAAW,EACX,cAA2D;QAE3D,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,cAAc,CAAC,EAAE,CAAC;YACxD,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;YACtE,IAAI,SAAS,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC1B,OAAO,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7D,CAAC;YACD,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC;YACjC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAClD,IAAI,SAAS,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC1B,OAAO,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7D,CAAC;YACD,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAA4B,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,6BAA6B,CACrC,KAAkD;QAElD,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult, failWithDetail } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { CollectibleFactoryCallback, CollectibleKey, ICollectible } from './collectible';\nimport { CollectorResultDetail } from './collector';\nimport { ConvertingCollector } from './convertingCollector';\nimport { IReadOnlyCollectorValidator } from './collectorValidator';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}.\n * @public\n */\nexport interface IConvertingCollectorValidatorCreateParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /** The converting collector to validate access to. */\n collector: ConvertingCollector<TITEM, TSRC>;\n /** The key-value converters for validation. */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n}\n\n/**\n * A {@link Collections.ConvertingCollector | ConvertingCollector} wrapper which validates weakly-typed keys\n * and values before calling the wrapped collector. Unlike the basic {@link Collections.CollectorValidator | CollectorValidator},\n * the converting collector expects the items to be in the source type of the converting collector, not the target type.\n * @public\n */\nexport class ConvertingCollectorValidator<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> implements IReadOnlyCollectorValidator<TITEM>\n{\n public readonly converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n public get map(): IReadOnlyResultMap<CollectibleKey<TITEM>, TITEM> {\n return this._collector.toReadOnly();\n }\n\n protected _collector: ConvertingCollector<TITEM, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}.\n * @param params - Required parameters for constructing the collector validator.\n */\n public constructor(params: IConvertingCollectorValidatorCreateParams<TITEM, TSRC>) {\n this._collector = params.collector;\n this.converters = params.converters;\n }\n\n /**\n * Adds an item to the collector using the default factory at a specified key,\n * failing if an item with that key already exists.\n * @param key - The weakly-typed key of the item to add.\n * @param value - The source representation of the item to be added.\n * @returns Returns {@link Success | Success} with the item if it is added, or {@link Failure | Failure} with\n * an error if the item cannot be created and indexed.\n */\n public add(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Adds an item to the collector using a supplied factory callback\n * at a specified key, validating the key first.\n */\n public add(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n public add(\n key: string,\n valueOrFactory: unknown | ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (this.has(key)) {\n return failWithDetail(`${key}: already exists`, 'exists');\n }\n return this.getOrAdd(key, valueOrFactory);\n }\n\n /**\n * {@inheritDoc Collections.Collector.get}\n */\n public get(key: string): DetailedResult<TITEM, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._collector.get(k);\n });\n }\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * by converting the supplied weakly-typed value if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param value - The weakly-typed source value to convert and add if the key does not exist.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(key: string, value: unknown): DetailedResult<TITEM, CollectorResultDetail>;\n\n /**\n * Gets an existing item with a key matching the supplied key, or adds a new item to the collector\n * using a factory callback if no item with that key exists.\n * @param key - The weakly-typed key of the item to get or add.\n * @param factory - The factory callback to create the item.\n * @returns Returns {@link DetailedSuccess | Success} with the item stored in the collector -\n * detail `exists` indicates that an existing item was returned and detail `added` indicates\n * that the item was added. Returns {@link DetailedFailure | Failure} with an error and\n * appropriate detail if the item could not be added.\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<CollectibleKey<TITEM>, TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail>;\n\n public getOrAdd(\n key: string,\n valueOrFactory: unknown | CollectibleFactoryCallback<TITEM>\n ): DetailedResult<TITEM, CollectorResultDetail> {\n if (!this._isCollectibleFactoryCallback(valueOrFactory)) {\n const converted = this.converters.convertEntry([key, valueOrFactory]);\n if (converted.isFailure()) {\n return failWithDetail(converted.message, converted.detail);\n }\n const [vk, vs] = converted.value;\n return this._collector.getOrAdd(vk, vs);\n } else {\n const converted = this.converters.convertKey(key);\n if (converted.isFailure()) {\n return failWithDetail(converted.message, converted.detail);\n }\n return this._collector.getOrAdd(converted.value, valueOrFactory);\n }\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n public has(key: string): boolean {\n return this._collector.has(key as CollectibleKey<TITEM>);\n }\n\n /**\n * {@inheritDoc Collections.Collector.toReadOnly}\n */\n public toReadOnly(): IReadOnlyCollectorValidator<TITEM> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.CollectibleFactoryCallback | CollectibleFactoryCallback},\n * `false` otherwise.\n * @public\n */\n protected _isCollectibleFactoryCallback(\n value: unknown | CollectibleFactoryCallback<TITEM>\n ): value is CollectibleFactoryCallback<TITEM> {\n return typeof value === 'function';\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAA0B,MAAM,SAAS,CAAC;AAGhE,OAAO,EACL,2BAA2B,EAG5B,MAAM,+BAA+B,CAAC;AAwBvC;;;;GAIG;AACH,MAAM,OAAO,iCAAiC;IAU5C;;;;OAIG;IACH,YAAmB,KAAc,EAAE,MAAuD;QACxF,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,GAAO,EAAE,KAAW;QAC7B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,GAAG,CAAC,GAAO,EAAE,KAAW;QAC7B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,GAAO,EAAE,KAAW;QAChC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IAC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;IAC9B,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,EAAgC,EAAE,OAAiB;QAChE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;IAClC,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,mBAKX,SAAQ,2BAA8C;IAYtD;;;OAGG;IACH,YAAmB,MAAyE;QAC1F,KAAK,CAAC,MAA0E,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,iCAAiC,CAA6B,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtG,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAU,MAAM,CAM3B,MAAyE;QAEzE,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;OAKG;IACa,gBAAgB,CAAC,GAAO;QACtC,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACa,WAAW;QACzB,KAAK,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, Result } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\nimport {\n ReadOnlyConvertingResultMap,\n ConvertingResultMapValueConverter,\n IReadOnlyConvertingResultMapConstructorParams\n} from './readOnlyConvertingResultMap';\nimport { IResultMap, ResultMapValueFactory } from './resultMap';\n\n/**\n * Parameters for constructing a {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @public\n */\nexport interface IConvertingResultMapConstructorParams<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> {\n /**\n * The inner map containing source values.\n */\n inner: TSRCMAP;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n}\n\n/**\n * A wrapper around a mutable result map that invalidates cache entries\n * in the parent {@link Collections.ConvertingResultMap | ConvertingResultMap} when mutations occur.\n * @public\n */\nexport class CacheInvalidatingResultMapWrapper<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> implements IResultMap<TK, TSRC>\n{\n private readonly _inner: TSRCMAP;\n private readonly _parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>;\n\n /**\n * Constructs a new cache-invalidating wrapper.\n * @param inner - The inner map to wrap.\n * @param parent - The parent converting map whose cache should be invalidated.\n */\n public constructor(inner: TSRCMAP, parent: ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>) {\n this._inner = inner;\n this._parent = parent;\n }\n\n /**\n * The number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Adds a key/value pair to the map if the key does not already exist.\n * Invalidates the cache entry for the key.\n * @param key - The key to add.\n * @param value - The value to add.\n * @returns The result of the add operation.\n */\n public add(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.add(key, value);\n }\n\n /**\n * Sets a key/value pair in the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns The result of the set operation.\n */\n public set(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.set(key, value);\n }\n\n /**\n * Updates an existing key in the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to update.\n * @param value - The new value.\n * @returns The result of the update operation.\n */\n public update(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.update(key, value);\n }\n\n /**\n * Deletes a key from the map.\n * Invalidates the cache entry for the key.\n * @param key - The key to delete.\n * @returns The result of the delete operation.\n */\n public delete(key: TK): DetailedResult<TSRC, ResultMapResultDetail> {\n this._parent._clearCacheEntry(key);\n return this._inner.delete(key);\n }\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns The result of the get operation.\n */\n public get(key: TK): DetailedResult<TSRC, ResultMapResultDetail> {\n return this._inner.get(key);\n }\n\n /**\n * Gets a value from the map, or adds a supplied value if it does not exist.\n * Invalidates the cache entry for the key if a new value is added.\n * @param key - The key to retrieve or add.\n * @param value - The value to add if the key does not exist.\n * @returns The result of the operation.\n */\n public getOrAdd(key: TK, value: TSRC): DetailedResult<TSRC, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory if it does not exist.\n * Invalidates the cache entry for the key if a new value is added.\n * @param key - The key to retrieve or add.\n * @param factory - A factory function to create the value if the key does not exist.\n * @returns The result of the operation.\n */\n public getOrAdd(\n key: TK,\n factory: ResultMapValueFactory<TK, TSRC>\n ): DetailedResult<TSRC, ResultMapResultDetail>;\n\n public getOrAdd(\n key: TK,\n valueOrFactory: TSRC | ResultMapValueFactory<TK, TSRC>\n ): DetailedResult<TSRC, ResultMapResultDetail> {\n const result =\n typeof valueOrFactory === 'function'\n ? this._inner.getOrAdd(key, valueOrFactory as ResultMapValueFactory<TK, TSRC>)\n : this._inner.getOrAdd(key, valueOrFactory);\n\n if (result.isSuccess() && result.detail === 'added') {\n this._parent._clearCacheEntry(key);\n }\n return result;\n }\n\n /**\n * Checks if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Clears all entries from the map.\n * Clears the entire cache.\n */\n public clear(): void {\n this._parent._clearCache();\n this._inner.clear();\n }\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public entries(): IterableIterator<KeyValueEntry<TK, TSRC>> {\n return this._inner.entries();\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n public values(): IterableIterator<TSRC> {\n return this._inner.values();\n }\n\n /**\n * Calls a callback for each entry in the map.\n * @param cb - The callback to call for each entry.\n * @param thisArg - Optional `this` argument for the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TSRC>, thisArg?: unknown): void {\n this._inner.forEach(cb, thisArg);\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TSRC>> {\n return this._inner[Symbol.iterator]();\n }\n\n /**\n * Gets a read-only version of this map.\n * @returns A read-only version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TSRC> {\n return this._inner.toReadOnly();\n }\n}\n\n/**\n * A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type\n * and returns lazily-converted, cached values of a target type. Exposes the inner map\n * via a {@link Collections.CacheInvalidatingResultMapWrapper | source} property that\n * invalidates cache entries when mutations occur.\n * @public\n */\nexport class ConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {\n /**\n * A wrapper around the inner map that invalidates cache entries when mutations occur.\n * Use this property to add, update, or delete source values.\n */\n public readonly source: CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>;\n\n /**\n * The inner map, typed as the specific source map type.\n */\n protected readonly _typedInner: TSRCMAP;\n\n /**\n * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>) {\n super(params as IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>);\n this._typedInner = params.inner;\n this.source = new CacheInvalidatingResultMapWrapper<TK, TSRC, TTARGET, TSRCMAP>(params.inner, this);\n }\n\n /**\n * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n >(\n params: IConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>\n ): Result<ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>> {\n return captureResult(() => new ConvertingResultMap(params));\n }\n\n /**\n * Clears a single entry from the cache.\n * This method is public to allow the cache-invalidating wrapper to call it.\n * @param key - The key to clear from the cache.\n * @internal\n */\n public override _clearCacheEntry(key: TK): void {\n super._clearCacheEntry(key);\n }\n\n /**\n * Clears all entries from the cache.\n * This method is public to allow the cache-invalidating wrapper to call it.\n * @internal\n */\n public override _clearCache(): void {\n super._clearCache();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Utils from './utils';\n\nexport * from './collectible';\nexport * from './convertingCollector';\nexport * from './convertingResultMap';\nexport * from './collector';\nexport * from './collectorValidator';\nexport * from './convertingCollectorValidator';\nexport * from './validatingConvertingCollector';\nexport * from './common';\nexport * from './keyValueConverters';\nexport * from './readonlyResultMap';\nexport * from './readOnlyConvertingResultMap';\nexport * from './resultMap';\nexport * from './resultMapValidator';\nexport * from './validatingCollector';\nexport * from './validatingConvertingResultMap';\nexport * from './validatingResultMap';\nexport * from './aggregatedResultMap';\n\nexport { Utils };\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyValueConverters.js","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAEL,cAAc,EACd,iBAAiB,EAEjB,OAAO,EACP,iBAAiB,EAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EAA4B,UAAU,EAAE,MAAM,eAAe,CAAC;AAuBrE;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAU7B;;;OAGG;IACH,YAAmB,EAAE,GAAG,EAAE,KAAK,EAA+C;QAC5E,IAAI,CAAC,GAAG,GAAG,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAA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,CAAC;QACvE,CAAC;QACD,sBAAsB;QACtB,OAAO,cAAc,CAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACxF,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,OAA0B;QAC9C,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAA4B,EAAE,CAAC;QAC9C,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;iBACvB,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;gBACf,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAClB,OAAO,iBAAiB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC,CAAC;iBACD,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACnD,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.\n * @public\n */\nexport interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;\n\n /**\n * Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;\n}\n\n/**\n * Helper class for converting strongly-typed keys, values, or entries\n * from unknown values.\n * @public\n */\nexport class KeyValueConverters<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly key: Validator<TK, unknown> | Converter<TK, unknown>;\n /**\n * Required value {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly value: Validator<TV, unknown> | Converter<TV, unknown>;\n\n /**\n * Constructs a new key-value validator.\n * @param params - Key and value converters or validators.\n */\n public constructor({ key, value }: IKeyValueConverterConstructorParams<TK, TV>) {\n this.key = typeof key === 'function' ? Converters.generic(key) : key;\n this.value = typeof value === 'function' ? Converters.generic(value) : value;\n }\n\n /**\n * Converts a supplied unknown to a valid key value of type `<TK>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted key value and 'success' detail if the key is valid,\n * or `Failure` with an error message and 'invalid-key' detail if the key is invalid.\n */\n public convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail> {\n return this.key.convert(key).withFailureDetail('invalid-key');\n }\n\n /**\n * Converts a supplied unknown to a valid value of type `<TV>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted value and 'success' detail if the value is valid,\n * or `Failure` with an error message and 'invalid-value' detail if the value is invalid.\n */\n public convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.value.convert(key).withFailureDetail('invalid-value');\n }\n\n /**\n * Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.\n * @param entry - The unknown to be converted.\n * @returns `Success` with the converted entry and 'success' detail if the entry\n * is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if\n * the entry is invalid\n */\n public convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail> {\n if (Array.isArray(entry) && entry.length === 2) {\n const errors = new MessageAggregator();\n const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();\n const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();\n if (key && value) {\n return succeedWithDetail([key, value], 'success');\n }\n const detail = key ? 'invalid-value' : 'invalid-key';\n return failWithDetail(`invalid entry: ${errors.toString()}`, detail);\n }\n /* c8 ignore next 2 */\n return failWithDetail(`malformed entry: \"${JSON.stringify(entry)}\"`, 'invalid-value');\n }\n\n /**\n * Converts a supplied iterable of unknowns to valid key-value pairs.\n * @param entries - The iterable of unknowns to be converted.\n * @returns `Success` with an array of converted key-value pairs if all entries are valid,\n * or `Failure` with an error message if any entry is invalid.\n */\n public convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]> {\n const errors = new MessageAggregator();\n const converted: KeyValueEntry<TK, TV>[] = [];\n for (const element of entries) {\n this.convertEntry(element)\n .onSuccess((e) => {\n converted.push(e);\n return succeedWithDetail(e, 'success');\n })\n .aggregateError(errors);\n }\n return errors.returnOrReport(succeed(converted));\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readOnlyConvertingResult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C,CAAC;YAC3E,KAAK,MAAM;gBACT,MAAA,IAAI,CAAC,OAAO,0CAAE,GAAG,CAAC,SAAS,EAAE,8BAA8B,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;gBACtF,MAAM;QACV,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;OAGG;IACO,gBAAgB,CAAC,GAAO;QAChC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACO,WAAW;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, failWithDetail, Result, succeedWithDetail } from '../base';\nimport { ILogger } from '../logging';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * A function that converts a source value to a target value.\n * @public\n */\nexport type ConvertingResultMapValueConverter<TK extends string, TSRC, TTARGET> = (\n src: TSRC,\n key: TK\n) => Result<TTARGET>;\n\n/**\n * Error handling behavior for conversion failures during iteration.\n * - `'ignore'`: Silently skip failed conversions (default behavior)\n * - `'warn'`: Log warning and skip failed conversions\n * - `'fail'`: Throw error on first conversion failure\n * @public\n */\nexport type ConversionErrorHandling = 'ignore' | 'warn' | 'fail';\n\n/**\n * Parameters for constructing a {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @public\n */\nexport interface IReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {\n /**\n * The inner map containing source values.\n */\n inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * Error handling behavior for conversion failures during iteration.\n * Defaults to `'ignore'` (silently skip failed conversions).\n */\n onConversionError?: ConversionErrorHandling;\n\n /**\n * Optional logger for warnings when `onConversionError` is `'warn'`.\n */\n logger?: ILogger;\n}\n\n/**\n * A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * of source type and returns lazily-converted, cached values of a target type.\n * @public\n */\nexport class ReadOnlyConvertingResultMap<TK extends string, TSRC, TTARGET>\n implements IReadOnlyResultMap<TK, TTARGET>\n{\n /**\n * The inner map containing source values.\n */\n protected readonly _inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n protected readonly _converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * Cache of converted target values.\n */\n protected readonly _cache: Map<TK, TTARGET>;\n\n /**\n * Error handling behavior for conversion failures during iteration.\n */\n protected readonly _onConversionError: ConversionErrorHandling;\n\n /**\n * Optional logger for warnings.\n */\n protected readonly _logger?: ILogger;\n\n /**\n * Constructs a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>) {\n this._inner = params.inner;\n this._converter = params.converter;\n this._cache = new Map<TK, TTARGET>();\n this._onConversionError = params.onConversionError ?? 'ignore';\n this._logger = params.logger;\n }\n\n /**\n * Creates a new {@link Collections.ReadOnlyConvertingResultMap | ReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static create<TK extends string, TSRC, TTARGET>(\n params: IReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>\n ): Result<ReadOnlyConvertingResultMap<TK, TSRC, TTARGET>> {\n return captureResult(() => new ReadOnlyConvertingResultMap(params));\n }\n\n /**\n * The number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Gets a converted value from the map by key.\n * @param key - The key to retrieve.\n * @returns `Success` with the converted value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found, or `Failure` with\n * detail `invalid-value` if conversion failed.\n */\n public get(key: TK): DetailedResult<TTARGET, ResultMapResultDetail> {\n const cached = this._cache.get(key);\n if (cached !== undefined) {\n return succeedWithDetail(cached, 'exists');\n }\n\n return this._inner.get(key).onSuccess((src) => {\n return this._convertAndCache(key, src);\n });\n }\n\n /**\n * Checks if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Returns an iterator over the map entries with converted values.\n * @returns An iterator over the map entries.\n */\n public *entries(): IterableIterator<KeyValueEntry<TK, TTARGET>> {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n yield [key, target];\n }\n }\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Returns an iterator over the converted map values.\n * @returns An iterator over the map values.\n */\n public *values(): IterableIterator<TTARGET> {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n yield target;\n }\n }\n }\n\n /**\n * Calls a callback for each entry in the map with converted values.\n * @param cb - The callback to call for each entry.\n * @param thisArg - Optional `this` argument for the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TTARGET>, thisArg?: unknown): void {\n for (const [key, src] of this._inner.entries()) {\n const target = this._getOrConvert(key, src);\n if (target !== undefined) {\n cb.call(thisArg, target, key, this);\n }\n }\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TTARGET>> {\n return this.entries();\n }\n\n /**\n * Gets a read-only version of this map.\n * @returns A read-only version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TTARGET> {\n return this;\n }\n\n /**\n * Converts a source value to a target value and caches the result.\n * @param key - The key of the value.\n * @param src - The source value to convert.\n * @returns `Success` with the converted value if successful, `Failure` otherwise.\n */\n protected _convertAndCache(key: TK, src: TSRC): DetailedResult<TTARGET, ResultMapResultDetail> {\n const result = this._converter(src, key);\n if (result.isFailure()) {\n return failWithDetail(result.message, 'invalid-value');\n }\n this._cache.set(key, result.value);\n return succeedWithDetail(result.value, 'exists');\n }\n\n /**\n * Gets a cached value or converts and caches a source value.\n * Used by iterators. Handles conversion failures according to `_onConversionError`.\n * @param key - The key of the value.\n * @param src - The source value to convert if not cached.\n * @returns The converted value, or `undefined` if conversion failed.\n * @throws Error if `_onConversionError` is `'fail'` and conversion fails.\n */\n protected _getOrConvert(key: TK, src: TSRC): TTARGET | undefined {\n const cached = this._cache.get(key);\n if (cached !== undefined) {\n return cached;\n }\n\n const result = this._converter(src, key);\n if (result.isSuccess()) {\n this._cache.set(key, result.value);\n return result.value;\n }\n\n switch (this._onConversionError) {\n case 'fail':\n throw new Error(`Conversion failed for key '${key}': ${result.message}`);\n case 'warn':\n this._logger?.log('warning', `Conversion failed for key '${key}': ${result.message}`);\n break;\n }\n return undefined;\n }\n\n /**\n * Clears a single entry from the cache.\n * @param key - The key to clear from the cache.\n */\n protected _clearCacheEntry(key: TK): void {\n this._cache.delete(key);\n }\n\n /**\n * Clears all entries from the cache.\n */\n protected _clearCache(): void {\n this._cache.clear();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readonlyResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/readonlyResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult } from '../base';\nimport { KeyValueEntry } from './common';\n\n/**\n * Additional success or failure details for {@link Collections.ResultMap | ResultMap} calls.\n * @public\n */\nexport type ResultMapResultDetail =\n | 'added'\n | 'deleted'\n | 'exists'\n | 'failure'\n | 'invalid-key'\n | 'invalid-value'\n | 'not-found'\n | 'success'\n | 'updated';\n\n/**\n * Callback for {@link Collections.ResultMap | ResultMap} `forEach` method.\n * @public\n */\nexport type ResultMapForEachCb<TK extends string = string, TE = unknown> = (\n value: TE,\n key: TK,\n map: IReadOnlyResultMap<TK, TE>,\n thisArg?: unknown\n) => void;\n\n/**\n * A readonly `ReadonlyMap<TK, TV>`-like object which reports success or failure\n * with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {\n /**\n * Returns the number of entries in the map.\n */\n readonly size: number;\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n entries(): IterableIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n forEach(cb: ResultMapForEachCb, arg?: unknown): void;\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Returns `true` if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n has(key: TK): boolean;\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n keys(): IterableIterator<TK>;\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n values(): IterableIterator<TV>;\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>>;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/resultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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AC;IAED;;;OAGG;IACI,MAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,CAAC,MAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,wBAAwB,CAChC,KAAyC;QAEzC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, failWithDetail, Result, succeed, succeedWithDetail } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapForEachCb, ResultMapResultDetail } from './readonlyResultMap';\nimport { isIterable } from './utils';\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<TK, TV>>;\n}\n\n/**\n * Deferred constructor for the {@link Collections.ResultMap.getOrAdd | getOrAdd} method.\n * @public\n */\nexport type ResultMapValueFactory<TK extends string = string, TV = unknown> = (key: TK) => Result<TV>;\n\n/**\n * Interface for a mutable {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {\n /**\n * Sets a key/value pair in the map if the key does not already exist.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the value and detail `added` if the key was added,\n * `Failure` with detail `exists` if the key already exists. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Sets a key/value pair in the map regardless of whether the key already exists.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the new value and the detail `updated` if the\n * key was found and updated, `Success` with the new value and detail\n * `added` if the key was not found and added. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Updates the value associated with a key in the map.\n * @param key - The key to update.\n * @param value - The value to set.\n * @returns `Success` with the value and detail 'updated' if the key was found\n * and the value updated, `Failure` an error message and with detail `not-found`\n * if the key was not found, or with detail 'invalid-key' or 'invalid-value'\n * if either is invalid.\n */\n update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Deletes a key from the map.\n * @param key - The key to delete.\n * @returns `Success` with the previous value and the detail 'deleted'\n * if the key was found and deleted, `Failure` with detail 'not-found'\n * if the key was not found, or with detail 'invalid-key' if the key is invalid.\n */\n delete(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a supplied value if it does not exist.\n * @param key - The key to be retrieved or created.\n * @param value - The value to add if the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Success` with the value and detail `added` if the key was not found and added.\n * Fails with detail 'invalid-key' or 'invalid-value' and an error message if either\n * is invalid.\n * {@label WITH_VALUE}\n */\n getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory function if it does not exist.\n * @param key - The key of the element to be retrieved or created.\n * @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if\n * the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found, `Success` with\n * the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'\n * or 'invalid-value' and an error message if either is invalid.\n * {@label WITH_FACTORY}\n */\n getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n entries(): IterableIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * Returns the number of entries in the map.\n */\n readonly size: number;\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n keys(): IterableIterator<TK>;\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n values(): IterableIterator<TV>;\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void;\n\n /**\n * Clears all entries from the map.\n */\n clear(): void;\n\n /**\n * Gets a readonly version of this map.\n */\n toReadOnly(): IReadOnlyResultMap<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} class as a `Map<TK, TV>`-like object which\n * reports success or failure with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport class ResultMap<TK extends string = string, TV = unknown> implements IResultMap<TK, TV> {\n /**\n * Protected raw access to the inner `Map<TK, TV>` object.\n * @public\n */\n protected readonly _inner: Map<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param iterable - An iterable to initialize the map.\n */\n public constructor(iterable?: Iterable<KeyValueEntry<TK, TV>>);\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param params - An optional set of parameters to configure the map.\n */\n public constructor(params: IResultMapConstructorParams);\n\n /**\n * Constructs a new {@link Collections.ResultMap | ResultMap}.\n * @param iterableOrParams - An iterable to initialize the map, or a set of parameters\n * to configure the map.\n */\n public constructor(\n iterableOrParams?: Iterable<KeyValueEntry<TK, TV>> | IResultMapConstructorParams<TK, TV>\n ) {\n const params = isIterable(iterableOrParams) ? { entries: iterableOrParams } : iterableOrParams ?? {};\n this._inner = new Map(params.entries);\n }\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param elements - An optional iterable to initialize the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n elements: Iterable<KeyValueEntry<TK, TV>>\n ): Result<ResultMap<TK, TV>>;\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param params - An optional set of parameters to configure the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n params?: IResultMapConstructorParams<TK, TV>\n ): Result<ResultMap<TK, TV>>;\n\n /**\n * Creates a new {@link Collections.ResultMap | ResultMap}.\n * @param elementsOrParams - An optional iterable to initialize the map, or a set of parameters\n * to configure the map.\n * @returns `Success` with the new map, or `Failure` with error details\n * if an error occurred.\n * @public\n */\n public static create<TK extends string = string, TV = unknown>(\n elementsOrParams?: Iterable<KeyValueEntry<TK, TV>> | IResultMapConstructorParams<TK, TV>\n ): Result<ResultMap<TK, TV>> {\n return captureResult(() => new ResultMap(elementsOrParams as IResultMapConstructorParams<TK, TV>));\n }\n\n /**\n * Sets a key/value pair in the map if the key does not already exist.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the value and detail `added` if the key was added,\n * `Failure` with detail `exists` if the key already exists. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n public add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return failWithDetail(`${key}: already exists.`, 'exists');\n }\n this._inner.set(key, value);\n return succeedWithDetail(value, 'added');\n }\n\n /**\n * Clears the map.\n */\n public clear(): void {\n this._inner.clear();\n }\n\n /**\n * Deletes a key from the map.\n * @param key - The key to delete.\n * @returns `Success` with the previous value and the detail 'deleted'\n * if the key was found and deleted, `Failure` with detail 'not-found'\n * if the key was not found, or with detail 'invalid-key' if the key is invalid.\n */\n public delete(key: TK): DetailedResult<TV, ResultMapResultDetail> {\n const was = this._inner.get(key);\n if (this._inner.delete(key)) {\n return succeedWithDetail(was!, 'deleted');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Returns an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public entries(): IterableIterator<KeyValueEntry<TK, TV>> {\n return this._inner.entries();\n }\n\n /**\n * Calls a function for each entry in the map.\n * @param cb - The function to call for each entry.\n * @param arg - An optional argument to pass to the callback.\n */\n public forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void {\n for (const [key, value] of this._inner.entries()) {\n cb(value, key as TK, this, arg);\n }\n }\n\n /**\n * Gets a value from the map.\n * @param key - The key to retrieve.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Failure` with detail `not-found` if the key was not found or with detail\n * `invalid-key` if the key is invalid.\n */\n public get(key: TK): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return succeedWithDetail(this._inner.get(key)!, 'exists');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Gets a value from the map, or adds a supplied value it if it does not exist.\n * @param key - The key to be retrieved or created.\n * @param value - The value to add if the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found,\n * `Success` with the value and detail `added` if the key was not found and added.\n * Fails with detail 'invalid-key' or 'invalid-value' and an error message if either\n * is invalid.\n * {@label WITH_VALUE}\n */\n public getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * Gets a value from the map, or adds a value created by a factory function if it does not exist.\n * @param key - The key of the element to be retrieved or created.\n * @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if\n * the key does not exist.\n * @returns `Success` with the value and detail `exists` if the key was found, `Success` with\n * the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'\n * or 'invalid-value' and an error message if either is invalid.\n * {@label WITH_FACTORY}\n */\n public getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: TK,\n valueOrFactory: TV | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n return succeedWithDetail(this._inner.get(key)!, 'exists');\n }\n\n const factory: ResultMapValueFactory<TK, TV> = this._isResultMapValueFactory(valueOrFactory)\n ? valueOrFactory\n : () => succeed(valueOrFactory);\n\n return factory(key)\n .onSuccess((val) => {\n this._inner.set(key, val);\n return succeedWithDetail(val, 'added');\n })\n .withDetail('invalid-value', 'added');\n }\n\n /**\n * Returns `true` if the map contains a key.\n * @param key - The key to check.\n * @returns `true` if the key exists, `false` otherwise.\n */\n public has(key: TK): boolean {\n return this._inner.has(key);\n }\n\n /**\n * Returns an iterator over the map keys.\n * @returns An iterator over the map keys.\n */\n public keys(): IterableIterator<TK> {\n return this._inner.keys();\n }\n\n /**\n * Sets a key/value pair in the map.\n * @param key - The key to set.\n * @param value - The value to set.\n * @returns `Success` with the new value and the detail `updated` if the\n * key was found and updated, `Success` with the new value and detail\n * `added` if the key was not found and added. Fails with detail\n * 'invalid-key' or 'invalid-value' and an error message if either is invalid.\n */\n public set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n const detail: ResultMapResultDetail = this._inner.has(key) ? 'updated' : 'added';\n this._inner.set(key, value);\n return succeedWithDetail(value, detail);\n }\n\n /**\n * Returns the number of entries in the map.\n */\n public get size(): number {\n return this._inner.size;\n }\n\n /**\n * Updates an existing key in the map - the map is not updated if the key does\n * not exist.\n * @param key - The key to update.\n * @param value - The value to set.\n * @returns `Success` with the value and detail 'exists' if the key was found\n * and the value updated, `Failure` an error message and with detail `not-found`\n * if the key was not found, or with detail 'invalid-key' or 'invalid-value'\n * if either is invalid.\n */\n public update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n if (this._inner.has(key)) {\n this._inner.set(key, value);\n return succeedWithDetail(value, 'updated');\n }\n return failWithDetail(`${key}: not found.`, 'not-found');\n }\n\n /**\n * Returns an iterator over the map values.\n * @returns An iterator over the map values.\n */\n public values(): IterableIterator<TV> {\n return this._inner.values();\n }\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n public [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>> {\n return this._inner[Symbol.iterator]();\n }\n\n /**\n * Gets a readonly version of this map.\n * @returns A readonly version of this map.\n */\n public toReadOnly(): IReadOnlyResultMap<TK, TV> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory},\n * `false` otherwise.\n * @public\n */\n protected _isResultMapValueFactory<TK extends string, TV>(\n value: TV | ResultMapValueFactory<TK, TV>\n ): value is ResultMapValueFactory<TK, TV> {\n return typeof value === 'function';\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resultMapValidator.js","sourceRoot":"","sources":["../../../src/packlets/collections/resultMapValidator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAmC5E;;;;GAIG;AACH,MAAM,OAAO,0BAA0B;IAQrC;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAID;;;;OAIG;IACH,YAAmB,GAA+B,EAAE,UAAsC;QACxF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5D,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,GAAW;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAI7B,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAID;;;OAGG;IACH,YAAmB,MAA+C;QAChE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,MA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AAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE;YACvE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACO,wBAAwB,CAChC,KAAyC;QAEzC,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;IACrC,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult, failWithDetail, succeedWithDetail } from '../base';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMap, ResultMapValueFactory } from './resultMap';\nimport { KeyValueConverters } from './keyValueConverters';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @public\n */\nexport interface IReadOnlyResultMapValidator<TK extends string = string, TV = unknown> {\n /**\n * {@inheritDoc Collections.ReadOnlyResultMapValidator.map}\n */\n readonly map: IReadOnlyResultMap<TK, TV>;\n\n /**\n * {@inheritDoc Collections.ResultMap.get}\n */\n get(key: string): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n has(key: string): boolean;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @public\n */\nexport interface IResultMapValidatorCreateParams<TK extends string = string, TV = unknown> {\n map: ResultMap<TK, TV>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A read-only validator for any {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * that validates weakly-typed keys before accessing values.\n * @public\n */\nexport class ReadOnlyResultMapValidator<TK extends string = string, TV = unknown>\n implements IReadOnlyResultMapValidator<TK, TV>\n{\n /**\n * The key-value converters used for validation.\n */\n public readonly converters: KeyValueConverters<TK, TV>;\n\n /**\n * The underlying map.\n */\n public get map(): IReadOnlyResultMap<TK, TV> {\n return this._map;\n }\n\n private readonly _map: IReadOnlyResultMap<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ReadOnlyResultMapValidator | ReadOnlyResultMapValidator}.\n * @param map - The map to validate access to.\n * @param converters - The key-value converters for validation.\n */\n public constructor(map: IReadOnlyResultMap<TK, TV>, converters: KeyValueConverters<TK, TV>) {\n this._map = map;\n this.converters = converters;\n }\n\n /**\n * Gets a value from the map by key, validating the key first.\n * @param key - The key to retrieve (will be validated).\n * @returns `Success` with the value if found, `Failure` otherwise.\n */\n public get(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((validKey) => {\n return this._map.get(validKey);\n });\n }\n\n /**\n * Checks if the map contains a key, validating the key first.\n * @param key - The key to check (will be validated).\n * @returns `true` if the key exists and is valid, `false` otherwise.\n */\n public has(key: string): boolean {\n const result = this.converters.convertKey(key);\n if (result.isFailure()) {\n return false;\n }\n return this._map.has(result.value);\n }\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} wrapper which validates weakly-typed keys\n * before calling the wrapped result map.\n * @public\n */\nexport class ResultMapValidator<TK extends string = string, TV = unknown>\n implements IReadOnlyResultMapValidator<TK, TV>\n{\n public readonly converters: KeyValueConverters<TK, TV>;\n public get map(): IReadOnlyResultMap<TK, TV> {\n return this._map;\n }\n\n protected _map: ResultMap<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ResultMapValidator | ResultMapValidator}.\n * @param params - Required parameters for constructing the result map validator.\n */\n public constructor(params: IResultMapValidatorCreateParams<TK, TV>) {\n this._map = params.map;\n this.converters = params.converters;\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.add}\n */\n public add(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.add(vk, vv);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.delete}\n */\n public delete(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.delete(k);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.get}\n */\n public get(key: string): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.get(k);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.getOrAdd}\n */\n public getOrAdd(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritDoc Collections.ResultMap.getOrAdd}\n */\n public getOrAdd(\n key: string,\n factory: ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: string,\n valueOrFactory: unknown | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (!this._isResultMapValueFactory(valueOrFactory)) {\n return this.converters.convertEntry([key, valueOrFactory]).onSuccess(([vk, vv]) => {\n return this._map.getOrAdd(vk, vv);\n });\n } else {\n return this.converters.convertKey(key).onSuccess((k) => {\n return this._map.get(k).onFailure(() => {\n const value = valueOrFactory(k)\n .onSuccess((value) => this.converters.convertEntry([k, value]))\n .onSuccess(([__key, value]) => succeedWithDetail(value, 'added'));\n\n return value.success\n ? this._map.add(k, value.value)\n : failWithDetail<TV, ResultMapResultDetail>(value.message, 'invalid-value');\n });\n });\n }\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.has}\n */\n public has(key: string): boolean {\n return this._map.has(key as TK);\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.set}\n */\n public set(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.set(vk, vv);\n });\n }\n\n /**\n * {@inheritDoc Collections.ResultMap.update}\n */\n public update(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {\n return this._map.update(vk, vv);\n });\n }\n\n /**\n * Gets a read-only version of this validator.\n */\n public toReadOnly(): IReadOnlyResultMapValidator<TK, TV> {\n return this;\n }\n\n /**\n * Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}.\n * @param value - The value to check.\n * @returns `true` if the value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory},\n * `false` otherwise.\n * @public\n */\n protected _isResultMapValueFactory<TK extends string, TV>(\n value: TV | ResultMapValueFactory<TK, TV>\n ): value is ResultMapValueFactory<TK, TV> {\n return typeof value === 'function';\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/collections/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,KAAc;IAEd,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC;AACnF,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Determines if a supplied value is an iterable object or some other type.\n * @param value - The value to be tested.\n * @returns `true` if the value is an iterable object, `false` otherwise.\n * @public\n */\nexport function isIterable<TE = unknown, TI extends Iterable<TE> = Iterable<TE>, TO = unknown>(\n value: TI | TO\n): value is TI {\n return (value && typeof value === 'object' && Symbol.iterator in value) === true;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingCollector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAKhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAmD1D;;;;GAIG;AACH,MAAM,OAAO,mBAGX,SAAQ,SAAgB;IASxB;;;;OAIG;IACH,YAAmB,MAAoD;;QACrE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAC7F,KAAK,MAAM,IAAI,IAAI,MAAA,MAAM,CAAC,KAAK,mCAAI,EAAE,EAAE,CAAC;YACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAGrC,MAAoD;QACpD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { CollectibleKey, ICollectible } from './collectible';\nimport { IReadOnlyCollectorValidator } from './collectorValidator';\nimport { IReadOnlyValidatingResultMap } from './validatingResultMap';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { Collector } from './collector';\nimport { CollectorValidator } from './collectorValidator';\n\n/**\n * A read-only interface exposing non-mutating methods of a\n * {@link Collections.ValidatingCollector | ValidatingCollector}.\n * @public\n */\n\nexport interface IReadOnlyValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {\n /**\n * A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n readonly validating: IReadOnlyCollectorValidator<TITEM>;\n\n /**\n * Gets the item at a specified index.\n * @param index - The index of the item to retrieve.\n * @returns `Success` with the item if it exists, or `Failure` with an error if the index is out of range.\n */\n getAt(index: number): Result<TITEM>;\n\n /**\n * Gets all items in the collection, ordered by index.\n * @returns An array of items in the collection, ordered by index.\n */\n valuesByIndex(): ReadonlyArray<TITEM>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.\n * @public\n */\nexport interface IValidatingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> {\n /**\n * {@inheritDoc Collections.ICollectorValidatorCreateParams.converters}\n */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n\n /**\n * {@inheritDoc Collections.ICollectorConstructorParams.items}\n */\n items?: unknown[];\n}\n\n/**\n * A {@link Collections.Collector | Collector} with a {@link Collections.CollectorValidator | CollectorValidator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n> extends Collector<TITEM> {\n /**\n * A {@link Collections.CollectorValidator | CollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly validating: CollectorValidator<TITEM>;\n\n protected readonly _converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;\n\n /**\n * Constructs a new {@link Collections.ValidatingCollector | ValidatingConvertingCollector}\n * from the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IValidatingCollectorConstructorParams<TITEM>) {\n super();\n this._converters = params.converters;\n this.validating = new CollectorValidator({ collector: this, converters: params.converters });\n for (const item of params.items ?? []) {\n this.validating.getOrAdd(item).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ValidatingCollector | ValidatingCollector} instance from\n * the supplied {@link Collections.IValidatingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>\n >(params: IValidatingCollectorConstructorParams<TITEM>): Result<ValidatingCollector<TITEM>> {\n return captureResult(() => new ValidatingCollector(params));\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyValidatingCollector<TITEM> {\n return this;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatingConvertingCollector.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingConvertingCollector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AA8B9E;;;;;GAKG;AACH,MAAM,OAAO,6BAIX,SAAQ,mBAAgC;IASxC;;;;OAIG;IACH,YAAmB,MAAoE;;QACrF,KAAK,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,IAAI,4BAA4B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QACvG,KAAK,MAAM,KAAK,IAAI,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,EAAE,CAAC;YACzC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CAKrC,MAAoE;QAEpE,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,6BAA6B,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { CollectibleFactory, CollectibleKey, ICollectible } from './collectible';\nimport { ConvertingCollector } from './convertingCollector';\nimport { ConvertingCollectorValidator } from './convertingCollectorValidator';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyValidatingCollector } from './validatingCollector';\n\n/**\n * Parameters for constructing a {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector}.\n * @public\n */\nexport interface IValidatingConvertingCollectorConstructorParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> {\n /**\n * {@inheritDoc Collections.IConvertingCollectorConstructorParams.factory}\n */\n factory: CollectibleFactory<TITEM, TSRC>;\n\n /**\n * {@inheritDoc Collections.IConvertingCollectorValidatorCreateParams.converters}\n */\n converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n /**\n * {@inheritDoc Collections.IConvertingCollectorConstructorParams.entries}\n */\n entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];\n}\n\n/**\n * A {@link Collections.ConvertingCollector | ConvertingCollector} with a\n * {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingConvertingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n> extends ConvertingCollector<TITEM, TSRC> {\n /**\n * A {@link Collections.ConvertingCollectorValidator | ConvertingCollectorValidator} which validates keys and values\n * before inserting them into this collector.\n */\n public readonly validating: ConvertingCollectorValidator<TITEM, TSRC>;\n\n protected readonly _converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;\n\n /**\n * Constructs a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector}\n * from the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n */\n public constructor(params: IValidatingConvertingCollectorConstructorParams<TITEM, TSRC>) {\n super({ factory: params.factory });\n this._converters = params.converters;\n this.validating = new ConvertingCollectorValidator({ collector: this, converters: params.converters });\n for (const entry of params.entries ?? []) {\n this.getOrAdd(entry[0], entry[1]).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Collections.ValidatingConvertingCollector | ValidatingConvertingCollector} instance from\n * the supplied {@link Collections.IValidatingConvertingCollectorConstructorParams | parameters}.\n * @param params - Required parameters for constructing the collector.\n * @returns {@link Success} with the new collector if successful, {@link Failure} otherwise.\n */\n public static createValidatingCollector<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n TITEM extends ICollectible<any, any>,\n TSRC = TITEM\n >(\n params: IValidatingConvertingCollectorConstructorParams<TITEM, TSRC>\n ): Result<ValidatingConvertingCollector<TITEM, TSRC>> {\n return captureResult(() => new ValidatingConvertingCollector(params));\n }\n\n /**\n * Gets a read-only version of this collector as a\n * {@link Collections.IReadOnlyValidatingResultMap | read-only map}.\n * @returns\n */\n public toReadOnly(): IReadOnlyValidatingCollector<TITEM> {\n return this;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatingConvertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingConvertingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO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;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMap } from './readonlyResultMap';\nimport {\n ReadOnlyConvertingResultMap,\n ConvertingResultMapValueConverter\n} from './readOnlyConvertingResultMap';\nimport { ConvertingResultMap } from './convertingResultMap';\nimport { IResultMap } from './resultMap';\nimport { ReadOnlyResultMapValidator } from './resultMapValidator';\n\n/**\n * Parameters for constructing a\n * {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @public\n */\nexport interface IValidatingReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {\n /**\n * The inner map containing source values.\n */\n inner: IReadOnlyResultMap<TK, TSRC>;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * The key-value converters for validating weakly-typed access.\n */\n converters: KeyValueConverters<TK, TTARGET>;\n}\n\n/**\n * A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}\n * of source type and returns lazily-converted, cached values of a target type, with a\n * {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access.\n * @public\n */\nexport class ValidatingReadOnlyConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET\n> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {\n /**\n * A validator for weakly-typed access to the map.\n */\n public readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;\n\n /**\n * The key-value converters used for validation.\n */\n protected readonly _converters: KeyValueConverters<TK, TTARGET>;\n\n /**\n * Constructs a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>) {\n super({ inner: params.inner, converter: params.converter });\n this._converters = params.converters;\n this.validating = new ReadOnlyResultMapValidator(this, params.converters);\n }\n\n /**\n * Creates a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<TK extends string, TSRC, TTARGET>(\n params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>\n ): Result<ValidatingReadOnlyConvertingResultMap<TK, TSRC, TTARGET>> {\n return captureResult(() => new ValidatingReadOnlyConvertingResultMap(params));\n }\n}\n\n/**\n * Parameters for constructing a\n * {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @public\n */\nexport interface IValidatingConvertingResultMapConstructorParams<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> {\n /**\n * The inner map containing source values.\n */\n inner: TSRCMAP;\n\n /**\n * The converter function to transform source values to target values.\n */\n converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;\n\n /**\n * The key-value converters for validating weakly-typed access.\n */\n converters: KeyValueConverters<TK, TTARGET>;\n}\n\n/**\n * A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type\n * and returns lazily-converted, cached values of a target type, with a\n * {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access\n * and a {@link Collections.CacheInvalidatingResultMapWrapper | source} property for mutable access\n * to the underlying source map.\n * @public\n */\nexport class ValidatingConvertingResultMap<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n> extends ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP> {\n /**\n * A validator for weakly-typed access to the map.\n */\n public readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;\n\n /**\n * The key-value converters used for validation.\n */\n protected readonly _converters: KeyValueConverters<TK, TTARGET>;\n\n /**\n * Constructs a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n */\n public constructor(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>) {\n super({ inner: params.inner, converter: params.converter });\n this._converters = params.converters;\n this.validating = new ReadOnlyResultMapValidator(this, params.converters);\n }\n\n /**\n * Creates a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.\n * @param params - Parameters for constructing the map.\n * @returns `Success` with the new map, or `Failure` with error details if an error occurred.\n */\n public static override create<\n TK extends string,\n TSRC,\n TTARGET,\n TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>\n >(\n params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>\n ): Result<ValidatingConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>> {\n return captureResult(() => new ValidatingConvertingResultMap(params));\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/validatingResultMap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,aAAa,EAAU,MAAM,SAAS,CAAC;AAIhD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAA+B,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwBvF;;;;GAIG;AACH,MAAM,OAAO,mBACX,SAAQ,SAAiB;IASzB;;;OAGG;IACH,YAAmB,MAAqD;;QACtE,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,kBAAkB,CAAS,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjG,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,yBAAyB,CACrC,MAAqD;QAErD,OAAO,aAAa,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Result } from '../base';\nimport { KeyValueEntry } from './common';\nimport { KeyValueConverters } from './keyValueConverters';\nimport { IReadOnlyResultMap } from './readonlyResultMap';\nimport { ResultMap } from './resultMap';\nimport { IReadOnlyResultMapValidator, ResultMapValidator } from './resultMapValidator';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ValidatingResultMap | ValidatingResultMap}.\n * @public\n */\nexport interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown>\n extends IReadOnlyResultMap<TK, TV> {\n /**\n * A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values\n * before inserting them into this collection.\n */\n readonly validating: IReadOnlyResultMapValidator<TK, TV>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IValidatingResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<string, unknown>>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapValidator | validator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ValidatingResultMap<TK extends string = string, TV = unknown>\n extends ResultMap<TK, TV>\n implements IReadOnlyValidatingResultMap<TK, TV>\n{\n /**\n * A {@link Collections.ResultMapValidator | ResultMapValidator} which validates keys and values\n * before inserting them into this collection.\n */\n public readonly validating: ResultMapValidator<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ValidatingResultMap | ValidatingResultMap}.\n * @param params - Required parameters for constructing the map.\n */\n public constructor(params: IValidatingResultMapConstructorParams<TK, TV>) {\n const entries = params.converters.convertEntries([...(params.entries ?? [])]).orThrow();\n super({ entries });\n this.validating = new ResultMapValidator<TK, TV>({ map: this, converters: params.converters });\n }\n\n /**\n * Creates a new {@link Collections.ValidatingResultMap | ValidatingResultMap} instance.\n * @param params - Required parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n * @public\n */\n public static createValidatingResultMap<TK extends string = string, TV = unknown>(\n params: IValidatingResultMapConstructorParams<TK, TV>\n ): Result<ValidatingResultMap<TK, TV>> {\n return captureResult(() => new ValidatingResultMap(params));\n }\n\n /**\n * Gets a read-only version of this map.\n */\n public toReadOnly(): IReadOnlyValidatingResultMap<TK, TV> {\n return this;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"advancedConverters.js","sourceRoot":"","sources":["../../../src/packlets/conversion/advancedConverters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAwB,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAmB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAuBrE;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,qBAAkF,EAClF,SAAiB,EACjB,eAAgE;IAEhE,OAAO,IAAI,eAAe,CAAkD;QAC1E,YAAY,EAAE,qBAAqB;QACnC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;QACxC,MAAM,EAAE,eAAe;KACxB,CAAC,CAAC,GAAG,CAAuC,CAAC,GAAG,EAAE,EAA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["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { fail, isKeyOf, mapResults, succeed, Success } from '../base';\nimport { Validator } from '../validation';\nimport { BaseConverter, ConverterResultTypes } from './baseConverter';\nimport { Converter } from './converter';\nimport { literal } from './basicConverters';\nimport { FieldConverters, ObjectConverter } from './objectConverter';\n\n/**\n * Represents a composite ID constructed of two strongly-typed string IDs\n * separated by a delimiter.\n * @public\n */\nexport interface ICompositeId<TCOLLECTIONID extends string, TITEMID extends string> {\n readonly collectionId: TCOLLECTIONID;\n readonly separator: string;\n readonly itemId: TITEMID;\n}\n\n/**\n * Represents a partial composite ID, where separator is optional.\n * @public\n */\nexport interface IPartialCompositeId<TCOLLECTIONID extends string, TITEMID extends string> {\n readonly collectionId: TCOLLECTIONID;\n readonly separator?: string;\n readonly itemId: TITEMID;\n}\n\n/**\n * Creates an {@link ObjectConverter | ObjectConverter} for a strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @param collectionIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdValidator - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns An {@link ObjectConverter | ObjectConverter} for the strongly-typed composite ICompositeId.\n * @public\n */\nexport function compositeIdFromObject<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdValidator: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdValidator: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return new ObjectConverter<IPartialCompositeId<TCOLLECTIONID, TITEMID>, TC>({\n collectionId: collectionIdValidator,\n separator: literal(separator).optional(),\n itemId: itemIdValidator\n }).map<ICompositeId<TCOLLECTIONID, TITEMID>>((obj) =>\n Success.with({\n collectionId: obj.collectionId,\n separator: obj.separator ?? separator,\n itemId: obj.itemId\n })\n );\n}\n\n/**\n * Converts a composite ID string into a strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @public\n */\nexport function compositeIdFromString<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return new BaseConverter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>(\n (from: unknown, __self?: Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC>, context?: TC) => {\n if (typeof from !== 'string') {\n return fail(`${from}: invalid non-string composite ID.`);\n }\n const parts = from.split(separator);\n if (parts.length < 2) {\n return fail(`${from}: invalid composite ID - separator '${separator}' not found.`);\n } else if (parts.length > 2) {\n return fail(`${from}: invalid composite ID - multiple separators '${separator}.' found.`);\n }\n return collectionIdConverter.convert(parts[0], context).onSuccess((collectionId) => {\n return itemIdConverter.convert(parts[1], context).onSuccess((itemId) => {\n return succeed({\n collectionId,\n separator,\n itemId\n });\n });\n });\n }\n );\n}\n\n/**\n * Creates a {@link Converter | Converter} for a strongly-typed {@link Converters.ICompositeId | CompositeId} from\n * either a string or an object representation.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} for the strongly-typed {@link Converters.ICompositeId | CompositeId}.\n * @public\n */\nexport function compositeId<TCOLLECTIONID extends string, TITEMID extends string, TC = unknown>(\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<ICompositeId<TCOLLECTIONID, TITEMID>, TC> {\n return compositeIdFromObject(collectionIdConverter, separator, itemIdConverter).or(\n compositeIdFromString(collectionIdConverter, separator, itemIdConverter)\n );\n}\n\n/**\n * Converts a strongly-typed {@link Converters.ICompositeId | CompositeId} into a string.\n * @param compositeIdConverter - {@link Converter | Converter} or {@link Validator | Validator} that validates/converts the composite ID string.\n * @param collectionIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the collection ID portion.\n * @param separator - The separator string.\n * @param itemIdConverter - {@link Converter | Converter} or {@link Validator | Validator} for the item ID portion.\n * @returns A {@link Converter | Converter} which produces a composite ID string.\n * @public\n */\nexport function compositeIdString<\n T extends string,\n TCOLLECTIONID extends string,\n TITEMID extends string,\n TC = unknown\n>(\n compositeIdConverter: Validator<T, TC> | Converter<T, TC>,\n collectionIdConverter: Converter<TCOLLECTIONID, TC> | Validator<TCOLLECTIONID, TC>,\n separator: string,\n itemIdConverter: Converter<TITEMID, TC> | Validator<TITEMID, TC>\n): Converter<T, TC> {\n const objectConverter = compositeIdFromObject(collectionIdConverter, separator, itemIdConverter);\n return new BaseConverter<T, TC>((from: unknown, __self?: Converter<T, TC>, context?: TC) => {\n if (typeof from === 'string') {\n return compositeIdConverter.convert(from, context);\n }\n return objectConverter.convert(from, context).onSuccess((compositeId) => {\n return compositeIdConverter.convert(`${compositeId.collectionId}${separator}${compositeId.itemId}`);\n });\n });\n}\n\n/**\n * Helper to create a {@link Converter | Converter} which converts a source object to a new object with a\n * different shape.\n *\n * @remarks\n * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new\n * object, which contains the converted values under the key names specified at initialization time.\n * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist\n * or cannot be converted.\n *\n * Fields that succeed but convert to undefined are omitted from the result object but do not\n * fail the conversion.\n *\n * @param properties - An object with key names that correspond to the target object and an\n * appropriate {@link Conversion.FieldConverters | FieldConverter} which extracts and converts\n * a single filed from the source object.\n * @returns A {@link Converter | Converter} with the specified conversion behavior.\n * @public\n */\nexport function transform<T, TC = unknown>(properties: FieldConverters<T, TC>): Converter<T, TC> {\n return new BaseConverter((from: unknown, __self, context?: TC) => {\n // eslint bug thinks key is used before defined\n\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n\n for (const key in properties) {\n if (properties[key]) {\n const result = properties[key].convert(from, context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n return errors.length === 0 ? succeed(converted) : fail(errors.join('\\n'));\n });\n}\n\n/**\n * Per-property converters and configuration for each field in the destination object of\n * a {@link Converters.transformObject} call.\n * @public\n */\nexport type FieldTransformers<TSRC, TDEST, TC = unknown> = {\n [key in keyof TDEST]: {\n /**\n * The name of the property in the source object to be converted.\n */\n from: keyof TSRC;\n /**\n * The converter or validator used to convert the property.\n */\n converter: Converter<TDEST[key], TC> | Validator<TDEST[key], TC>;\n /**\n * If `true` then a missing source property is ignored. If `false` or omitted\n * then a missing source property causes an error.\n */\n optional?: boolean;\n };\n};\n\n/**\n * Options for a {@link Converters.transformObject} call.\n * @public\n */\n\nexport interface TransformObjectOptions<TSRC> {\n /**\n * If `strict` is `true` then unused properties in the source object cause\n * an error, otherwise they are ignored.\n */\n strict: true;\n\n /**\n * An optional list of source properties to be ignored when strict mode\n * is enabled.\n */\n ignore?: (keyof TSRC)[];\n\n /**\n * An optional description of this transform to be used for error messages.\n */\n description?: string;\n}\n\n/**\n * Helper to create a strongly-typed {@link Converter | Converter} which converts a source object to a\n * new object with a different shape.\n *\n * @remarks\n * On successful conversion, the resulting {@link Converter | Converter} returns {@link Success | Success} with a new\n * object, which contains the converted values under the key names specified at initialization time.\n *\n * It returns {@link Failure | Failure} with an error message if any fields to be extracted do not exist\n * or cannot be converted.\n *\n * @param destinationFields - An object with key names that correspond to the target object and an\n * appropriate {@link Converters.FieldTransformers | FieldTransformers} which specifies the name\n * of the corresponding property in the source object, the converter or validator used for each source\n * property and any other configuration to guide the conversion.\n * @param options - Options which affect the transformation.\n *\n * @returns A {@link Converter | Converter} with the specified conversion behavior.\n * @public\n */\nexport function transformObject<TSRC, TDEST, TC = unknown>(\n destinationFields: FieldTransformers<TSRC, TDEST, TC>,\n options?: TransformObjectOptions<TSRC>\n): Converter<TDEST, TC> {\n return new BaseConverter((from: unknown, __self, context?: TC) => {\n // eslint bug thinks key is used before defined\n\n const converted = {} as { [key in keyof TDEST]: TDEST[key] };\n const errors: string[] = [];\n const used: Set<keyof TSRC> = new Set(options?.ignore);\n\n if (typeof from === 'object' && !Array.isArray(from) && from !== null) {\n for (const destinationKey in destinationFields) {\n if (destinationFields[destinationKey]) {\n const srcKey = destinationFields[destinationKey].from;\n const converter = destinationFields[destinationKey].converter;\n\n if (isKeyOf(srcKey, from)) {\n const result = converter.convert(from[srcKey], context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[destinationKey] = result.value;\n } else if (result.isFailure()) {\n errors.push(`${srcKey}->${destinationKey}: ${result.message}`);\n }\n used.add(srcKey);\n } else if (destinationFields[destinationKey].optional !== true) {\n errors.push(`${String(srcKey)}: required property missing in source object.`);\n }\n }\n }\n\n if (options?.strict === true) {\n for (const key in from) {\n if (isKeyOf(key, from) && !used.has(key as keyof TSRC)) {\n errors.push(`${key}: unexpected property in source object`);\n }\n }\n }\n } else {\n errors.push('source is not an object');\n }\n\n return errors.length === 0\n ? succeed(converted)\n : fail(options?.description ? `${options.description}:\\n ${errors.join('\\n ')}` : errors.join('\\n'));\n });\n}\n\n/**\n * Creates a {@link Converter | Converter} that converts an array to a strongly-typed tuple,\n * using the supplied tuple of {@link Converter | Converters} to convert each element.\n *\n * @remarks\n * The resulting {@link Converter | Converter} returns {@link Success | Success} with a tuple\n * containing the converted values if all conversions succeed. Returns {@link Failure | Failure}\n * with an error message if the source is not an array, has the wrong number of elements, or\n * any element conversion fails.\n *\n * @example\n * ```typescript\n * const converter = tuple([Converters.string, Converters.number, Converters.boolean]);\n * // Type is Converter<[string, number, boolean]>\n *\n * converter.convert(['hello', 42, true]);\n * // Returns Success with ['hello', 42, true]\n * ```\n *\n * @param converters - A tuple of {@link Converter | Converters} defining the expected types\n * for each element of the tuple.\n * @returns A {@link Converter | Converter} that returns a strongly-typed tuple.\n * @public\n */\nexport function tuple<T extends readonly Converter<unknown, TC>[], TC = unknown>(\n converters: [...T]\n): Converter<ConverterResultTypes<T>, TC> {\n return new BaseConverter<ConverterResultTypes<T>, TC>(\n (from: unknown, __self: Converter<ConverterResultTypes<T>, TC>, context?: TC) => {\n if (!Array.isArray(from)) {\n return fail(`Not an array: ${JSON.stringify(from)}`);\n }\n\n if (from.length !== converters.length) {\n return fail(\n `Expected array of length ${converters.length}, got ${from.length}: ${JSON.stringify(from)}`\n );\n }\n\n const results = converters.map((converter, index) => {\n return converter.convert(from[index], context);\n });\n\n return mapResults(results) as ReturnType<Converter<ConverterResultTypes<T>, TC>['convert']>;\n }\n );\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseConverter.js","sourceRoot":"","sources":["../../../src/packlets/conversion/baseConverter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAiB,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AASnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAmDnE;;;GAGG;AACH,MAAM,OAAO,aAAa;IAgBxB;;;;;;OAMG;IACH,YAAmB,SAA+B,EAAE,cAAmB,EAAE,MAAwB;QAlBjG;;WAEG;QACO,gBAAW,GAAY,KAAK,CAAC;QAgBrC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,MAAK,IAAI,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;OAQG;IACI,OAAO,CAAC,IAAa,EAAE,OAAY;QACxC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,IAAI,CAAC,eAAe,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACI,eAAe,CAAC,IAAa,EAAE,OAAY,EAAE,OAAiB;QACnE,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,IA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AC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;gBAC3E,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACO,OAAO,CAAC,MAAiC;QACjD,uBACE,UAAU,EAAE,IAAI,CAAC,UAAU,EAC3B,KAAK,EAAE,IAAI,CAAC,KAAK,IACd,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EACjB;IACJ,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,MAAgC;QAC9C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","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 */\nimport { Brand, Result, fail, mapResults, succeed } from '../base';\nimport {\n ConstraintOptions,\n ConversionErrorFormatter,\n Converter,\n ConverterTraits,\n DefaultingConverter,\n OnError\n} from './converter';\nimport { GenericDefaultingConverter } from './defaultingConverter';\n\n/**\n * Internal helper that recursively unwraps converter and array types.\n * @internal\n */\ntype InnerInferredType<TCONV> = TCONV extends Converter<infer TTO>\n ? TTO extends Array<infer TTOELEM>\n ? InnerInferredType<TTOELEM>[]\n : TTO\n : TCONV extends Array<infer TELEM>\n ? InnerInferredType<TELEM>[]\n : TCONV;\n\n/**\n * Infers the type that will be returned by an instantiated converter. Works\n * for complex as well as simple types, including nested arrays.\n * @example `Infer<typeof Converters.mapOf(Converters.stringArray)>` is `Map<string, string[]>`\n * @public\n */\nexport type Infer<TCONV> = TCONV extends Converter<infer TTO, unknown> ? InnerInferredType<TTO> : never;\n\n/**\n * Deprecated name for {@link Conversion.Infer | Infer\n * } retained for compatibility.\n * @deprecated Use {@link Conversion.Infer | Infer} instead.\n * @public\n */\nexport type ConvertedToType<TCONV> = Infer<TCONV>;\n\n/**\n * Helper type to extract the result type from a {@link Converter | Converter}.\n * For simple single-level extraction. For complex nested types, use {@link Conversion.Infer | Infer}.\n * @public\n */\nexport type ConverterResultType<C> = C extends Converter<infer T, unknown> ? T : never;\n\n/**\n * Helper type to map a tuple of {@link Converter | Converters} to a tuple of their result types.\n * @public\n */\nexport type ConverterResultTypes<T extends readonly Converter<unknown, unknown>[]> = {\n [K in keyof T]: T[K] extends Converter<infer R, unknown> ? R : never;\n};\n\n/**\n * Function signature for a converter function.\n * @public\n */\nexport type ConverterFunc<T, TC> = (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>;\n\n/**\n * Base templated wrapper to simplify creation of new {@link Converter}s.\n * @public\n */\nexport class BaseConverter<T, TC = unknown> implements Converter<T, TC> {\n /**\n * @internal\n */\n protected readonly _defaultContext?: TC;\n /**\n * @internal\n */\n protected _isOptional: boolean = false;\n /**\n * @internal\n */\n protected _brand?: string;\n\n private readonly _converter: (from: unknown, self: Converter<T, TC>, context?: TC) => Result<T>;\n\n /**\n * Constructs a new {@link Converter} which uses the supplied function to perform the conversion.\n * @param converter - The conversion function to be applied.\n * @param defaultContext - Optional conversion context to be used by default.\n * @param traits - Optional {@link Conversion.ConverterTraits | traits} to be assigned to the resulting\n * converter.\n */\n public constructor(converter: ConverterFunc<T, TC>, defaultContext?: TC, traits?: ConverterTraits) {\n this._converter = converter;\n this._defaultContext = defaultContext;\n this._isOptional = traits?.isOptional === true;\n this._brand = traits?.brand;\n }\n\n /**\n * Indicates whether this element is explicitly optional.\n */\n public get isOptional(): boolean {\n return this._isOptional;\n }\n\n /**\n * Returns the brand for a branded type.\n */\n public get brand(): string | undefined {\n return this._brand;\n }\n\n /**\n * Converts from `unknown` to `<T>`. For objects and arrays, is guaranteed\n * to return a new entity, with any unrecognized properties removed.\n * @param from - The `unknown` to be converted\n * @param context - An optional conversion context of type `<TC>` to be used in\n * the conversion.\n * @returns A {@link Result} with a {@link Success} and a value on success or an\n * {@link Failure} with a a message on failure.\n */\n public convert(from: unknown, context?: TC): Result<T> {\n return this._converter(from, this, context ?? this._defaultContext);\n }\n\n /**\n * Converts from `unknown` to `<T>` or `undefined`, as appropriate.\n *\n * @remarks\n * If `onError` is `failOnError`, the converter succeeds for\n * `undefined` or any convertible value, but reports an error\n * if it encounters a value that cannot be converted.\n *\n * If `onError` is `ignoreErrors` (default) then values that\n * cannot be converted result in a successful return of `undefined`.\n * @param from - The `unknown` to be converted\n * @param context - An optional conversion context of type `<TC>` to be used in\n * the conversion.\n * @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).\n * @returns A {@link Result} with a {@link Success} and a value on success or an\n * {@link Failure} with a a message on failure.\n */\n public convertOptional(from: unknown, context?: TC, onError?: OnError): Result<T | undefined> {\n const result = this._converter(from, this, this._context(context));\n if (result.isFailure()) {\n onError = onError ?? 'ignoreErrors';\n return from === undefined || onError === 'ignoreErrors' ? succeed(undefined) : result;\n }\n return result;\n }\n\n /**\n * Creates a {@link Converter} for an optional value.\n *\n * @remarks\n * If `onError` is `failOnError`, the resulting converter will accept `undefined`\n * or a convertible value, but report an error if it encounters a value that cannot be\n * converted.\n *\n * If `onError` is `ignoreErrors` (default) then values that cannot be converted will\n * result in a successful return of `undefined`.\n *\n * @param onError - Specifies handling of values that cannot be converted (default `ignoreErrors`).\n * @returns A new {@link Converter} returning `<T|undefined>`.\n */\n public optional(onError?: OnError): Converter<T | undefined, TC> {\n return new BaseConverter((from: unknown, __self: Converter<T | undefined, TC>, context?: TC) => {\n onError = onError ?? 'failOnError';\n return this.convertOptional(from, this._context(context), onError);\n })._with(this._traits({ isOptional: true }));\n }\n\n /**\n * Creates a {@link Converter} which applies a (possibly) mapping conversion to\n * the converted value of this {@link Converter}.\n * @param mapper - A function which maps from the the result type `<T>` of this\n * converter to a new result type `<T2>`.\n * @returns A new {@link Converter} returning `<T2>`.\n */\n public map<T2>(mapper: (from: T, context?: TC) => Result<T2>): Converter<T2, TC> {\n return new BaseConverter<T2, TC>((from: unknown, __self: Converter<T2, TC>, context?: TC) => {\n const innerResult = this._converter(from, this, this._context(context));\n if (innerResult.isSuccess()) {\n return mapper(innerResult.value, this._context(context));\n }\n return fail(innerResult.message);\n })._with(this._traits());\n }\n\n /**\n * Creates a {@link Converter} which applies an additional supplied\n * converter to the result of this converter.\n *\n * @param mapConverter - The {@link Converter} to be applied to the\n * converted result from this {@link Converter}.\n * @returns A new {@link Converter} returning `<T2>`.\n */\n public mapConvert<T2>(mapConverter: Converter<T2>): Converter<T2, TC> {\n return new BaseConverter<T2, TC>((from: unknown, __self: Converter<T2, TC>, context?: TC) => {\n const innerResult = this._converter(from, this, this._context(context));\n if (innerResult.isSuccess()) {\n return mapConverter.convert(innerResult.value, this._context(context));\n }\n return fail(innerResult.message);\n })._with(this._traits());\n }\n\n /**\n * Creates a {@link Converter} which maps the individual items of a collection\n * resulting from this {@link Converter} using the supplied map function.\n *\n * @remarks\n * Fails if `from` is not an array.\n *\n * @param mapper - The map function to be applied to each element of the\n * result of this {@link Converter}.\n * @returns A new {@link Converter} returning `<TI[]>`.\n */\n public mapItems<TI>(mapper: (from: unknown, context?: TC) => Result<TI>): Converter<TI[], TC> {\n return new BaseConverter<TI[], TC>((from: unknown, __self: Converter<TI[], TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onSuccess((items) => {\n if (Array.isArray(items)) {\n return mapResults(items.map((i) => mapper(i, this._context(context))));\n }\n return fail('Cannot map items - not an array');\n });\n });\n }\n\n /**\n * Creates a {@link Converter} which maps the individual items of a collection\n * resulting from this {@link Converter} using the supplied {@link Converter}.\n *\n * @remarks\n * Fails if `from` is not an array.\n *\n * @param mapConverter - The {@link Converter} to be applied to each element of the\n * result of this {@link Converter}.\n * @returns A new {@link Converter} returning `<TI[]>`.\n */\n public mapConvertItems<TI>(mapConverter: Converter<TI, unknown>): Converter<TI[], TC> {\n return new BaseConverter<TI[], TC>((from: unknown, __self: Converter<TI[], TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onSuccess((items) => {\n if (Array.isArray(items)) {\n return mapResults(items.map((i) => mapConverter.convert(i, this._context(context))));\n }\n return fail('Cannot map items - not an array');\n });\n });\n }\n\n /**\n * Creates a {@link Converter | Converter} which applies a supplied action after\n * conversion. The supplied action is always called regardless of success or failure\n * of the base conversion and is allowed to mutate the return type.\n * @param action - The action to be applied.\n */\n public withAction<TI>(action: (result: Result<T>, context?: TC) => Result<TI>): Converter<TI, TC> {\n return new BaseConverter<TI, TC>((from: unknown, __self: Converter<TI, TC>, context?: TC) => {\n return action(this._converter(from, this, this._context(context)), this._context(context));\n })._with(this._traits());\n }\n\n /**\n * Creates a {@link Converter} which applies a supplied type guard to the conversion\n * result.\n * @param guard - The type guard function to apply.\n * @param message - Optional message to be reported if the type guard fails.\n * @returns A new {@link Converter} returning `<TI>`.\n */\n public withTypeGuard<TI>(\n guard: (from: unknown, context?: TC) => from is TI,\n message?: string\n ): Converter<TI, TC> {\n return new BaseConverter<TI, TC>((from: unknown, __self: Converter<TI, TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onSuccess((inner) => {\n message = message ?? 'invalid type';\n return guard(inner, this._context(context))\n ? succeed(inner)\n : fail(`${message}: ${JSON.stringify(from)}`);\n });\n })._with(this._traits());\n }\n\n /**\n * Creates a {@link Converter} which applies a supplied type guard to each member of\n * the conversion result from this converter.\n *\n * @remarks\n * Fails if the conversion result is not an array or if any member fails the\n * type guard.\n * @param guard - The type guard function to apply to each element.\n * @param message - Optional message to be reported if the type guard fails.\n * @returns A new {@link Converter} returning `<TI>`.\n */\n public withItemTypeGuard<TI>(\n guard: (from: unknown, context?: TC) => from is TI,\n message?: string\n ): Converter<TI[], TC> {\n return new BaseConverter<TI[], TC>((from: unknown, __self: Converter<TI[], TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onSuccess((items) => {\n if (Array.isArray(items)) {\n return mapResults(\n items.map((i) => {\n message = message ?? 'invalid type';\n return guard(i, this._context(context))\n ? succeed(i)\n : fail(`${message}: ${JSON.stringify(from)}`);\n })\n );\n }\n return fail('Cannot guard item type - not an array');\n });\n })._with(this._traits());\n }\n\n /**\n * Creates a {@link Converter} which applies an optional constraint to the result\n * of this conversion. If this {@link Converter} (the base converter) succeeds, the new\n * converter calls a supplied constraint evaluation function with the conversion, which\n * fails the entire conversion if the constraint function returns either `false` or\n * {@link Failure | Failure<T>}.\n *\n * @param constraint - Constraint evaluation function.\n * @param options - {@link Conversion.ConstraintOptions | Options} for constraint evaluation.\n * @returns A new {@link Converter} returning `<T>`.\n */\n public withConstraint(\n constraint: (val: T, context?: TC) => boolean | Result<T>,\n options?: ConstraintOptions\n ): Converter<T, TC> {\n return new BaseConverter<T, TC>((from: unknown, __self: Converter<T, TC>, context?: TC) => {\n const result = this._converter(from, this, this._context(context));\n if (result.isSuccess()) {\n const constraintResult = constraint(result.value, this._context(context));\n if (typeof constraintResult === 'boolean') {\n return constraintResult\n ? result\n : fail(\n `\"${JSON.stringify(result.value)}\": ${options?.description ?? 'does not meet constraint'}`\n );\n }\n return constraintResult;\n }\n return result;\n })._with(this._traits());\n }\n\n /**\n * Returns a converter which adds a brand to the type to prevent mismatched usage\n * of simple types.\n * @param brand - The brand to be applied to the result value.\n * @returns A {@link Converter} returning `Brand<T, B>`.\n */\n public withBrand<B extends string>(brand: B): Converter<Brand<T, B>, TC> {\n if (this._brand) {\n throw new Error(`Cannot replace existing brand \"${this._brand}\" with \"${brand}\".`);\n }\n\n return new BaseConverter<Brand<T, B>, TC>((from: unknown, __self: Converter<T, TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onSuccess((v) => {\n return succeed(v as Brand<T, B>);\n });\n })._with(this._traits({ brand }));\n }\n\n /**\n * Returns a Converter which always succeeds with a default value rather than failing.\n * @param defaultValue - The default value to use if conversion fails.\n */\n public withDefault<TD = T>(defaultValue: TD): DefaultingConverter<T, TD, TC> {\n return new GenericDefaultingConverter<T, TD, TC>(this, defaultValue);\n }\n\n public or(other: Converter<T, TC>): Converter<T, TC> {\n return new BaseConverter<T, TC>((from: unknown, __self: Converter<T, TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onFailure(() => {\n return other.convert(from, this._context(context));\n });\n });\n }\n\n /**\n * @internal\n */\n protected _context(supplied?: TC): TC | undefined {\n return supplied ?? this._defaultContext;\n }\n\n /**\n * Creates a new {@link Converter} which is derived from this one but which returns an\n * error message formatted by the supplied formatter if the conversion fails.\n * @param formatter - The formatter to be applied.\n * @returns A new {@link Converter} returning `<T>`.\n */\n public withFormattedError(formatter: ConversionErrorFormatter<TC>): Converter<T, TC> {\n return new BaseConverter<T, TC>((from: unknown, __self: Converter<T, TC>, context?: TC) => {\n return this._converter(from, this, this._context(context)).onFailure((msg) => {\n return fail(formatter(from, msg, this._context(context)));\n });\n })._with(this._traits());\n }\n\n /**\n * @internal\n */\n protected _traits(traits?: Partial<ConverterTraits>): ConverterTraits {\n return {\n isOptional: this.isOptional,\n brand: this.brand,\n ...(traits ?? {})\n };\n }\n\n /**\n * @internal\n */\n protected _with(traits: Partial<ConverterTraits>): this {\n this._isOptional = traits.isOptional === true;\n this._brand = traits.brand;\n return this;\n }\n}\n"]}