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 🙏

© 2024 – Pkg Stats / Ryan Hefner

xact-id-tiny

v0.0.7

Published

A tiny little transaction ID tracker.

Downloads

18,805

Readme

xact-id-tiny

Keeping state sucks. Nobody wants to do it.

If you find yourself in a situation where you are tracking transaction IDs (because, say, you have an asynchronous network app and you want to know how many are outstanding at any given time) you may feel like the code required to track your transactions is too large and pollutes an otherwise small codebase that just does whatever it's supposed to do.

So let something else do the lifting for tracking transaction IDs and generating unique values for those transactions. That's what this package is for.

quickly

I know you're busy. Here's the real simple use pattern:

var xit  = require( 'xact-id-tiny' )
  , xact = xit.add_xact( );

database.do_a_thing( args, function (e, rvalue) {
  if (e) { return new Error( 'gasp! database breakage!' ) }
  else   { xit.end_xact( xact ); return rvalue;           }
} );

Easy, right? The rest of the API is defined below.

api

var n = xit.nonce()

Returns a guaranteed-to-be-unique string. Note that this string is not actually stored in the register of open transactions. If you would like xact-id-tiny to use your fancy unique ID generator, just overwrite the nonce() function with your own.

var t = new xit.xact()
var t = new xit.xact(serial)

Returns a transaction object suitable for use with add_xact() and end_xact(). If you wish to use your own serial (because you have a means of providing your own or whatever), pass it in as an optional argument. The transaction object is very simple:

{
  'serial'  : nonce,
  'state'   : scalar, // 'open' or 'closed'
  'opened'  : scalar, // the return from moment().format()
  'closed'  : scalar, // the return from moment().format()
}

You may pass in any object that contains these four keys and use it to keep state through transactions.

var xact = xit.add_xact( transaction );
var xact = xit.add_xact( );

Attempts to "open" a new transaction, Returns the transaction object stored in the transaction register. Any failures will result in an Error being returned with a hopefully-useful string.

When called without arguments, it will create the transaction object for you, using the internal nonce() function.

var xact = xit.end_xact( transaction );
var xact = xit.end_xact( serial );

Attempts to "close" the transaction specified. Returns an Error with a hopefully-useful string in the event something goes wrong.

var xact = xit.get_xact( transaction );
var xact = xit.get_xact( serial );

Attempts to return to you a transaction object from either the transaction object (as it exists in the register, which may differ than what you have in your local code if you are doing things concurrently or in separate packages) or the serial that was used to track that object.

extra stuff

  • You may set the comment field of your transaction objects. When the transaction is closed, if there is a comment ('opening a socket to foomatic dot com' or whichever), this will be sent to log4js in the INFO facility along with the delta for that transaction.
  • There's no magic to the objects. Theoretically, you can store anything you like in them, and the api only pays attention to the four (five…) fields listed above.