UNPKG

proxy-connection

Version:

Proxy client with automatic connection management, health checking, and fetch-like API

130 lines 4.33 kB
interface SnowflakeConfig { epoch?: number; machineIdBits?: number; sequenceBits?: number; } declare class SnowflakeGenerator { private machineId; private sequence; private lastTimestamp; private readonly epoch; private readonly machineIdBits; private readonly sequenceBits; private readonly timestampBits; private readonly maxMachineId; private readonly maxSequence; private readonly machineIdShift; private readonly timestampShift; constructor(machineId?: number | 'auto', config?: SnowflakeConfig); /** * Generate a new Snowflake ID * @returns {string} 64-bit ID as string */ generate(): string; /** * Generate multiple IDs * @param count Number of IDs to generate * @returns Array of Snowflake IDs */ generateBatch(count: number): string[]; /** * Wait for next millisecond * @param lastTimestamp Previous timestamp * @returns New timestamp */ private waitNextMillis; /** * Parse Snowflake ID to extract components * @param id Snowflake ID string * @returns Object with timestamp, machineId, and sequence */ static parse(id: string, config?: SnowflakeConfig): { timestamp: number; machineId: number; sequence: number; date: Date; }; /** * Parse Snowflake ID using this generator's configuration * @param id Snowflake ID string * @returns Object with timestamp, machineId, and sequence */ parse(id: string): { timestamp: number; machineId: number; sequence: number; date: Date; }; /** * Get generator configuration */ getConfig(): Required<SnowflakeConfig> & { timestampBits: number; maxMachineId: number; maxSequence: number; }; } /** * Generate a Snowflake ID using default generator * @returns Snowflake ID string */ export declare function generateSnowflakeId(): string; /** * Generate multiple Snowflake IDs * @param count Number of IDs to generate * @returns Array of Snowflake IDs */ export declare function generateSnowflakeIds(count: number): string[]; /** * Create a new Snowflake generator with custom machine ID and configuration * @param machineId Machine ID (0 to maxMachineId based on config) * @param config Optional configuration for bit allocation * @returns SnowflakeGenerator instance */ export declare function createSnowflakeGenerator(machineId?: number | 'auto', config?: SnowflakeConfig): SnowflakeGenerator; export declare function createCustomSnowflakeGenerator(config: SnowflakeConfig, machineId?: number | 'auto'): SnowflakeGenerator; /** * Parse Snowflake ID to extract components using default configuration * @param id Snowflake ID string * @param config Optional configuration (should match the generator's config) * @returns Object with timestamp, machineId, sequence, and date */ export declare function parseSnowflakeId(id: string, config?: SnowflakeConfig): { timestamp: number; machineId: number; sequence: number; date: Date; }; /** * Try to get a unique machine ID based on MAC address, hostname, or fallback to random. * @param maxMachineId Maximum allowed machineId (by bit width) */ declare function getAutoMachineId(maxMachineId: number): number; export declare const SnowflakeConfigs: { /** Standard Twitter Snowflake: 42-bit timestamp, 10-bit machine, 12-bit sequence */ STANDARD: { epoch: number; machineIdBits: number; sequenceBits: number; }; /** High frequency: 41-bit timestamp, 8-bit machine, 15-bit sequence (32K/ms per machine) */ HIGH_FREQUENCY: { epoch: number; machineIdBits: number; sequenceBits: number; }; /** Many machines: 40-bit timestamp, 14-bit machine, 10-bit sequence (16K machines, 1K/ms each) */ MANY_MACHINES: { epoch: number; machineIdBits: number; sequenceBits: number; }; /** Minimal machines: 44-bit timestamp, 6-bit machine, 14-bit sequence (64 machines, 16K/ms each) */ MINIMAL_MACHINES: { epoch: number; machineIdBits: number; sequenceBits: number; }; }; export { SnowflakeGenerator, type SnowflakeConfig, getAutoMachineId }; //# sourceMappingURL=index.d.ts.map