opusdev/vector-similarity-api
1
1import { BSONValue } from './bson_value';2import { type InspectFn, defaultInspect } from './parser/utils';3 4/** @public */5export interface BSONSymbolExtended {6 $symbol: string;7}8 9/**10 * A class representation of the BSON Symbol type.11 * @public12 * @category BSONType13 */14export class BSONSymbol extends BSONValue {15 get _bsontype(): 'BSONSymbol' {16 return 'BSONSymbol';17 }18 19 value!: string;20 /**21 * @param value - the string representing the symbol.22 */23 constructor(value: string) {24 super();25 this.value = value;26 }27 28 /** Access the wrapped string value. */29 valueOf(): string {30 return this.value;31 }32 33 toString(): string {34 return this.value;35 }36 37 toJSON(): string {38 return this.value;39 }40 41 /** @internal */42 toExtendedJSON(): BSONSymbolExtended {43 return { $symbol: this.value };44 }45 46 /** @internal */47 static fromExtendedJSON(doc: BSONSymbolExtended): BSONSymbol {48 return new BSONSymbol(doc.$symbol);49 }50 51 inspect(depth?: number, options?: unknown, inspect?: InspectFn): string {52 inspect ??= defaultInspect;53 return `new BSONSymbol(${inspect(this.value, options)})`;54 }55}56 