Skip to content

Commit

Permalink
chore: fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Dec 16, 2024
1 parent 6b90041 commit d2f956a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/client-side-encryption/auto_encrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export class AutoEncrypter {
_mongocrypt: MongoCrypt;

/**
* @internal
* Used by devtools to enable decorating decryption results.
*
* When set and enabled, `decrypt` will automatically recursively
Expand Down
27 changes: 5 additions & 22 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,11 @@ export function parseOptions(
);
}

const loggerFeatureFlag = '__enableMongoLogger';
mongoOptions[loggerFeatureFlag] = mongoOptions[loggerFeatureFlag] ?? false;
mongoOptions.__enableMongoLogger = mongoOptions.__enableMongoLogger ?? false;

let loggerEnvOptions: MongoLoggerEnvOptions = {};
let loggerClientOptions: MongoLoggerMongoClientOptions = {};
if (mongoOptions[loggerFeatureFlag]) {
if (mongoOptions.__enableMongoLogger) {
loggerEnvOptions = {
MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND,
MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,
Expand All @@ -523,7 +522,7 @@ export function parseOptions(
MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH,
...mongoOptions['__internalLoggerConfig']
...mongoOptions.__internalLoggerConfig
};
loggerClientOptions = {
mongodbLogPath: mongoOptions.mongodbLogPath,
Expand Down Expand Up @@ -1313,27 +1312,11 @@ export const OPTIONS = {
mongodbLogMaxDocumentLength: { type: 'uint' },
__enableMongoLogger: { type: 'boolean' },
__skipPingOnConnect: { type: 'boolean' },
__internalLoggerConfig: { type: 'any' }
} as Record<
keyof Omit<
MongoClientOptions,
'__enableMongoLogger' | '__internalLoggerConfig' | '__skipPingOnConnect'
>,
OptionDescriptor
>;
__internalLoggerConfig: { type: 'record' }
} as Record<keyof MongoClientOptions, OptionDescriptor>;

export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
Object.entries(OPTIONS)
.filter(([, descriptor]) => descriptor.default != null)
.map(([k, d]) => [k, d.default])
);

/**
* Set of permitted feature flags
* @internal
*/
export const FEATURE_FLAGS = new Set([
'__skipPingOnConnect',
'__enableMongoLogger',
'__internalLoggerConfig'
]);
3 changes: 2 additions & 1 deletion src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
type LogComponentSeveritiesClientOptions,
type MongoDBLogWritable,
MongoLogger,
type MongoLoggerEnvOptions,
type MongoLoggerOptions,
SeverityLevel
} from './mongo_logger';
Expand Down Expand Up @@ -301,7 +302,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
/** @internal */
__skipPingOnConnect?: boolean;
/** @internal */
__internalLoggerConfig?: any;
__internalLoggerConfig?: MongoLoggerEnvOptions;
/** @internal */
__enableMongoLogger?: boolean;
}
Expand Down
5 changes: 2 additions & 3 deletions src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
import type { ConnectionEvents } from '../cmap/connection';
import type { ConnectionPoolEvents } from '../cmap/connection_pool';
import type { ClientMetadata } from '../cmap/handshake/client_metadata';
import { DEFAULT_OPTIONS, FEATURE_FLAGS } from '../connection_string';
import { DEFAULT_OPTIONS } from '../connection_string';
import {
CLOSE,
CONNECT,
Expand Down Expand Up @@ -251,8 +251,7 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
// Options should only be undefined in tests, MongoClient will always have defined options
options = options ?? {
hosts: [HostAddress.fromString('localhost:27017')],
...Object.fromEntries(DEFAULT_OPTIONS.entries()),
...Object.fromEntries(FEATURE_FLAGS.entries())
...Object.fromEntries(DEFAULT_OPTIONS.entries())
};

if (typeof seeds === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CapturingMongoClient extends MongoClient {
commandStartedEvents: Array<CommandStartedEvent> = [];
clientsCreated = 0;
constructor(url: string, options: MongoClientOptions = {}) {
options = { ...options, monitorCommands: true, [Symbol.for('@@mdb.skipPingOnConnect')]: true };
options = { ...options, monitorCommands: true, __skipPingOnConnect: true };
if (process.env.MONGODB_API_VERSION) {
options.serverApi = process.env.MONGODB_API_VERSION as MongoClientOptions['serverApi'];
}
Expand Down Expand Up @@ -102,7 +102,7 @@ const metadata = {
topology: '!load-balanced'
}
};
describe('Connection Pool Deadlock Prevention', function () {
describe.only('Connection Pool Deadlock Prevention', function () {
beforeEach(async function () {
const url: string = this.configuration.url();

Expand Down

0 comments on commit d2f956a

Please sign in to comment.