-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathexplain.ts
52 lines (43 loc) · 1.45 KB
/
explain.ts
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
44
45
46
47
48
49
50
51
52
import { MongoInvalidArgumentError } from './error';
/** @public */
export const ExplainVerbosity = Object.freeze({
queryPlanner: 'queryPlanner',
queryPlannerExtended: 'queryPlannerExtended',
executionStats: 'executionStats',
allPlansExecution: 'allPlansExecution'
} as const);
/** @public */
export type ExplainVerbosity = string;
/**
* For backwards compatibility, true is interpreted as "allPlansExecution"
* and false as "queryPlanner". Prior to server version 3.6, aggregate()
* ignores the verbosity parameter and executes in "queryPlanner".
* @public
*/
export type ExplainVerbosityLike = ExplainVerbosity | boolean;
/** @public */
export interface ExplainOptions {
/** Specifies the verbosity mode for the explain output. */
explain?: ExplainVerbosityLike;
}
/** @internal */
export class Explain {
verbosity: ExplainVerbosity;
constructor(verbosity: ExplainVerbosityLike) {
if (typeof verbosity === 'boolean') {
this.verbosity = verbosity
? ExplainVerbosity.allPlansExecution
: ExplainVerbosity.queryPlanner;
} else {
this.verbosity = verbosity;
}
}
static fromOptions(options?: ExplainOptions): Explain | undefined {
if (options?.explain == null) return;
const explain = options.explain;
if (typeof explain === 'boolean' || typeof explain === 'string') {
return new Explain(explain);
}
throw new MongoInvalidArgumentError('Field "explain" must be a string or a boolean');
}
}