Skip to content

Commit 130691d

Browse files
refactor(NODE-5764): add commandName to AbstractOperation subclasses (mongodb#3934)
1 parent ad2d15c commit 130691d

34 files changed

+539
-2
lines changed

src/bulk/common.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,17 @@ const executeCommandsAsync = promisify(executeCommands);
880880
* We would like this logic to simply live inside the BulkWriteOperation class
881881
* @internal
882882
*/
883-
class BulkWriteShimOperation extends AbstractOperation {
883+
export class BulkWriteShimOperation extends AbstractOperation {
884884
bulkOperation: BulkOperationBase;
885885
constructor(bulkOperation: BulkOperationBase, options: BulkWriteOptions) {
886886
super(options);
887887
this.bulkOperation = bulkOperation;
888888
}
889889

890+
get commandName(): string {
891+
return 'bulkWrite' as const;
892+
}
893+
890894
execute(_server: Server, session: ClientSession | undefined): Promise<any> {
891895
if (this.options.session == null) {
892896
// An implicit session could have been created by 'executeOperation'

src/operations/aggregate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
8282
}
8383
}
8484

85+
override get commandName() {
86+
return 'aggregate' as const;
87+
}
88+
8589
override get canRetryRead(): boolean {
8690
return !this.hasWriteStage;
8791
}

src/operations/bulk_write.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class BulkWriteOperation extends AbstractOperation<BulkWriteResult> {
2626
this.operations = operations;
2727
}
2828

29+
override get commandName() {
30+
return 'bulkWrite' as const;
31+
}
32+
2933
override async execute(
3034
server: Server,
3135
session: ClientSession | undefined

src/operations/collections.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class CollectionsOperation extends AbstractOperation<Collection[]> {
1919
this.db = db;
2020
}
2121

22+
override get commandName() {
23+
return 'listCollections' as const;
24+
}
25+
2226
override async execute(
2327
server: Server,
2428
session: ClientSession | undefined

src/operations/count.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class CountOperation extends CommandOperation<number> {
3232
this.query = filter;
3333
}
3434

35+
override get commandName() {
36+
return 'count' as const;
37+
}
38+
3539
override async execute(server: Server, session: ClientSession | undefined): Promise<number> {
3640
const options = this.options;
3741
const cmd: Document = {

src/operations/create_collection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
120120
this.name = name;
121121
}
122122

123+
override get commandName() {
124+
return 'create' as const;
125+
}
126+
123127
override async execute(server: Server, session: ClientSession | undefined): Promise<Collection> {
124128
const db = this.db;
125129
const name = this.name;

src/operations/delete.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
5353
this.statements = statements;
5454
}
5555

56+
override get commandName() {
57+
return 'delete' as const;
58+
}
59+
5660
override get canRetryWrite(): boolean {
5761
if (super.canRetryWrite === false) {
5862
return false;

src/operations/distinct.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class DistinctOperation extends CommandOperation<any[]> {
3838
this.query = query;
3939
}
4040

41+
override get commandName() {
42+
return 'distinct' as const;
43+
}
44+
4145
override async execute(server: Server, session: ClientSession | undefined): Promise<any[]> {
4246
const coll = this.collection;
4347
const key = this.key;

src/operations/drop.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
2525
this.name = name;
2626
}
2727

28+
override get commandName() {
29+
return 'drop' as const;
30+
}
31+
2832
override async execute(server: Server, session: ClientSession | undefined): Promise<boolean> {
2933
const db = this.db;
3034
const options = this.options;
@@ -88,6 +92,10 @@ export class DropDatabaseOperation extends CommandOperation<boolean> {
8892
super(db, options);
8993
this.options = options;
9094
}
95+
override get commandName() {
96+
return 'dropDatabase' as const;
97+
}
98+
9199
override async execute(server: Server, session: ClientSession | undefined): Promise<boolean> {
92100
await super.executeCommand(server, session, { dropDatabase: 1 });
93101
return true;

src/operations/estimated_document_count.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
2626
this.collectionName = collection.collectionName;
2727
}
2828

29+
override get commandName() {
30+
return 'count' as const;
31+
}
32+
2933
override async execute(server: Server, session: ClientSession | undefined): Promise<number> {
3034
const cmd: Document = { count: this.collectionName };
3135

0 commit comments

Comments
 (0)