uuniq
Version:
Short yet unique IDs.
51 lines (45 loc) • 1.24 kB
TypeScript
type SnowflakeOptions = {
format?: 'numeric' | 'symbolic';
charset?: string;
epoch?: string;
place_id?: number;
};
type SnowflakeResolve = {
created_at: string;
place_id: number;
sequence: number;
};
declare class Snowflake {
private readonly options;
private readonly epoch;
private sequence;
private last_timestamp;
private readonly anybase_encode;
private readonly anybase_decode;
constructor(options?: SnowflakeOptions);
private currentTimestamp;
private waitForNextTime;
generate(): string;
resolve(id: string): SnowflakeResolve;
}
type IncrementOptions = {
format?: 'numeric' | 'symbolic';
initial?: number;
charset?: string;
place_id?: number;
store: {
set: (key: string, value: unknown) => unknown;
get: (key: string) => unknown;
};
};
declare class Increment {
private readonly options;
private readonly store;
private sequence;
private readonly anybase_encode;
constructor(options: IncrementOptions);
private initial;
private readonly syncSequence;
generate(): Promise<string>;
}
export { Increment, type IncrementOptions, Snowflake, type SnowflakeOptions, type SnowflakeResolve };