|
|
import { BSONValue } from './bson_value'; |
|
|
|
|
|
|
|
|
export interface BSONSymbolExtended { |
|
|
$symbol: string; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class BSONSymbol extends BSONValue { |
|
|
get _bsontype(): 'BSONSymbol' { |
|
|
return 'BSONSymbol'; |
|
|
} |
|
|
|
|
|
value!: string; |
|
|
|
|
|
|
|
|
|
|
|
constructor(value: string) { |
|
|
super(); |
|
|
this.value = value; |
|
|
} |
|
|
|
|
|
|
|
|
valueOf(): string { |
|
|
return this.value; |
|
|
} |
|
|
|
|
|
toString(): string { |
|
|
return this.value; |
|
|
} |
|
|
|
|
|
inspect(): string { |
|
|
return `new BSONSymbol("${this.value}")`; |
|
|
} |
|
|
|
|
|
toJSON(): string { |
|
|
return this.value; |
|
|
} |
|
|
|
|
|
|
|
|
toExtendedJSON(): BSONSymbolExtended { |
|
|
return { $symbol: this.value }; |
|
|
} |
|
|
|
|
|
|
|
|
static fromExtendedJSON(doc: BSONSymbolExtended): BSONSymbol { |
|
|
return new BSONSymbol(doc.$symbol); |
|
|
} |
|
|
|
|
|
|
|
|
[Symbol.for('nodejs.util.inspect.custom')](): string { |
|
|
return this.inspect(); |
|
|
} |
|
|
} |
|
|
|