Skip to content

Commit 884c551

Browse files
committed
move getTopology to topology file
1 parent 588cbec commit 884c551

File tree

14 files changed

+32
-37
lines changed

14 files changed

+32
-37
lines changed

src/admin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
} from './operations/list_databases';
1212
import { executeOperation } from './operations/execute_operation';
1313
import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
14-
import { Callback, getTopology } from './utils';
14+
import type { Callback } from './utils';
1515
import type { Document } from './bson';
1616
import type { CommandOperationOptions } from './operations/command';
1717
import type { Db } from './db';
18+
import { getTopology } from './sdam/topology';
1819

1920
/** @internal */
2021
export interface AdminPrivate {

src/bulk/common.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import {
88
hasAtomicOperators,
99
Callback,
1010
MongoDBNamespace,
11-
maxWireVersion,
12-
getTopology
11+
maxWireVersion
1312
} from '../utils';
1413
import { executeOperation } from '../operations/execute_operation';
1514
import { InsertOperation } from '../operations/insert';
1615
import { UpdateOperation } from '../operations/update';
1716
import { DeleteOperation } from '../operations/delete';
1817
import { WriteConcern } from '../write_concern';
1918
import type { Collection } from '../collection';
20-
import type { Topology } from '../sdam/topology';
19+
import { getTopology, Topology } from '../sdam/topology';
2120
import type { CommandOperationOptions } from '../operations/command';
2221
import type { CollationOptions } from '../cmap/wire_protocol/write_command';
2322
import type { Hint } from '../operations/operation';

src/change_stream.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import {
1111
now,
1212
maybePromise,
1313
MongoDBNamespace,
14-
Callback,
15-
getTopology
14+
Callback
1615
} from './utils';
1716
import type { ReadPreference } from './read_preference';
1817
import type { Timestamp, Document } from './bson';
19-
import type { Topology } from './sdam/topology';
18+
import { getTopology, Topology } from './sdam/topology';
2019
import type { OperationParent } from './operations/command';
2120
import type { CollationOptions } from './cmap/wire_protocol/write_command';
2221
const kResumeQueue = Symbol('resumeQueue');

src/collection.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { emitDeprecatedOptionWarning, getTopology } from './utils';
1+
import { emitDeprecatedOptionWarning } from './utils';
22
import { ReadPreference, ReadPreferenceLike } from './read_preference';
33
import { deprecate } from 'util';
44
import {
@@ -86,6 +86,7 @@ import type { PkFactory } from './mongo_client';
8686
import type { Logger, LoggerOptions } from './logger';
8787
import type { OperationParent } from './operations/command';
8888
import type { Sort } from './sort';
89+
import { getTopology } from './sdam/topology';
8990

9091
/** @public */
9192
export interface Collection {

src/db.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { deprecate } from 'util';
2-
import { emitDeprecatedOptionWarning, Callback, getTopology } from './utils';
2+
import { emitDeprecatedOptionWarning, Callback } from './utils';
33
import { loadAdmin } from './dynamic_loaders';
44
import { AggregationCursor, CommandCursor } from './cursor';
55
import { ObjectId, Code, Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
@@ -53,7 +53,7 @@ import { executeOperation } from './operations/execute_operation';
5353
import { EvalOperation, EvalOptions } from './operations/eval';
5454
import type { IndexInformationOptions } from './operations/common_functions';
5555
import type { MongoClient, PkFactory } from './mongo_client';
56-
import type { Topology } from './sdam/topology';
56+
import { getTopology, Topology } from './sdam/topology';
5757
import type { OperationParent } from './operations/command';
5858
import type { Admin } from './admin';
5959

src/gridfs-stream/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
GridFSBucketReadStreamOptionsWithRevision
77
} from './download';
88
import { GridFSBucketWriteStream, GridFSBucketWriteStreamOptions, TFileId } from './upload';
9-
import { executeLegacyOperation, Callback, getTopology } from '../utils';
9+
import { executeLegacyOperation, Callback } from '../utils';
1010
import { WriteConcernOptions, WriteConcern } from '../write_concern';
1111
import type { Document } from '../bson';
1212
import type { Db } from '../db';
@@ -16,6 +16,7 @@ import type { Cursor } from './../cursor/cursor';
1616
import type { FindOptions } from './../operations/find';
1717
import type { Sort } from '../sort';
1818
import type { Logger } from '../logger';
19+
import { getTopology } from '../sdam/topology';
1920

2021
const DEFAULT_GRIDFS_BUCKET_OPTIONS: {
2122
bucketName: string;

src/operations/add_user.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import * as crypto from 'crypto';
22
import { Aspect, defineAspects } from './operation';
33
import { CommandOperation, CommandOperationOptions } from './command';
44
import { MongoClientClosedError, MongoError } from '../error';
5-
import { Callback, getTopology } from '../utils';
5+
import type { Callback } from '../utils';
66
import type { Document } from '../bson';
77
import type { Server } from '../sdam/server';
88
import type { Db } from '../db';
9+
import { getTopology } from '../sdam/topology';
910

1011
/** @public */
1112
export interface AddUserOptions extends CommandOperationOptions {

src/operations/common_functions.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { MongoError } from '../error';
2-
import {
3-
applyRetryableWrites,
4-
applyWriteConcern,
5-
decorateWithCollation,
6-
Callback,
7-
getTopology
8-
} from '../utils';
2+
import { applyRetryableWrites, applyWriteConcern, decorateWithCollation, Callback } from '../utils';
93
import type { Document } from '../bson';
104
import type { Db } from '../db';
115
import type { ClientSession } from '../sessions';
@@ -15,6 +9,7 @@ import type { Collection } from '../collection';
159
import type { UpdateOptions } from './update';
1610
import type { WriteCommandOptions } from '../cmap/wire_protocol/write_command';
1711
import type { DeleteOptions } from './delete';
12+
import { getTopology } from '../sdam/topology';
1813

1914
/** @internal */
2015
export interface IndexInformationOptions {

src/operations/count.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Aspect, defineAspects } from './operation';
22
import { CommandOperation, CommandOperationOptions } from './command';
3-
import { decorateWithCollation, decorateWithReadConcern, Callback, getTopology } from '../utils';
3+
import { decorateWithCollation, decorateWithReadConcern, Callback } from '../utils';
44
import type { Document } from '../bson';
55
import type { Server } from '../sdam/server';
66
import type { Collection } from '../collection';
77
import type { Cursor } from '../cursor/cursor';
8+
import { getTopology } from '../sdam/topology';
89

910
/** @public */
1011
export interface CountOptions extends CommandOperationOptions {

src/operations/distinct.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Aspect, defineAspects } from './operation';
22
import { CommandOperation, CommandOperationOptions } from './command';
3-
import { decorateWithCollation, decorateWithReadConcern, Callback, getTopology } from '../utils';
3+
import { decorateWithCollation, decorateWithReadConcern, Callback } from '../utils';
44
import type { Document } from '../bson';
55
import type { Server } from '../sdam/server';
66
import type { Collection } from '../collection';
7+
import { getTopology } from '../sdam/topology';
78

89
/** @public */
910
export type DistinctOptions = CommandOperationOptions;

src/operations/find_and_modify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
decorateWithCollation,
66
applyWriteConcern,
77
hasAtomicOperators,
8-
Callback,
9-
getTopology
8+
Callback
109
} from '../utils';
1110
import { MongoError } from '../error';
1211
import { CommandOperation, CommandOperationOptions } from './command';
@@ -15,6 +14,7 @@ import type { Document } from '../bson';
1514
import type { Server } from '../sdam/server';
1615
import type { Collection } from '../collection';
1716
import { Sort, formatSort } from '../sort';
17+
import { getTopology } from '../sdam/topology';
1818

1919
/** @public */
2020
export interface FindAndModifyOptions extends CommandOperationOptions {

src/operations/map_reduce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
decorateWithCollation,
66
decorateWithReadConcern,
77
isObject,
8-
Callback,
9-
getTopology
8+
Callback
109
} from '../utils';
1110
import { ReadPreference, ReadPreferenceMode } from '../read_preference';
1211
import { CommandOperation, CommandOperationOptions } from './command';
@@ -15,6 +14,7 @@ import type { Collection } from '../collection';
1514
import type { Sort } from '../sort';
1615
import { MongoError } from '../error';
1716
import type { ObjectId } from '../bson';
17+
import { getTopology } from '../sdam/topology';
1818

1919
const exclusionList = [
2020
'readPreference',

src/sdam/topology.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { DestroyOptions, Connection } from '../cmap/connection';
5757
import { RunCommandOperation } from '../operations/run_command';
5858
import type { CursorOptions } from '../cursor/cursor';
5959
import type { MongoClientOptions } from '../mongo_client';
60+
import { Db, Collection, MongoClient } from '..';
6061

6162
// Global state
6263
let globalTopologyCounter = 0;
@@ -1053,3 +1054,10 @@ export class ServerCapabilities {
10531054
return this.maxWireVersion >= 5;
10541055
}
10551056
}
1057+
1058+
/** @internal */
1059+
export function getTopology(provider: MongoClient | Db | Collection): Topology | undefined {
1060+
if (provider instanceof MongoClient) return provider.topology;
1061+
if (provider instanceof Db) return provider.s.client.topology;
1062+
if (provider instanceof Collection) return provider.s.db.s.client.topology;
1063+
}

src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import { readFileSync } from 'fs';
1616
import { resolve } from 'path';
1717
import type { Document } from './bson';
1818
import type { IndexSpecification, IndexDirection } from './operations/indexes';
19-
import type { MongoClient } from './mongo_client';
20-
import { loadCollection, loadDb, loadMongoClient } from './dynamic_loaders';
2119

2220
/** @public MongoDB Driver style callback */
2321
export type Callback<T = any> = (error?: AnyError, result?: T) => void;
@@ -712,16 +710,6 @@ export function maxWireVersion(topologyOrServer?: Connection | Topology | Server
712710
return 0;
713711
}
714712

715-
export function getTopology(provider: MongoClient | Db | Collection): Topology | undefined {
716-
const Collection = loadCollection();
717-
const Db = loadDb();
718-
const MongoClient = loadMongoClient();
719-
720-
if (provider instanceof MongoClient) return provider.topology;
721-
if (provider instanceof Db) return provider.s.client.topology;
722-
if (provider instanceof Collection) return provider.s.db.s.client.topology;
723-
}
724-
725713
/**
726714
* Checks that collation is supported by server.
727715
* @internal

0 commit comments

Comments
 (0)