fluent-type-results
Advanced tools
Comparing version 1.0.9 to 1.0.10
{ | ||
"name": "fluent-type-results", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "FluentTypeResults is a lightweight Typescript library built to solve a common problem - returning an object to either indicate success or failure of an operation instead of using exceptions.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,1 @@ | ||
# FluentTypeResults | ||
@@ -6,14 +5,16 @@ | ||
FluentTypeResults is a Typescript version of [FluentResults](https://github.com/altmann/FluentResults) and uses the same syntax and works great together. | ||
FluentTypeResults is the Typescript version of [FluentResults](https://github.com/altmann/FluentResults) and uses the same syntax and works great together! | ||
**Feedback and pull requests are greatly appreciated!** | ||
## Key Features | ||
- Storing multiple errors in one Result object | ||
- Storing powerful Error and Success objects and not only error string messages | ||
- Designing Errors/Success in an object-oriented way | ||
- Storing the root cause chain of errors in a hierarchical way | ||
* Fully works with the Result class from [FluentResults](https://github.com/altmann/FluentResults) | ||
* Storing multiple errors in one Result object | ||
* Designing Errors/Success in an object-oriented way | ||
* Storing the root cause chain of errors in a hierarchical way | ||
## Installation | ||
```bash | ||
``` bash | ||
npm i fluent-type-results | ||
@@ -24,20 +25,31 @@ ``` | ||
```javascript | ||
import Axios, { AxiosResponse } from 'axios'; | ||
*It is assumed that the web api always returns a `Result<Account>` response.* | ||
``` javascript | ||
import Axios from 'axios'; | ||
import Result from 'fluent-type-results'; | ||
import IAccount from '@dto/IAccount'; | ||
import IAccount from './dto/IAccount'; | ||
export async function getUserAccount(id: number): Promise<Result<IAccount>> { | ||
await Axios.get<Result<IPlexAccount>>(`/account/${id}`).then(({ data }) => { | ||
if (data.isFailed) { | ||
console.log(data.toErrorString); | ||
} | ||
export async function getUserAccount(id: number): Promise<IAccount | null> { | ||
const { data } = await Axios.get<Result<IAccount>>(`/account/${id}`); | ||
return data.value; | ||
}); | ||
if (data.isFailed) { | ||
console.log(data.toErrorString); | ||
} | ||
// value is always null if the result has failed and will otherwise contain the value | ||
return data.value; | ||
} | ||
``` | ||
## Important notes | ||
* Compared to FluentResults, a Result.Ok() function always requires a valid object to be passed with it. | ||
## Articles | ||
- [Clean Up Your Client to Business Logic Relationship With a Result Pattern (C#)](https://alexdunn.org/2019/02/25/clean-up-your-client-to-business-logic-relationship-with-a-result-pattern-c/) | ||
* [Clean Up Your Client to Business Logic Relationship With a Result Pattern (C#)](https://alexdunn.org/2019/02/25/clean-up-your-client-to-business-logic-relationship-with-a-result-pattern-c/) | ||
## Credits | ||
* [Altman](https://github.com/altmann) - For his awesome work on [FluentResults](https://github.com/altmann/FluentResults) |
49099
54