|
1 | 1 | import type { BSONSerializeOptions, Document } from '../bson';
|
| 2 | +import { type Db } from '../db'; |
| 3 | +import { type TODO_NODE_3286 } from '../mongo_types'; |
2 | 4 | import type { ReadPreferenceLike } from '../read_preference';
|
3 | 5 | import type { Server } from '../sdam/server';
|
4 | 6 | import type { ClientSession } from '../sessions';
|
5 |
| -import { type Callback, MongoDBNamespace } from '../utils'; |
6 |
| -import { CommandCallbackOperation, type OperationParent } from './command'; |
| 7 | +import { MongoDBNamespace } from '../utils'; |
| 8 | +import { AbstractOperation } from './operation'; |
7 | 9 |
|
8 | 10 | /** @public */
|
9 | 11 | export type RunCommandOptions = {
|
10 | 12 | /** Specify ClientSession for this command */
|
11 | 13 | session?: ClientSession;
|
12 | 14 | /** The read preference */
|
13 | 15 | readPreference?: ReadPreferenceLike;
|
14 |
| - |
15 |
| - // The following options were "accidentally" supported |
16 |
| - // Since the options are generally supported through inheritance |
17 |
| - |
18 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
19 |
| - willRetryWrite?: any; |
20 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
21 |
| - omitReadPreference?: any; |
22 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
23 |
| - writeConcern?: any; |
24 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
25 |
| - explain?: any; |
26 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
27 |
| - readConcern?: any; |
28 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
29 |
| - collation?: any; |
30 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
31 |
| - maxTimeMS?: any; |
32 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
33 |
| - comment?: any; |
34 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
35 |
| - retryWrites?: any; |
36 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
37 |
| - dbName?: any; |
38 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
39 |
| - authdb?: any; |
40 |
| - /** @deprecated This is an internal option that has undefined behavior for this API */ |
41 |
| - noResponse?: any; |
42 |
| - |
43 |
| - /** @internal Used for transaction commands */ |
44 |
| - bypassPinningCheck?: boolean; |
45 | 16 | } & BSONSerializeOptions;
|
46 | 17 |
|
47 | 18 | /** @internal */
|
48 |
| -export class RunCommandOperation<T = Document> extends CommandCallbackOperation<T> { |
49 |
| - override options: RunCommandOptions; |
50 |
| - command: Document; |
51 |
| - |
52 |
| - constructor(parent: OperationParent | undefined, command: Document, options?: RunCommandOptions) { |
53 |
| - super(parent, options); |
54 |
| - this.options = options ?? {}; |
55 |
| - this.command = command; |
| 19 | +export class RunCommandOperation<T = Document> extends AbstractOperation<T> { |
| 20 | + constructor(parent: Db, public command: Document, public override options: RunCommandOptions) { |
| 21 | + super(options); |
| 22 | + this.ns = parent.s.namespace.withCollection('$cmd'); |
56 | 23 | }
|
57 | 24 |
|
58 |
| - override executeCallback( |
59 |
| - server: Server, |
60 |
| - session: ClientSession | undefined, |
61 |
| - callback: Callback<T> |
62 |
| - ): void { |
63 |
| - const command = this.command; |
64 |
| - this.executeCommandCallback(server, session, command, callback); |
| 25 | + override async execute(server: Server, session: ClientSession | undefined): Promise<T> { |
| 26 | + this.server = server; |
| 27 | + return server.commandAsync(this.ns, this.command, { |
| 28 | + ...this.options, |
| 29 | + readPreference: this.readPreference, |
| 30 | + session |
| 31 | + }) as TODO_NODE_3286; |
65 | 32 | }
|
66 | 33 | }
|
67 | 34 |
|
68 |
| -export class RunAdminCommandOperation<T = Document> extends RunCommandOperation<T> { |
69 |
| - constructor(parent: OperationParent | undefined, command: Document, options?: RunCommandOptions) { |
70 |
| - super(parent, command, options); |
71 |
| - this.ns = new MongoDBNamespace('admin'); |
| 35 | +export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T> { |
| 36 | + constructor( |
| 37 | + public command: Document, |
| 38 | + public override options: RunCommandOptions & { |
| 39 | + noResponse?: boolean; |
| 40 | + bypassPinningCheck?: boolean; |
| 41 | + } |
| 42 | + ) { |
| 43 | + super(options); |
| 44 | + this.ns = new MongoDBNamespace('admin', '$cmd'); |
| 45 | + } |
| 46 | + |
| 47 | + override async execute(server: Server, session: ClientSession | undefined): Promise<T> { |
| 48 | + this.server = server; |
| 49 | + return server.commandAsync(this.ns, this.command, { |
| 50 | + ...this.options, |
| 51 | + readPreference: this.readPreference, |
| 52 | + session |
| 53 | + }) as TODO_NODE_3286; |
72 | 54 | }
|
73 | 55 | }
|
0 commit comments