snowyflake
Version:
A modern implementation Snowflake on TypeScript
60 lines (59 loc) • 1.67 kB
TypeScript
import type { IDeconstructedSnowflake, ISnowyflakeDeconstructOptions, ISnowyflakeGenerateCustomIdOptions, ISnowyflakeOptions, Snowflake } from './interfaces';
export declare class Snowyflake {
/**
* Snowflake start epoch
*/
readonly epoch: bigint;
/**
* Internal worker ID
*/
readonly workerId: bigint;
/**
* Internal process ID
*/
readonly processId: bigint;
/**
* Sequence increment for process
*/
private sequence;
/**
* Latest timestamp
*/
private latestTimestamp;
/**
* Constructor
*/
constructor({ epoch, workerId, processId, }?: ISnowyflakeOptions);
/**
* Generate a Snowflake
*/
nextId(): Snowflake;
/**
* Deconstruct the Snowflake with local epoch
*/
deconstruct(snowflake: Snowflake): IDeconstructedSnowflake;
/**
* Generate a custom Snowflake
*/
generateCustomId({ timestamp, sequence }: ISnowyflakeGenerateCustomIdOptions): Snowflake;
/**
* Deconstruct the Snowflake timestamp
*/
static deconstructTimestamp(snowflake: Snowflake, epoch: bigint): bigint;
/**
* Deconstruct the Snowflake workerId
*/
static deconstructWorkerId(snowflake: Snowflake): bigint;
/**
* Deconstruct the Snowflake processId
*/
static deconstructProcessId(snowflake: Snowflake): bigint;
/**
* Deconstruct the Snowflake sequence
*/
static deconstructSequence(snowflake: Snowflake): bigint;
/**
* Deconstruct the Snowflake
*/
static deconstruct(snowflake: Snowflake, { epoch }: ISnowyflakeDeconstructOptions): IDeconstructedSnowflake;
}