@fgv/ts-utils 5.1.0-27 → 5.1.0-29

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.
@@ -303,6 +303,45 @@ export class Failure {
303
303
  reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message);
304
304
  return this;
305
305
  }
306
+ /**
307
+ * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
308
+ * propagation under a different success type.
309
+ * @remarks
310
+ * Supports the canonical Result early-return-after-`isFailure()` pattern when the
311
+ * outer function's success type differs from the inner Result's success type:
312
+ *
313
+ * ```ts
314
+ * const storeResult = await PromptStoreFixture.build(seed);
315
+ * if (storeResult.isFailure()) {
316
+ * return storeResult.withType<PromptLibrary>();
317
+ * }
318
+ * return PromptLibrary.create({ store: storeResult.value, ... });
319
+ * ```
320
+ *
321
+ * Without this helper, TypeScript rejects `return storeResult` because
322
+ * `Failure<IPromptStore>` is invariant in `T` and not assignable to
323
+ * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
324
+ * semantically equivalent but allocates a new {@link Failure} instance;
325
+ * `withType` returns `this` and only retypes statically.
326
+ *
327
+ * This method is sound because a {@link Failure} variant carries no `T`-shaped
328
+ * data — only an error message — so re-typing it as `Failure<U>` cannot
329
+ * misrepresent any value. The same operation is NOT exposed on {@link Success}
330
+ * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
331
+ *
332
+ * For `DetailedResult` propagation that preserves a typed `detail`, consider
333
+ * propagating the {@link DetailedFailure} directly through `onSuccess` (which
334
+ * already re-types the success arm) rather than reaching for `withType`.
335
+ *
336
+ * @returns This same {@link Failure} instance, statically retyped as
337
+ * {@link Failure | Failure<U>}.
338
+ * @public
339
+ */
340
+ withType() {
341
+ // Safe by construction: Failure carries no T-shaped data, only a message.
342
+ // Re-typing the static T parameter cannot misrepresent any value.
343
+ return this;
344
+ }
306
345
  /**
307
346
  * Get a 'friendly' string representation of this object.
308
347
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAiBH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAI,MAAqC;IACvE,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC;AACtC,CAAC;AAoWD;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAgBlB;;;OAGG;IACH,YAAmB,KAAQ;QAnB3B;;WAEG;QACa,YAAO,GAAS,IAAI,CAAC;QAErC;;WAEG;QACa,YAAO,GAAc,SAAS,CAAC;QAY7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAWM,OAAO,CAAC,QAAyC;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAUM,SAAS,CAAC,IAAQ;;QACvB,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,QAAwB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,IAAQ;;QAC/B,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,SAAS,CAAK,EAA8B;QACjD,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,EAA0B;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,aAAa,CAAK,EAAmC;QAC1D,IAAI,CAAC;Y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C,CAAC;IAC3E,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,MAA0B,EAAE,SAA0B;QAC1E,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAA6B,EAAE,OAAuC;QAClF,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,IAAsB;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this._message;\n }\n\n /**\n * Creates a {@link Failure | Failure<T>} with the supplied error message.\n * @param message - The error message to be returned.\n * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.\n */\n public static with<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @remarks\n * A `succeeds` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added\n * to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * {@inheritDoc succeed}\n * @public\n */\nexport function succeeds<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @remarks\n * A `fails` alias was added in release 5.0 due to\n * issues with the name `fail` being used test frameworks and libraries.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * {@inheritDoc fail}\n * @public\n */\nexport function fails<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Uses a value or calls a supplied initializer if the supplied value is undefined.\n * @param value - the value\n * @param initializer - a function that initializes the value if it is undefined\n * @returns `Success` with the value if it is defined, or the result of calling the initializer function.\n * @public\n */\nexport function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T> {\n return value !== undefined ? succeed(value) : initializer();\n}\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to\n * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success\n * details in addition to the error message.\n * @public\n */\nexport class DetailedSuccess<out T, out TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this._value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param __cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedSuccess<T, TD> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n // Cast reporter to preserve detail type when calling reportSuccess\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportSuccess(level, this._value, this._detail, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and\n * optional detail.\n */\n public static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n }\n\n /**\n * Returns this {@link DetailedSuccess} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional\n * failure details in addition to the error message.\n * @public\n */\nexport class DetailedFailure<out T, out TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail?: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param __cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this._message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this._message, this._detail);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this._message, this._detail), this._detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this {\n const message = formatter ? formatter(this._message, this._detail) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedFailure<T, TD> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n // Cast formatter to handle detail type properly\n const formatter = failureOptions.message as ErrorFormatter<TD> | undefined;\n const message = formatter?.(this._message, this._detail) ?? this._message;\n // Cast reporter to preserve detail type when calling reportFailure\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportFailure(level, message, this._detail);\n return this;\n }\n\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message, this._detail));\n } else {\n logOrFormat.error(this._message, this._detail);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * Returns this {@link DetailedFailure} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message\n * and optional detail.\n * @param message - The error message to be returned.\n * @param detail - The error detail to be returned.\n * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * error message and detail.\n * @public\n */\n public static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n }\n}\n\n/**\n * Represents a result with additional detail.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResultValueType<T> = T extends DetailedResult<infer TV, unknown> ? TV : never;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @remarks\n * The `succeedsWithDetail` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added to avoid conflicts\n * with test frameworks and libraries.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * {@inheritDoc succeedWithDetail}\n * @public\n */\nexport function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @remarks\n * The `failsWithDetail` alias was added in release 5.0 for naming consistency\n * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * {@inheritDoc failWithDetail}\n * @public\n */\nexport function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Extracts a message string from an unknown thrown/rejected value.\n * @param err - The caught error value.\n * @returns The error message string.\n * @internal\n */\nexport function _errorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n return String(err);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error` or string.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail(_errorMessage(err));\n }\n}\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} is successful, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise.\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` that resolves to a {@link Result}.\n */\n public constructor(promise: Promise<Result<T>>) {\n this._promise = promise.catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The async function to be captured.\n * @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on\n * success, or {@link Failure} with the thrown error message if `func` throws or rejects.\n * @public\n */\nexport async function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>> {\n try {\n return succeed(await func());\n } catch (err: unknown) {\n return fail(_errorMessage(err));\n }\n}\n"]}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAiBH;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAI,MAAqC;IACvE,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC;AACtC,CAAC;AAoWD;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAgBlB;;;OAGG;IACH,YAAm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AE;YACvB,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAA6B,EAAE,OAAuC;QAClF,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAI,IAAsB;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * 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 `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise.\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` that resolves to a {@link Result}.\n */\n public constructor(promise: Promise<Result<T>>) {\n this._promise = promise.catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The async function to be captured.\n * @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on\n * success, or {@link Failure} with the thrown error message if `func` throws or rejects.\n * @public\n */\nexport async function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>> {\n try {\n return succeed(await func());\n } catch (err: unknown) {\n return fail(_errorMessage(err));\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CA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M,UAAU,WAAW,CACzB,GAAwB,EACxB,OAAsC;IAEtC,MAAM,MAAM,GAAmB,EAAoB,CAAC;IACpD,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACtB,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAgBjD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,IAAkB,CAAC;AAC5B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAiB,CAAC,CAAC,EAAE,CAAC;QAChG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAgC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CA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AAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,IAAI,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;gBAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Union of all values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type OneOf<T> = T extends readonly unknown[] ? T[number] : never;\r\n\r\n/**\r\n * Union of all string values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type StringOneOf<T> = Extract<OneOf<T>, string>;\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
@@ -2486,6 +2486,41 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
2486
2486
  * {@inheritDoc IResult.report}
