@fgv/ts-utils 5.1.0-4 → 5.1.0-40

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 (303) hide show
  1. package/README.md +21 -0
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -0
  4. package/dist/packlets/base/brand.js.map +1 -0
  5. package/dist/packlets/base/index.js +2 -0
  6. package/dist/packlets/base/index.js.map +1 -0
  7. package/dist/packlets/base/mapResults.js.map +1 -0
  8. package/dist/packlets/base/messageAggregator.js.map +1 -0
  9. package/dist/packlets/base/normalize.js +54 -1
  10. package/dist/packlets/base/normalize.js.map +1 -0
  11. package/dist/packlets/base/result.js +326 -2
  12. package/dist/packlets/base/result.js.map +1 -0
  13. package/dist/packlets/base/shouldNotFail.js +123 -0
  14. package/dist/packlets/base/shouldNotFail.js.map +1 -0
  15. package/dist/packlets/base/utils.js.map +1 -0
  16. package/dist/packlets/base/uuid.js +55 -0
  17. package/dist/packlets/base/uuid.js.map +1 -0
  18. package/dist/packlets/collections/aggregatedResultMap.js.map +1 -0
  19. package/dist/packlets/collections/collectible.js.map +1 -0
  20. package/dist/packlets/collections/collector.js +23 -9
  21. package/dist/packlets/collections/collector.js.map +1 -0
  22. package/dist/packlets/collections/collectorValidator.js +6 -1
  23. package/dist/packlets/collections/collectorValidator.js.map +1 -0
  24. package/dist/packlets/collections/common.js.map +1 -0
  25. package/dist/packlets/collections/converters.js.map +1 -0
  26. package/dist/packlets/collections/convertingCollector.js.map +1 -0
  27. package/dist/packlets/collections/convertingCollectorValidator.js.map +1 -0
  28. package/dist/packlets/collections/convertingResultMap.js.map +1 -0
  29. package/dist/packlets/collections/index.js +1 -0
  30. package/dist/packlets/collections/index.js.map +1 -0
  31. package/dist/packlets/collections/keyValueConverters.js.map +1 -0
  32. package/dist/packlets/collections/readOnlyConvertingResultMap.js +18 -0
  33. package/dist/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
  34. package/dist/packlets/collections/readonlyResultMap.js.map +1 -0
  35. package/dist/packlets/collections/resultMap.js.map +1 -0
  36. package/dist/packlets/collections/resultMapValidator.js.map +1 -0
  37. package/dist/packlets/collections/retainingRingBuffer.js +159 -0
  38. package/dist/packlets/collections/retainingRingBuffer.js.map +1 -0
  39. package/dist/packlets/collections/utils.js.map +1 -0
  40. package/dist/packlets/collections/validatingCollector.js.map +1 -0
  41. package/dist/packlets/collections/validatingConvertingCollector.js.map +1 -0
  42. package/dist/packlets/collections/validatingConvertingResultMap.js.map +1 -0
  43. package/dist/packlets/collections/validatingResultMap.js.map +1 -0
  44. package/dist/packlets/conversion/advancedConverters.js.map +1 -0
  45. package/dist/packlets/conversion/baseConverter.js +107 -18
  46. package/dist/packlets/conversion/baseConverter.js.map +1 -0
  47. package/dist/packlets/conversion/basicConverters.js +24 -5
  48. package/dist/packlets/conversion/basicConverters.js.map +1 -0
  49. package/dist/packlets/conversion/converter.js +11 -1
  50. package/dist/packlets/conversion/converter.js.map +1 -0
  51. package/dist/packlets/conversion/converters.js.map +1 -0
  52. package/dist/packlets/conversion/defaultingConverter.js.map +1 -0
  53. package/dist/packlets/conversion/index.js.map +1 -0
  54. package/dist/packlets/conversion/objectConverter.js.map +1 -0
  55. package/dist/packlets/conversion/stringConverter.js.map +1 -0
  56. package/dist/packlets/hash/crcNormalizer.js.map +1 -0
  57. package/dist/packlets/hash/hashingNormalizer.js.map +1 -0
  58. package/dist/packlets/hash/index.js.map +1 -0
  59. package/dist/packlets/logging/bootLogger.js.map +1 -0
  60. package/dist/packlets/logging/index.js +2 -0
  61. package/dist/packlets/logging/index.js.map +1 -0
  62. package/dist/packlets/logging/logReporter.js.map +1 -0
  63. package/dist/packlets/logging/logger.js +51 -18
  64. package/dist/packlets/logging/logger.js.map +1 -0
  65. package/dist/packlets/logging/multiLogger.js +104 -0
  66. package/dist/packlets/logging/multiLogger.js.map +1 -0
  67. package/dist/packlets/logging/retainingLogger.js +114 -0
  68. package/dist/packlets/logging/retainingLogger.js.map +1 -0
  69. package/dist/packlets/logging-interface/index.js +28 -0
  70. package/dist/packlets/logging-interface/index.js.map +1 -0
  71. package/dist/packlets/validation/array.js.map +1 -0
  72. package/dist/packlets/validation/boolean.js.map +1 -0
  73. package/dist/packlets/validation/classes.js.map +1 -0
  74. package/dist/packlets/validation/common.js.map +1 -0
  75. package/dist/packlets/validation/compositeId.js.map +1 -0
  76. package/dist/packlets/validation/field.js.map +1 -0
  77. package/dist/packlets/validation/genericValidator.js.map +1 -0
  78. package/dist/packlets/validation/index.js.map +1 -0
  79. package/dist/packlets/validation/number.js.map +1 -0
  80. package/dist/packlets/validation/object.js.map +1 -0
  81. package/dist/packlets/validation/oneOf.js.map +1 -0
  82. package/dist/packlets/validation/string.js.map +1 -0
  83. package/dist/packlets/validation/traits.js.map +1 -0
  84. package/dist/packlets/validation/typeGuard.js.map +1 -0
  85. package/dist/packlets/validation/validator.js.map +1 -0
  86. package/dist/packlets/validation/validatorBase.js.map +1 -0
  87. package/dist/packlets/validation/validators.js.map +1 -0
  88. package/dist/ts-utils.d.ts +1089 -59
  89. package/dist/tsdoc-metadata.json +1 -1
  90. package/lib/index.d.ts +2 -2
  91. package/lib/index.d.ts.map +1 -0
  92. package/lib/index.js +2 -1
  93. package/lib/index.js.map +1 -0
  94. package/lib/packlets/base/brand.d.ts.map +1 -0
  95. package/lib/packlets/base/brand.js.map +1 -0
  96. package/lib/packlets/base/index.d.ts +2 -0
  97. package/lib/packlets/base/index.d.ts.map +1 -0
  98. package/lib/packlets/base/index.js +2 -0
  99. package/lib/packlets/base/index.js.map +1 -0
  100. package/lib/packlets/base/mapResults.d.ts.map +1 -0
  101. package/lib/packlets/base/mapResults.js.map +1 -0
  102. package/lib/packlets/base/messageAggregator.d.ts.map +1 -0
  103. package/lib/packlets/base/messageAggregator.js.map +1 -0
  104. package/lib/packlets/base/normalize.d.ts +24 -0
  105. package/lib/packlets/base/normalize.d.ts.map +1 -0
  106. package/lib/packlets/base/normalize.js +53 -0
  107. package/lib/packlets/base/normalize.js.map +1 -0
  108. package/lib/packlets/base/result.d.ts +295 -1
  109. package/lib/packlets/base/result.d.ts.map +1 -0
  110. package/lib/packlets/base/result.js +330 -3
  111. package/lib/packlets/base/result.js.map +1 -0
  112. package/lib/packlets/base/shouldNotFail.d.ts +53 -0
  113. package/lib/packlets/base/shouldNotFail.d.ts.map +1 -0
  114. package/lib/packlets/base/shouldNotFail.js +129 -0
  115. package/lib/packlets/base/shouldNotFail.js.map +1 -0
  116. package/lib/packlets/base/utils.d.ts +12 -0
  117. package/lib/packlets/base/utils.d.ts.map +1 -0
  118. package/lib/packlets/base/utils.js.map +1 -0
  119. package/lib/packlets/base/uuid.d.ts +27 -0
  120. package/lib/packlets/base/uuid.d.ts.map +1 -0
  121. package/lib/packlets/base/uuid.js +59 -0
  122. package/lib/packlets/base/uuid.js.map +1 -0
  123. package/lib/packlets/collections/aggregatedResultMap.d.ts.map +1 -0
  124. package/lib/packlets/collections/aggregatedResultMap.js.map +1 -0
  125. package/lib/packlets/collections/collectible.d.ts.map +1 -0
  126. package/lib/packlets/collections/collectible.js.map +1 -0
  127. package/lib/packlets/collections/collector.d.ts +23 -9
  128. package/lib/packlets/collections/collector.d.ts.map +1 -0
  129. package/lib/packlets/collections/collector.js +23 -9
  130. package/lib/packlets/collections/collector.js.map +1 -0
  131. package/lib/packlets/collections/collectorValidator.d.ts +29 -5
  132. package/lib/packlets/collections/collectorValidator.d.ts.map +1 -0
  133. package/lib/packlets/collections/collectorValidator.js +6 -1
  134. package/lib/packlets/collections/collectorValidator.js.map +1 -0
  135. package/lib/packlets/collections/common.d.ts.map +1 -0
  136. package/lib/packlets/collections/common.js.map +1 -0
  137. package/lib/packlets/collections/converters.d.ts.map +1 -0
  138. package/lib/packlets/collections/converters.js.map +1 -0
  139. package/lib/packlets/collections/convertingCollector.d.ts +21 -3
  140. package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
  141. package/lib/packlets/collections/convertingCollector.js.map +1 -0
  142. package/lib/packlets/collections/convertingCollectorValidator.d.ts +22 -3
  143. package/lib/packlets/collections/convertingCollectorValidator.d.ts.map +1 -0
  144. package/lib/packlets/collections/convertingCollectorValidator.js.map +1 -0
  145. package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
  146. package/lib/packlets/collections/convertingResultMap.js.map +1 -0
  147. package/lib/packlets/collections/index.d.ts +1 -0
  148. package/lib/packlets/collections/index.d.ts.map +1 -0
  149. package/lib/packlets/collections/index.js +1 -0
  150. package/lib/packlets/collections/index.js.map +1 -0
  151. package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
  152. package/lib/packlets/collections/keyValueConverters.js.map +1 -0
  153. package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts +13 -1
  154. package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts.map +1 -0
  155. package/lib/packlets/collections/readOnlyConvertingResultMap.js +19 -1
  156. package/lib/packlets/collections/readOnlyConvertingResultMap.js.map +1 -0
  157. package/lib/packlets/collections/readonlyResultMap.d.ts +18 -7
  158. package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -0
  159. package/lib/packlets/collections/readonlyResultMap.js.map +1 -0
  160. package/lib/packlets/collections/resultMap.d.ts.map +1 -0
  161. package/lib/packlets/collections/resultMap.js.map +1 -0
  162. package/lib/packlets/collections/resultMapValidator.d.ts.map +1 -0
  163. package/lib/packlets/collections/resultMapValidator.js.map +1 -0
  164. package/lib/packlets/collections/retainingRingBuffer.d.ts +147 -0
  165. package/lib/packlets/collections/retainingRingBuffer.d.ts.map +1 -0
  166. package/lib/packlets/collections/retainingRingBuffer.js +163 -0
  167. package/lib/packlets/collections/retainingRingBuffer.js.map +1 -0
  168. package/lib/packlets/collections/utils.d.ts.map +1 -0
  169. package/lib/packlets/collections/utils.js.map +1 -0
  170. package/lib/packlets/collections/validatingCollector.d.ts +7 -3
  171. package/lib/packlets/collections/validatingCollector.d.ts.map +1 -0
  172. package/lib/packlets/collections/validatingCollector.js.map +1 -0
  173. package/lib/packlets/collections/validatingConvertingCollector.d.ts.map +1 -0
  174. package/lib/packlets/collections/validatingConvertingCollector.js.map +1 -0
  175. package/lib/packlets/collections/validatingConvertingResultMap.d.ts.map +1 -0
  176. package/lib/packlets/collections/validatingConvertingResultMap.js.map +1 -0
  177. package/lib/packlets/collections/validatingResultMap.d.ts +2 -1
  178. package/lib/packlets/collections/validatingResultMap.d.ts.map +1 -0
  179. package/lib/packlets/collections/validatingResultMap.js.map +1 -0
  180. package/lib/packlets/conversion/advancedConverters.d.ts.map +1 -0
  181. package/lib/packlets/conversion/advancedConverters.js.map +1 -0
  182. package/lib/packlets/conversion/baseConverter.d.ts +108 -19
  183. package/lib/packlets/conversion/baseConverter.d.ts.map +1 -0
  184. package/lib/packlets/conversion/baseConverter.js +107 -18
  185. package/lib/packlets/conversion/baseConverter.js.map +1 -0
  186. package/lib/packlets/conversion/basicConverters.d.ts +14 -0
  187. package/lib/packlets/conversion/basicConverters.d.ts.map +1 -0
  188. package/lib/packlets/conversion/basicConverters.js +24 -5
  189. package/lib/packlets/conversion/basicConverters.js.map +1 -0
  190. package/lib/packlets/conversion/converter.d.ts +9 -1
  191. package/lib/packlets/conversion/converter.d.ts.map +1 -0
  192. package/lib/packlets/conversion/converter.js +12 -0
  193. package/lib/packlets/conversion/converter.js.map +1 -0
  194. package/lib/packlets/conversion/converters.d.ts.map +1 -0
  195. package/lib/packlets/conversion/converters.js.map +1 -0
  196. package/lib/packlets/conversion/defaultingConverter.d.ts.map +1 -0
  197. package/lib/packlets/conversion/defaultingConverter.js.map +1 -0
  198. package/lib/packlets/conversion/index.d.ts.map +1 -0
  199. package/lib/packlets/conversion/index.js.map +1 -0
  200. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -0
  201. package/lib/packlets/conversion/objectConverter.js.map +1 -0
  202. package/lib/packlets/conversion/stringConverter.d.ts.map +1 -0
  203. package/lib/packlets/conversion/stringConverter.js.map +1 -0
  204. package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -0
  205. package/lib/packlets/hash/crcNormalizer.js.map +1 -0
  206. package/lib/packlets/hash/hashingNormalizer.d.ts.map +1 -0
  207. package/lib/packlets/hash/hashingNormalizer.js.map +1 -0
  208. package/lib/packlets/hash/index.d.ts.map +1 -0
  209. package/lib/packlets/hash/index.js.map +1 -0
  210. package/lib/packlets/logging/bootLogger.d.ts.map +1 -0
  211. package/lib/packlets/logging/bootLogger.js.map +1 -0
  212. package/lib/packlets/logging/index.d.ts +2 -0
  213. package/lib/packlets/logging/index.d.ts.map +1 -0
  214. package/lib/packlets/logging/index.js +2 -0
  215. package/lib/packlets/logging/index.js.map +1 -0
  216. package/lib/packlets/logging/logReporter.d.ts.map +1 -0
  217. package/lib/packlets/logging/logReporter.js.map +1 -0
  218. package/lib/packlets/logging/logger.d.ts +25 -70
  219. package/lib/packlets/logging/logger.d.ts.map +1 -0
  220. package/lib/packlets/logging/logger.js +54 -20
  221. package/lib/packlets/logging/logger.js.map +1 -0
  222. package/lib/packlets/logging/multiLogger.d.ts +54 -0
  223. package/lib/packlets/logging/multiLogger.d.ts.map +1 -0
  224. package/lib/packlets/logging/multiLogger.js +108 -0
  225. package/lib/packlets/logging/multiLogger.js.map +1 -0
  226. package/lib/packlets/logging/retainingLogger.d.ts +123 -0
  227. package/lib/packlets/logging/retainingLogger.d.ts.map +1 -0
  228. package/lib/packlets/logging/retainingLogger.js +118 -0
  229. package/lib/packlets/logging/retainingLogger.js.map +1 -0
  230. package/lib/packlets/logging-interface/index.d.ts +98 -0
  231. package/lib/packlets/logging-interface/index.d.ts.map +1 -0
  232. package/lib/packlets/logging-interface/index.js +32 -0
  233. package/lib/packlets/logging-interface/index.js.map +1 -0
  234. package/lib/packlets/validation/array.d.ts.map +1 -0
  235. package/lib/packlets/validation/array.js.map +1 -0
  236. package/lib/packlets/validation/boolean.d.ts.map +1 -0
  237. package/lib/packlets/validation/boolean.js.map +1 -0
  238. package/lib/packlets/validation/classes.d.ts.map +1 -0
  239. package/lib/packlets/validation/classes.js.map +1 -0
  240. package/lib/packlets/validation/common.d.ts.map +1 -0
  241. package/lib/packlets/validation/common.js.map +1 -0
  242. package/lib/packlets/validation/compositeId.d.ts.map +1 -0
  243. package/lib/packlets/validation/compositeId.js.map +1 -0
  244. package/lib/packlets/validation/field.d.ts.map +1 -0
  245. package/lib/packlets/validation/field.js.map +1 -0
  246. package/lib/packlets/validation/genericValidator.d.ts.map +1 -0
  247. package/lib/packlets/validation/genericValidator.js.map +1 -0
  248. package/lib/packlets/validation/index.d.ts.map +1 -0
  249. package/lib/packlets/validation/index.js.map +1 -0
  250. package/lib/packlets/validation/number.d.ts.map +1 -0
  251. package/lib/packlets/validation/number.js.map +1 -0
  252. package/lib/packlets/validation/object.d.ts.map +1 -0
  253. package/lib/packlets/validation/object.js.map +1 -0
  254. package/lib/packlets/validation/oneOf.d.ts.map +1 -0
  255. package/lib/packlets/validation/oneOf.js.map +1 -0
  256. package/lib/packlets/validation/string.d.ts.map +1 -0
  257. package/lib/packlets/validation/string.js.map +1 -0
  258. package/lib/packlets/validation/traits.d.ts.map +1 -0
  259. package/lib/packlets/validation/traits.js.map +1 -0
  260. package/lib/packlets/validation/typeGuard.d.ts.map +1 -0
  261. package/lib/packlets/validation/typeGuard.js.map +1 -0
  262. package/lib/packlets/validation/validator.d.ts.map +1 -0
  263. package/lib/packlets/validation/validator.js.map +1 -0
  264. package/lib/packlets/validation/validatorBase.d.ts +2 -1
  265. package/lib/packlets/validation/validatorBase.d.ts.map +1 -0
  266. package/lib/packlets/validation/validatorBase.js.map +1 -0
  267. package/lib/packlets/validation/validators.d.ts.map +1 -0
  268. package/lib/packlets/validation/validators.js.map +1 -0
  269. package/package.json +3 -3
  270. package/dist/test/helpers/jest/helpers/fsHelpers.js +0 -139
  271. package/dist/test/helpers/jest/helpers/index.js +0 -2
  272. package/dist/test/helpers/jest/index.js +0 -17
  273. package/dist/test/helpers/jest/matchers/index.js +0 -14
  274. package/dist/test/helpers/jest/matchers/toFail/index.js +0 -23
  275. package/dist/test/helpers/jest/matchers/toFail/predicate.js +0 -5
  276. package/dist/test/helpers/jest/matchers/toFailTest/index.js +0 -28
  277. package/dist/test/helpers/jest/matchers/toFailTest/predicate.js +0 -8
  278. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/index.js +0 -24
  279. package/dist/test/helpers/jest/matchers/toFailTestAndMatchSnapshot/predicate.js +0 -11
  280. package/dist/test/helpers/jest/matchers/toFailTestWith/index.js +0 -29
  281. package/dist/test/helpers/jest/matchers/toFailTestWith/predicate.js +0 -26
  282. package/dist/test/helpers/jest/matchers/toFailWith/index.js +0 -27
  283. package/dist/test/helpers/jest/matchers/toFailWith/predicate.js +0 -16
  284. package/dist/test/helpers/jest/matchers/toFailWithDetail/index.js +0 -27
  285. package/dist/test/helpers/jest/matchers/toFailWithDetail/predicate.js +0 -22
  286. package/dist/test/helpers/jest/matchers/toSucceed/index.js +0 -23
  287. package/dist/test/helpers/jest/matchers/toSucceed/predicate.js +0 -5
  288. package/dist/test/helpers/jest/matchers/toSucceedAndMatchInlineSnapshot/index.js +0 -24
  289. package/dist/test/helpers/jest/matchers/toSucceedAndMatchSnapshot/index.js +0 -24
  290. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/index.js +0 -53
  291. package/dist/test/helpers/jest/matchers/toSucceedAndSatisfy/predicate.js +0 -17
  292. package/dist/test/helpers/jest/matchers/toSucceedWith/index.js +0 -27
  293. package/dist/test/helpers/jest/matchers/toSucceedWith/predicate.js +0 -12
  294. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/index.js +0 -27
  295. package/dist/test/helpers/jest/matchers/toSucceedWithDetail/predicate.js +0 -17
  296. package/dist/test/helpers/jest/resolvers/cli.js +0 -10
  297. package/dist/test/helpers/jest/resolvers/ide.js +0 -10
  298. package/dist/test/helpers/jest/ts-utils.js +0 -2
  299. package/dist/test/helpers/jest/types/index.js +0 -3
  300. package/dist/test/helpers/jest/utils/matcherHelpers.js +0 -47
  301. package/dist/test/helpers/jest/utils/snapshotResolver.js +0 -11
  302. package/dist/test/unit/collections/helpers.js +0 -106
  303. package/dist/test/unit/hashTextEncodeCompat.js +0 -23
