UNPKG

btuid

Version:

Btuid library provides an interface to generate UIDs (Unique Identifiers) that are safe, cryptographically secure, and unpredictable, ensuring that every UUID is unique. The library also supports B+tree indexing, which makes it ideal for use in database s

57 lines (43 loc) 2.75 kB
import {BtuidGenerator,} from '../src/btuid'//'btuid' if install it from npm import * as path from 'path'; //path to save last uuid data ,default save every day const filePath = path.join(__dirname,"btuidDataFolder",'dataTableName.json'); //if you want best Performance make generator for every table or one for every tables for more securaty const generator = new BtuidGenerator( {path: filePath,securityKey : "mykey"} ); const extraBtuid = generator.getExtraBtuid(); //get btuid --> use this console.log(extraBtuid) //06e77028e74c0082-26c4838e4a1f408b //advance import {DegreeConfig ,ConstructorParams,RestConfigData} from '../src/btuid' //DegreeConfig for Btree (search in your database setting for your table ) let degreeConfig :DegreeConfig ={ pageSize: 8192, // Total size of one page in bytes (usually 8 KB) keySize: 16, // Size of the key used in indexing TIDSize: 6, // Size of the TID (tuple ID or pointer to actual data) indexTupleDataSize: 4, // Size of the data stored with each index entry linePointerSize: 4, // Size of a pointer to a line (record) in the page addingPaddingSize: 2, // Extra padding size to align memory correctly degree: 0 // will be calculated from previous values or if enter value another 0 as 10 // it set degree =10 and ignores another values (menual set degree) } //RestConfigData to set this value if you want start without dataTableName.json from any point let restConfigData :RestConfigData = { depth: 0, // Current depth level of the tree structure degree: 0, // Again, branching factor – repeated here chunkLength: 0n, // Length of the ID chunk (in BigInt format) indexInCurrentDepth: 0n, // Position within the current depth level startValue: 0n, // Start value for ID generation or indexing usedIdCount: 0n // 0 or 1 }; let constructorParams :ConstructorParams ={ degreeConfig: degreeConfig, // Pass in the Btree Degree config startValue: 16428364n, // Where to start generated IDs from it Ignores everything before it displacementRate: 7, // The field reduces the minimum and maximum used as a type of encryption. restConfigData: restConfigData, path: filePath, // Path to a file or location (probably to save state) saveTime: 86400 , // How often to save the data (in mseconds) – 86400 = 1 day hexLength : 16, randomLength : 16, securityKey : "myprivatekey" } //not all params required const advanceGenerator = new BtuidGenerator( constructorParams );