From 6c60c3dafe4475af5a2dee6e26c4a21d50ea0f04 Mon Sep 17 00:00:00 2001 From: Malik Javaid Date: Thu, 3 Aug 2023 13:10:17 -0400 Subject: [PATCH 1/4] deleted eval.ts --- src/operations/eval.ts | 74 ------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 src/operations/eval.ts diff --git a/src/operations/eval.ts b/src/operations/eval.ts deleted file mode 100644 index 3f7699e067c..00000000000 --- a/src/operations/eval.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Code, type Document } from '../bson'; -import type { Collection } from '../collection'; -import type { Db } from '../db'; -import { MongoServerError } from '../error'; -import { ReadPreference } from '../read_preference'; -import type { Server } from '../sdam/server'; -import type { ClientSession } from '../sessions'; -import { CommandOperation, type CommandOperationOptions } from './command'; - -/** @public */ -export interface EvalOptions extends CommandOperationOptions { - nolock?: boolean; -} - -/** @internal */ -export class EvalOperation extends CommandOperation { - override options: EvalOptions; - code: Code; - parameters?: Document | Document[]; - - constructor( - db: Db | Collection, - code: Code, - parameters?: Document | Document[], - options?: EvalOptions - ) { - super(db, options); - - this.options = options ?? {}; - this.code = code; - this.parameters = parameters; - // force primary read preference - Object.defineProperty(this, 'readPreference', { - value: ReadPreference.primary, - configurable: false, - writable: false - }); - } - - override async execute(server: Server, session: ClientSession | undefined): Promise { - let finalCode = this.code; - let finalParameters: Document[] = []; - - // If not a code object translate to one - if (!(finalCode && (finalCode as unknown as { _bsontype: string })._bsontype === 'Code')) { - finalCode = new Code(finalCode as never); - } - - // Ensure the parameters are correct - if (this.parameters != null && typeof this.parameters !== 'function') { - finalParameters = Array.isArray(this.parameters) ? this.parameters : [this.parameters]; - } - - // Create execution selector - const cmd: Document = { $eval: finalCode, args: finalParameters }; - - // Check if the nolock parameter is passed in - if (this.options.nolock) { - cmd.nolock = this.options.nolock; - } - - // Execute the command - const result = await super.executeCommand(server, session, cmd); - if (result && result.ok === 1) { - return result.retval; - } - - if (result) { - throw new MongoServerError({ message: `eval failed: ${result.errmsg}` }); - } - - return result; - } -} From 6e2d221a1ba2aa7d25c37c49f3669bb2b955c06e Mon Sep 17 00:00:00 2001 From: Malik Javaid Date: Thu, 3 Aug 2023 13:12:04 -0400 Subject: [PATCH 2/4] removed eval from index and mongodb.ts --- src/index.ts | 1 - test/mongodb.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index cbe08602526..c41a58fdd4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -401,7 +401,6 @@ export type { DeleteOptions, DeleteResult, DeleteStatement } from './operations/ export type { DistinctOptions } from './operations/distinct'; export type { DropCollectionOptions, DropDatabaseOptions } from './operations/drop'; export type { EstimatedDocumentCountOptions } from './operations/estimated_document_count'; -export type { EvalOptions } from './operations/eval'; export type { ExecutionResult } from './operations/execute_operation'; export type { FindOptions } from './operations/find'; export type { diff --git a/test/mongodb.ts b/test/mongodb.ts index 4a8f21214b8..df85d2cd641 100644 --- a/test/mongodb.ts +++ b/test/mongodb.ts @@ -164,7 +164,6 @@ export * from '../src/operations/delete'; export * from '../src/operations/distinct'; export * from '../src/operations/drop'; export * from '../src/operations/estimated_document_count'; -export * from '../src/operations/eval'; export * from '../src/operations/execute_operation'; export * from '../src/operations/find'; export * from '../src/operations/find_and_modify'; From 2477871f0aae2ad52c9725606d337dcb9a1e4cbd Mon Sep 17 00:00:00 2001 From: Malik Javaid <67246038+malikj2000@users.noreply.github.com> Date: Thu, 3 Aug 2023 13:08:41 -0400 Subject: [PATCH 3/4] refactor(NODE-5473): remove unused callback inheritance in operations layer (#3793) --- src/operations/eval.ts | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/operations/eval.ts diff --git a/src/operations/eval.ts b/src/operations/eval.ts new file mode 100644 index 00000000000..3f7699e067c --- /dev/null +++ b/src/operations/eval.ts @@ -0,0 +1,74 @@ +import { Code, type Document } from '../bson'; +import type { Collection } from '../collection'; +import type { Db } from '../db'; +import { MongoServerError } from '../error'; +import { ReadPreference } from '../read_preference'; +import type { Server } from '../sdam/server'; +import type { ClientSession } from '../sessions'; +import { CommandOperation, type CommandOperationOptions } from './command'; + +/** @public */ +export interface EvalOptions extends CommandOperationOptions { + nolock?: boolean; +} + +/** @internal */ +export class EvalOperation extends CommandOperation { + override options: EvalOptions; + code: Code; + parameters?: Document | Document[]; + + constructor( + db: Db | Collection, + code: Code, + parameters?: Document | Document[], + options?: EvalOptions + ) { + super(db, options); + + this.options = options ?? {}; + this.code = code; + this.parameters = parameters; + // force primary read preference + Object.defineProperty(this, 'readPreference', { + value: ReadPreference.primary, + configurable: false, + writable: false + }); + } + + override async execute(server: Server, session: ClientSession | undefined): Promise { + let finalCode = this.code; + let finalParameters: Document[] = []; + + // If not a code object translate to one + if (!(finalCode && (finalCode as unknown as { _bsontype: string })._bsontype === 'Code')) { + finalCode = new Code(finalCode as never); + } + + // Ensure the parameters are correct + if (this.parameters != null && typeof this.parameters !== 'function') { + finalParameters = Array.isArray(this.parameters) ? this.parameters : [this.parameters]; + } + + // Create execution selector + const cmd: Document = { $eval: finalCode, args: finalParameters }; + + // Check if the nolock parameter is passed in + if (this.options.nolock) { + cmd.nolock = this.options.nolock; + } + + // Execute the command + const result = await super.executeCommand(server, session, cmd); + if (result && result.ok === 1) { + return result.retval; + } + + if (result) { + throw new MongoServerError({ message: `eval failed: ${result.errmsg}` }); + } + + return result; + } +} From 19ad78793009209a90ff2b7912a7f6648afc83b6 Mon Sep 17 00:00:00 2001 From: Malik Javaid Date: Thu, 3 Aug 2023 14:49:26 -0400 Subject: [PATCH 4/4] removed eval.ts --- src/operations/eval.ts | 74 ------------------------------------------ 1 file changed, 74 deletions(-) delete mode 100644 src/operations/eval.ts diff --git a/src/operations/eval.ts b/src/operations/eval.ts deleted file mode 100644 index 3f7699e067c..00000000000 --- a/src/operations/eval.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { Code, type Document } from '../bson'; -import type { Collection } from '../collection'; -import type { Db } from '../db'; -import { MongoServerError } from '../error'; -import { ReadPreference } from '../read_preference'; -import type { Server } from '../sdam/server'; -import type { ClientSession } from '../sessions'; -import { CommandOperation, type CommandOperationOptions } from './command'; - -/** @public */ -export interface EvalOptions extends CommandOperationOptions { - nolock?: boolean; -} - -/** @internal */ -export class EvalOperation extends CommandOperation { - override options: EvalOptions; - code: Code; - parameters?: Document | Document[]; - - constructor( - db: Db | Collection, - code: Code, - parameters?: Document | Document[], - options?: EvalOptions - ) { - super(db, options); - - this.options = options ?? {}; - this.code = code; - this.parameters = parameters; - // force primary read preference - Object.defineProperty(this, 'readPreference', { - value: ReadPreference.primary, - configurable: false, - writable: false - }); - } - - override async execute(server: Server, session: ClientSession | undefined): Promise { - let finalCode = this.code; - let finalParameters: Document[] = []; - - // If not a code object translate to one - if (!(finalCode && (finalCode as unknown as { _bsontype: string })._bsontype === 'Code')) { - finalCode = new Code(finalCode as never); - } - - // Ensure the parameters are correct - if (this.parameters != null && typeof this.parameters !== 'function') { - finalParameters = Array.isArray(this.parameters) ? this.parameters : [this.parameters]; - } - - // Create execution selector - const cmd: Document = { $eval: finalCode, args: finalParameters }; - - // Check if the nolock parameter is passed in - if (this.options.nolock) { - cmd.nolock = this.options.nolock; - } - - // Execute the command - const result = await super.executeCommand(server, session, cmd); - if (result && result.ok === 1) { - return result.retval; - } - - if (result) { - throw new MongoServerError({ message: `eval failed: ${result.errmsg}` }); - } - - return result; - } -}