@@ -21,7 +21,7 @@
21
21
  * SOFTWARE.
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.DetailedFailure = exports.DetailedSuccess = exports.Failure = exports.Success = void 0;
24
+ exports.AsyncResult = exports.DetailedFailure = exports.DetailedSuccess = exports.Failure = exports.Success = exports.allMessageLogLevels = void 0;
25
25
  exports.isDeferredResult = isDeferredResult;
26
26
  exports.succeed = succeed;
27
27
  exports.succeeds = succeeds;
@@ -33,7 +33,10 @@ exports.succeedsWithDetail = succeedsWithDetail;
33
33
  exports.failWithDetail = failWithDetail;
34
34
  exports.failsWithDetail = failsWithDetail;
35
35
  exports.propagateWithDetail = propagateWithDetail;
36
+ exports._errorMessage = _errorMessage;
36
37
  exports.captureResult = captureResult;
38
+ exports.captureAsyncResult = captureAsyncResult;
39
+ const shouldNotFail_1 = require("./shouldNotFail");
37
40
  /**
38
41
  * Checks if a result is a deferred result.
39
42
  * @param result - The result to check.
@@ -43,6 +46,17 @@ exports.captureResult = captureResult;
43
46
  function isDeferredResult(result) {
44
47
  return typeof result === 'function';
45
48
  }
49
+ // Untyped (literal-tuple-inferred) source of truth for allMessageLogLevels, kept separate from the
50
+ // widened public export below so the exhaustiveness check actually inspects the literal values instead
51
+ // of being widened away to `MessageLogLevel` before the check runs.
52
+ const messageLogLevelValues = ['quiet', 'detail', 'info', 'warning', 'error'];
53
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
54
+ const _messageLogLevelExhaustivenessCheck = true;
55
+ /**
56
+ * Exhaustive list of all {@link MessageLogLevel} values.
57
+ * @public
58
+ */
59
+ exports.allMessageLogLevels = messageLogLevelValues;
46
60
  /**
47
61
  * Reports a successful {@link IResult | result} from some operation and the
48
62
  * corresponding value.
@@ -85,6 +99,12 @@ class Success {
85
99
  orThrow(__logger) {
86
100
  return this._value;
87
101
  }
102
+ /**
103
+ * {@inheritDoc IResult.shouldNotFail}
104
+ */
105
+ shouldNotFail(__label, __frameDepth) {
106
+ return this._value;
107
+ }
88
108
  orDefault(dflt) {
89
109
  var _a;
90
110
  return (_a = this._value) !== null && _a !== void 0 ? _a : dflt;
@@ -116,6 +136,26 @@ class Success {
116
136
  onFailure(__) {
117
137
  return this;
118
138
  }
139
+ /**
140
+ * {@inheritDoc IResult.thenOnSuccess}
141
+ */
142
+ thenOnSuccess(cb) {
143
+ try {
144
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
145
+ return new AsyncResult(cb(this._value));
146
+ }
147
+ catch (err) {
148
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
149
+ return AsyncResult.from(fail(_errorMessage(err)));
150
+ }
151
+ }
152
+ /**
153
+ * {@inheritDoc IResult.thenOnFailure}
154
+ */
155
+ thenOnFailure(__) {
156
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
157
+ return AsyncResult.from(this);
158
+ }
119
159
  /**
120
160
  * {@inheritDoc IResult.withErrorFormat}
121
161
  */
@@ -210,6 +250,32 @@ class Failure {
210
250
  }
211
251
  throw new Error(this._message);
212
252
  }
253
+ /**
254
+ * {@inheritDoc IResult.shouldNotFail}
255
+ */
256
+ shouldNotFail(label, frameDepth = 1) {
257
+ // Parse a probe Error's stack to identify the caller frame for message
258
+ // composition. We must NOT reuse this probe as the thrown Error: in V8,
259
+ // `.stack` is materialized lazily on first access (which happens below in
260
+ // `_findShouldNotFailFrame`), and once materialized the cached stack
261
+ // header carries whatever message was set at that moment. Mutating
262
+ // `.message` afterwards does not refresh the cached `.stack` header.
263
+ const probe = new Error();
264
+ if (typeof Error.captureStackTrace === 'function') {
265
+ Error.captureStackTrace(probe, this.shouldNotFail);
266
+ }
267
+ const frame = (0, shouldNotFail_1._findShouldNotFailFrame)(probe.stack, frameDepth);
268
+ const message = (0, shouldNotFail_1._formatShouldNotFailMessage)(this._message, label, frame);
269
+ // Build the final Error with the formatted message and re-elide
270
+ // `shouldNotFail` from its stack, so the thrown error's `.stack` shows
271
+ // both the formatted message in its header and the caller as its top
272
+ // frame.
273
+ const err = new Error(message);
274
+ if (typeof Error.captureStackTrace === 'function') {
275
+ Error.captureStackTrace(err, this.shouldNotFail);
276
+ }
277
+ throw err;
278
+ }
213
279
  orDefault(dflt) {
214
280
  return dflt;
215
281
  }
@@ -242,6 +308,26 @@ class Failure {
242
308
  onFailure(cb) {
243
309
  return cb(this._message);
244
310
  }
311
+ /**
312
+ * {@inheritDoc IResult.thenOnSuccess}
313
+ */
314
+ thenOnSuccess(__) {
315
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
316
+ return AsyncResult.from(fail(this._message));
317
+ }
318
+ /**
319
+ * {@inheritDoc IResult.thenOnFailure}
320
+ */
321
+ thenOnFailure(cb) {
322
+ try {
323
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
324
+ return new AsyncResult(cb(this._message));
325
+ }
326
+ catch (err) {
327
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
328
+ return AsyncResult.from(fail(_errorMessage(err)));
329
+ }
330
+ }
245
331
  /**
246
332
  * {@inheritDoc IResult.withErrorFormat}
247
333
  */
@@ -279,6 +365,45 @@ class Failure {
279
365
  reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message);
280
366
  return this;
281
367
  }
368
+ /**
369
+ * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
370
+ * propagation under a different success type.
371
+ * @remarks
372
+ * Supports the canonical Result early-return-after-`isFailure()` pattern when the
373
+ * outer function's success type differs from the inner Result's success type:
374
+ *
375
+ * ```ts
376
+ * const storeResult = await PromptStoreFixture.build(seed);
377
+ * if (storeResult.isFailure()) {
378
+ * return storeResult.withType<PromptLibrary>();
379
+ * }
380
+ * return PromptLibrary.create({ store: storeResult.value, ... });
381
+ * ```
382
+ *
383
+ * Without this helper, TypeScript rejects `return storeResult` because
384
+ * `Failure<IPromptStore>` is invariant in `T` and not assignable to
385
+ * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
386
+ * semantically equivalent but allocates a new {@link Failure} instance;
387
+ * `withType` returns `this` and only retypes statically.
388
+ *
389
+ * This method is sound because a {@link Failure} variant carries no `T`-shaped
390
+ * data — only an error message — so re-typing it as `Failure<U>` cannot
391
+ * misrepresent any value. The same operation is NOT exposed on {@link Success}
392
+ * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
393
+ *
394
+ * For `DetailedResult` propagation that preserves a typed `detail`, consider
395
+ * propagating the {@link DetailedFailure} directly through `onSuccess` (which
396
+ * already re-types the success arm) rather than reaching for `withType`.
397
+ *
398
+ * @returns This same {@link Failure} instance, statically retyped as
399
+ * {@link Failure | Failure<U>}.
400
+ * @public
401
+ */
402
+ withType() {
403
+ // Safe by construction: Failure carries no T-shaped data, only a message.
404
+ // Re-typing the static T parameter cannot misrepresent any value.
405
+ return this;
406
+ }
282
407
  /**
283
408
  * Get a 'friendly' string representation of this object.
284
409
  * @remarks
@@ -610,13 +735,25 @@ function propagateWithDetail(result, detail, successDetail) {
610
735
  ? succeedWithDetail(result.value, successDetail !== null && successDetail !== void 0 ? successDetail : detail)
611
736
  : failWithDetail(result.message, detail);
612
737
  }
738
+ /**
739
+ * Extracts a message string from an unknown thrown/rejected value.
740
+ * @param err - The caught error value.
741
+ * @returns The error message string.
742
+ * @internal
743
+ */
744
+ function _errorMessage(err) {
745
+ if (err instanceof Error) {
746
+ return err.message;
747
+ }
748
+ return String(err);
749
+ }
613
750
  /**
614
751
  * Wraps a function which might throw to convert exception results
615
752
  * to {@link Failure}.
616
753
  * @param func - The function to be captured.
617
754
  * @returns Returns {@link Success} with a value of type `<T>` on
618
755
  * success , or {@link Failure} with the thrown error message if
619
- * `func` throws an `Error`.
756
+ * `func` throws an `Error` or string.
620
757
  * @public
621
758
  */
622
759
  function captureResult(func) {
@@ -624,7 +761,197 @@ function captureResult(func) {
624
761
  return succeed(func());
625
762
  }
626
763
  catch (err) {
627
- return fail(err.message);
764
+ return fail(_errorMessage(err));
765
+ }
766
+ }
767
+ /**
768
+ * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both
769
+ * synchronous and asynchronous operations.
770
+ *
771
+ * @remarks
772
+ * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.
773
+ * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge
774
+ * from synchronous to asynchronous result chains.
775
+ *
776
+ * @example
777
+ * ```typescript
778
+ * const result: Result<Final> = await parseInput(input)
779
+ * .thenOnSuccess(async (parsed) => fetchData(parsed))
780
+ * .onSuccess((data) => transform(data))
781
+ * .thenOnSuccess(async (transformed) => saveData(transformed))
782
+ * .withErrorFormat((msg) => `pipeline failed: ${msg}`);
783
+ * ```
784
+ *
785
+ * @public
786
+ */
787
+ class AsyncResult {
788
+ /**
789
+ * Constructs an {@link AsyncResult} wrapping the supplied promise (or any
790
+ * `PromiseLike` that resolves to a {@link Result}, such as another
791
+ * {@link AsyncResult}).
792
+ * @remarks
793
+ * If the supplied promise rejects, the rejection is caught and converted
794
+ * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always
795
+ * yields a {@link Result}.
796
+ * @param promise - A `Promise` (or `PromiseLike`) that resolves to a
797
+ * {@link Result}.
798
+ */
799
+ constructor(promise) {
800
+ this._promise = Promise.resolve(promise).catch((err) => fail(_errorMessage(err)));
801
+ }
802
+ /**
803
+ * Calls a supplied {@link SuccessContinuation | success continuation} if
804
+ * the wrapped result is successful.
805
+ * @param cb - The synchronous {@link SuccessContinuation | success continuation}
806
+ * to be called in the event of success.
807
+ * @returns A new {@link AsyncResult} wrapping the continuation result.
808
+ */
809
+ onSuccess(cb) {
810
+ return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));
811
+ }
812
+ /**
813
+ * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if
814
+ * the wrapped result is successful.
815
+ * @remarks
816
+ * Both synchronous throws and async rejections from the callback are caught
817
+ * and converted to a {@link Failure}.
818
+ * @param cb - The {@link AsyncSuccessContinuation | async success continuation}
819
+ * to be called in the event of success.
820
+ * @returns A new {@link AsyncResult} wrapping the async continuation result.
821
+ */
822
+ thenOnSuccess(cb) {
823
+ return new AsyncResult(this._promise.then(async (r) => {
824
+ if (r.isFailure()) {
825
+ return fail(r.message);
826
+ }
827
+ try {
828
+ return await cb(r.value);
829
+ }
830
+ catch (err) {
831
+ return fail(_errorMessage(err));
832
+ }
833
+ }));
834
+ }
835
+ /**
836
+ * Calls a supplied {@link FailureContinuation | failure continuation} if
837
+ * the wrapped result is a failure.
838
+ * @param cb - The synchronous {@link FailureContinuation | failure continuation}
839
+ * to be called in the event of failure.
840
+ * @returns A new {@link AsyncResult} wrapping the continuation result.
841
+ */
842
+ onFailure(cb) {
843
+ return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));
844
+ }
845
+ /**
846
+ * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if
847
+ * the wrapped result is a failure.
848
+ * @remarks
849
+ * Both synchronous throws and async rejections from the callback are caught
850
+ * and converted to a {@link Failure}.
851
+ * @param cb - The {@link AsyncFailureContinuation | async failure continuation}
852
+ * to be called in the event of failure.
853
+ * @returns A new {@link AsyncResult} wrapping the async continuation result.
854
+ */
855
+ thenOnFailure(cb) {
856
+ return new AsyncResult(this._promise.then(async (r) => {
857
+ if (r.isSuccess()) {
858
+ return r;
859
+ }
860
+ try {
861
+ return await cb(r.message);
862
+ }
863
+ catch (err) {
864
+ return fail(_errorMessage(err));
865
+ }
866
+ }));
867
+ }
868
+ /**
869
+ * Calls a supplied {@link ErrorFormatter | error formatter} if
870
+ * the wrapped result is a failure.
871
+ * @param cb - The {@link ErrorFormatter | error formatter} to
872
+ * be called in the event of failure.
873
+ * @returns A new {@link AsyncResult} with the formatted error message,
874
+ * or the original success result.
875
+ */
876
+ withErrorFormat(cb) {
877
+ return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));
878
+ }
879
+ /**
880
+ * Propagates the wrapped result, appending any error message to the
881
+ * supplied errors aggregator.
882
+ * @param errors - {@link IMessageAggregator | Error aggregator} in which
883
+ * errors will be aggregated.
884
+ * @param formatter - An optional {@link ErrorFormatter | error formatter}
885
+ * to be used to format the error message.
886
+ * @returns A new {@link AsyncResult} wrapping the result after aggregation.
887
+ */
888
+ aggregateError(errors, formatter) {
889
+ return new AsyncResult(this._promise.then((r) => {
890
+ r.aggregateError(errors, formatter);
891
+ return r;
892
+ }));
893
+ }
894
+ /**
895
+ * Reports the wrapped result to the supplied reporter.
896
+ * @param reporter - The {@link IResultReporter | reporter} to which the result
897
+ * will be reported.
898
+ * @param options - The {@link IResultReportOptions | options} for reporting the result.
899
+ * @returns A new {@link AsyncResult} wrapping the result after reporting.
900
+ */
901
+ report(reporter, options) {
902
+ return new AsyncResult(this._promise.then((r) => {
903
+ r.report(reporter, options);
904
+ return r;
905
+ }));
906
+ }
907
+ /**
908
+ * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.
909
+ * @param onfulfilled - Callback invoked when the promise resolves.
910
+ * @param onrejected - Callback invoked when the promise rejects.
911
+ * @returns A `Promise` resolving to the callback result.
912
+ */
913
+ /* eslint-disable @rushstack/no-new-null */
914
+ then(onfulfilled, onrejected) {
915
+ /* eslint-enable @rushstack/no-new-null */
916
+ return this._promise.then(onfulfilled, onrejected);
917
+ }
918
+ /**
919
+ * Creates an {@link AsyncResult} from a {@link Result}.
920
+ * @param result - The {@link Result} to wrap.
921
+ * @returns A new {@link AsyncResult} wrapping the supplied result.
922
+ */
923
+ static from(result) {
924
+ return new AsyncResult(Promise.resolve(result));
925
+ }
926
+ }
927
+ exports.AsyncResult = AsyncResult;
928
+ /**
929
+ * Wraps an async function which might throw to convert exception results
930
+ * to {@link Failure}.
931
+ * @remarks
932
+ * Returns an {@link AsyncResult} so callers can fluently chain
933
+ * (`.onSuccess` / `.thenOnSuccess` / `.withErrorFormat`) directly off the
934
+ * captured result. Because {@link AsyncResult} implements
935
+ * `PromiseLike<Result<T>>`, existing `await captureAsyncResult(...)` call
936
+ * sites continue to work unchanged and yield the same {@link Result}.
937
+ *
938
+ * Synchronous throws from `func` (before it returns its `Promise`), promise
939
+ * rejections, and successful resolutions are all funneled through the
940
+ * returned {@link AsyncResult}, which resolves to a {@link Failure} for the
941
+ * throw/reject cases and a {@link Success} wrapping the resolved value
942
+ * otherwise.
943
+ * @param func - The async function to be captured.
944
+ * @returns An {@link AsyncResult} resolving to {@link Success} with a value
945
+ * of type `<T>` on success, or {@link Failure} with the thrown error message
946
+ * if `func` throws or rejects.
947
+ * @public
948
+ */
949
+ function captureAsyncResult(func) {
950
+ try {
951
+ return new AsyncResult(func().then((value) => succeed(value)));
952
+ }
953
+ catch (err) {
954
+ return AsyncResult.from(fail(_errorMessage(err)));
628
955
  }
629
956
  }
