npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@decaf-ts/transactional-decorators

v0.3.6

Published

Locking and transactions

Readme

Banner

Transactional Decorators

A comprehensive TypeScript library providing transaction management capabilities through decorators, locks, and utilities. This library enables atomic operations, concurrency control, and error handling in your TypeScript applications, ensuring data integrity and thread safety.

Release docs refreshed on 2025-11-26. See workdocs/reports/RELEASE_NOTES.md for ticket summaries.

Core Concepts

  • @transactional: A method decorator that wraps a method in a transaction, ensuring that it is executed atomically.
  • Transaction Class: The core class for managing transaction lifecycle, including creation, execution, and cleanup.
  • Locks: The library provides different lock implementations to control concurrency.
    • SynchronousLock: A simple lock that allows only one transaction to execute at a time.
    • MultiLock: A more advanced lock that allows multiple transactions to execute concurrently, with a configurable limit.

Licence GitHub language count GitHub top language

Build & Test CodeQLSnyk Analysis Pages builder .github/workflows/release-on-tag.yaml

Open Issues Closed Issues Pull Requests Maintained

Forks Stars Watchers

Node Version NPM Version

Documentation available here

Description

The Transactional Decorators library is a standalone module that provides a robust implementation for handling concurrency and transaction management in TypeScript applications. It offers a comprehensive set of tools for ensuring data integrity and thread safety in your code.

Core Components

  • Transaction Class: The central class that manages the lifecycle of transactions, including creation, execution, and cleanup. It provides mechanisms for binding transactions to objects and methods, ensuring proper transaction context propagation.

  • Lock System: A flexible locking mechanism for controlling access to shared resources:

    • Lock: A base class providing fundamental locking capabilities with support for queuing and executing functions when the lock is available.
    • TransactionLock: An interface defining the contract for transaction lock implementations that manage transaction execution order and concurrency.
    • SyncronousLock: A default implementation of TransactionLock that processes transactions one at a time in the order they are submitted.
  • Decorators:

    • @transactional(): A method decorator that enables transactional behavior by wrapping the original method in a transaction context that handles transaction creation, binding, and error handling.
    • transactionalSuperCall(): A utility function for handling super calls in transactional methods, ensuring transaction continuity through the inheritance chain.

Key Features

  • Simple yet powerful locking: The library provides a flexible locking system that can be customized to suit your application's needs.
  • Method decoration with @transactional(): Easily add transactional behavior to your methods with a simple decorator.
  • Instance proxying: The Transaction class can bind to objects, creating proxies that maintain transaction context across method calls.
  • Transaction chaining: Transactions can be linked together, allowing you to group multiple operations into a single atomic transaction.
  • Customizable Transaction Lock: You can implement your own TransactionLock to customize how transactions are processed.
  • Error handling: The library includes built-in error handling to ensure transactions are properly released even when errors occur.
  • Seamless integration with db-decorators: The library works well with the db-decorators package for database operations.

This library is ideal for applications that need to ensure data consistency and handle concurrent operations safely, such as database applications, financial systems, or any application where atomic operations are important.

How to Use

This guide provides examples of how to use the main features of the @decaf-ts/transactional-decorators library.

Transactional Decorator

The @transactional decorator ensures that a method is executed within a transaction.

import { transactional } from '@decaf-ts/transactional-decorators';

class MyService {
  @transactional()
  async myTransactionalMethod() {
    // This method will be executed within a transaction.
  }
}

Locks

The library provides different lock implementations to control concurrency.

SynchronousLock

The SynchronousLock allows only one transaction to execute at a time. This is the default lock.

import { Transaction, SynchronousLock } from '@decaf-ts/transactional-decorators';

Transaction.setLock(new SynchronousLock());

MultiLock

The MultiLock allows multiple transactions to execute concurrently, with a configurable limit.

import { Transaction, MultiLock } from '@decaf-ts/transactional-decorators';

// Allow up to 5 transactions to execute concurrently
Transaction.setLock(new MultiLock(5));

Manual Transaction Management

You can also manage transactions manually using the Transaction class.

import { Transaction } from '@decaf-ts/transactional-decorators';

const myTransaction = new Transaction(
  'MyManualTransaction',
  'myAction',
  async () => {
    // Transaction logic here
  }
);

Transaction.submit(myTransaction);

Related

decaf-ts core decorator-validation db-decorators

Social

LinkedIn

Languages

TypeScript JavaScript NodeJS ShellScript

Getting help

If you have bug reports, questions or suggestions please create a new issue.

Contributing

I am grateful for any contributions made to this project. Please read this to get started.

Supporting

The first and easiest way you can support it is by Contributing. Even just finding a typo in the documentation is important.

Financial support is always welcome and helps keep both me and the project alive and healthy.

So if you can, if this project in any way. either by learning something or simply by helping you save precious time, please consider donating.

License

This project is released under the MIT License.

By developers, for developers...