UNPKG

snowflake-id-maker

Version:

Snowflake.io, generates k-ordered, conflict-free snowflake IDs in a distributed environment.

92 lines (88 loc) 2.59 kB
interface SnowflakeIOOptions { id?: number; datacenter?: number; worker?: number; epoch?: number; seqMask?: number; } type BigInt2String = string; /** * 分布式ID生成器 (雪花算法改进版) * 64位ID结构: [时间戳(42位) | 节点ID(10位) | 序列号(12位)] */ declare class SnowflakeId { private static readonly MAX_DATACENTER; private static readonly MAX_WORKER; private static readonly MAX_SEQUENCE; private readonly id; private readonly genId; private readonly epoch; private readonly seqMask; private seq; private lastTime; private overflow; constructor(options?: SnowflakeIOOptions); next(cb?: (err: Error | null, id?: Buffer) => void): Buffer | undefined; private handleClockBackwards; private handleOverflow; private generateId; } /** * Snowflake * @description 雪花算法生成类 */ declare class Snowflake { private static instance; private instances; /** * @description 生成雪花算法ID * @param options */ static generate(options?: SnowflakeIOOptions): Buffer; private maker; /** * @description 设置雪花算法配置 * @param options */ setOptions(options: SnowflakeIOOptions): SnowflakeId; /** * @description 快速生成雪花id,Buffer */ static generateSnowflakeIdBuffer(options?: SnowflakeIOOptions): Buffer; /** * @description 快速生成雪花id,BigInt */ static generateSnowflakeIdBigint(options?: SnowflakeIOOptions): BigInt; /** * @description 快速生成雪花id,String(BigInt) */ static generateSnowflakeIdString(options?: SnowflakeIOOptions): BigInt2String; /** * @description Snowflake Instance */ static getInstance(): Snowflake; } /** * 快速生成雪花id,Buffer * @param options * @return Buffer */ declare const generateSnowflakeIdBuffer: (options?: SnowflakeIOOptions) => Buffer; /** * 快速生成雪花id,BigInt * @param options * @return BigInt */ declare const generateSnowflakeIdBigint: (options?: SnowflakeIOOptions) => BigInt; /** * 快速生成雪花id,String(BigInt) * @param options * @return String(BigInt) */ declare const generateSnowflakeIdString: (options?: SnowflakeIOOptions) => BigInt2String; /** * 快速生成雪花id,String(BigInt) * @param options */ declare const snowflakeId: (options?: SnowflakeIOOptions) => BigInt2String; export { Snowflake, SnowflakeIOOptions, generateSnowflakeIdBigint, generateSnowflakeIdBuffer, generateSnowflakeIdString, snowflakeId };