SchemaArrayOptions.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const SchemaTypeOptions = require('./SchemaTypeOptions');
  3. /**
  4. * The options defined on an Array schematype.
  5. *
  6. * ####Example:
  7. *
  8. * const schema = new Schema({ tags: [String] });
  9. * schema.path('tags').options; // SchemaArrayOptions instance
  10. *
  11. * @api public
  12. * @inherits SchemaTypeOptions
  13. * @constructor SchemaArrayOptions
  14. */
  15. class SchemaArrayOptions extends SchemaTypeOptions {}
  16. const opts = require('./propertyOptions');
  17. /**
  18. * If this is an array of strings, an array of allowed values for this path.
  19. * Throws an error if this array isn't an array of strings.
  20. *
  21. * @api public
  22. * @property enum
  23. * @memberOf SchemaArrayOptions
  24. * @type Array
  25. * @instance
  26. */
  27. Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
  28. /**
  29. * If set, specifies the type of this array's values. Equivalent to setting
  30. * `type` to an array whose first element is `of`.
  31. *
  32. * ####Example:
  33. *
  34. * // `arr` is an array of numbers.
  35. * new Schema({ arr: [Number] });
  36. * // Equivalent way to define `arr` as an array of numbers
  37. * new Schema({ arr: { type: Array, of: Number } });
  38. *
  39. * @api public
  40. * @property of
  41. * @memberOf SchemaArrayOptions
  42. * @type Function|String
  43. * @instance
  44. */
  45. Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
  46. /*!
  47. * ignore
  48. */
  49. module.exports = SchemaArrayOptions;