-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move explain cmd/options to separate file
- Loading branch information
1 parent
7090c39
commit 82f0e60
Showing
13 changed files
with
104 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { CommandOperation, OperationParent, CommandOperationOptions } from './command'; | ||
import { Explain, Verbosity, VerbosityLike } from '../explain'; | ||
import { Callback, Document, MongoError, Server } from '..'; | ||
|
||
/** @public */ | ||
export interface ExplainOptions { | ||
explain?: VerbosityLike; | ||
} | ||
|
||
/** @internal */ | ||
export abstract class ExplainableCommand< | ||
T extends ExplainOptions & CommandOperationOptions, | ||
TResult = Document | ||
> extends CommandOperation<T, TResult> { | ||
explain?: Explain; | ||
|
||
constructor(parent?: OperationParent, options?: T) { | ||
super(parent, options); | ||
|
||
if (!Explain.valid(options)) { | ||
throw new MongoError(`explain must be one of ${Object.keys(Verbosity)} or a boolean`); | ||
} | ||
|
||
this.explain = Explain.fromOptions(options); | ||
} | ||
|
||
get canRetryWrite(): boolean { | ||
return this.explain === undefined; | ||
} | ||
|
||
executeCommand(server: Server, cmd: Document, callback: Callback): void { | ||
if (this.explain) { | ||
if (!Explain.explainSupportedOnCmd(server, cmd)) { | ||
callback(new MongoError(`server ${server.name} does not support explain on this command`)); | ||
return; | ||
} | ||
|
||
cmd.explain = this.explain; | ||
} | ||
super.executeCommand(server, cmd, callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters