CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
run_command.ts80 linesDownload Raw Back to operations
1import { type Abortable } from '..';2import type { BSONSerializeOptions, Document } from '../bson';3import { type Connection } from '../cmap/connection';4import { CursorResponse, MongoDBResponse } from '../cmap/wire_protocol/responses';5import { AbstractOperation } from '../operations/operation';6import type { ReadPreferenceLike } from '../read_preference';7import type { ServerCommandOptions } from '../sdam/server';8import type { ClientSession } from '../sessions';9import { type TimeoutContext } from '../timeout';10import { type MongoDBNamespace } from '../utils';11 12/** @public */13export type RunCommandOptions = {14  /** Specify ClientSession for this command */15  session?: ClientSession;16  /** The read preference */17  readPreference?: ReadPreferenceLike;18  /**19   * @experimental20   * Specifies the time an operation will run until it throws a timeout error21   */22  timeoutMS?: number;23  /** @internal */24  omitMaxTimeMS?: boolean;25 26  /**27   * @internal Hints to `executeOperation` that this operation should not unpin on an ended transaction28   * This is only used by the driver for transaction commands29   */30  bypassPinningCheck?: boolean;31} & BSONSerializeOptions &32  Abortable;33 34/** @internal */35export class RunCommandOperation<T = Document> extends AbstractOperation<T> {36  override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;37  command: Document;38  override options: RunCommandOptions;39 40  constructor(namespace: MongoDBNamespace, command: Document, options: RunCommandOptions) {41    super(options);42    this.command = command;43    this.options = options;44    this.ns = namespace.withCollection('$cmd');45  }46 47  override get commandName() {48    return 'runCommand' as const;49  }50 51  override buildCommand(_connection: Connection, _session?: ClientSession): Document {52    return this.command;53  }54 55  override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {56    return {57      ...this.options,58      session: this.session,59      timeoutContext,60      signal: this.options.signal,61      readPreference: this.options.readPreference62    };63  }64}65 66/**67 * @internal68 *69 * A specialized subclass of RunCommandOperation for cursor-creating commands.70 */71export class RunCursorCommandOperation extends RunCommandOperation {72  override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;73 74  override handleOk(75    response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>76  ): CursorResponse {77    return response;78  }79}80