Skip to content

eCollect/distributed-id-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

distributed-id-generator v0.6.1

System wide singleton distributed ID generator.

The library contains the following module groups :

  • Hashing algorithms ( Base32, node-fe1-fpe )
  • Checksum generation and validation ( Modified )
  • ID Generation and validation logic.
  • Guardstore implementation - Redis backend to ensure consistent distributed ID generation

Currently two types of IDs are supported, strictly numeric or base32 alpha-numeric ones.

Usage guidelines

To avoid id format errors and ensure consistency between system services all external usage of the library should be through the definitions found here, after configuring the guardstore.

Example :

	const path = require('path');
	const DistributedIdGenerator = require('distributed-id-generator');

	const idGenerator = DistributedIdGenerator.configureGuardstore({ // Redis optional settings
		host: 'localhost', // default
		port: 6379, // default
		db: 1, // default
		prefix: 'id-guard-store', // default
	}).loadDefinitions(path.join(process.cwd(), './app/ids/'));

Defining Ids :

	const { IdDefinition } = require('distributed-id-generator');

	// name, length including checksum, prefix, algorith either numeric or base32
	module.exports = new IdDefinition('account', 8, 'acc', 'base32');

Definition that is based on another :

	const accountIdDefinition = require('./account');

	// this will produce ids that are : cus-XXXXXXXX-XXXXXXXX
	module.exports = accountIdDefinition.extend('customer', 8, 'cus', 'base32');

About

Prefixed id generator over distributed services

Resources

Stars

Watchers

Forks

Packages

No packages published