Skip to content

Commit

Permalink
create getTopology util
Browse files Browse the repository at this point in the history
  • Loading branch information
HanaPearlman committed Nov 2, 2020
1 parent d2a1e75 commit 588cbec
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 130 deletions.
12 changes: 6 additions & 6 deletions src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './operations/list_databases';
import { executeOperation } from './operations/execute_operation';
import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
import type { Callback } from './utils';
import { Callback, getTopology } from './utils';
import type { Document } from './bson';
import type { CommandOperationOptions } from './operations/command';
import type { Db } from './db';
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Admin {
options = Object.assign({ dbName: 'admin' }, options);

return executeOperation(
this.s.db.topology,
getTopology(this.s.db),
new RunCommandOperation(this.s.db, command, options),
callback
);
Expand Down Expand Up @@ -204,7 +204,7 @@ export class Admin {
options = Object.assign({ dbName: 'admin' }, options);

return executeOperation(
this.s.db.topology,
getTopology(this.s.db),
new AddUserOperation(this.s.db, username, password, options),
callback
);
Expand All @@ -230,7 +230,7 @@ export class Admin {
options = Object.assign({ dbName: 'admin' }, options);

return executeOperation(
this.s.db.topology,
getTopology(this.s.db),
new RemoveUserOperation(this.s.db, username, options),
callback
);
Expand Down Expand Up @@ -260,7 +260,7 @@ export class Admin {
options = options || {};

return executeOperation(
this.s.db.topology,
getTopology(this.s.db),
new ValidateCollectionOperation(this, collectionName, options),
callback
);
Expand All @@ -284,7 +284,7 @@ export class Admin {
options = options || {};

return executeOperation(
this.s.db.topology,
getTopology(this.s.db),
new ListDatabasesOperation(this.s.db, options),
callback
);
Expand Down
5 changes: 3 additions & 2 deletions src/bulk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
hasAtomicOperators,
Callback,
MongoDBNamespace,
maxWireVersion
maxWireVersion,
getTopology
} from '../utils';
import { executeOperation } from '../operations/execute_operation';
import { InsertOperation } from '../operations/insert';
Expand Down Expand Up @@ -908,7 +909,7 @@ export abstract class BulkOperationBase {
// determine whether bulkOperation is ordered or unordered
this.isOrdered = isOrdered;

const topology = collection.getTopology();
const topology = getTopology(collection);
if (!topology) throw new MongoClientClosedError();
options = options == null ? {} : options;
// TODO Bring from driver information in isMaster
Expand Down
8 changes: 3 additions & 5 deletions src/change_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
now,
maybePromise,
MongoDBNamespace,
Callback
Callback,
getTopology
} from './utils';
import type { ReadPreference } from './read_preference';
import type { Timestamp, Document } from './bson';
Expand Down Expand Up @@ -221,22 +222,19 @@ export class ChangeStream extends EventEmitter {
this.parent = parent;
this.namespace = parent.s.namespace;

let topology: Topology | undefined;
if (parent instanceof Collection) {
this.type = CHANGE_DOMAIN_TYPES.COLLECTION;
topology = parent.getTopology();
} else if (parent instanceof Db) {
this.type = CHANGE_DOMAIN_TYPES.DATABASE;
topology = parent.topology;
} else if (parent instanceof MongoClient) {
this.type = CHANGE_DOMAIN_TYPES.CLUSTER;
topology = parent.topology;
} else {
throw new TypeError(
'parent provided to ChangeStream constructor is not an instance of Collection, Db, or MongoClient'
);
}

const topology = getTopology(parent);
if (!topology) throw new MongoClientClosedError();
this.topology = topology;

Expand Down
Loading

0 comments on commit 588cbec

Please sign in to comment.