11import { bson as BSON } from './bson-export' ;
2+ import { inspect as utilInspect } from 'util' ;
23const inspectCustom = Symbol . for ( 'nodejs.util.inspect.custom' ) ;
34type BSONClassKey = ( typeof BSON ) [ Exclude <
45 keyof typeof BSON ,
@@ -19,7 +20,7 @@ function makeClasslessInspect<K extends BSONClassKey>(className: K) {
1920 this : ( typeof BSON ) [ typeof className ] [ 'prototype' ] ,
2021 ...args : any
2122 ) {
22- return removeNewFromInspectResult ( originalInspect . apply ( this , args as any ) ) ;
23+ return removeNewFromInspectResult ( originalInspect . apply ( this , args ) ) ;
2324 } ;
2425}
2526
@@ -43,10 +44,38 @@ export const bsonStringifiers: Record<
4344 BSONRegExp : makeClasslessInspect ( 'BSONRegExp' ) ,
4445 Binary : function (
4546 this : typeof BSON . Binary . prototype ,
47+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4648 ...args : any [ ]
4749 ) : string {
4850 const hexString = this . toString ( 'hex' ) ;
4951 switch ( this . sub_type ) {
52+ case BSON . Binary . SUBTYPE_VECTOR :
53+ switch ( this . buffer [ 0 ] ) {
54+ case BSON . Binary . VECTOR_TYPE . Int8 :
55+ return `Int8(${ utilInspect (
56+ Array . from ( this . toInt8Array ( ) ) ,
57+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
58+ ...args
59+ ) } )`;
60+ case BSON . Binary . VECTOR_TYPE . Float32 :
61+ return `Float32(${ utilInspect (
62+ Array . from ( this . toFloat32Array ( ) ) ,
63+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
64+ ...args
65+ ) } )`;
66+ case BSON . Binary . VECTOR_TYPE . PackedBit :
67+ return `PackedBit(${ utilInspect (
68+ hexString ,
69+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
70+ ...args
71+ ) } )`;
72+ default :
73+ return `Vector(${ utilInspect (
74+ hexString ,
75+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
76+ ...args
77+ ) } )`;
78+ }
5079 case BSON . Binary . SUBTYPE_MD5 :
5180 return `MD5('${ hexString } ')` ;
5281 case BSON . Binary . SUBTYPE_UUID :
0 commit comments