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

snowmaker-refreshed

v1.0.1

Published

An updated node.js version of Snowmaker for adding autoincrement ids to azure tables

Downloads

6

Readme

snowmaker-refreshed

Build Status An version of node-snowmaker that has been updated with the latest npm packages to clear out npm audit issues. Will potentially update this to expose a promise based API as well as the callback-based API.

TODO: Find out why the tests were failing when I found them.

Below is the original README:

A node.js high performance, distributed unique id generator library for Azure storage tables. This gives Azure table storage autoincrement fields.

This is a pure javascript implementation of Tatham Oddie's awesome Snowmaker library

Usage

// Simplest usage:
var snowmaker = require('snowmaker-refreshed');

snowmaker.connect(function (err) {
	snowmaker.nextId("productorders", function(err,value) {		
		console.log("Next productorderid is "+value);
	});
});

Install

API

Snowmaker uses async callbacks to connect to the table storage server and set/return identifiers. The first time a table is queried, Snowmaker will create a blob container and a blob to store the next identifier. Snowmaker will "take" a batch of identifiers all at once, which it will then dispense one at a time for every nextId() call until the batch is used. It will then get another batch. This makes the library high-performance and allows concurrency.

Snowmaker instance methods

These methods are accessible via the snowmaker object, which is a singleton. Only one instance should be running per domain.

snowmaker.connect([connectionString,] callback)

Connects to blob storage and creates a new blob container if it doesn't exist that will store all the identifiers for all tables. Optional connectionString is used to supply connection information. If no connection string is used, then it will connect to the local Azure storage emulator client running on your computer.

connect callback signature: callback(err)

snowmaker.nextId(tableName, callback)

Checks to see if it has any more identifiers left to dispense and if so returns the next one. If not, it will first connect back to blob storage, and will create a blob if one doesn't exist for the specified table, and will grab another batch of identifiers and will write the max+1 batch identifier to storage.

nextId callback signature: callback(err, value)

Snowmaker instance properties

int batchSize (default 1000)

This is the number of identifiers that Snowmaker will "reserve" at a time.

int retries (default 25)

Snowmaker uses Azure's optimistic concurrency feature to make sure its write operation fails if another client running Snowmaker has already written that same batch identifier to blob storage. This ensures that no two running instances of Snowmaker get the same batches or overwrite each other. Snowmaker will retry the write operation this many times before giving up.

string containerName (default "table-ids")

This is the name of the blob container that will store all the identifiers for all the tables in your Azure table storage instance.

bool alphaNumeric (default true)

Snowmaker will use alphanumeric identifiers by default. If this is set, then Snowmaker will convert the identifier from an int to a base-62 encoded string. This is useful if you want shorter more human friendly identifiers instead of large ints or GUIDs. Set to false to use normal ints. Keep in mind that Azure Table Storage sorts keys alphanumerically, so ints won't appear in numeric order in Table Storage.

For instance, this is the same numeric value stored as different types:

Type | Value --- | --- GUID | 00ab1985-0000-0000-0000-000000000000 int | 11213189 base62 | L33T

Plus, large numbers are compressed into small strings using base62. For instance, if one of your table identifiers ever reached 68,289,801,377,242 then that ID would be stored as "johnhamm"!

bool caseSensitive (default true)

Snowmaker will use alphanumeric identifiers with both uppercase and lowercase letters if this is set to true.

Snowmaker and Concurrency

This is Tatham Oddie's diagram from his blog which explains how Snowmaker handles concurrent clients:

Snowmaker concurrent model

More Information

For more information on Snowmaker, please see this blog article on Tatham Oddie's blog.