Commit With Frontend and Backend in MERN

This commit is contained in:
sanikapendurkar
2025-02-10 14:24:56 +05:30
commit 0f4e1a3183
2518 changed files with 448667 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
import { type TimeoutContext } from '../../timeout';
import { AbstractOperation } from '../operation';
/**
* @public
*/
export interface SearchIndexDescription extends Document {
/** The name of the index. */
name?: string;
/** The index definition. */
definition: Document;
/** The type of the index. Currently `search` or `vectorSearch` are supported. */
type?: string;
}
/** @internal */
export class CreateSearchIndexesOperation extends AbstractOperation<string[]> {
constructor(
private readonly collection: Collection,
private readonly descriptions: ReadonlyArray<SearchIndexDescription>
) {
super();
}
override get commandName() {
return 'createSearchIndexes' as const;
}
override async execute(
server: Server,
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<string[]> {
const namespace = this.collection.fullNamespace;
const command = {
createSearchIndexes: namespace.collection,
indexes: this.descriptions
};
const res = await server.command(namespace, command, {
session,
timeoutContext
});
const indexesCreated: Array<{ name: string }> = res?.indexesCreated ?? [];
return indexesCreated.map(({ name }) => name);
}
}

View File

@@ -0,0 +1,47 @@
import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
import { type TimeoutContext } from '../../timeout';
import { AbstractOperation } from '../operation';
/** @internal */
export class DropSearchIndexOperation extends AbstractOperation<void> {
constructor(
private readonly collection: Collection,
private readonly name: string
) {
super();
}
override get commandName() {
return 'dropSearchIndex' as const;
}
override async execute(
server: Server,
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<void> {
const namespace = this.collection.fullNamespace;
const command: Document = {
dropSearchIndex: namespace.collection
};
if (typeof this.name === 'string') {
command.name = this.name;
}
try {
await server.command(namespace, command, { session, timeoutContext });
} catch (error) {
const isNamespaceNotFoundError =
error instanceof MongoServerError && error.code === MONGODB_ERROR_CODES.NamespaceNotFound;
if (!isNamespaceNotFoundError) {
throw error;
}
}
}
}

View File

@@ -0,0 +1,37 @@
import type { Document } from '../../bson';
import type { Collection } from '../../collection';
import type { Server } from '../../sdam/server';
import type { ClientSession } from '../../sessions';
import { type TimeoutContext } from '../../timeout';
import { AbstractOperation } from '../operation';
/** @internal */
export class UpdateSearchIndexOperation extends AbstractOperation<void> {
constructor(
private readonly collection: Collection,
private readonly name: string,
private readonly definition: Document
) {
super();
}
override get commandName() {
return 'updateSearchIndex' as const;
}
override async execute(
server: Server,
session: ClientSession | undefined,
timeoutContext: TimeoutContext
): Promise<void> {
const namespace = this.collection.fullNamespace;
const command = {
updateSearchIndex: namespace.collection,
name: this.name,
definition: this.definition
};
await server.command(namespace, command, { session, timeoutContext });
return;
}
}