Skip to content

Commit e3d3a1b

Browse files
committed
refactor(NODE-4633): executeOperation to use maybeCallback
1 parent 8c63447 commit e3d3a1b

File tree

17 files changed

+237
-236
lines changed

17 files changed

+237
-236
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@types/express": "^4.17.13",
4242
"@types/kerberos": "^1.1.1",
4343
"@types/mocha": "^9.1.1",
44-
"@types/node": "^18.7.13",
44+
"@types/node": "^18.7.22",
4545
"@types/saslprep": "^1.0.1",
4646
"@types/semver": "^7.3.12",
4747
"@types/sinon": "^10.0.11",

src/bulk/common.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,41 +1276,37 @@ export abstract class BulkOperationBase {
12761276
: typeof options === 'function'
12771277
? options
12781278
: undefined;
1279-
options = options != null && typeof options !== 'function' ? options : {};
1279+
return maybeCallback(async () => {
1280+
options = options != null && typeof options !== 'function' ? options : {};
12801281

1281-
if (this.s.executed) {
1282-
// eslint-disable-next-line @typescript-eslint/require-await
1283-
return maybeCallback(async () => {
1282+
if (this.s.executed) {
12841283
throw new MongoBatchReExecutionError();
1285-
}, callback);
1286-
}
1284+
}
12871285

1288-
const writeConcern = WriteConcern.fromOptions(options);
1289-
if (writeConcern) {
1290-
this.s.writeConcern = writeConcern;
1291-
}
1286+
const writeConcern = WriteConcern.fromOptions(options);
1287+
if (writeConcern) {
1288+
this.s.writeConcern = writeConcern;
1289+
}
12921290

1293-
// If we have current batch
1294-
if (this.isOrdered) {
1295-
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1296-
} else {
1297-
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1298-
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1299-
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1300-
}
1301-
// If we have no operations in the bulk raise an error
1302-
if (this.s.batches.length === 0) {
1303-
// eslint-disable-next-line @typescript-eslint/require-await
1304-
return maybeCallback(async () => {
1291+
// If we have current batch
1292+
if (this.isOrdered) {
1293+
if (this.s.currentBatch) this.s.batches.push(this.s.currentBatch);
1294+
} else {
1295+
if (this.s.currentInsertBatch) this.s.batches.push(this.s.currentInsertBatch);
1296+
if (this.s.currentUpdateBatch) this.s.batches.push(this.s.currentUpdateBatch);
1297+
if (this.s.currentRemoveBatch) this.s.batches.push(this.s.currentRemoveBatch);
1298+
}
1299+
// If we have no operations in the bulk raise an error
1300+
if (this.s.batches.length === 0) {
13051301
throw new MongoInvalidArgumentError('Invalid BulkOperation, Batch cannot be empty');
1306-
}, callback);
1307-
}
1302+
}
13081303

1309-
this.s.executed = true;
1310-
const finalOptions = { ...this.s.options, ...options };
1311-
const operation = new BulkWriteShimOperation(this, finalOptions);
1304+
this.s.executed = true;
1305+
const finalOptions = { ...this.s.options, ...options };
1306+
const operation = new BulkWriteShimOperation(this, finalOptions);
13121307

1313-
return executeOperation(this.s.collection.s.db.s.client, operation, callback);
1308+
return await executeOperation(this.s.collection.s.db.s.client, operation);
1309+
}, callback);
13141310
}
13151311

13161312
/**

src/collection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ export class Collection<TSchema extends Document = Document> {
662662
new RenameOperation(this as TODO_NODE_3286, newName, {
663663
...options,
664664
readPreference: ReadPreference.PRIMARY
665-
}),
665+
}) as TODO_NODE_3286,
666666
callback
667667
);
668668
}
@@ -1299,7 +1299,7 @@ export class Collection<TSchema extends Document = Document> {
12991299

13001300
return executeOperation(
13011301
this.s.db.s.client,
1302-
new CollStatsOperation(this as TODO_NODE_3286, options),
1302+
new CollStatsOperation(this as TODO_NODE_3286, options) as TODO_NODE_3286,
13031303
callback
13041304
);
13051305
}

src/operations/command.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
119119
return true;
120120
}
121121

122-
abstract override execute(
123-
server: Server,
124-
session: ClientSession | undefined,
125-
callback: Callback<T>
126-
): void;
127-
128122
executeCommand(
129123
server: Server,
130124
session: ClientSession | undefined,

src/operations/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface DeleteStatement {
4444
}
4545

4646
/** @internal */
47-
export class DeleteOperation extends CommandOperation<Document> {
47+
export class DeleteOperation extends CommandOperation<DeleteResult> {
4848
override options: DeleteOptions;
4949
statements: DeleteStatement[];
5050

0 commit comments

Comments
 (0)