composable-functions
Advanced tools
Comparing version 4.4.0 to 4.5.0
@@ -203,3 +203,3 @@ import { composable, failure, fromSuccess, success } from './constructors.js'; | ||
/** | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. The mapper receives the original input. | ||
* | ||
@@ -212,4 +212,4 @@ * @example | ||
* const increment = ({ id }: { id: number }) => id + 1 | ||
* const incrementWithErrorSummary = mapErrors(increment, (result) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length }], | ||
* const incrementWithErrorSummary = mapErrors(increment, (result, {id}) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length + ' for id: ' + String(id) }], | ||
* })) | ||
@@ -223,3 +223,3 @@ * ``` | ||
return success(res.data); | ||
const mapped = await composable(mapper)(res.errors); | ||
const mapped = await composable(mapper)(res.errors, ...args); | ||
if (mapped.success) { | ||
@@ -226,0 +226,0 @@ return failure(mapped.data); |
{ | ||
"name": "composable-functions", | ||
"version": "4.4.0", | ||
"version": "4.5.0", | ||
"description": "Types and functions to make composition easy and safe", | ||
@@ -5,0 +5,0 @@ "author": "Seasoned", |
@@ -214,3 +214,3 @@ "use strict"; | ||
/** | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. The mapper receives the original input. | ||
* | ||
@@ -223,4 +223,4 @@ * @example | ||
* const increment = ({ id }: { id: number }) => id + 1 | ||
* const incrementWithErrorSummary = mapErrors(increment, (result) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length }], | ||
* const incrementWithErrorSummary = mapErrors(increment, (result, {id}) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length + ' for id: ' + String(id) }], | ||
* })) | ||
@@ -234,3 +234,3 @@ * ``` | ||
return (0, constructors_js_1.success)(res.data); | ||
const mapped = await (0, constructors_js_1.composable)(mapper)(res.errors); | ||
const mapped = await (0, constructors_js_1.composable)(mapper)(res.errors, ...args); | ||
if (mapped.success) { | ||
@@ -237,0 +237,0 @@ return (0, constructors_js_1.failure)(mapped.data); |
@@ -145,3 +145,3 @@ import type { BranchReturn, CanComposeInParallel, CanComposeInSequence, Composable, MapParametersReturn, MergeObjects, PipeReturn, RecordToTuple, Result, SequenceReturn, UnpackData } from './types.js'; | ||
/** | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. | ||
* Creates a new function that will apply a transformation over the list of Errors of a Failure from a given function. When the given function succeeds, its result is returned without changes. The mapper receives the original input. | ||
* | ||
@@ -154,8 +154,8 @@ * @example | ||
* const increment = ({ id }: { id: number }) => id + 1 | ||
* const incrementWithErrorSummary = mapErrors(increment, (result) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length }], | ||
* const incrementWithErrorSummary = mapErrors(increment, (result, {id}) => ({ | ||
* errors: [{ message: 'Errors count: ' + result.errors.length + ' for id: ' + String(id) }], | ||
* })) | ||
* ``` | ||
*/ | ||
declare function mapErrors<Fn extends Function>(fn: Fn, mapper: (err: Error[]) => Error[] | Promise<Error[]>): Fn extends Internal.AnyFn ? Composable<Fn> : never; | ||
declare function mapErrors<Fn extends Function>(fn: Fn, mapper: (err: Error[], ...originalInput: Parameters<Extract<Fn, Internal.AnyFn>>) => Error[] | Promise<Error[]>): Fn extends Internal.AnyFn ? Composable<Fn> : never; | ||
/** | ||
@@ -162,0 +162,0 @@ * Whenever you need to intercept inputs and a composable result without changing them you can use this function. |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
252236
50
1