list_collections.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ListCollectionsOperation = void 0;
  4. const utils_1 = require("../utils");
  5. const command_1 = require("./command");
  6. const operation_1 = require("./operation");
  7. /** @internal */
  8. class ListCollectionsOperation extends command_1.CommandCallbackOperation {
  9. constructor(db, filter, options) {
  10. super(db, options);
  11. this.options = { ...options };
  12. delete this.options.writeConcern;
  13. this.db = db;
  14. this.filter = filter;
  15. this.nameOnly = !!this.options.nameOnly;
  16. this.authorizedCollections = !!this.options.authorizedCollections;
  17. if (typeof this.options.batchSize === 'number') {
  18. this.batchSize = this.options.batchSize;
  19. }
  20. }
  21. executeCallback(server, session, callback) {
  22. return super.executeCommandCallback(server, session, this.generateCommand((0, utils_1.maxWireVersion)(server)), callback);
  23. }
  24. /* This is here for the purpose of unit testing the final command that gets sent. */
  25. generateCommand(wireVersion) {
  26. const command = {
  27. listCollections: 1,
  28. filter: this.filter,
  29. cursor: this.batchSize ? { batchSize: this.batchSize } : {},
  30. nameOnly: this.nameOnly,
  31. authorizedCollections: this.authorizedCollections
  32. };
  33. // we check for undefined specifically here to allow falsy values
  34. // eslint-disable-next-line no-restricted-syntax
  35. if (wireVersion >= 9 && this.options.comment !== undefined) {
  36. command.comment = this.options.comment;
  37. }
  38. return command;
  39. }
  40. }
  41. exports.ListCollectionsOperation = ListCollectionsOperation;
  42. (0, operation_1.defineAspects)(ListCollectionsOperation, [
  43. operation_1.Aspect.READ_OPERATION,
  44. operation_1.Aspect.RETRYABLE,
  45. operation_1.Aspect.CURSOR_CREATING
  46. ]);
  47. //# sourceMappingURL=list_collections.js.map