From a1fe6649506c3242caf7975dbbeb06d7dfe432ae Mon Sep 17 00:00:00 2001 From: Josh Betz Date: Sat, 10 Dec 2022 15:44:16 -0600 Subject: [PATCH] Add option types --- src/hashpool.ts | 8 ++++++-- src/memcached.ts | 7 ++++++- src/pool.ts | 19 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/hashpool.ts b/src/hashpool.ts index 20b22b6..ccda73d 100644 --- a/src/hashpool.ts +++ b/src/hashpool.ts @@ -1,18 +1,22 @@ import { EventEmitter } from 'events'; -import Pool from './pool'; +import Pool, { type PoolOptions } from './pool'; const HashRing = require( 'hashring' ); +export type HashPoolOptions = { + retry: ( retries: number ) => number; +} & PoolOptions; + type PoolNode = { pool: Pool; reconnecting: boolean; }; export default class HashPool extends EventEmitter { - opts: any; hashring: typeof HashRing; nodes: Map; isReady: boolean; retries: number; + opts: HashPoolOptions; constructor( nodes: Array, opts?: any ) { super(); diff --git a/src/memcached.ts b/src/memcached.ts index dadcb8e..f956fb8 100644 --- a/src/memcached.ts +++ b/src/memcached.ts @@ -1,10 +1,15 @@ import { createConnection, type Socket } from 'net'; import { EventEmitter } from 'events'; +export type MemcachedOptions = { + prefix: string; + socketTimeout: number; +}; + export default class Memcached extends EventEmitter { client: Socket; isReady: boolean; - opts: any; + opts: MemcachedOptions; constructor( port: number, host: string, opts?: any ) { super(); diff --git a/src/pool.ts b/src/pool.ts index a65e2f4..64bc306 100644 --- a/src/pool.ts +++ b/src/pool.ts @@ -1,10 +1,25 @@ import { createPool, type Pool as GenericPool } from 'generic-pool'; import { EventEmitter } from 'events'; -import Memcached from './memcached'; +import Memcached, { type MemcachedOptions } from './memcached'; + +export type PoolOptions = { + max: number; + min: number; + acquireTimeoutMillis: number; + destroyTimeoutMillis: number; + maxWaitingClients: number; + idleTimeoutMillis: number; + + // internal + forwardPoolErrors: boolean; + autostart: boolean; + fifo: boolean; + evictionRunIntervalMillis: number; +} & MemcachedOptions; export default class Pool extends EventEmitter { - opts: any; pool: GenericPool; + opts: PoolOptions; constructor( port: number, host: string, opts?: any ) { super();