Skip to content

feat(NODE-4849): Add Typescript support for log path in client options #3886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 23, 2023
9 changes: 6 additions & 3 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ export function parseOptions(
...mongoOptions[Symbol.for('@@mdb.internalLoggerConfig')]
};
loggerClientOptions = {
mongodbLogPath: mongoOptions.mongodbLogPath
mongodbLogPath: mongoOptions.mongoLoggerClientOptions.mongodbLogPath
};
}
mongoOptions.mongoLoggerOptions = MongoLogger.resolveOptions(
Expand Down Expand Up @@ -1224,8 +1224,11 @@ export const OPTIONS = {
'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version'
} as OptionDescriptor,
// MongoLogger
// TODO(NODE-4849): Tighten the type of mongodbLogPath
mongodbLogPath: { type: 'any' }
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongoLoggerClientOptions: { type: 'any' }
} as Record<keyof MongoClientOptions, OptionDescriptor>;

export const DEFAULT_OPTIONS = new CaseInsensitiveMap(
Expand Down
21 changes: 19 additions & 2 deletions src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { MONGO_CLIENT_EVENTS } from './constants';
import { Db, type DbOptions } from './db';
import type { Encrypter } from './encrypter';
import { MongoInvalidArgumentError } from './error';
import { MongoLogger, type MongoLoggerOptions } from './mongo_logger';
import {
MongoLogger,
type MongoLoggerMongoClientOptions,
type MongoLoggerOptions
} from './mongo_logger';
import { TypedEventEmitter } from './mongo_types';
import { executeOperation } from './operations/execute_operation';
import { RunAdminCommandOperation } from './operations/run_command';
Expand Down Expand Up @@ -252,6 +256,11 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
srvPoller?: SrvPoller;
/** @internal */
connectionType?: typeof Connection;
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongoLoggerClientOptions?: MongoLoggerMongoClientOptions;

/** @internal */
[featureFlag: symbol]: any;
Expand Down Expand Up @@ -825,6 +834,14 @@ export interface MongoOptions
/** @internal */
[featureFlag: symbol]: any;

/** @internal */
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongoLoggerOptions: MongoLoggerOptions;
/**
* @internal
* TODO: NODE-5671 - remove internal flag
*/
mongoLoggerClientOptions?: MongoLoggerMongoClientOptions;
}
2 changes: 1 addition & 1 deletion src/mongo_logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function createStdioLogger(stream: {
*/
function resolveLogPath(
{ MONGODB_LOG_PATH }: MongoLoggerEnvOptions,
{ mongodbLogPath }: { mongodbLogPath?: string | Writable | MongoDBLogWritable }
{ mongodbLogPath }: MongoLoggerMongoClientOptions
): MongoDBLogWritable {
if (typeof mongodbLogPath === 'string' && /^stderr$/i.test(mongodbLogPath)) {
return createStdioLogger(process.stderr);
Expand Down
5 changes: 2 additions & 3 deletions test/tools/unified-spec-runner/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ export class UnifiedMongoClient extends MongoClient {
[Symbol.for('@@mdb.skipPingOnConnect')]: true,
[Symbol.for('@@mdb.enableMongoLogger')]: true,
[Symbol.for('@@mdb.internalLoggerConfig')]: componentSeverities,
// @ts-expect-error TODO(NODE-4849): Remove this once we have support for mongodbLogPath
mongodbLogPath: logCollector,
...getEnvironmentalOptions(),
...(description.serverApi ? { serverApi: description.serverApi } : {})
...(description.serverApi ? { serverApi: description.serverApi } : {}),
mongoLoggerClientOptions: { mongodbLogPath: logCollector }
} as any);
this.logCollector = logCollector;

Expand Down