Skip to content

Commit

Permalink
fix(types): add missing pool stats (nodejs#1573)
Browse files Browse the repository at this point in the history
* fix(types): add missing pool stats

* fix(test): expect type fix
  • Loading branch information
SkeLLLa authored and crysmags committed Feb 27, 2024
1 parent be0119d commit ea8444f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/types/pool.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Duplex, Readable, Writable } from 'stream'
import { expectAssignable } from 'tsd'
import { expectAssignable, expectType } from 'tsd'
import { Dispatcher, Pool, Client } from '../..'
import { URL } from 'url'

Expand All @@ -16,6 +16,7 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
// properties
expectAssignable<boolean>(pool.closed)
expectAssignable<boolean>(pool.destroyed)
expectAssignable<Pool.PoolStats>(pool.stats)

// request
expectAssignable<Promise<Dispatcher.ResponseData>>(pool.request({ origin: '', path: '', method: 'GET' }))
Expand Down Expand Up @@ -100,4 +101,12 @@ expectAssignable<Pool>(new Pool('', { connections: 1 }))
expectAssignable<void>(pool.destroy(() => {}))
expectAssignable<void>(pool.destroy(new Error(), () => {}))
expectAssignable<void>(pool.destroy(null, () => {}))

// stats
expectType<number>(pool.stats.connected)
expectType<number>(pool.stats.free)
expectType<number>(pool.stats.pending)
expectType<number>(pool.stats.queued)
expectType<number>(pool.stats.running)
expectType<number>(pool.stats.size)
}
19 changes: 19 additions & 0 deletions types/pool-stats.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Pool = require("./pool")

export = PoolStats

declare class PoolStats {
constructor(pool: Pool);
/** Number of open socket connections in this pool. */
connected: number;
/** Number of open socket connections in this pool that do not have an active request. */
free: number;
/** Number of pending requests across all clients in this pool. */
pending: number;
/** Number of queued requests across all clients in this pool. */
queued: number;
/** Number of currently active requests across all clients in this pool. */
running: number;
/** Number of active, pending, or queued requests across all clients in this pool. */
size: number;
}
4 changes: 4 additions & 0 deletions types/pool.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Client = require('./client')
import Dispatcher = require('./dispatcher')
import TPoolStats = require('./pool-stats')
import { URL } from 'url'

export = Pool
Expand All @@ -10,9 +11,12 @@ declare class Pool extends Dispatcher {
closed: boolean;
/** `true` after `pool.destroyed()` has been called or `pool.close()` has been called and the pool shutdown has completed. */
destroyed: boolean;
/** Aggregate stats for a Pool. */
readonly stats: TPoolStats;
}

declare namespace Pool {
export type PoolStats = TPoolStats;
export interface Options extends Client.Options {
/** Default: `(origin, opts) => new Client(origin, opts)`. */
factory?(origin: URL, opts: object): Dispatcher;
Expand Down

0 comments on commit ea8444f

Please sign in to comment.