Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed May 16, 2023
1 parent 7851975 commit a2bac9d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
17 changes: 4 additions & 13 deletions src/operations/get_more.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface GetMoreOptions extends OperationOptions {
* @internal
*/
export interface GetMoreCommand {
getMore: Long | bigint;
getMore: Long;
collection: string;
batchSize?: number;
maxTimeMS?: number;
Expand All @@ -36,15 +36,10 @@ export interface GetMoreCommand {

/** @internal */
export class GetMoreOperation extends AbstractOperation {
cursorId: Long | bigint;
cursorId: Long;
override options: GetMoreOptions;

constructor(
ns: MongoDBNamespace,
cursorId: Long | bigint,
server: Server,
options: GetMoreOptions
) {
constructor(ns: MongoDBNamespace, cursorId: Long, server: Server, options: GetMoreOptions) {
super(options);

this.options = options;
Expand All @@ -68,11 +63,7 @@ export class GetMoreOperation extends AbstractOperation {
);
}

if (
this.cursorId == null ||
this.cursorId === 0n ||
(typeof this.cursorId === 'object' && this.cursorId.isZero())
) {
if (this.cursorId == null || this.cursorId.isZero()) {
return callback(new MongoRuntimeError('Unable to iterate cursor with no id'));
}

Expand Down
13 changes: 4 additions & 9 deletions src/operations/kill_cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ import { AbstractOperation, Aspect, defineAspects, OperationOptions } from './op
*/
interface KillCursorsCommand {
killCursors: string;
cursors: (Long | bigint)[];
cursors: Long[];
comment?: unknown;
}

export class KillCursorsOperation extends AbstractOperation {
cursorId: Long | bigint;

constructor(
cursorId: Long | bigint,
ns: MongoDBNamespace,
server: Server,
options: OperationOptions
) {
cursorId: Long;

constructor(cursorId: Long, ns: MongoDBNamespace, server: Server, options: OperationOptions) {
super(options);
this.ns = ns;
this.cursorId = cursorId;
Expand Down
9 changes: 4 additions & 5 deletions src/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ConnectionPoolMetrics } from './cmap/metrics';
import { isSharded } from './cmap/wire_protocol/shared';
import { PINNED, UNPINNED } from './constants';
import type { AbstractCursor } from './cursor/abstract_cursor';
import type { RunCommandCursor } from './cursor/run_command_cursor';
import {
AnyError,
MongoAPIError,
Expand Down Expand Up @@ -54,7 +53,7 @@ export interface ClientSessionOptions {
defaultTransactionOptions?: TransactionOptions;

/** @internal */
owner?: symbol | AbstractCursor | RunCommandCursor;
owner?: symbol | AbstractCursor;
/** @internal */
explicit?: boolean;
/** @internal */
Expand Down Expand Up @@ -109,7 +108,7 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
operationTime?: Timestamp;
explicit: boolean;
/** @internal */
owner?: symbol | AbstractCursor | RunCommandCursor;
owner?: symbol | AbstractCursor;
defaultTransactionOptions: TransactionOptions;
transaction: Transaction;
/** @internal */
Expand Down Expand Up @@ -506,7 +505,7 @@ export function maybeClearPinnedConnection(
const loadBalancer = servers[0];

if (options?.error == null || options?.force) {
loadBalancer.s.pool.checkIn(conn);
loadBalancer.pool.checkIn(conn);
conn.emit(
UNPINNED,
session.transaction.state !== TxnState.NO_TRANSACTION
Expand All @@ -515,7 +514,7 @@ export function maybeClearPinnedConnection(
);

if (options?.forceClear) {
loadBalancer.s.pool.clear({ serviceId: conn.serviceId });
loadBalancer.pool.clear({ serviceId: conn.serviceId });
}
}

Expand Down
22 changes: 14 additions & 8 deletions test/integration/node-specific/examples/run_command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ describe('examples.runCommand:', function () {
db = undefined;
});

it('supports runCommand 1', async function () {
// Start runCommand example 1
await db.command({ buildInfo: 1 });
// End runCommand example 1
it('supports runCommand 1', {
metadata: { requires: { topology: ['single'] } },
test: async function () {
// Start runCommand example 1
await db.command({ buildInfo: 1 });
// End runCommand example 1
}
});

it('supports runCommand 2', async function () {
// Start runCommand example 2
await db.command({ collStats: 'restaurants' });
// End runCommand example 2
it('supports runCommand 2', {
metadata: { requires: { topology: ['single'] } },
test: async function () {
// Start runCommand example 2
await db.command({ collStats: 'restaurants' });
// End runCommand example 2
}
});
});
10 changes: 3 additions & 7 deletions test/tools/unified-spec-runner/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
MongoCredentials,
ReadConcern,
ReadPreference,
RunCommandCursor,
SENSITIVE_COMMANDS,
ServerDescriptionChangedEvent,
TopologyDescription,
Expand Down Expand Up @@ -172,7 +171,7 @@ export class UnifiedMongoClient extends MongoClient {
const transformedLog = {
level: log.s,
component: log.c,
data: { ...log, s: undefined, c: undefined }
data: { ...log }
};

this.buffer.push(transformedLog);
Expand All @@ -192,12 +191,12 @@ export class UnifiedMongoClient extends MongoClient {
monitorCommands: true,
[Symbol.for('@@mdb.skipPingOnConnect')]: true,
[Symbol.for('@@mdb.enableMongoLogger')]: true,
[Symbol.for('@@mdb.internalMongoLoggerConfig')]: componentSeverities,
[Symbol.for('@@mdb.internalLoggerConfig')]: componentSeverities,
// @ts-expect-error TODO(NODE-4849): Remove this once we have support for mongodbLogPath
mongodbLogPath: logCollector,
...getEnvironmentalOptions(),
...(description.serverApi ? { serverApi: description.serverApi } : {})
});
} as any);
this.logCollector = logCollector;

this.ignoredEvents = [
Expand Down Expand Up @@ -442,9 +441,6 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
throw new Error(`Unknown type ${type}`);
}
if (!(entity instanceof ctor)) {
if (type === 'cursor' && entity instanceof RunCommandCursor) {
return entity;
}
throw new Error(`${key} is not an instance of ${type}`);
}
return entity;
Expand Down

0 comments on commit a2bac9d

Please sign in to comment.