seasonedcc / composable-functions

Types and functions to make composition easy and safe
MIT License
649 stars 13 forks source link

feat: Add and export makeSuccessResult and makeErrorResult helpers #138

Closed gustavoguichard closed 5 months ago

gustavoguichard commented 5 months ago

Often times, especially in tests, we want to construct the Result type and we have to type all the structure. These functions should help with that by allowing us to construct an ErrorResult like so:

// before: 
const error: ErrorResult = {
  success: false,
  errors: [myError],
  environmentErrors: [],
  inputErrors: [],
}

// after:
const error: ErrorResult = makeErrorResult({ errors: [MyError] })

or a SuccessResult like so:

// before: 
const result: SuccessResult = {
  success: true,
  data,
  errors: [],
  inputErrors: [],
  environmentErrors: [],
}

// after:
const result: SuccessResult = makeSuccessResult(data)