Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 1.45 KB

README.md

File metadata and controls

61 lines (40 loc) · 1.45 KB

Transaction Client

Description

A transaction client to ensure all logical steps in an atomic transaction are completed or rolled back.

Use

Install

yarn add transaction-client

Example

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 });
  });

Development

Dependencies

The following dependencies must be available on your machine:

  • node @ ^8.10.0 || ^10.13.0 || >=11.10.1
  • yarn @ ^1.17

Local Setup

  1. Run yarn install to install package dependencies
  2. Run yarn test to ensure that tests are passing
  3. Run yarn dev to build TypeScript with hot reloading
  4. Make changes to package

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for code of conduct details, and the process for submitting pull requests.

License

This project is licensed under the GNU GPL 3 License - see the LICENSE file for details.