Skip to content

Commit 6c94b4a

Browse files
authored
feat(NODE-4992): Deprecate methods and options that reference legacy logger (#3532)
1 parent 4c49b2e commit 6c94b4a

File tree

5 files changed

+59
-25
lines changed

5 files changed

+59
-25
lines changed

src/db.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,15 @@ export class Db {
774774
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
775775
}
776776

777-
/** Return the db logger */
777+
/**
778+
* Return the db logger
779+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
780+
*/
778781
getLogger(): Logger {
779782
return this.s.logger;
780783
}
781784

785+
/** @deprecated The Legacy Logger is deprecated and will be removed in the next major version. */
782786
get logger(): Logger {
783787
return this.s.logger;
784788
}

src/gridfs/download.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import type { FindOptions } from '../operations/find';
1313
import type { ReadPreference } from '../read_preference';
1414
import type { Sort } from '../sort';
15-
import type { Callback } from '../utils';
15+
import { Callback, maybeCallback } from '../utils';
1616
import type { GridFSChunk } from './upload';
1717

1818
/** @public */
@@ -185,22 +185,26 @@ export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableS
185185
*
186186
* @param callback - called when the cursor is successfully closed or an error occurred.
187187
*/
188-
abort(callback?: Callback<void>): void {
189-
this.push(null);
190-
this.destroyed = true;
191-
if (this.s.cursor) {
192-
this.s.cursor.close(error => {
193-
this.emit(GridFSBucketReadStream.CLOSE);
194-
callback && callback(error);
195-
});
196-
} else {
197-
if (!this.s.init) {
198-
// If not initialized, fire close event because we will never
199-
// get a cursor
200-
this.emit(GridFSBucketReadStream.CLOSE);
188+
abort(): Promise<void>;
189+
/** @deprecated Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance */
190+
abort(callback: Callback<void>): void;
191+
abort(callback?: Callback<void>): Promise<void> | void {
192+
return maybeCallback(async () => {
193+
this.push(null);
194+
this.destroyed = true;
195+
if (this.s.cursor) {
196+
await this.s.cursor.close().catch(error => {
197+
this.emit(GridFSBucketReadStream.CLOSE);
198+
throw error;
199+
});
200+
} else {
201+
if (!this.s.init) {
202+
// If not initialized, fire close event because we will never
203+
// get a cursor
204+
this.emit(GridFSBucketReadStream.CLOSE);
205+
}
201206
}
202-
callback && callback();
203-
}
207+
}, callback);
204208
}
205209
}
206210

src/gridfs/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
226226
}, callback);
227227
}
228228

229-
/** Get the Db scoped logger. */
229+
/**
230+
* Get the Db scoped logger.
231+
*
232+
* @deprecated Legacy Logger is deprecated and will be removed in the next major version.
233+
*/
230234
getLogger(): Logger {
231235
return this.s.db.s.logger;
232236
}

src/logger.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ const pid = process.pid;
1515
// eslint-disable-next-line no-console
1616
let currentLogger: LoggerFunction = console.warn;
1717

18-
/** @public */
18+
/**
19+
* @public
20+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
21+
*/
1922
export const LoggerLevel = Object.freeze({
2023
ERROR: 'error',
2124
WARN: 'warn',
@@ -27,13 +30,22 @@ export const LoggerLevel = Object.freeze({
2730
debug: 'debug'
2831
} as const);
2932

30-
/** @public */
33+
/**
34+
* @public
35+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
36+
*/
3137
export type LoggerLevel = typeof LoggerLevel[keyof typeof LoggerLevel];
3238

33-
/** @public */
39+
/**
40+
* @public
41+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
42+
*/
3443
export type LoggerFunction = (message?: any, ...optionalParams: any[]) => void;
3544

36-
/** @public */
45+
/**
46+
* @public
47+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
48+
*/
3749
export interface LoggerOptions {
3850
logger?: LoggerFunction;
3951
loggerLevel?: LoggerLevel;

src/mongo_client.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,15 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
233233
* @deprecated Setting a custom promise library is deprecated the next major version will use the global Promise constructor only.
234234
*/
235235
promiseLibrary?: any;
236-
/** The logging level */
236+
/**
237+
* The logging level
238+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
239+
*/
237240
loggerLevel?: LegacyLoggerLevel;
238-
/** Custom logger object */
241+
/**
242+
* Custom logger object
243+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
244+
*/
239245
logger?: LegacyLogger;
240246
/** Enable command monitoring for this client */
241247
monitorCommands?: boolean;
@@ -421,6 +427,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
421427
return this.s.bsonOptions;
422428
}
423429

430+
/** @deprecated The Legacy Logger is deprecated and will be removed in the next major version. */
424431
get logger(): LegacyLogger {
425432
return this.s.logger;
426433
}
@@ -711,7 +718,10 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
711718
return new ChangeStream<TSchema, TChange>(this, pipeline, resolveOptions(this, options));
712719
}
713720

714-
/** Return the mongo client logger */
721+
/**
722+
* Return the mongo client logger
723+
* @deprecated The Legacy Logger is deprecated and will be removed in the next major version.
724+
*/
715725
getLogger(): LegacyLogger {
716726
return this.s.logger;
717727
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy