@@ -7,6 +7,11 @@ module.exports = Object.create(null);
77Object . defineProperty ( module . exports , '__esModule' , { value : true } ) ;
88
99module . exports . makeLegacyFindCursor = function ( baseClass ) {
10+ function toLegacyHelper ( cursor ) {
11+ Object . setPrototypeOf ( cursor , LegacyFindCursor . prototype ) ;
12+ return cursor ;
13+ }
14+
1015 class LegacyFindCursor extends baseClass {
1116 /** @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead */
1217 count ( options , callback ) {
@@ -56,19 +61,28 @@ module.exports.makeLegacyFindCursor = function (baseClass) {
5661 tryNext ( callback ) {
5762 return maybeCallback ( super . tryNext ( ) , callback ) ;
5863 }
64+ clone ( ) {
65+ const cursor = super . clone ( ) ;
66+ return toLegacyHelper ( cursor ) ;
67+ }
5968 }
6069
6170 Object . defineProperty ( baseClass . prototype , toLegacy , {
6271 enumerable : false ,
6372 value : function ( ) {
64- return Object . setPrototypeOf ( this , LegacyFindCursor . prototype ) ;
73+ return toLegacyHelper ( this ) ;
6574 }
6675 } ) ;
6776
6877 return LegacyFindCursor ;
6978} ;
7079
7180module . exports . makeLegacyListCollectionsCursor = function ( baseClass ) {
81+ function toLegacyHelper ( cursor ) {
82+ Object . setPrototypeOf ( cursor , LegacyListCollectionsCursor . prototype ) ;
83+ return cursor ;
84+ }
85+
7286 class LegacyListCollectionsCursor extends baseClass {
7387 close ( options , callback ) {
7488 callback =
@@ -95,19 +109,28 @@ module.exports.makeLegacyListCollectionsCursor = function (baseClass) {
95109 tryNext ( callback ) {
96110 return maybeCallback ( super . tryNext ( ) , callback ) ;
97111 }
112+ clone ( ) {
113+ const cursor = super . clone ( ) ;
114+ return toLegacyHelper ( cursor ) ;
115+ }
98116 }
99117
100118 Object . defineProperty ( baseClass . prototype , toLegacy , {
101119 enumerable : false ,
102120 value : function ( ) {
103- return Object . setPrototypeOf ( this , LegacyListCollectionsCursor . prototype ) ;
121+ return toLegacyHelper ( this ) ;
104122 }
105123 } ) ;
106124
107125 return LegacyListCollectionsCursor ;
108126} ;
109127
110128module . exports . makeLegacyListIndexesCursor = function ( baseClass ) {
129+ function toLegacyHelper ( cursor ) {
130+ Object . setPrototypeOf ( cursor , LegacyListIndexesCursor . prototype ) ;
131+ return cursor ;
132+ }
133+
111134 class LegacyListIndexesCursor extends baseClass {
112135 close ( options , callback ) {
113136 callback =
@@ -134,19 +157,28 @@ module.exports.makeLegacyListIndexesCursor = function (baseClass) {
134157 tryNext ( callback ) {
135158 return maybeCallback ( super . tryNext ( ) , callback ) ;
136159 }
160+ clone ( ) {
161+ const cursor = super . clone ( ) ;
162+ return toLegacyHelper ( cursor ) ;
163+ }
137164 }
138165
139166 Object . defineProperty ( baseClass . prototype , toLegacy , {
140167 enumerable : false ,
141168 value : function ( ) {
142- return Object . setPrototypeOf ( this , LegacyListIndexesCursor . prototype ) ;
169+ return toLegacyHelper ( this ) ;
143170 }
144171 } ) ;
145172
146173 return LegacyListIndexesCursor ;
147174} ;
148175
149176module . exports . makeLegacyAggregationCursor = function ( baseClass ) {
177+ function toLegacyHelper ( cursor ) {
178+ Object . setPrototypeOf ( cursor , LegacyAggregationCursor . prototype ) ;
179+ return cursor ;
180+ }
181+
150182 class LegacyAggregationCursor extends baseClass {
151183 explain ( verbosity , callback ) {
152184 callback =
@@ -184,12 +216,16 @@ module.exports.makeLegacyAggregationCursor = function (baseClass) {
184216 tryNext ( callback ) {
185217 return maybeCallback ( super . tryNext ( ) , callback ) ;
186218 }
219+ clone ( ) {
220+ const cursor = super . clone ( ) ;
221+ return toLegacyHelper ( cursor ) ;
222+ }
187223 }
188224
189225 Object . defineProperty ( baseClass . prototype , toLegacy , {
190226 enumerable : false ,
191227 value : function ( ) {
192- return Object . setPrototypeOf ( this , LegacyAggregationCursor . prototype ) ;
228+ return toLegacyHelper ( this ) ;
193229 }
194230 } ) ;
195231
0 commit comments