Skip to content

Commit 6263225

Browse files
committed
Merged APM code prototype and made test suite pass
1 parent 91e1f30 commit 6263225

File tree

7 files changed

+119
-66
lines changed

7 files changed

+119
-66
lines changed

lib/admin.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
var toError = require('./utils').toError,
4+
Define = require('./metadata'),
45
shallowClone = require('./utils').shallowClone;
56

67
/**
@@ -44,6 +45,8 @@ var Admin = function(db, topology, promiseLibrary) {
4445
}
4546
}
4647

48+
var define = Admin.define = new Define('Admin', Admin, false);
49+
4750
/**
4851
* The callback format for results
4952
* @callback Admin~resultCallback
@@ -80,9 +83,10 @@ Admin.prototype.command = function(command, options, callback) {
8083
resolve(doc);
8184
});
8285
});
83-
8486
}
8587

88+
define.classMethod('command', {callback: true, promise:true});
89+
8690
/**
8791
* Retrieve the server information for the current
8892
* instance of the db client
@@ -104,6 +108,8 @@ Admin.prototype.buildInfo = function(callback) {
104108
});
105109
}
106110

111+
define.classMethod('buildInfo', {callback: true, promise:true});
112+
107113
/**
108114
* Retrieve the server information for the current
109115
* instance of the db client
@@ -128,6 +134,8 @@ Admin.prototype.serverInfo = function(callback) {
128134
});
129135
}
130136

137+
define.classMethod('serverInfo', {callback: true, promise:true});
138+
131139
/**
132140
* Retrieve this db's server status.
133141
*
@@ -160,6 +168,8 @@ var serverStatus = function(self, callback) {
160168
});
161169
}
162170

171+
define.classMethod('serverStatus', {callback: true, promise:true});
172+
163173
/**
164174
* Retrieve the current profiling Level for MongoDB
165175
*
@@ -197,6 +207,8 @@ var profilingLevel = function(self, callback) {
197207
});
198208
}
199209

210+
define.classMethod('profilingLevel', {callback: true, promise:true});
211+
200212
/**
201213
* Ping the MongoDB server and retrieve results
202214
*
@@ -221,6 +233,8 @@ Admin.prototype.ping = function(options, callback) {
221233
});
222234
}
223235

236+
define.classMethod('ping', {callback: true, promise:true});
237+
224238
/**
225239
* Authenticate a user against the server.
226240
* @method
@@ -243,6 +257,8 @@ Admin.prototype.authenticate = function(username, password, callback) {
243257
});
244258
}
245259

260+
define.classMethod('authenticate', {callback: true, promise:true});
261+
246262
/**
247263
* Logout user from server, fire off on all connections and remove all auth info
248264
* @method
@@ -263,6 +279,8 @@ Admin.prototype.logout = function(callback) {
263279
});
264280
}
265281

282+
define.classMethod('logout', {callback: true, promise:true});
283+
266284
// Get write concern
267285
var writeConcern = function(options, db) {
268286
options = shallowClone(options);
@@ -324,6 +342,8 @@ Admin.prototype.addUser = function(username, password, options, callback) {
324342
});
325343
}
326344

345+
define.classMethod('addUser', {callback: true, promise:true});
346+
327347
/**
328348
* Remove a user from a database
329349
* @method
@@ -361,6 +381,8 @@ Admin.prototype.removeUser = function(username, options, callback) {
361381
});
362382
}
363383

384+
define.classMethod('removeUser', {callback: true, promise:true});
385+
364386
/**
365387
* Set the current profiling level of MongoDB
366388
*
@@ -409,6 +431,8 @@ var setProfilingLevel = function(self, level, callback) {
409431
});
410432
}
411433

434+
define.classMethod('setProfilingLevel', {callback: true, promise:true});
435+
412436
/**
413437
* Retrive the current profiling information for MongoDB
414438
*
@@ -438,6 +462,8 @@ var profilingInfo = function(self, callback) {
438462
}
439463
}
440464

465+
define.classMethod('profilingLevel', {callback: true, promise:true});
466+
441467
/**
442468
* Validate an existing collection
443469
*
@@ -494,6 +520,8 @@ var validateCollection = function(self, collectionName, options, callback) {
494520
});
495521
}
496522

523+
define.classMethod('validateCollection', {callback: true, promise:true});
524+
497525
/**
498526
* List the available databases
499527
*
@@ -514,6 +542,8 @@ Admin.prototype.listDatabases = function(callback) {
514542
});
515543
}
516544

545+
define.classMethod('listDatabases', {callback: true, promise:true});
546+
517547
/**
518548
* Get ReplicaSet status
519549
*
@@ -542,4 +572,6 @@ var replSetGetStatus = function(self, callback) {
542572
});
543573
}
544574

575+
define.classMethod('replSetGetStatus', {callback: true, promise:true});
576+
545577
module.exports = Admin;

lib/aggregation_cursor.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ var AggregationCursor = function(bson, ns, cmd, options, topology, topologyOptio
140140
// Inherit from Readable
141141
inherits(AggregationCursor, Readable);
142142

143+
// Set the methods to inherit from prototype
144+
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
145+
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
146+
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified'];
147+
143148
// Extend the Cursor
144149
for(var name in CoreCursor.prototype) {
145150
AggregationCursor.prototype[name] = CoreCursor.prototype[name];
@@ -311,15 +316,12 @@ define.classMethod('unwind', {callback: false, promise:false, returns: [Aggregat
311316

312317
AggregationCursor.prototype.get = AggregationCursor.prototype.toArray;
313318

314-
define.classMethod('get', {callback: true, promise:false});
315-
316319
// Inherited methods
317-
define.classMethod('toArray', {callback: true, promise:false});
320+
define.classMethod('toArray', {callback: true, promise:true});
318321
define.classMethod('each', {callback: true, promise:false});
319322
define.classMethod('forEach', {callback: true, promise:false});
320-
define.classMethod('next', {callback: true, promise:false});
321-
define.classMethod('explain', {callback: true, promise:false});
322-
define.classMethod('close', {callback: true, promise:false});
323+
define.classMethod('next', {callback: true, promise:true});
324+
define.classMethod('close', {callback: true, promise:true});
323325
define.classMethod('isClosed', {callback: false, promise:false, returns: [Boolean]});
324326
define.classMethod('rewind', {callback: false, promise:false});
325327
define.classMethod('bufferedCount', {callback: false, promise:false, returns: [Number]});

lib/collection.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,12 +958,6 @@ var deleteMany = function(self, filter, options, callback) {
958958
});
959959
}
960960

961-
define.classMethod('deleteMany', {callback: true, promise:true});
962-
963-
Collection.prototype.removeMany = Collection.prototype.deleteMany;
964-
965-
define.classMethod('removeMany', {callback: true, promise:true});
966-
967961
var removeDocuments = function(self, selector, options, callback) {
968962
if(typeof options == 'function') {
969963
callback = options, options = {};
@@ -998,6 +992,12 @@ var removeDocuments = function(self, selector, options, callback) {
998992
});
999993
}
1000994

995+
define.classMethod('deleteMany', {callback: true, promise:true});
996+
997+
Collection.prototype.removeMany = Collection.prototype.deleteMany;
998+
999+
define.classMethod('removeMany', {callback: true, promise:true});
1000+
10011001
/**
10021002
* Remove documents.
10031003
* @method

lib/command_cursor.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ inherits(CommandCursor, Readable);
142142
// Set the methods to inherit from prototype
143143
var methodsToInherit = ['_next', 'next', 'each', 'forEach', 'toArray'
144144
, 'rewind', 'bufferedCount', 'readBufferedDocuments', 'close', 'isClosed', 'kill'
145-
, '_find', '_getmore', '_killcursor'];
145+
, '_find', '_getmore', '_killcursor', 'isDead', 'explain', 'isNotified'];
146146

147147
// Only inherit the types we need
148148
for(var i = 0; i < methodsToInherit.length; i++) {
@@ -188,12 +188,11 @@ CommandCursor.prototype.get = CommandCursor.prototype.toArray;
188188
define.classMethod('get', {callback: true, promise:false});
189189

190190
// Inherited methods
191-
define.classMethod('toArray', {callback: true, promise:false});
191+
define.classMethod('toArray', {callback: true, promise:true});
192192
define.classMethod('each', {callback: true, promise:false});
193193
define.classMethod('forEach', {callback: true, promise:false});
194-
define.classMethod('next', {callback: true, promise:false});
195-
define.classMethod('explain', {callback: true, promise:false});
196-
define.classMethod('close', {callback: true, promise:false});
194+
define.classMethod('next', {callback: true, promise:true});
195+
define.classMethod('close', {callback: true, promise:true});
197196
define.classMethod('isClosed', {callback: false, promise:false, returns: [Boolean]});
198197
define.classMethod('rewind', {callback: false, promise:false});
199198
define.classMethod('bufferedCount', {callback: false, promise:false, returns: [Number]});

lib/cursor.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Cursor.prototype.hasNext = function(callback) {
201201
});
202202
}
203203

204+
define.classMethod('hasNext', {callback: true, promise:true});
204205

205206
/**
206207
* Get the next available document from the cursor, returns null if no more documents are available.
@@ -242,6 +243,8 @@ Cursor.prototype.next = function(callback) {
242243
});
243244
}
244245

246+
define.classMethod('next', {callback: true, promise:true});
247+
245248
/**
246249
* Set the cursor query
247250
* @method
@@ -268,6 +271,8 @@ Cursor.prototype.maxScan = function(maxScan) {
268271
return this;
269272
}
270273

274+
define.classMethod('maxScan', {callback: false, promise:false, returns: [Cursor]});
275+
271276
/**
272277
* Set the cursor hint
273278
* @method
@@ -280,6 +285,8 @@ Cursor.prototype.hint = function(hint) {
280285
return this;
281286
}
282287

288+
define.classMethod('hint', {callback: false, promise:false, returns: [Cursor]});
289+
283290
/**
284291
* Set the cursor min
285292
* @method
@@ -292,6 +299,8 @@ Cursor.prototype.min = function(min) {
292299
return this;
293300
}
294301

302+
define.classMethod('min', {callback: false, promise:false, returns: [Cursor]});
303+
295304
/**
296305
* Set the cursor max
297306
* @method
@@ -304,6 +313,8 @@ Cursor.prototype.max = function(max) {
304313
return this;
305314
}
306315

316+
define.classMethod('max', {callback: false, promise:false, returns: [Cursor]});
317+
307318
/**
308319
* Set the cursor returnKey
309320
* @method
@@ -316,6 +327,8 @@ Cursor.prototype.returnKey = function(value) {
316327
return this;
317328
}
318329

330+
define.classMethod('returnKey', {callback: false, promise:false, returns: [Cursor]});
331+
319332
/**
320333
* Set the cursor showRecordId
321334
* @method
@@ -328,6 +341,8 @@ Cursor.prototype.showRecordId = function(value) {
328341
return this;
329342
}
330343

344+
define.classMethod('showRecordId', {callback: false, promise:false, returns: [Cursor]});
345+
331346
/**
332347
* Set the cursor snapshot
333348
* @method
@@ -340,6 +355,8 @@ Cursor.prototype.snapshot = function(value) {
340355
return this;
341356
}
342357

358+
define.classMethod('snapshot', {callback: false, promise:false, returns: [Cursor]});
359+
343360
/**
344361
* Set a node.js specific cursor option
345362
* @method
@@ -648,6 +665,8 @@ var loop = function(self, callback) {
648665
*/
649666
Cursor.prototype.next = Cursor.prototype.nextObject;
650667

668+
define.classMethod('next', {callback: true, promise:true});
669+
651670
/**
652671
* Iterates over all the documents for this cursor. As with **{cursor.toArray}**,
653672
* not all of the elements will be iterated if this cursor had been previouly accessed.

0 commit comments

Comments
 (0)