Rewrite into TypeScript

This commit is contained in:
Wessel T
2019-08-01 16:49:14 +02:00
parent 9e7df46abb
commit 496cd5641c
29 changed files with 863 additions and 174 deletions

33
lib/types.ts Normal file
View File

@@ -0,0 +1,33 @@
export interface SnowflakeConfig {
name?: string;
async?: boolean;
epoch?: number;
workerId?: any,
processId?: number,
stringify?: boolean,
workerBits: number,
processBits: number,
incrementBits: number
}
export interface SnowflakeMutable {
locks: any;
locked: boolean;
increment: any;
lastTimestamp: number;
}
export type Snowflake = number;
export interface SnowflakeWorker {
options: SnowflakeConfig;
workerId: number;
_mutable: SnowflakeMutable;
processId: number;
_maxIncrement: number;
_lock(): void;
_unlock(): void;
generate(): Snowflake;
_generate(): Snowflake;
_generateAsync(): Snowflake;
}