collection.js 814 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. /**
  3. * methods a collection must implement
  4. */
  5. const methods = [
  6. 'find',
  7. 'findOne',
  8. 'update',
  9. 'updateMany',
  10. 'updateOne',
  11. 'replaceOne',
  12. 'remove',
  13. 'count',
  14. 'distinct',
  15. 'findOneAndDelete',
  16. 'findOneAndUpdate',
  17. 'aggregate',
  18. 'findCursor',
  19. 'deleteOne',
  20. 'deleteMany'
  21. ];
  22. /**
  23. * Collection base class from which implementations inherit
  24. */
  25. function Collection() {}
  26. for (let i = 0, len = methods.length; i < len; ++i) {
  27. const method = methods[i];
  28. Collection.prototype[method] = notImplemented(method);
  29. }
  30. module.exports = exports = Collection;
  31. Collection.methods = methods;
  32. /**
  33. * creates a function which throws an implementation error
  34. */
  35. function notImplemented(method) {
  36. return function() {
  37. throw new Error('collection.' + method + ' not implemented');
  38. };
  39. }