A transaction client to ensure all logical steps in an atomic transaction are completed or rolled back.
yarn add transaction-client
import { TransactionClient, TransactionStep } from 'transaction-client';
const client = new TransactionClient();
const getFirstTodoItem = new TransactionStep('fetchRoleFromDb', async () => ({
todo1: await fetch('https://jsonplaceholder.typicode.com/todos/1'),
}));
const getSecondTodoItem = new TransactionStep('fetchRoleFromDb', async () => ({
todo2: await fetch('https://jsonplaceholder.typicode.com/todos/2'),
}));
const data = client
.addStep(getFirstTodoItem)
.addStep(getSecondTodoItem)
.start({ checkErrors: true })
.then(({ todo1, todo2 }) => {
console.log({ todo1, todo2 });
});
The following dependencies must be available on your machine:
- node @ ^8.10.0 || ^10.13.0 || >=11.10.1
- yarn @ ^1.17
- Run
yarn install
to install package dependencies - Run
yarn test
to ensure that tests are passing - Run
yarn dev
to build TypeScript with hot reloading - Make changes to package
Contributions are welcome. Please read CONTRIBUTING.md for code of conduct details, and the process for submitting pull requests.
This project is licensed under the GNU GPL 3 License - see the LICENSE file for details.