1
- import type { Callback , Document } from '.' ;
2
- import { MongoError } from './error' ;
3
- import { CommandOperation , CommandOperationOptions , OperationParent } from './operations/command' ;
1
+ import type { Document } from '.' ;
2
+ import type { ExplainOptions } from './operations/explainable_command' ;
4
3
import type { Server } from './sdam/server' ;
5
4
import { maxWireVersion } from './utils' ;
6
5
@@ -10,45 +9,6 @@ const SUPPORTS_EXPLAIN_WITH_DISTINCT = 3.2;
10
9
const SUPPORTS_EXPLAIN_WITH_FIND_AND_MODIFY = 3.2 ;
11
10
const SUPPORTS_EXPLAIN_WITH_MAP_REDUCE = 4.4 ;
12
11
13
- /** @internal */
14
- export abstract class ExplainableCommand <
15
- T extends ExplainOptions = ExplainOptions ,
16
- TResult = Document
17
- > extends CommandOperation < T , TResult > {
18
- explain ?: Explain ;
19
-
20
- constructor ( parent ?: OperationParent , options ?: T ) {
21
- super ( parent , options ) ;
22
-
23
- if ( ! Explain . explainOptionsValid ( options ) ) {
24
- throw new MongoError ( `explain must be one of ${ Object . keys ( Verbosity ) } or a boolean` ) ;
25
- }
26
-
27
- this . explain = Explain . fromOptions ( options ) ;
28
- }
29
-
30
- get canRetryWrite ( ) : boolean {
31
- return this . explain === undefined ;
32
- }
33
-
34
- executeCommand ( server : Server , cmd : Document , callback : Callback ) : void {
35
- if ( this . explain ) {
36
- if ( ! Explain . explainSupportedOnCmd ( server , cmd ) ) {
37
- callback ( new MongoError ( `server ${ server . name } does not support explain on this command` ) ) ;
38
- return ;
39
- }
40
-
41
- cmd . explain = this . explain ;
42
- }
43
- super . executeCommand ( server , cmd , callback ) ;
44
- }
45
- }
46
-
47
- /** @public */
48
- export interface ExplainOptions extends CommandOperationOptions {
49
- explain ?: VerbosityLike ;
50
- }
51
-
52
12
/** @public */
53
13
export enum Verbosity {
54
14
queryPlanner = 'queryPlanner' ,
@@ -81,7 +41,7 @@ export class Explain {
81
41
return new Explain ( options . explain ) ;
82
42
}
83
43
84
- static explainOptionsValid ( options ?: ExplainOptions ) : boolean {
44
+ static valid ( options ?: ExplainOptions ) : boolean {
85
45
if ( options == null || options . explain === undefined ) {
86
46
return true ;
87
47
}
0 commit comments