VirtualOptions.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use strict';
  2. const opts = require('./propertyOptions');
  3. class VirtualOptions {
  4. constructor(obj) {
  5. Object.assign(this, obj);
  6. if (obj != null && obj.options != null) {
  7. this.options = Object.assign({}, obj.options);
  8. }
  9. }
  10. }
  11. /**
  12. * Marks this virtual as a populate virtual, and specifies the model to
  13. * use for populate.
  14. *
  15. * @api public
  16. * @property ref
  17. * @memberOf VirtualOptions
  18. * @type String|Model|Function
  19. * @instance
  20. */
  21. Object.defineProperty(VirtualOptions.prototype, 'ref', opts);
  22. /**
  23. * Marks this virtual as a populate virtual, and specifies the path that
  24. * contains the name of the model to populate
  25. *
  26. * @api public
  27. * @property refPath
  28. * @memberOf VirtualOptions
  29. * @type String|Function
  30. * @instance
  31. */
  32. Object.defineProperty(VirtualOptions.prototype, 'refPath', opts);
  33. /**
  34. * The name of the property in the local model to match to `foreignField`
  35. * in the foreign model.
  36. *
  37. * @api public
  38. * @property localField
  39. * @memberOf VirtualOptions
  40. * @type String|Function
  41. * @instance
  42. */
  43. Object.defineProperty(VirtualOptions.prototype, 'localField', opts);
  44. /**
  45. * The name of the property in the foreign model to match to `localField`
  46. * in the local model.
  47. *
  48. * @api public
  49. * @property foreignField
  50. * @memberOf VirtualOptions
  51. * @type String|Function
  52. * @instance
  53. */
  54. Object.defineProperty(VirtualOptions.prototype, 'foreignField', opts);
  55. /**
  56. * Whether to populate this virtual as a single document (true) or an
  57. * array of documents (false).
  58. *
  59. * @api public
  60. * @property justOne
  61. * @memberOf VirtualOptions
  62. * @type Boolean
  63. * @instance
  64. */
  65. Object.defineProperty(VirtualOptions.prototype, 'justOne', opts);
  66. /**
  67. * If true, populate just the number of documents where `localField`
  68. * matches `foreignField`, as opposed to the documents themselves.
  69. *
  70. * If `count` is set, it overrides `justOne`.
  71. *
  72. * @api public
  73. * @property count
  74. * @memberOf VirtualOptions
  75. * @type Boolean
  76. * @instance
  77. */
  78. Object.defineProperty(VirtualOptions.prototype, 'count', opts);
  79. /**
  80. * Add an additional filter to populate, in addition to `localField`
  81. * matches `foreignField`.
  82. *
  83. * @api public
  84. * @property match
  85. * @memberOf VirtualOptions
  86. * @type Object|Function
  87. * @instance
  88. */
  89. Object.defineProperty(VirtualOptions.prototype, 'match', opts);
  90. /**
  91. * Additional options to pass to the query used to `populate()`:
  92. *
  93. * - `sort`
  94. * - `skip`
  95. * - `limit`
  96. *
  97. * @api public
  98. * @property options
  99. * @memberOf VirtualOptions
  100. * @type Object
  101. * @instance
  102. */
  103. Object.defineProperty(VirtualOptions.prototype, 'options', opts);
  104. /**
  105. * If true, add a `skip` to the query used to `populate()`.
  106. *
  107. * @api public
  108. * @property skip
  109. * @memberOf VirtualOptions
  110. * @type Number
  111. * @instance
  112. */
  113. Object.defineProperty(VirtualOptions.prototype, 'skip', opts);
  114. /**
  115. * If true, add a `limit` to the query used to `populate()`.
  116. *
  117. * @api public
  118. * @property limit
  119. * @memberOf VirtualOptions
  120. * @type Number
  121. * @instance
  122. */
  123. Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
  124. /**
  125. * The `limit` option for `populate()` has [some unfortunate edge cases](/docs/populate.html#query-conditions)
  126. * when working with multiple documents, like `.find().populate()`. The
  127. * `perDocumentLimit` option makes `populate()` execute a separate query
  128. * for each document returned from `find()` to ensure each document
  129. * gets up to `perDocumentLimit` populated docs if possible.
  130. *
  131. * @api public
  132. * @property perDocumentLimit
  133. * @memberOf VirtualOptions
  134. * @type Number
  135. * @instance
  136. */
  137. Object.defineProperty(VirtualOptions.prototype, 'perDocumentLimit', opts);
  138. module.exports = VirtualOptions;