2487
2487
  */
2488
2488
  report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T>;
2489
+ /**
2490
+ * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
2491
+ * propagation under a different success type.
2492
+ * @remarks
2493
+ * Supports the canonical Result early-return-after-`isFailure()` pattern when the
2494
+ * outer function's success type differs from the inner Result's success type:
2495
+ *
2496
+ * ```ts
2497
+ * const storeResult = await PromptStoreFixture.build(seed);
2498
+ * if (storeResult.isFailure()) {
2499
+ * return storeResult.withType<PromptLibrary>();
2500
+ * }
2501
+ * return PromptLibrary.create({ store: storeResult.value, ... });
2502
+ * ```
2503
+ *
2504
+ * Without this helper, TypeScript rejects `return storeResult` because
2505
+ * `Failure<IPromptStore>` is invariant in `T` and not assignable to
2506
+ * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
2507
+ * semantically equivalent but allocates a new {@link Failure} instance;
2508
+ * `withType` returns `this` and only retypes statically.
2509
+ *
2510
+ * This method is sound because a {@link Failure} variant carries no `T`-shaped
2511
+ * data — only an error message — so re-typing it as `Failure<U>` cannot
2512
+ * misrepresent any value. The same operation is NOT exposed on {@link Success}
2513
+ * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
2514
+ *
2515
+ * For `DetailedResult` propagation that preserves a typed `detail`, consider
2516
+ * propagating the {@link DetailedFailure} directly through `onSuccess` (which
2517
+ * already re-types the success arm) rather than reaching for `withType`.
2518
+ *
2519
+ * @returns This same {@link Failure} instance, statically retyped as
2520
+ * {@link Failure | Failure<U>}.
2521
+ * @public
2522
+ */
2523
+ withType<U>(): Failure<U>;
2489
2524
  /**
2490
2525
  * Get a 'friendly' string representation of this object.
2491
2526
  * @remarks
@@ -4934,6 +4969,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4934
4969
  */
4935
4970
  export declare function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K>;
4936
4971
 
4972
+ /**
4973
+ * Union of all values in an array/tuple type, preserving literal types if possible.
4974
+ * If T is not an array/tuple, results in `never`.
4975
+ * @public
4976
+ */
4977
+ export declare type OneOf<T> = T extends readonly unknown[] ? T[number] : never;
4978
+
4937
4979
  /**
4938
4980
  * A helper function to create a {@link Converter | Converter} for polymorphic values.
4939
4981
  * Returns a converter which invokes the wrapped converters in sequence, returning the
@@ -5845,6 +5887,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
5845
5887
  message?: string;
5846
5888
  }
5847
5889
 
5890
+ /**
5891
+ * Union of all string values in an array/tuple type, preserving literal types if possible.
5892
+ * If T is not an array/tuple, results in `never`.
5893
+ * @public
5894
+ */
5895
+ export declare type StringOneOf<T> = Extract<OneOf<T>, string>;
5896
+
5848
5897
  /**
5849
5898
  * An in-place {@link Validation.Validator | Validator} for `string` values.
5850
5899
  * @public
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.57.7"
8
+ "packageVersion": "7.58.7"
9
9
  }
10
10
  ]
11
11
  }
@@ -536,6 +536,41 @@ export declare class Failure<out T> implements IResult<T> {
536
536
  * {@inheritDoc IResult.report}
537
537
  */
