@fgv/ts-utils
Advanced tools
Comparing version 3.0.1-alpha.4 to 3.0.1-alpha.5
import * as Logging from './logger'; | ||
export * from './brand'; | ||
export * from './mapResults'; | ||
export * from './messageAggregator'; | ||
export { Normalizer } from './normalize'; | ||
@@ -5,0 +6,0 @@ export * from './result'; |
@@ -55,2 +55,3 @@ "use strict"; | ||
__exportStar(require("./mapResults"), exports); | ||
__exportStar(require("./messageAggregator"), exports); | ||
var normalize_1 = require("./normalize"); | ||
@@ -57,0 +58,0 @@ Object.defineProperty(exports, "Normalizer", { enumerable: true, get: function () { return normalize_1.Normalizer; } }); |
@@ -1,2 +0,2 @@ | ||
import { DetailedResult, Result } from './result'; | ||
import { DetailedResult, IMessageAggregator, Result } from './result'; | ||
/** | ||
@@ -12,3 +12,3 @@ * Aggregates successful result values from a collection of {@link Result | Result<T>}. | ||
*/ | ||
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>; | ||
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): Result<T[]>; | ||
/** | ||
@@ -27,3 +27,3 @@ * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>}, | ||
*/ | ||
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?: string[]): Result<T[]>; | ||
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?: IMessageAggregator): Result<T[]>; | ||
/** | ||
@@ -40,3 +40,3 @@ * Aggregates successful results from a a collection of {@link Result | Result<T>}. | ||
*/ | ||
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>; | ||
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): Result<T[]>; | ||
/** | ||
@@ -53,3 +53,3 @@ * Aggregates error messages from a collection of {@link Result | Result<T>}. | ||
*/ | ||
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): string[]; | ||
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?: IMessageAggregator): string[]; | ||
/** | ||
@@ -66,3 +66,3 @@ * Determines if an iterable collection of {@link Result | Result<T>} were all successful. | ||
*/ | ||
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: string[]): Result<T>; | ||
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: IMessageAggregator): Result<T>; | ||
/** | ||
@@ -110,3 +110,3 @@ * String-keyed record of initialization functions to be passed to {@link (populateObject:1)} | ||
*/ | ||
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>, aggregatedErrors?: string[]): Result<T>; | ||
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>, aggregatedErrors?: IMessageAggregator): Result<T>; | ||
/** | ||
@@ -125,3 +125,3 @@ * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}. | ||
*/ | ||
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: string[]): Result<T>; | ||
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: IMessageAggregator): Result<T>; | ||
//# sourceMappingURL=mapResults.d.ts.map |
@@ -48,3 +48,3 @@ "use strict"; | ||
if (errors.length > 0) { | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessages(errors); | ||
return (0, result_1.fail)(errors.join('\n')); | ||
@@ -80,3 +80,3 @@ } | ||
if (errors.length > 0) { | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessages(errors); | ||
return (0, result_1.fail)(errors.join('\n')); | ||
@@ -110,3 +110,3 @@ } | ||
if (elements.length === 0 && errors.length > 0) { | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessages(errors); | ||
return (0, result_1.fail)(errors.join('\n')); | ||
@@ -133,3 +133,3 @@ } | ||
errors.push(result.message); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(result.message); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessage(result.message); | ||
} | ||
@@ -161,3 +161,3 @@ } | ||
if (errors.length > 0) { | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessages(errors); | ||
return (0, result_1.fail)(errors.join('\n')); | ||
@@ -207,3 +207,3 @@ } | ||
if (errors.length > 0) { | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors); | ||
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.addMessages(errors); | ||
return (0, result_1.fail)(errors.join('\n')); | ||
@@ -210,0 +210,0 @@ } |
@@ -38,2 +38,36 @@ /** | ||
/** | ||
* Simple error aggregator to simplify collecting all errors in | ||
* a flow. | ||
* @public | ||
*/ | ||
export interface IMessageAggregator { | ||
/** | ||
* Indicates whether any messages have been aggregated. | ||
*/ | ||
readonly hasMessages: boolean; | ||
/** | ||
* The aggregated messages. | ||
*/ | ||
readonly messages: ReadonlyArray<string>; | ||
/** | ||
* Adds a message to the aggregator, if defined. | ||
* @param message - The message to add - pass `undefined` | ||
* or the empty string to continue without adding a message. | ||
*/ | ||
addMessage(message: string | undefined): this; | ||
/** | ||
* Adds multiple messages to the aggregator. | ||
* @param messages - the messages to add. | ||
*/ | ||
addMessages(messages: string[] | undefined): this; | ||
/** | ||
* Returns all messages as a single string joined | ||
* using the optionally-supplied `separator`, or | ||
* newline if no separator is specified. | ||
* @param separator - The optional separator used | ||
* to join strings. | ||
*/ | ||
toString(separator?: string): string; | ||
} | ||
/** | ||
* Represents the result of some operation of sequence of operations. | ||
@@ -159,2 +193,9 @@ * @remarks | ||
withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>; | ||
/** | ||
* Propagates interior result, appending any error message to the | ||
* supplied errors array. | ||
* @param errors - {@link IMessageAggregator | Error aggregator} in which | ||
* errors will be aggregated. | ||
*/ | ||
aggregateError(errors: IMessageAggregator): this; | ||
} | ||
@@ -230,2 +271,6 @@ /** | ||
withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>; | ||
/** | ||
* {@inheritdoc IResult.aggregateError} | ||
*/ | ||
aggregateError(errors: IMessageAggregator): this; | ||
} | ||
@@ -301,2 +346,6 @@ /** | ||
/** | ||
* {@inheritdoc IResult.aggregateError} | ||
*/ | ||
aggregateError(errors: IMessageAggregator): this; | ||
/** | ||
* Get a 'friendly' string representation of this object. | ||
@@ -303,0 +352,0 @@ * @remarks |
@@ -109,2 +109,8 @@ "use strict"; | ||
} | ||
/** | ||
* {@inheritdoc IResult.aggregateError} | ||
*/ | ||
aggregateError(errors) { | ||
return this; | ||
} | ||
} | ||
@@ -200,2 +206,9 @@ exports.Success = Success; | ||
/** | ||
* {@inheritdoc IResult.aggregateError} | ||
*/ | ||
aggregateError(errors) { | ||
errors.addMessage(this.message); | ||
return this; | ||
} | ||
/** | ||
* Get a 'friendly' string representation of this object. | ||
@@ -202,0 +215,0 @@ * @remarks |
{ | ||
"name": "@fgv/ts-utils", | ||
"version": "3.0.1-alpha.4", | ||
"version": "3.0.1-alpha.5", | ||
"description": "Assorted Typescript Utilities", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
795357
147
9615