All files / src/operations stats.ts

90.9% Statements 10/11
50% Branches 1/2
100% Functions 3/3
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43          135x 135x                 135x       422x 422x       466x               378x 378x       378x       135x  
import type { Document } from '../bson';
import type { Db } from '../db';
import type { Server } from '../sdam/server';
import type { ClientSession } from '../sessions';
import { type TimeoutContext } from '../timeout';
import { CommandOperation, type CommandOperationOptions } from './command';
import { Aspect, defineAspects } from './operation';
 
/** @public */
export interface DbStatsOptions extends CommandOperationOptions {
  /** Divide the returned sizes by scale value. */
  scale?: number;
}
 
/** @internal */
export class DbStatsOperation extends CommandOperation<Document> {
  override options: DbStatsOptions;
 
  constructor(db: Db, options: DbStatsOptions) {
    super(db, options);
    this.options = options;
  }
 
  override get commandName() {
    return 'dbStats' as const;
  }
 
  override async execute(
    server: Server,
    session: ClientSession | undefined,
    timeoutContext: TimeoutContext
  ): Promise<Document> {
    const command: Document = { dbStats: true };
    Iif (this.options.scale != null) {
      command.scale = this.options.scale;
    }
 
    return await super.executeCommand(server, session, command, timeoutContext);
  }
}
 
defineAspects(DbStatsOperation, [Aspect.READ_OPERATION]);