1- // import type * as _BSON from 'bson';
2- // let BSON: typeof _BSON = require('bson');
3- // try {
4- // BSON = require('bson-ext');
5- // } catch {} // eslint-disable-line
1+ import type {
2+ serialize as serializeFn ,
3+ deserialize as deserializeFn ,
4+ calculateObjectSize as calculateObjectSizeFn
5+ } from 'bson' ;
6+
7+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8+ let BSON = require ( 'bson' ) ;
9+ try {
10+ BSON = require ( 'bson-ext' ) ;
11+ } catch { } // eslint-disable-line
612
7- // export = BSON;
13+ /** @internal */
14+ export const deserialize = BSON . deserialize as typeof deserializeFn ;
15+ /** @internal */
16+ export const serialize = BSON . serialize as typeof serializeFn ;
17+ /** @internal */
18+ export const calculateObjectSize = BSON . calculateObjectSize as typeof calculateObjectSizeFn ;
819
920export {
1021 Long ,
@@ -21,38 +32,27 @@ export {
2132 BSONRegExp ,
2233 BSONSymbol ,
2334 Map ,
24- deserialize ,
25- serialize ,
26- calculateObjectSize
35+ Document
2736} from 'bson' ;
2837
29- /** @public */
30- export interface Document {
31- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32- [ key : string ] : any ;
33- }
38+ import type { DeserializeOptions , SerializeOptions } from 'bson' ;
3439
35- import type { SerializeOptions } from 'bson' ;
36-
37- // TODO: Remove me when types from BSON are updated
3840/**
3941 * BSON Serialization options.
4042 * @public
4143 */
42- export interface BSONSerializeOptions extends Omit < SerializeOptions , 'index' > {
43- /** Return document results as raw BSON buffers */
44- fieldsAsRaw ?: { [ key : string ] : boolean } ;
45- /** Promotes BSON values to native types where possible, set to false to only receive wrapper types */
46- promoteValues ?: boolean ;
47- /** Promotes Binary BSON values to native Node Buffers */
48- promoteBuffers ?: boolean ;
49- /** Promotes long values to number if they fit inside the 53 bits resolution */
50- promoteLongs ?: boolean ;
51- /** Serialize functions on any object */
52- serializeFunctions ?: boolean ;
53- /** Specify if the BSON serializer should ignore undefined fields */
54- ignoreUndefined ?: boolean ;
55-
44+ export interface BSONSerializeOptions
45+ extends Omit < SerializeOptions , 'index' > ,
46+ Omit <
47+ DeserializeOptions ,
48+ | 'evalFunctions'
49+ | 'cacheFunctions'
50+ | 'cacheFunctionsCrc32'
51+ | 'bsonRegExp'
52+ | 'allowObjectSmallerThanBufferSize'
53+ | 'index'
54+ > {
55+ /** Return BSON filled buffers from operations */
5656 raw ?: boolean ;
5757}
5858
0 commit comments