Skip to content

Commit

Permalink
fix(NODE-3335): do not validate explain verbosity in client (#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
rose-m authored Jun 24, 2021
1 parent 079bd6c commit 1a57ba8
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ExplainVerbosity = Object.freeze({
} as const);

/** @public */
export type ExplainVerbosity = typeof ExplainVerbosity[keyof typeof ExplainVerbosity];
export type ExplainVerbosity = string;

/**
* For backwards compatibility, true is interpreted as "allPlansExecution"
Expand All @@ -35,20 +35,18 @@ export class Explain {
? ExplainVerbosity.allPlansExecution
: ExplainVerbosity.queryPlanner;
} else {
this.verbosity = ExplainVerbosity[verbosity];
this.verbosity = verbosity;
}
}

static fromOptions(options?: ExplainOptions): Explain | undefined {
if (options?.explain === undefined) return;

const explain = options.explain;
if (typeof explain === 'boolean' || explain in ExplainVerbosity) {
if (typeof explain === 'boolean' || typeof explain === 'string') {
return new Explain(explain);
}

throw new MongoDriverError(
`explain must be one of ${Object.keys(ExplainVerbosity)} or a boolean`
);
throw new MongoDriverError('explain must be a string or a boolean');
}
}

0 comments on commit 1a57ba8

Please sign in to comment.