538
538
  report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T>;
539
+ /**
540
+ * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
541
+ * propagation under a different success type.
542
+ * @remarks
543
+ * Supports the canonical Result early-return-after-`isFailure()` pattern when the
544
+ * outer function's success type differs from the inner Result's success type:
545
+ *
546
+ * ```ts
547
+ * const storeResult = await PromptStoreFixture.build(seed);
548
+ * if (storeResult.isFailure()) {
549
+ * return storeResult.withType<PromptLibrary>();
550
+ * }
551
+ * return PromptLibrary.create({ store: storeResult.value, ... });
552
+ * ```
553
+ *
554
+ * Without this helper, TypeScript rejects `return storeResult` because
555
+ * `Failure<IPromptStore>` is invariant in `T` and not assignable to
556
+ * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
557
+ * semantically equivalent but allocates a new {@link Failure} instance;
558
+ * `withType` returns `this` and only retypes statically.
559
+ *
560
+ * This method is sound because a {@link Failure} variant carries no `T`-shaped
561
+ * data — only an error message — so re-typing it as `Failure<U>` cannot
562
+ * misrepresent any value. The same operation is NOT exposed on {@link Success}
563
+ * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
564
+ *
565
+ * For `DetailedResult` propagation that preserves a typed `detail`, consider
566
+ * propagating the {@link DetailedFailure} directly through `onSuccess` (which
567
+ * already re-types the success arm) rather than reaching for `withType`.
568
+ *
569
+ * @returns This same {@link Failure} instance, statically retyped as
570
+ * {@link Failure | Failure<U>}.
571
+ * @public
572
+ */
573
+ withType<U>(): Failure<U>;
539
574
  /**
540
575
  * Get a 'friendly' string representation of this object.
541
576
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAsBA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhD;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,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 : reporter.reportFailure(level, message);
322
322
  return this;
323
323
  }
324
+ /**
325
+ * Re-types this {@link Failure | Failure<T>} as {@link Failure | Failure<U>} for
326
+ * propagation under a different success type.
327
+ * @remarks
328
+ * Supports the canonical Result early-return-after-`isFailure()` pattern when the
329
+ * outer function's success type differs from the inner Result's success type:
330
+ *
331
+ * ```ts
332
+ * const storeResult = await PromptStoreFixture.build(seed);
333
+ * if (storeResult.isFailure()) {
334
+ * return storeResult.withType<PromptLibrary>();
335
+ * }
336
+ * return PromptLibrary.create({ store: storeResult.value, ... });
337
+ * ```
338
+ *
339
+ * Without this helper, TypeScript rejects `return storeResult` because
340
+ * `Failure<IPromptStore>` is invariant in `T` and not assignable to
341
+ * `Result<PromptLibrary>`. The workaround `return fail<U>(r.message)` is
342
+ * semantically equivalent but allocates a new {@link Failure} instance;
343
+ * `withType` returns `this` and only retypes statically.
344
+ *
345
+ * This method is sound because a {@link Failure} variant carries no `T`-shaped
346
+ * data — only an error message — so re-typing it as `Failure<U>` cannot
347
+ * misrepresent any value. The same operation is NOT exposed on {@link Success}
348
+ * because `Success<T>` carries `T`-shaped data and re-typing would be a lie.
349
+ *
350
+ * For `DetailedResult` propagation that preserves a typed `detail`, consider
351
+ * propagating the {@link DetailedFailure} directly through `onSuccess` (which
352
+ * already re-types the success arm) rather than reaching for `withType`.
353
+ *
354
+ * @returns This same {@link Failure} instance, statically retyped as
355
+ * {@link Failure | Failure<U>}.
356
+ * @public
357
+ */
358
+ withType() {
359
+ // Safe by construction: Failure carries no T-shaped data, only a message.
360
+ // Re-typing the static T parameter cannot misrepresent any value.
361
+ return this;
362
+ }
324
363
  /**
325
364
  * Get a 'friendly' string representation of this object.
326
365
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAuBH,4CAEC;AAiuBD,0BAEC;AAMD,4BAEC;AAUD,oBA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3E,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,MAA0B,EAAE,SAA0B;QAC1E,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAA6B,EAAE,OAAuC;QAClF,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AA5JD,kCA4JC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAAI,IAAsB;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this._message;\n }\n\n /**\n * Creates a {@link Failure | Failure<T>} with the supplied error message.\n * @param message - The error message to be returned.\n * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.\n */\n public static with<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @remarks\n * A `succeeds` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added\n * to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * {@inheritDoc succeed}\n * @public\n */\nexport function succeeds<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @remarks\n * A `fails` alias was added in release 5.0 due to\n * issues with the name `fail` being used test frameworks and libraries.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * {@inheritDoc fail}\n * @public\n */\nexport function fails<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Uses a value or calls a supplied initializer if the supplied value is undefined.\n * @param value - the value\n * @param initializer - a function that initializes the value if it is undefined\n * @returns `Success` with the value if it is defined, or the result of calling the initializer function.\n * @public\n */\nexport function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T> {\n return value !== undefined ? succeed(value) : initializer();\n}\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to\n * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success\n * details in addition to the error message.\n * @public\n */\nexport class DetailedSuccess<out T, out TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this._value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param __cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedSuccess<T, TD> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n // Cast reporter to preserve detail type when calling reportSuccess\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportSuccess(level, this._value, this._detail, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and\n * optional detail.\n */\n public static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n }\n\n /**\n * Returns this {@link DetailedSuccess} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional\n * failure details in addition to the error message.\n * @public\n */\nexport class DetailedFailure<out T, out TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail?: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param __cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this._message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this._message, this._detail);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this._message, this._detail), this._detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter<TD>): this {\n const message = formatter ? formatter(this._message, this._detail) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(\n reporter?: IResultReporter<T, unknown>,\n options?: IResultReportOptions<unknown>\n ): DetailedFailure<T, TD> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n // Cast formatter to handle detail type properly\n const formatter = failureOptions.message as ErrorFormatter<TD> | undefined;\n const message = formatter?.(this._message, this._detail) ?? this._message;\n // Cast reporter to preserve detail type when calling reportFailure\n const detailedReporter = reporter as IResultReporter<T, TD> | undefined;\n detailedReporter?.reportFailure(level, message, this._detail);\n return this;\n }\n\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message, this._detail));\n } else {\n logOrFormat.error(this._message, this._detail);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * Returns this {@link DetailedFailure} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message\n * and optional detail.\n * @param message - The error message to be returned.\n * @param detail - The error detail to be returned.\n * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * error message and detail.\n * @public\n */\n public static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n }\n}\n\n/**\n * Represents a result with additional detail.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResultValueType<T> = T extends DetailedResult<infer TV, unknown> ? TV : never;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @remarks\n * The `succeedsWithDetail` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added to avoid conflicts\n * with test frameworks and libraries.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * {@inheritDoc succeedWithDetail}\n * @public\n */\nexport function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @remarks\n * The `failsWithDetail` alias was added in release 5.0 for naming consistency\n * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * {@inheritDoc failWithDetail}\n * @public\n */\nexport function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Extracts a message string from an unknown thrown/rejected value.\n * @param err - The caught error value.\n * @returns The error message string.\n * @internal\n */\nexport function _errorMessage(err: unknown): string {\n if (err instanceof Error) {\n return err.message;\n }\n return String(err);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error` or string.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail(_errorMessage(err));\n }\n}\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} is successful, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise.\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` that resolves to a {@link Result}.\n */\n public constructor(promise: Promise<Result<T>>) {\n this._promise = promise.catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The async function to be captured.\n * @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on\n * success, or {@link Failure} with the thrown error message if `func` throws or rejects.\n * @public\n */\nexport async function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>> {\n try {\n return succeed(await func());\n } catch (err: unknown) {\n return fail(_errorMessage(err));\n }\n}\n"]}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAuBH,4CAEC;AAywBD,0BAEC;AAMD,4BAEC;AAUD,oBAEC;AAMD,sBAEC;AASD,0CAEC;AAoSD,8CAEC;AAMD,gDAEC;AAaD,wCAEC;AAMD,0CAEC;AAaD,kDAQC;AAQD,sCAKC;AAWD,sCAMC;AA0MD,g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E,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,MAA0B,EAAE,SAA0B;QAC1E,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,QAA6B,EAAE,OAAuC;QAClF,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACvB,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,CAAC,CAAC;QACX,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,2CAA2C;IACpC,IAAI,CACT,WAA6E,EAC7E,UAA2E;QAE3E,0CAA0C;QAC1C,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAI,MAAiB;QACrC,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AA5JD,kCA4JC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,kBAAkB,CAAI,IAAsB;IAChE,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n\n/**\n * Represents a deferred result that will be evaluated if needed.\n * @public\n */\nexport type DeferredResult<T> = () => Result<T>;\n\n/**\n * Checks if a result is a deferred result.\n * @param result - The result to check.\n * @returns `true` if the result is a deferred result, `false` otherwise.\n * @public\n */\nexport function isDeferredResult<T>(result: Result<T> | DeferredResult<T>): result is DeferredResult<T> {\n return typeof result === 'function';\n}\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the result type of an {@link IResult}.\n * @beta\n */\nexport type IResultValueType<T> = T extends IResult<infer TV> ? TV : never;\n\n/**\n * Type inference to determine the value type returned from a result-map style\n * `get` method.\n * @remarks\n * Useful for extracting collection entry types from maps whose `get` method\n * returns an {@link IResult}.\n * @beta\n */\nexport type ResultMapValueType<TCollection extends { get: (...args: readonly unknown[]) => unknown }> =\n Exclude<IResultValueType<ReturnType<TCollection['get']>>, undefined>;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow | orThrow(logger)} and {@link IResult.orThrow | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * The severity level at which a message should be logged.\n * @public\n */\nexport type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';\n\n/**\n * Details for reporting a message.\n * @public\n */\nexport interface IMessageReportDetail<TD = unknown> {\n level?: MessageLogLevel;\n message?: ErrorFormatter<TD>;\n detail?: TD;\n}\n\n/**\n * Options for reporting a result.\n * @public\n */\nexport interface IResultReportOptions<TD = unknown> {\n /**\n * The level of reporting to be used for failure results. Default is 'error'.\n */\n failure?: MessageLogLevel | IMessageReportDetail<TD>;\n\n /**\n * The level of reporting to be used for success results. Default is 'quiet'.\n */\n success?: MessageLogLevel | IMessageReportDetail<TD>;\n}\n\n/**\n * Interface for reporting a result.\n * @public\n */\nexport interface IResultReporter<T, TD = unknown> {\n /** Reports a successful result at the specified log level. */\n reportSuccess(level: MessageLogLevel, value: T, detail?: TD, message?: ErrorFormatter<TD>): void;\n /** Reports a failed result at the specified log level. */\n reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow(logger)} or {@link IResult.orThrow | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.orDefault | orDefault(T)} or {@link IResult.orDefault | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the operation was a success, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation} to\n * be called in the event of success.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the error message from this failure.\n */\n thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN>;\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the operation failed, bridging into an {@link AsyncResult} chain.\n * @remarks\n * If the async callback rejects, the rejection is caught and converted\n * to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation} to\n * be called in the event of failure.\n * @returns An {@link AsyncResult} wrapping the async continuation result, or\n * propagating the success value from this result.\n */\n thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter} to be used to format the error message.\n */\n aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this;\n\n /**\n * Reports the result to the supplied reporter\n * @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n */\n report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Result<T>;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow(logger)} or {@link Success.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.orDefault | orDefault(T)} or {@link Success.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._value));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(__: AsyncFailureContinuation<T>): AsyncResult<T> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(this);\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator, __formatter?: ErrorFormatter): this {\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Success<T> {\n const successOptions =\n typeof options?.success === 'object' ? options.success : { level: options?.success };\n const level = successOptions.level ?? 'quiet';\n reporter?.reportSuccess(level, this._value, undefined, successOptions.message);\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<out T> implements IResult<T> {\n /**\n * {@inheritDoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritDoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritDoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritDoc IResult.orThrow}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritDoc IResult.orDefault}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow(logger)} or {@link Failure.orThrow | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritDoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.orDefault | orDefault(T)} or {@link Failure.orDefault | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritDoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritDoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritDoc IResult.thenOnSuccess}\n */\n public thenOnSuccess<TN>(__: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<TN>(this._message));\n }\n\n /**\n * {@inheritDoc IResult.thenOnFailure}\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return new AsyncResult(cb(this._message));\n } catch (err: unknown) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return AsyncResult.from(fail<T>(_errorMessage(err)));\n }\n }\n\n /**\n * {@inheritDoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritDoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritDoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): this {\n const message = formatter ? formatter(this._message) : this._message;\n errors.addMessage(message);\n return this;\n }\n\n /**\n * {@inheritDoc IResult.report}\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): Failure<T> {\n const failureOptions =\n typeof options?.failure === 'object' ? options.failure : { level: options?.failure };\n const level = failureOptions.level ?? 'error';\n const message = failureOptions.message?.(this._message) ?? this._message;\n reporter?.reportFailure(level, message);\n return this;\n }\n\n /**\n * 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 `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncSuccessContinuation<T, TN> = (value: T) => Promise<Result<TN>>;\n\n/**\n * Async continuation callback to be called in the event that a\n * {@link Result} fails, returning a `Promise` of a new {@link Result}.\n * @public\n */\nexport type AsyncFailureContinuation<T> = (message: string) => Promise<Result<T>>;\n\n/**\n * Wraps a `Promise` of a {@link Result} to enable fluent chaining of both\n * synchronous and asynchronous operations.\n *\n * @remarks\n * `AsyncResult<T>` implements `PromiseLike` so it can be directly `await`ed.\n * Use the `thenOnSuccess` and `thenOnFailure` methods on {@link Result} to bridge\n * from synchronous to asynchronous result chains.\n *\n * @example\n * ```typescript\n * const result: Result<Final> = await parseInput(input)\n * .thenOnSuccess(async (parsed) => fetchData(parsed))\n * .onSuccess((data) => transform(data))\n * .thenOnSuccess(async (transformed) => saveData(transformed))\n * .withErrorFormat((msg) => `pipeline failed: ${msg}`);\n * ```\n *\n * @public\n */\nexport class AsyncResult<T> implements PromiseLike<Result<T>> {\n private readonly _promise: Promise<Result<T>>;\n\n /**\n * Constructs an {@link AsyncResult} wrapping the supplied promise.\n * @remarks\n * If the supplied promise rejects, the rejection is caught and converted\n * to a {@link Failure}, ensuring that awaiting an {@link AsyncResult} always\n * yields a {@link Result}.\n * @param promise - A `Promise` that resolves to a {@link Result}.\n */\n public constructor(promise: Promise<Result<T>>) {\n this._promise = promise.catch((err: unknown) => fail<T>(_errorMessage(err)));\n }\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the wrapped result is successful.\n * @param cb - The synchronous {@link SuccessContinuation | success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(this._promise.then((r) => r.onSuccess(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncSuccessContinuation | async success continuation} if\n * the wrapped result is successful.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncSuccessContinuation | async success continuation}\n * to be called in the event of success.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnSuccess<TN>(cb: AsyncSuccessContinuation<T, TN>): AsyncResult<TN> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isFailure()) {\n return fail<TN>(r.message);\n }\n try {\n return await cb(r.value);\n } catch (err: unknown) {\n return fail<TN>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link FailureContinuation | failure continuation} if\n * the wrapped result is a failure.\n * @param cb - The synchronous {@link FailureContinuation | failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the continuation result.\n */\n public onFailure(cb: FailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.onFailure(cb)));\n }\n\n /**\n * Calls a supplied {@link AsyncFailureContinuation | async failure continuation} if\n * the wrapped result is a failure.\n * @remarks\n * Both synchronous throws and async rejections from the callback are caught\n * and converted to a {@link Failure}.\n * @param cb - The {@link AsyncFailureContinuation | async failure continuation}\n * to be called in the event of failure.\n * @returns A new {@link AsyncResult} wrapping the async continuation result.\n */\n public thenOnFailure(cb: AsyncFailureContinuation<T>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then(async (r) => {\n if (r.isSuccess()) {\n return r;\n }\n try {\n return await cb(r.message);\n } catch (err: unknown) {\n return fail<T>(_errorMessage(err));\n }\n })\n );\n }\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the wrapped result is a failure.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns A new {@link AsyncResult} with the formatted error message,\n * or the original success result.\n */\n public withErrorFormat(cb: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(this._promise.then((r) => r.withErrorFormat(cb)));\n }\n\n /**\n * Propagates the wrapped result, appending any error message to the\n * supplied errors aggregator.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n * @param formatter - An optional {@link ErrorFormatter | error formatter}\n * to be used to format the error message.\n * @returns A new {@link AsyncResult} wrapping the result after aggregation.\n */\n public aggregateError(errors: IMessageAggregator, formatter?: ErrorFormatter): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.aggregateError(errors, formatter);\n return r;\n })\n );\n }\n\n /**\n * Reports the wrapped result to the supplied reporter.\n * @param reporter - The {@link IResultReporter | reporter} to which the result\n * will be reported.\n * @param options - The {@link IResultReportOptions | options} for reporting the result.\n * @returns A new {@link AsyncResult} wrapping the result after reporting.\n */\n public report(reporter?: IResultReporter<T>, options?: IResultReportOptions<unknown>): AsyncResult<T> {\n return new AsyncResult(\n this._promise.then((r) => {\n r.report(reporter, options);\n return r;\n })\n );\n }\n\n /**\n * Implementation of `PromiseLike.then` enabling `await` on {@link AsyncResult}.\n * @param onfulfilled - Callback invoked when the promise resolves.\n * @param onrejected - Callback invoked when the promise rejects.\n * @returns A `Promise` resolving to the callback result.\n */\n /* eslint-disable @rushstack/no-new-null */\n public then<TResult1 = Result<T>, TResult2 = never>(\n onfulfilled?: ((value: Result<T>) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null\n ): Promise<TResult1 | TResult2> {\n /* eslint-enable @rushstack/no-new-null */\n return this._promise.then(onfulfilled, onrejected);\n }\n\n /**\n * Creates an {@link AsyncResult} from a {@link Result}.\n * @param result - The {@link Result} to wrap.\n * @returns A new {@link AsyncResult} wrapping the supplied result.\n */\n public static from<T>(result: Result<T>): AsyncResult<T> {\n return new AsyncResult(Promise.resolve(result));\n }\n}\n\n/**\n * Wraps an async function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The async function to be captured.\n * @returns Returns a `Promise` of {@link Success} with a value of type `<T>` on\n * success, or {@link Failure} with the thrown error message if `func` throws or rejects.\n * @public\n */\nexport async function captureAsyncResult<T>(func: () => Promise<T>): Promise<Result<T>> {\n try {\n return succeed(await func());\n } catch (err: unknown) {\n return fail(_errorMessage(err));\n }\n}\n"]}
@@ -1,4 +1,16 @@
1
1
  import { Result } from './result';
