API Docs for: 2.2.2
Show:

File: lib/commands/kv/storebucketprops.js

  1. 'use strict';
  2.  
  3. var inherits = require('util').inherits;
  4. var Joi = require('joi');
  5.  
  6. var StorePropsBase = require('./storepropsbase');
  7.  
  8. /**
  9. * Provides the StoreBucketProps class, its builder, and its response.
  10. * @module KV
  11. */
  12.  
  13. /**
  14. * Command used to set the properties on a bucket in Riak.
  15. *
  16. * As a convenience, a builder class is provided:
  17. *
  18. * var storeProps = new StoreBucketProps.Builder()
  19. * .withBucket('my-bucket')
  20. * .withAllowMult(true)
  21. * .build();
  22. *
  23. * See {{#crossLink "StoreBucketProps.Builder"}}StoreBucketProps.Builder{{/crossLink}}
  24. *
  25. * @class StoreBucketProps
  26. * @constructor
  27. * @param {Object} options The properties to store
  28. * @param {String} options.bucket The bucket in riak.
  29. * @param {String} [options.bucketType] The bucket type in riak. If not supplied 'default is used'
  30. * @param {Function} callback The callback to be executed when the operation completes.
  31. * @param {String} callback.err An error message. Will be null if no error.
  32. * @param {Boolean} callback.response the response from Riak. This will be true.
  33. * @param {Function} callback The callback to be executed when the operation completes.
  34. * @param {String} callback.err An error message. Will ne null if no error.
  35. * @param {Object} callback.response The response from Riak. This is an oject with all the bucket properties.
  36. * @param {Object} callback.data additional error data. Will be null if no error.
  37. * @extends StorePropsBase
  38. */
  39. function StoreBucketProps(options, callback) {
  40. StorePropsBase.call(this, options, 'RpbSetBucketReq', 'RpbSetBucketResp', callback);
  41. this.validateOptions(options, schema, { allowUnknown: true });
  42. }
  43.  
  44. inherits(StoreBucketProps, StorePropsBase);
  45.  
  46. StoreBucketProps.prototype.constructPbRequest = function() {
  47. var protobuf = StoreBucketProps.super_.prototype.constructPbRequest.call(this);
  48. protobuf.setBucket(new Buffer(this.options.bucket));
  49. protobuf.setType(new Buffer(this.options.bucketType));
  50. return protobuf;
  51. };
  52.  
  53. var schema = Joi.object().keys({
  54. bucket: Joi.string().required(),
  55. bucketType: Joi.string().default('default')
  56. });
  57.  
  58. /**
  59. * A builder for constructing StoreBucketProps instances
  60. *
  61. * Rather than having to manually construct the __options__ and instantiating
  62. * a StoreBucketProps directly, this builder may be used.
  63. *
  64. * var storeProps = new StoreBucketProps.Builder()
  65. * .withAllowMult(true)
  66. * .build();
  67. *
  68. * @class StoreBucketProps.Builder
  69. * @constructor
  70. * @extends StorePropsBase.Builder
  71. */
  72. function Builder() {
  73. StorePropsBase.Builder.call(this);
  74. this.precommit = [];
  75. this.postcommit = [];
  76. }
  77.  
  78. inherits(Builder, StorePropsBase.Builder);
  79.  
  80. /**
  81. * Set the bucket.
  82. * @method withBucket
  83. * @param {String} bucket the bucket in Riak
  84. * @chainable
  85. */
  86. Builder.prototype.withBucket = function(bucket) {
  87. this.bucket = bucket;
  88. return this;
  89. };
  90.  
  91. /**
  92. * Construct a StoreBucketProps instance.
  93. * @method build
  94. * @return {StoreBucketProps}
  95. */
  96. Builder.prototype.build = function() {
  97. var cb = this.callback;
  98. delete this.callback;
  99. return new StoreBucketProps(this, cb);
  100. };
  101.  
  102. module.exports = StoreBucketProps;
  103. module.exports.Builder = Builder;
  104.