630
957
  //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAyBH,4CAEC;AA+2BD,0BAEC;AAMD,4BAEC;AAUD,oBAEC;AAMD,sBAEC;AASD,0CAEC;AAoSD,8CAEC;AAMD,gDAEC;AAaD,wCAEC;AAMD,0CAEC;AAaD,kDAQC;AAQD,sCAKC;AAWD,sCAMC;AAqOD,gDAMC;AAphDD,mDAAuF;AAiBvF;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAI,MAAqC;IACvE,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC;AACtC,CAAC;AAiED,mGAAmG;AACnG,uGAAuG;AACvG,oEAAoE;AACpE,MAAM,qBAAqB,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAC;AAcvF,6DAA6D;AAC7D,MAAM,mCAAmC,GAAwC,IAAI,CAAC;AAEtF;;;GAGG;AACU,QAAA,mBAAmB,GAA+B,qBAAqB,CAAC;AA+UrF;;;;GA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,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AA/JD,kCA+JC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,kBAAkB,CAAI,IAAsB;IAC1D,IAAI,CAAC;QACH,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,CAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { _findShouldNotFailFrame, _formatShouldNotFailMessage } from './shouldNotFail';\n\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n// Untyped (literal-tuple-inferred) source of truth for allMessageLogLevels, kept separate from the\n// widened public export below so the exhaustiveness check actually inspects the literal values instead\n// of being widened away to `MessageLogLevel` before the check runs.\nconst messageLogLevelValues = ['quiet', 'detail', 'info', 'warning', 'error'] as const;\n\n/**\n * Compile-time exhaustiveness guard ensuring {@link messageLogLevelValues} exactly matches every member of\n * {@link MessageLogLevel}. Adding or removing a union member without updating the array fails the build.\n * Deliberately not exported - this exists only to force the compiler to evaluate the check below.\n */\ntype _MessageLogLevelExhaustivenessCheck = [\n Exclude<MessageLogLevel, (typeof messageLogLevelValues)[number]>,\n Exclude<(typeof messageLogLevelValues)[number], MessageLogLevel>\n] extends [never, never]\n ? true\n : never;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst _messageLogLevelExhaustivenessCheck: _MessageLogLevelExhaustivenessCheck = true;\n\n/**\n * Exhaustive list of all {@link MessageLogLevel} values.\n * @public\n */\nexport const allMessageLogLevels: readonly MessageLogLevel[] = messageLogLevelValues;\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Asserts at the call site that this {@link IResult | result} MUST be a success.\n * Returns the value on success; on failure, throws an `Error` whose message\n * is composed from the original failure message and the captured call-site\n * location (file, line, and where useful function name).\n *\n * @remarks\n * Use for declaration-time / setup-time invariants — module-level `const`\n * initializers, static class properties, static initialization blocks, and\n * test fixtures — where a failure indicates a coding bug that should\n * surface at the call site rather than propagate as a `Result`. For chains\n * where the throw is intentional control flow, prefer `orThrow`.\n *\n * On V8 (Node + Chromium) `Error.captureStackTrace` is used to elide\n * `shouldNotFail` itself from the captured stack so the parsed frame is\n * the user's call site directly. On WebKit (where `captureStackTrace` is\n * unavailable) the stack is parsed manually and frames whose **parsed\n * function name** contains `shouldNotFail` are filtered out — the raw\n * stack-line text (including the file path) is deliberately NOT inspected,\n * so consumer files named after `shouldNotFail` are not collateral damage.\n * Function names and exact line numbers depend on source-map availability\n * in the runtime. When no caller frame is recoverable (e.g. `frameDepth`\n * out of range, or `frameDepth: 0`) the message falls back to the\n * label-only form (or the bare original message when no label is given).\n *\n * Error message format (depending on whether a label and a usable function\n * name are available):\n * - both: `<label> (at <fn> in <file>:<line>): <original>`\n * - label only: `<label> (at <file>:<line>): <original>`\n * - fn only: `<fn> at <file>:<line>: <original>`\n * - neither: `<file>:<line>: <original>`\n *\n * @param label - Optional human-meaningful identifier (e.g. the constant\n * name) prefixed to the error message.\n * @param frameDepth - Optional 1-indexed depth into the caller stack.\n * Default `1` (immediate caller). Library authors wrapping `shouldNotFail`\n * inside their own helper pass `2` to attribute to their caller.\n * @returns The result value, if the operation was successful.\n * @throws `Error` if the result was a failure.\n */\n shouldNotFail(label?: string, frameDepth?: number): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.shouldNotFail}\n */\n public shouldNotFail(__label?: string, __frameDepth?: number): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.shouldNotFail}\n */\n public shouldNotFail(label?: string, frameDepth: number = 1): never {\n // Parse a probe Error's stack to identify the caller frame for message\n // composition. We must NOT reuse this probe as the thrown Error: in V8,\n // `.stack` is materialized lazily on first access (which happens below in\n // `_findShouldNotFailFrame`), and once materialized the cached stack\n // header carries whatever message was set at that moment. Mutating\n // `.message` afterwards does not refresh the cached `.stack` header.\n const probe = new Error();\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(probe, this.shouldNotFail);\n }\n const frame = _findShouldNotFailFrame(probe.stack, frameDepth);\n const message = _formatShouldNotFailMessage(this._message, label, frame);\n // Build the final Error with the formatted message and re-elide\n // `shouldNotFail` from its stack, so the thrown error's `.stack` shows\n // both the formatted message in its header and the caller as its top\n // frame.\n const err = new Error(message);\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(err, this.shouldNotFail);\n }\n throw err;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for\n * propagation under a different success type.\n * @remarks\n * Supports the canonical Result early-return-after-`isFailure()` pattern when the\n * outer function's success type differs from the inner Result's success type:\n *\n * ```ts\n * const storeResult = await PromptStoreFixture.build(seed);\n * if (storeResult.isFailure()) {\n * return storeResult.withType<PromptLibrary>();\n * }\n * return PromptLibrary.create({ store: storeResult.value, ... });\n * ```\n *\n * Without this helper, TypeScript rejects `return storeResult` because\n * `Failure<IPromptStore>` is invariant in `T` and not assignable to\n * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is\n * semantically equivalent but allocates a new {@link Failure} instance;\n * `withType` returns `this` and only retypes statically.\n *\n * This method is sound because a {@link Failure} variant carries no `T`-shaped\n * data — only an error message — so re-typing it as `Failure<U>` cannot\n * misrepresent any value. The same operation is NOT exposed on {@link Success}\n * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.\n *\n * For `DetailedResult` propagation that preserves a typed `detail`, consider\n * propagating the {@link DetailedFailure} directly through `onSuccess` (which\n * already re-types the success arm) rather than reaching for `withType`.\n *\n * @returns This same {@link Failure} instance, statically retyped as\n * {@link Failure | Failure<U>}.\n * @public\n */\n public withType<U>(): Failure<U> {\n // Safe by construction: Failure carries no T-shaped data, only a message.\n // Re-typing the static T parameter cannot misrepresent any value.\n return this as unknown as Failure<U>;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this._message;\n }\n\n /**\n * Creates a {@link Failure | Failure<T>} with the supplied error message.\n * @param message - The error message to be returned.\n * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.\n */\n public static with<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @remarks\n * A `succeeds` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added\n * to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * {@inheritDoc succeed}\n * @public\n */\nexport function succeeds<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @remarks\n * A `fails` alias was added in release 5.0 due to\n * issues with the name `fail` being used test frameworks and libraries.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * {@inheritDoc fail}\n * @public\n */\nexport function fails<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Uses a value or calls a supplied initializer if the supplied value is undefined.\n * @param value - the value\n * @param initializer - a function that initializes the value if it is undefined\n * @returns `Success` with the value if it is defined, or the result of calling the initializer function.\n * @public\n */\nexport function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T> {\n return value !== undefined ? succeed(value) : initializer();\n}\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to\n * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success\n * details in addition to the error message.\n * @public\n */\nexport class DetailedSuccess<out T, out TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this._value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param __cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedSuccess<T, TD> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n // Cast reporter to preserve detail type when calling reportSuccess\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportSuccess(level, this._value, this._detail, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and\n * optional detail.\n */\n public static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n }\n\n /**\n * Returns this {@link DetailedSuccess} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional\n * failure details in addition to the error message.\n * @public\n */\nexport class DetailedFailure<out T, out TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail?: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param __cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this._message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this._message, this._detail);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this._message, this._detail), this._detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this {\n const message = formatter ? formatter(this._message, this._detail) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedFailure<T, TD> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n // Cast formatter to handle detail type properly\n const formatter = failureOptions.message as ErrorFormatter<TD> | undefined;\n const message = formatter?.(this._message, this._detail) ?? this._message;\n // Cast reporter to preserve detail type when calling reportFailure\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportFailure(level, message, this._detail);\n return this;\n }\n\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message, this._detail));\n } else {\n logOrFormat.error(this._message, this._detail);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * Returns this {@link DetailedFailure} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message\n * and optional detail.\n * @param message - The error message to be returned.\n * @param detail - The error detail to be returned.\n * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * error message and detail.\n * @public\n */\n public static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n }\n}\n\n/**\n * Represents a result with additional detail.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResultValueType<T> = T extends DetailedResult<infer TV, unknown> ? TV : never;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @remarks\n * The `succeedsWithDetail` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added to avoid conflicts\n * with test frameworks and libraries.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * {@inheritDoc succeedWithDetail}\n * @public\n */\nexport function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @remarks\n * The `failsWithDetail` alias was added in release 5.0 for naming consistency\n * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * {@inheritDoc failWithDetail}\n * @public\n */\nexport function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Extracts a message string from an unknown thrown/rejected value.\n * @param err - The caught error value.\n * @returns The error message string.\n * @internal\n */\nexport function _errorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n return String(err);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error` or string.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail(_errorMessage(err));\n }\n}\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} is successful, returning a `PromiseLike` of a new\n * {@link Result}.\n * @remarks\n * Typed as `PromiseLike<Result<TN>>` rather than `Promise<Result<TN>>` so\n * callers can return the result of {@link captureAsyncResult} (which is an\n * {@link AsyncResult}, itself a `PromiseLike<Result<TN>>`) directly from a\n * `thenOnSuccess` callback without an `async` wrapper to coerce the\n * contextual return type back through `Awaited<>`. The continuation result\n * is always wrapped into an {@link AsyncResult}, so chaining is unaffected.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => PromiseLike<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `PromiseLike` of a new {@link Result}.\n * @remarks\n * See {@link AsyncSuccessContinuation} for the rationale behind accepting\n * any `PromiseLike<Result<T>>` rather than only a `Promise<Result<T>>`.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => PromiseLike<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise (or any\n * `PromiseLike` that resolves to a {@link Result}, such as another\n * {@link AsyncResult}).\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` (or `PromiseLike`) that resolves to a\n * {@link Result}.\n */\n public constructor(promise: PromiseLike<Result<T>>) {\n this._promise = Promise.resolve(promise).catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @remarks\n * Returns an {@link AsyncResult} so callers can fluently chain\n * (`.onSuccess` / `.thenOnSuccess` / `.withErrorFormat`) directly off the\n * captured result. Because {@link AsyncResult} implements\n * `PromiseLike<Result<T>>`, existing `await captureAsyncResult(...)` call\n * sites continue to work unchanged and yield the same {@link Result}.\n *\n * Synchronous throws from `func` (before it returns its `Promise`), promise\n * rejections, and successful resolutions are all funneled through the\n * returned {@link AsyncResult}, which resolves to a {@link Failure} for the\n * throw/reject cases and a {@link Success} wrapping the resolved value\n * otherwise.\n * @param func - The async function to be captured.\n * @returns An {@link AsyncResult} resolving to {@link Success} with a value\n * of type `<T>` on success, or {@link Failure} with the thrown error message\n * if `func` throws or rejects.\n * @public\n */\nexport function captureAsyncResult<T>(func: () => Promise<T>): AsyncResult<T> {\n try {\n return new AsyncResult(func().then((value) => succeed(value)));\n } catch (err: unknown) {\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n}\n"]}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Internal helpers for `Result<T>.shouldNotFail()`. Parsing and message