2
+ /**
3
+ * Union of all values in an array/tuple type, preserving literal types if possible.
4
+ * If T is not an array/tuple, results in `never`.
5
+ * @public
6
+ */
7
+ export type OneOf<T> = T extends readonly unknown[] ? T[number] : never;
8
+ /**
9
+ * Union of all string values in an array/tuple type, preserving literal types if possible.
10
+ * If T is not an array/tuple, results in `never`.
11
+ * @public
12
+ */
13
+ export type StringOneOf<T> = Extract<OneOf<T>, string>;
2
14
  /**
3
15
  * Helper type-guard function to report whether a specified key is present in
4
16
  * a supplied object.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjD;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,CAEhG;AAED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CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/packlets/base/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AA0BH,0BAEC;AAUD,oBAQC;AAWD,oBAOC;AAQD,sCAEC;AAQD,0CAEC;AAQD,4CAEC;AAQD,8CAEC;AAiBD,kCAEC;AAaD,kEAMC;AAaD,8CAeC;AAgBD,kCAgBC;AAUD,kDAKC;AAUD,4EAKC;AAUD,kCAgBC;AAUD,kDAKC;AAUD,4EAKC;AA9RD,qCAAiD;AAgBjD;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAmB,GAA6B,EAAE,IAAO;IAC9E,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,IAAI,CAAsC,IAAO,EAAE,OAAY;IAC7E,MAAM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AAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gCAAgC,CAC9C,GAAoC,EACpC,OAAsC;IAEtC,OAAO,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAA,gBAAO,EAAC,EAAoB,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/*\r\n * Copyright (c) 2020 Erik Fortune\r\n *\r\n * Permission is hereby granted, free of charge, to any person obtaining a copy\r\n * of this software and associated documentation files (the \"Software\"), to deal\r\n * in the Software without restriction, including without limitation the rights\r\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n * copies of the Software, and to permit persons to whom the Software is\r\n * furnished to do so, subject to the following conditions:\r\n *\r\n * The above copyright notice and this permission notice shall be included in all\r\n * copies or substantial portions of the Software.\r\n *\r\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n * SOFTWARE.\r\n */\r\n\r\nimport { Result, fail, succeed } from './result';\r\n\r\n/**\r\n * Union of all values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type OneOf<T> = T extends readonly unknown[] ? T[number] : never;\r\n\r\n/**\r\n * Union of all string values in an array/tuple type, preserving literal types if possible.\r\n * If T is not an array/tuple, results in `never`.\r\n * @public\r\n */\r\nexport type StringOneOf<T> = Extract<OneOf<T>, string>;\r\n\r\n/**\r\n * Helper type-guard function to report whether a specified key is present in\r\n * a supplied object.\r\n * @param key - The key to be tested.\r\n * @param item - The object to be tested.\r\n * @returns Returns `true` if the key is present, `false` otherwise.\r\n * @public\r\n */\r\nexport function isKeyOf<T extends object>(key: string | number | symbol, item: T): key is keyof T {\r\n return item.hasOwnProperty(key);\r\n}\r\n\r\n/**\r\n * Simple implicit pick function, which picks a set of properties from a supplied\r\n * object. Ignores picked properties that do not exist regardless of type signature.\r\n * @param from - The object from which keys are to be picked.\r\n * @param include - The keys of the properties to be picked from `from`.\r\n * @returns A new object containing the requested properties from `from`, where present.\r\n * @public\r\n */\r\nexport function pick<T extends object, K extends keyof T>(from: T, include: K[]): Pick<T, K> {\r\n const rtrn: Partial<Pick<T, K>> = {};\r\n for (const key of include) {\r\n if (key in from) {\r\n rtrn[key] = from[key];\r\n }\r\n }\r\n return rtrn as Pick<T, K>;\r\n}\r\n\r\n/**\r\n * Simple implicit omit function, which picks all of the properties from a supplied\r\n * object except those specified for exclusion.\r\n * @param from - The object from which keys are to be picked.\r\n * @param exclude - The keys of the properties to be excluded from the returned object.\r\n * @returns A new object containing all of the properties from `from` that were not\r\n * explicitly excluded.\r\n * @public\r\n */\r\nexport function omit<T extends object, K extends keyof T>(from: T, exclude: K[]): Omit<T, K> {\r\n const rtrn: Partial<Omit<T, K>> = {};\r\n for (const entry of Object.entries(from).filter((e) => !exclude.includes(e[0] as keyof T as K))) {\r\n rtrn[entry[0] as unknown as keyof Omit<T, K>] = entry[1];\r\n }\r\n\r\n return rtrn as Omit<T, K>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) key extractor for typed records.\r\n * @param obj - The record from which keys are to be extracted.\r\n * @returns The keys of the record as an array.\r\n * @public\r\n */\r\nexport function keysForRecord<TK extends string>(obj: Record<TK, unknown>): TK[] {\r\n return Object.keys(obj) as TK[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) value extractor for typed records.\r\n * @param obj - The record from which values are to be extracted.\r\n * @returns The values of the record as an array.\r\n * @public\r\n */\r\nexport function valuesForRecord<TK extends string, TV>(obj: Record<TK, TV>): TV[] {\r\n return Object.values(obj) as TV[];\r\n}\r\n\r\n/**\r\n * Type-safe(ish) entries extractor for typed records.\r\n * @param obj - The record from which entries are to be extracted.\r\n * @returns The entries of the record as an array of `[key, value]` tuples.\r\n * @public\r\n */\r\nexport function entriesForRecord<TK extends string, TV>(obj: Record<TK, TV>): Array<[TK, TV]> {\r\n return Object.entries(obj) as Array<[TK, TV]>;\r\n}\r\n\r\n/**\r\n * Type-safe(ish) record constructor from an iterable of `[key, value]` tuples.\r\n * @param entries - The iterable of `[key, value]` tuples from which to construct the record.\r\n * @returns A record constructed from the supplied entries.\r\n * @public\r\n */\r\nexport function recordFromEntries<TK extends string, TV>(entries: Iterable<[TK, TV]>): Record<TK, TV> {\r\n return Object.fromEntries(entries) as Record<TK, TV>;\r\n}\r\n\r\n/**\r\n * Helper type to extract the element type and preserve readonly status.\r\n * @public\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport type EnsureArrayResult<T> = T extends readonly (infer _U)[] ? T : T[];\r\n\r\n/**\r\n * Ensures the input is an array. If already an array, returns it as-is.\r\n * If a single item, wraps it in an array.\r\n * Preserves readonly status of input arrays.\r\n * @param items - A single item or an array of items.\r\n * @returns The input array unchanged, or a new array containing the single item.\r\n * @public\r\n */\r\nexport function ensureArray<T>(items: T): EnsureArrayResult<T> {\r\n return (Array.isArray(items) ? items : [items]) as EnsureArrayResult<T>;\r\n}\r\n\r\n/**\r\n * Gets the value of a property specified by key from an arbitrary object,\r\n * or a default value if the property does not exist.\r\n * @param key - The key specifying the property to be retrieved.\r\n * @param item - The object from which the property is to be retrieved.\r\n * @param defaultValue - An optional default value to be returned if the property\r\n * is not present (default `undefined`).\r\n * @returns The value of the requested property, or the default value if the\r\n * requested property does not exist.\r\n * @public\r\n */\r\nexport function getValueOfPropertyOrDefault<T extends object>(\r\n key: string | number | symbol,\r\n item: T,\r\n defaultValue?: unknown\r\n): unknown | undefined {\r\n return isKeyOf(key, item) ? item[key] : defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the type of a property specified by key from an arbitrary object.\r\n * @param key - The key specifying the property to be tested.\r\n * @param item - The object from which the property is to be tested.\r\n * @returns The type of the requested property, or `undefined` if the\r\n * property does not exist.\r\n * @example\r\n * Returns `'undefined'` (a string) if the property exists but has the value\r\n * undefined but `undefined` (the literal) if the property does not exist.\r\n * @public\r\n */\r\nexport function getTypeOfProperty<T extends object>(\r\n key: string | number | symbol,\r\n item: T\r\n):\r\n | 'string'\r\n | 'number'\r\n | 'bigint'\r\n | 'boolean'\r\n | 'symbol'\r\n | 'undefined'\r\n | 'undefined'\r\n | 'object'\r\n | 'function'\r\n | undefined {\r\n return isKeyOf(key, item) ? typeof item[key] : undefined;\r\n}\r\n\r\n/**\r\n * Type for factory methods which convert a key-value pair to a new unique value.\r\n * @public\r\n */\r\ntype KeyedThingFactory<TS, TD, TK extends string = string> = (key: TK, thing: TS) => Result<TD>;\r\n\r\n/**\r\n * Applies a factory method to convert a `Record<TK, TS>` into a `Map<TK, TD>`.\r\n * @param src - The `Record` to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map on success, or {@link Failure} with a\r\n * message if an error occurs.\r\n * @public\r\n */\r\nexport function recordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n const map = new Map<TK, TD>();\r\n for (const key in src) {\r\n if (src[key] !== undefined) {\r\n const itemResult = factory(key, src[key]);\r\n if (itemResult.isSuccess()) {\r\n map.set(key, itemResult.value);\r\n } else {\r\n return fail(`${key}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(map);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`, or `undefined`.\r\n * @param src - The `Record` to be converted, or undefined.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map if conversion succeeds, or {@link Success} with `undefined`\r\n * if `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `Record<TK, TS>` into a `Map<TK, TD>`\r\n * @param src - The `Record` to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting map (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalRecordToPossiblyEmptyMap<TS, TD, TK extends string = string>(\r\n src: Record<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Map<TK, TD>> {\r\n return src === undefined ? succeed(new Map<TK, TD>()) : recordToMap(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.\r\n * @param src - The `Map` object to be converted.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting `Record<TK, TD>` if conversion succeeds, or\r\n * {@link Failure} with an error message if an error occurs.\r\n * @public\r\n */\r\nexport function mapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS>,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n const record: Record<TK, TD> = {} as Record<TK, TD>;\r\n for (const kvp of src) {\r\n if (kvp[1] !== undefined) {\r\n const itemResult = factory(kvp[0], kvp[1]);\r\n if (itemResult.isSuccess()) {\r\n record[kvp[0]] = itemResult.value;\r\n } else {\r\n return fail(`${kvp[0]}: ${itemResult.message}`);\r\n }\r\n }\r\n }\r\n return succeed(record);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>` or `undefined`.\r\n * @param src - The `Map` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record if conversion succeeds, or {@link Success} with `undefined` if\r\n * `src` is `undefined`. Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD> | undefined> {\r\n return src === undefined ? succeed(undefined) : mapToRecord(src, factory);\r\n}\r\n\r\n/**\r\n * Applies a factory method to convert an optional `ReadonlyMap<string, TS>` into a `Record<string, TD>`\r\n * @param src - The `ReadonlyMap` object to be converted, or `undefined`.\r\n * @param factory - The factory method used to convert elements.\r\n * @returns {@link Success} with the resulting record (empty if `src` is `undefined`) if conversion succeeds.\r\n * Returns {@link Failure} with a message if an error occurs.\r\n * @public\r\n */\r\nexport function optionalMapToPossiblyEmptyRecord<TS, TD, TK extends string = string>(\r\n src: ReadonlyMap<TK, TS> | undefined,\r\n factory: KeyedThingFactory<TS, TD, TK>\r\n): Result<Record<TK, TD>> {\r\n return src === undefined ? succeed({} as Record<TK, TD>) : mapToRecord(src, factory);\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "5.1.0-27",
3
+ "version": "5.1.0-29",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "module": "dist/index.js",
@@ -54,8 +54,8 @@
54
54
  "@rushstack/heft-jest-plugin": "1.2.6",
55
55
  "eslint-plugin-tsdoc": "~0.5.2",
56
56
  "typedoc": "~0.28.16",
57
- "@fgv/heft-dual-rig": "5.1.0-27",
58
- "@fgv/typedoc-compact-theme": "5.1.0-27"
57
+ "@fgv/heft-dual-rig": "5.1.0-29",
58
+ "@fgv/typedoc-compact-theme": "5.1.0-29"
59
59
  },
60
60
  "repository": {
61
61
  "type": "git",