Skip to content

Commit 6fd568b

Browse files
chore(NODE-5073): remove dead code (mongodb#3588)
Co-authored-by: Durran Jordan <durran@gmail.com>
1 parent 900cc91 commit 6fd568b

File tree

4 files changed

+9
-113
lines changed

4 files changed

+9
-113
lines changed

src/cmap/connection.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const INVALID_QUEUE_SIZE = 'Connection internal queue contains more than 1 opera
7474

7575
/** @internal */
7676
export interface CommandOptions extends BSONSerializeOptions {
77-
command?: boolean;
7877
secondaryOk?: boolean;
7978
/** Specify read preference if command supports it */
8079
readPreference?: ReadPreferenceLike;
@@ -401,22 +400,14 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
401400
this.emit(Connection.CLUSTER_TIME_RECEIVED, document.$clusterTime);
402401
}
403402

404-
if (operationDescription.command) {
405-
if (document.writeConcernError) {
406-
callback(new MongoWriteConcernError(document.writeConcernError, document), document);
407-
return;
408-
}
403+
if (document.writeConcernError) {
404+
callback(new MongoWriteConcernError(document.writeConcernError, document), document);
405+
return;
406+
}
409407

410-
if (document.ok === 0 || document.$err || document.errmsg || document.code) {
411-
callback(new MongoServerError(document));
412-
return;
413-
}
414-
} else {
415-
// Pre 3.2 support
416-
if (document.ok === 0 || document.$err || document.errmsg) {
417-
callback(new MongoServerError(document));
418-
return;
419-
}
408+
if (document.ok === 0 || document.$err || document.errmsg || document.code) {
409+
callback(new MongoServerError(document));
410+
return;
420411
}
421412
}
422413

@@ -538,7 +529,6 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
538529

539530
const commandOptions: Document = Object.assign(
540531
{
541-
command: true,
542532
numberToSkip: 0,
543533
numberToReturn: -1,
544534
checkKeys: false,
@@ -678,7 +668,6 @@ function write(
678668
session: options.session,
679669
noResponse: typeof options.noResponse === 'boolean' ? options.noResponse : false,
680670
documentsReturnedIn: options.documentsReturnedIn,
681-
command: !!options.command,
682671

683672
// for BSON parsing
684673
useBigInt64: typeof options.useBigInt64 === 'boolean' ? options.useBigInt64 : false,

src/cmap/message_stream.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface MessageStreamOptions extends DuplexOptions {
3030
export interface OperationDescription extends BSONSerializeOptions {
3131
started: number;
3232
cb: Callback<Document>;
33-
command: boolean;
3433
documentsReturnedIn?: string;
3534
noResponse: boolean;
3635
raw: boolean;

src/cmap/wire_protocol/shared.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import type { Server } from '../../sdam/server';
77
import type { ServerDescription } from '../../sdam/server_description';
88
import type { Topology } from '../../sdam/topology';
99
import { TopologyDescription } from '../../sdam/topology_description';
10-
import type { OpQueryOptions } from '../commands';
11-
import type { CommandOptions, Connection } from '../connection';
10+
import type { Connection } from '../connection';
1211

1312
export interface ReadPreferenceOption {
1413
readPreference?: ReadPreferenceLike;
@@ -35,27 +34,6 @@ export function getReadPreference(cmd: Document, options?: ReadPreferenceOption)
3534
return readPreference;
3635
}
3736

38-
export function applyCommonQueryOptions(
39-
queryOptions: OpQueryOptions,
40-
options: CommandOptions
41-
): CommandOptions {
42-
Object.assign(queryOptions, {
43-
raw: typeof options.raw === 'boolean' ? options.raw : false,
44-
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
45-
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
46-
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
47-
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
48-
enableUtf8Validation:
49-
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
50-
});
51-
52-
if (options.session) {
53-
queryOptions.session = options.session;
54-
}
55-
56-
return queryOptions;
57-
}
58-
5937
export function isSharded(topologyOrServer?: Topology | Server | Connection): boolean {
6038
if (topologyOrServer == null) {
6139
return false;

src/utils.ts

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { ServerType } from './sdam/common';
2929
import type { Server } from './sdam/server';
3030
import type { Topology } from './sdam/topology';
3131
import type { ClientSession } from './sessions';
32-
import { W, WriteConcern, WriteConcernOptions } from './write_concern';
32+
import { WriteConcern } from './write_concern';
3333

3434
/**
3535
* MongoDB Driver style callback
@@ -167,9 +167,6 @@ export function applyRetryableWrites<T extends HasRetryableWrites>(target: T, db
167167
return target;
168168
}
169169

170-
interface HasWriteConcern {
171-
writeConcern?: WriteConcernOptions | WriteConcern | W;
172-
}
173170
/**
174171
* Applies a write concern to a command based on well defined inheritance rules, optionally
175172
* detecting support for the write concern in the first place.
@@ -179,39 +176,6 @@ interface HasWriteConcern {
179176
* @param sources - sources where we can inherit default write concerns from
180177
* @param options - optional settings passed into a command for write concern overrides
181178
*/
182-
export function applyWriteConcern<T extends HasWriteConcern>(
183-
target: T,
184-
sources: { db?: Db; collection?: Collection },
185-
options?: OperationOptions & WriteConcernOptions
186-
): T {
187-
options = options ?? {};
188-
const db = sources.db;
189-
const coll = sources.collection;
190-
191-
if (options.session && options.session.inTransaction()) {
192-
// writeConcern is not allowed within a multi-statement transaction
193-
if (target.writeConcern) {
194-
delete target.writeConcern;
195-
}
196-
197-
return target;
198-
}
199-
200-
const writeConcern = WriteConcern.fromOptions(options);
201-
if (writeConcern) {
202-
return Object.assign(target, { writeConcern });
203-
}
204-
205-
if (coll && coll.writeConcern) {
206-
return Object.assign(target, { writeConcern: Object.assign({}, coll.writeConcern) });
207-
}
208-
209-
if (db && db.writeConcern) {
210-
return Object.assign(target, { writeConcern: Object.assign({}, db.writeConcern) });
211-
}
212-
213-
return target;
214-
}
215179

216180
/**
217181
* Checks if a given value is a Promise
@@ -483,40 +447,6 @@ export function eachAsync<T = Document>(
483447
}
484448
}
485449

486-
/** @internal */
487-
export function eachAsyncSeries<T = any>(
488-
arr: T[],
489-
eachFn: (item: T, callback: (err?: AnyError) => void) => void,
490-
callback: Callback
491-
): void {
492-
arr = arr || [];
493-
494-
let idx = 0;
495-
let awaiting = arr.length;
496-
if (awaiting === 0) {
497-
callback();
498-
return;
499-
}
500-
501-
function eachCallback(err?: AnyError) {
502-
idx++;
503-
awaiting--;
504-
if (err) {
505-
callback(err);
506-
return;
507-
}
508-
509-
if (idx === arr.length && awaiting <= 0) {
510-
callback();
511-
return;
512-
}
513-
514-
eachFn(arr[idx], eachCallback);
515-
}
516-
517-
eachFn(arr[idx], eachCallback);
518-
}
519-
520450
/** @internal */
521451
export function arrayStrictEqual(arr: unknown[], arr2: unknown[]): boolean {
522452
if (!Array.isArray(arr) || !Array.isArray(arr2)) {

0 commit comments

Comments
 (0)