3
+ * composition live here so the `Result` class file stays focused on the
4
+ * Result hierarchy itself; the helpers are exported with the `_` prefix
5
+ * convention and `@internal` tag so unit tests can cover them directly
6
+ * without adding test-only public exports.
7
+ */
8
+ /**
9
+ * Parsed stack-frame information used by `Result<T>.shouldNotFail`.
10
+ * All fields are optional — runtimes that don't expose stack traces produce
11
+ * an empty frame and the call site is omitted from the message.
12
+ * @internal
13
+ */
14
+ export interface _IShouldNotFailFrame {
15
+ fn?: string;
16
+ file?: string;
17
+ line?: number;
18
+ }
19
+ /**
20
+ * Parses a single stack-trace line in either V8 or WebKit format.
21
+ *
22
+ * V8: ` at <fn> (<file>:<line>:<col>)` or ` at <file>:<line>:<col>`
23
+ * WebKit: `<fn>@<file>:<line>:<col>` or `@<file>:<line>:<col>`
24
+ * @internal
25
+ */
26
+ export declare function _parseStackFrame(line: string): _IShouldNotFailFrame;
27
+ /**
28
+ * Finds the caller frame at the supplied depth in a stack string.
29
+ *
30
+ * Filters out frames whose **parsed function name** contains `shouldNotFail`
31
+ * (the file path is deliberately NOT inspected — consumer test files may
32
+ * themselves be named after `shouldNotFail` and their frames must not be
33
+ * filtered out). Covers both the V8 path — where `Error.captureStackTrace`
34
+ * should have done this already but the extra filter is harmless — and the
35
+ * WebKit fallback path where `captureStackTrace` is unavailable. `frameDepth`
36
+ * is 1-indexed: `1` selects the immediate caller.
37
+ * @internal
38
+ */
39
+ export declare function _findShouldNotFailFrame(stack: string | undefined, frameDepth: number): _IShouldNotFailFrame;
40
+ /**
41
+ * Normalizes a function name from a stack frame, returning `undefined` when
42
+ * the name is empty or one of the well-known anonymous-IIFE noise patterns
43
+ * (typically emitted by V8 for module-top-level code).
44
+ * @internal
45
+ */
46
+ export declare function _normalizeShouldNotFailFnName(fn: string | undefined): string | undefined;
47
+ /**
48
+ * Composes the error message thrown by `Result<T>.shouldNotFail` from the
49
+ * captured frame and optional label.
50
+ * @internal
51
+ */
52
+ export declare function _formatShouldNotFailMessage(originalMessage: string, label: string | undefined, frame: _IShouldNotFailFrame): string;
53
+ //# sourceMappingURL=shouldNotFail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shouldNotFail.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/shouldNotFail.ts"],"names":[],"mappings":"AAsBA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,oBAAoB,CAenE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,oBAAoB,CAqB3G;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKxF;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,EAAE,oBAAoB,GAC1B,MAAM,CA2BR"}