Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

block-sequence

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

block-sequence - npm Package Compare versions

Comparing version 0.1.6 to 1.0.0

_config.yml

2

lib/Block.js

@@ -1,2 +0,2 @@

var EventEmitter = require('events')
var EventEmitter = require('events').EventEmitter
var debug = require('debug')('block-sequence:block')

@@ -3,0 +3,0 @@ var util = require('util')

var debug = require('debug')('block-sequence:blockarray')
var EventEmitter = require('events')
var EventEmitter = require('events').EventEmitter
var util = require('util')

@@ -32,2 +32,2 @@ var _ = require('lodash')

module.exports = BlockArray
module.exports = BlockArray
{
"name": "block-sequence",
"version": "0.1.6",
"version": "1.0.0",
"description": "A sequential id generator, which grabs blocks of ids rather than just one at a time",
"main": "index.js",
"scripts": {
"test": "mocha tests",
"test": "mocha",
"lint": "eslint .",
"istanbul": "istanbul cover --report html --report lcov _mocha",
"codeclimate": "codeclimate-test-reporter < coverage/lcov.info",
"prepush": "npm run lint && npm test"

@@ -20,15 +22,28 @@ },

"dependencies": {
"async": "^2.0.0-rc.3",
"debug": "^2.2.0",
"dot": "^1.0.3",
"lodash": "^4.11.1"
"async": "^2.1.4",
"debug": "^2.6.0",
"dot": "^1.1.1",
"lodash": "^4.17.4"
},
"devDependencies": {
"eslint": "^0.24.1",
"eslint-config-imperative": "0.0.6",
"eslint-plugin-imperative": "0.0.2",
"block-sequence-reference": "0.1.0",
"husky": "^0.11.4",
"mocha": "^2.4.5"
}
"codeclimate-test-reporter": "^0.4.0",
"eslint": "^3.12.2",
"eslint-config-imperative": "^1.0.0",
"eslint-plugin-imperative": "^1.0.0",
"husky": "^0.13.0",
"istanbul": "^0.4.5",
"mocha": "^3.2.0"
},
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/guidesmiths/block-sequence.git"
},
"bugs": {
"url": "https://github.com/guidesmiths/block-sequence/issues"
},
"homepage": "https://guidesmiths.github.io/block-sequence/"
}
# block-sequence
A sequential id generator, which grabs blocks of ids rather than just one at a time. You can configure active/passive blocks and rotate through them, recharging exhausted blocks in the background while assigning ids from the active one. Driver implementations exist for mongo, redis, mysql and postgres.
[![NPM version](https://img.shields.io/npm/v/block-sequence.svg?style=flat-square)](https://www.npmjs.com/package/block-sequence)
[![NPM downloads](https://img.shields.io/npm/dm/block-sequence.svg?style=flat-square)](https://www.npmjs.com/package/block-sequence)
[![Build Status](https://img.shields.io/travis/guidesmiths/block-sequence/master.svg)](https://travis-ci.org/guidesmiths/block-sequence)
[![Code Climate](https://codeclimate.com/github/guidesmiths/block-sequence/badges/gpa.svg)](https://codeclimate.com/github/guidesmiths/block-sequence)
[![Test Coverage](https://codeclimate.com/github/guidesmiths/block-sequence/badges/coverage.svg)](https://codeclimate.com/github/guidesmiths/block-sequence/coverage)
[![Code Style](https://img.shields.io/badge/code%20style-imperative-brightgreen.svg)](https://github.com/guidesmiths/eslint-config-imperative)
[![Dependency Status](https://david-dm.org/guidesmiths/block-sequence.svg)](https://david-dm.org/guidesmiths/block-sequence)
[![devDependencies Status](https://david-dm.org/guidesmiths/block-sequence/dev-status.svg)](https://david-dm.org/guidesmiths/block-sequence?type=dev)
## tl;dr
```js
var BlockArray = require('block-sequence').BlockArray
var init = require('block-sequence-mysql')
const BlockArray = require('block-sequence').BlockArray
const init = require('block-sequence-mysql')
// Initialise the MySql Block Sequence Driver. Other drivers are available
init({ host: '127.0.0.1', database: 'bs_test', user: 'root' }, function(err, driver) {
init({ host: '127.0.0.1', database: 'bs_test', user: 'root' }, (err, driver) => {
if (err) throw err
// Ensure the sequence exists
driver.ensure({ name: 'my-sequence' }, function(err, sequence) {
driver.ensure({ name: 'my-sequence' }, (err, sequence) => {
if (err) throw err

@@ -21,3 +30,3 @@

// Grab the next id
idGenerator.next(function(err, id) {
idGenerator.next((err, id) => {
if (err) throw err

@@ -34,3 +43,3 @@ console.log(id)

## Why not use something like shortId
I like shortId, but in a multi process / multi host architecture you need to congure each process with a unique worker id. There are also limitations on alphabet making it likely you'll need to use mixed case letters. This can cause problems for MySQL which is case insenstive by defaults and doesn't have a case sensitive utf-8 character set, meaning you have to do horrible things like use different character sets for id columns and data columns in the same table.
I like shortId, but in a multi process / multi host architecture you need to configure each process with a unique worker id. There are also limitations on alphabet making it likely you'll need to use mixed case letters. This can cause problems for MySQL which is case insenstive by default and doesn't have a case sensitive utf-8 character set, meaning you have to do horrible things like use different character sets for id columns and data columns in the same table.

@@ -42,3 +51,3 @@ ## Should I use strings or integers for Ids?

2. If you only use numbers a malicious script or accidental programming mistake could burn through ids very rapidly. If you've prefixed your ids with a string, you can change the prefix and reset the sequence.
2. If you only use numbers a malicious script or programming error could burn through ids very rapidly. If you've prefixed your ids with a string, you can change the prefix and reset the sequence.

@@ -53,4 +62,5 @@ ## What string format should I use?

1. Ids cannot be used to sort records by age (you probably shouldn't do this anyway)
2. When block-sequence initialises it charges its id blocks immediately. If you node app crashes and restarts repeatedly you will end up burning through ids very quickly. You can disable this behaviour by setting "prime" to false in the block configuration, however doing so will mean the first id request will incur a small delay. Even when setting "prime" to false you may burn through ids very quickly if something your application crashes and restarts repeatedly after the first id request.
2. When block-sequence initialises it charges its id blocks immediately. If your node app crashes and restarts repeatedly you will end up burning through ids very quickly. You can disable this behaviour by setting "prime" to false in the block configuration, however doing so will mean the first id request will incur a small delay. Even when setting "prime" to false you may burn through ids very quickly if your application crashes and restarts repeatedly after the first id request.
## How are the sequences stored?

@@ -68,3 +78,2 @@ block-sequence uses plugable drivers to keep track of sequences. The current drivers are

## BlockArray Configuration

@@ -71,0 +80,0 @@ ```json

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc