@@ -95,35 +95,31 @@ export class MongoDBResponse extends OnDemandDocument {
95
95
return this . clusterTime ?? null ;
96
96
}
97
97
98
- public override toObject ( options : BSONSerializeOptions = { } ) : Record < string , any > {
98
+ public override toObject ( options ? : BSONSerializeOptions ) : Record < string , any > {
99
99
const exactBSONOptions = {
100
- useBigInt64 : options . useBigInt64 ,
101
- promoteLongs : options . promoteLongs ,
102
- promoteValues : options . promoteValues ,
103
- promoteBuffers : options . promoteBuffers ,
104
- bsonRegExp : options . bsonRegExp ,
105
- raw : options . raw ?? false ,
106
- fieldsAsRaw : options . fieldsAsRaw ?? { } ,
100
+ useBigInt64 : options ? .useBigInt64 ,
101
+ promoteLongs : options ? .promoteLongs ,
102
+ promoteValues : options ? .promoteValues ,
103
+ promoteBuffers : options ? .promoteBuffers ,
104
+ bsonRegExp : options ? .bsonRegExp ,
105
+ raw : options ? .raw ?? false ,
106
+ fieldsAsRaw : options ? .fieldsAsRaw ?? { } ,
107
107
validation : this . parseBsonSerializationOptions ( options )
108
108
} ;
109
109
return super . toObject ( exactBSONOptions ) ;
110
110
}
111
111
112
- private parseBsonSerializationOptions ( { enableUtf8Validation } : BSONSerializeOptions ) : {
112
+ private parseBsonSerializationOptions ( options ?: { enableUtf8Validation ?: boolean } ) : {
113
113
utf8 : { writeErrors : false } | false ;
114
114
} {
115
+ const enableUtf8Validation = options ?. enableUtf8Validation ;
115
116
if ( enableUtf8Validation === false ) {
116
117
return { utf8 : false } ;
117
118
}
118
-
119
119
return { utf8 : { writeErrors : false } } ;
120
120
}
121
121
}
122
122
123
- function throwUnsupportedError ( ) {
124
- throw new Error ( 'Unsupported method' ) ;
125
- }
126
-
127
123
/** @internal */
128
124
export class CursorResponse extends MongoDBResponse {
129
125
static emptyGetMore = new CursorResponse (
@@ -139,7 +135,6 @@ export class CursorResponse extends MongoDBResponse {
139
135
140
136
public id : Long | null = null ;
141
137
public ns : MongoDBNamespace | null = null ;
142
- public documents : any | null = null ;
143
138
public batchSize = 0 ;
144
139
145
140
private batch : OnDemandDocument | null = null ;
@@ -163,35 +158,35 @@ export class CursorResponse extends MongoDBResponse {
163
158
else if ( cursor . has ( 'nextBatch' ) ) this . batch = cursor . get ( 'nextBatch' , BSONType . array , true ) ;
164
159
else throw new MongoUnexpectedServerResponseError ( 'Cursor document did not contain a batch' ) ;
165
160
166
- this . values = this . batch . valuesAs ( BSONType . object ) ;
167
161
this . batchSize = this . batch . size ( ) ;
168
- this . iterated = 0 ;
169
- this . documents = Object . defineProperties ( Object . create ( null ) , {
170
- length : {
171
- get : ( ) => {
172
- return Math . max ( this . batchSize - this . iterated , 0 ) ;
173
- }
174
- } ,
175
- shift : {
176
- value : ( options ?: BSONSerializeOptions ) => {
177
- this . iterated += 1 ;
178
- const result = this . values ?. next ( ) ;
179
- if ( ! result || result . done ) return null ;
180
- if ( options ?. raw ) {
181
- return result . value . toBytes ( ) ;
182
- } else {
183
- return result . value . toObject ( options ) ;
184
- }
185
- }
186
- } ,
187
- clear : {
188
- value : ( ) => {
189
- this . iterated = this . batchSize ;
190
- this . values ?. return ( ) ;
191
- }
192
- } ,
193
- pushMany : { value : throwUnsupportedError } ,
194
- push : { value : throwUnsupportedError }
195
- } ) ;
162
+ }
163
+
164
+ get length ( ) {
165
+ return Math . max ( this . batchSize - this . iterated , 0 ) ;
166
+ }
167
+
168
+ shift ( options ?: BSONSerializeOptions ) : any {
169
+ this . iterated += 1 ;
170
+ this . values ??= this . batch ?. valuesAs ( BSONType . object ) ?? null ;
171
+ const result = this . values ?. next ( ) ;
172
+ if ( ! result || result . done ) return null ;
173
+ if ( options ?. raw ) {
174
+ return result . value . toBytes ( ) ;
175
+ } else {
176
+ return result . value . toObject ( options ) ;
177
+ }
178
+ }
179
+
180
+ clear ( ) {
181
+ this . iterated = this . batchSize ;
182
+ this . values ?. return ( ) ;
183
+ }
184
+
185
+ pushMany ( ) {
186
+ throw new Error ( 'pushMany Unsupported method' ) ;
187
+ }
188
+
189
+ push ( ) {
190
+ throw new Error ( 'push Unsupported method' ) ;
196
191
}
197
192
}
0 commit comments