UNPKG

uid-pool

Version:

High-performance UUID and unique ID pooling for Node.js. Pre-generate IDs in background worker threads for O(1) synchronous acquisition. Drop-in replacement for uuid.v4() and nanoid() with 10-100x better performance under load.

133 lines 3.71 kB
/** * Base class for all ID pool errors */ export class IdPoolError extends Error { code; constructor(message, code) { super(message); this.name = this.constructor.name; this.code = code; Error.captureStackTrace?.(this, this.constructor); } } /** * Configuration and validation errors */ export class InvalidConfigurationError extends IdPoolError { constructor(message) { super(message, "INVALID_CONFIGURATION"); } } export class InvalidGeneratorError extends IdPoolError { constructor(message = "generator must be a function") { super(message, "INVALID_GENERATOR"); } } export class InvalidPoolSizeError extends IdPoolError { constructor(message = "poolSize must be positive") { super(message, "INVALID_POOL_SIZE"); } } export class InvalidMinSizeError extends IdPoolError { constructor(message = "minSize must be between 0 and poolSize") { super(message, "INVALID_MIN_SIZE"); } } export class InvalidRefillBatchSizeError extends IdPoolError { constructor(message = "refillBatchSize must be positive") { super(message, "INVALID_REFILL_BATCH_SIZE"); } } export class InvalidCapacityError extends IdPoolError { constructor(message = "Capacity must be a positive integer") { super(message, "INVALID_CAPACITY"); } } /** * Runtime operation errors */ export class PoolEmptyError extends IdPoolError { constructor(message = "ID pool is empty") { super(message, "POOL_EMPTY"); } } export class PoolNotReadyError extends IdPoolError { constructor(message = "ID pool is not running") { super(message, "POOL_NOT_READY"); } } export class PoolStoppedError extends IdPoolError { constructor(message = "ID pool stopped while waiting for ID") { super(message, "POOL_STOPPED"); } } export class PoolTimeoutError extends IdPoolError { constructor(message = "Timeout waiting for ID") { super(message, "POOL_TIMEOUT"); } } /** * Generator-related errors */ export class GeneratorFailureError extends IdPoolError { cause; constructor(message, cause) { super(message, "GENERATOR_FAILURE"); this.cause = cause; } } export class InvalidGeneratorOutputError extends IdPoolError { constructor(message) { super(message, "INVALID_GENERATOR_OUTPUT"); } } /** * Worker thread errors */ export class WorkerNotInitializedError extends IdPoolError { constructor(message = "Worker not initialized") { super(message, "WORKER_NOT_INITIALIZED"); } } export class WorkerTimeoutError extends IdPoolError { constructor(message = "Worker timeout") { super(message, "WORKER_TIMEOUT"); } } export class WorkerCrashError extends IdPoolError { exitCode; constructor(message, exitCode) { super(message, "WORKER_CRASH"); this.exitCode = exitCode; } } export class WorkerGenerationError extends IdPoolError { constructor(message) { super(message, "WORKER_GENERATION_ERROR"); } } /** * System and serialization errors */ export class SerializationError extends IdPoolError { cause; constructor(message, cause) { super(message, "SERIALIZATION_ERROR"); this.cause = cause; this.cause = cause; } } export class ResourceExhaustionError extends IdPoolError { constructor(message) { super(message, "RESOURCE_EXHAUSTION"); } } /** * Runtime context errors */ export class InvalidRuntimeError extends IdPoolError { constructor(message = "This file must be run as a worker thread") { super(message, "INVALID_RUNTIME"); } } //# sourceMappingURL=errors.js.map