Sha256: 081bdd9209b18ebca74bb8d093ac7b3376f6453c0c384b8f342b66fb025e9298

Contents?: true

Size: 1.28 KB

Versions: 35

Compression:

Stored size: 1.28 KB

Contents

var util = require('../core').util;
var typeOf = require('./types').typeOf;

/**
 * @api private
 */
var DynamoDBSet = util.inherit({

  constructor: function Set(list, options) {
    options = options || {};
    this.initialize(list, options.validate);
  },

  initialize: function(list, validate) {
    var self = this;
    self.values = [].concat(list);
    self.detectType();
    if (validate) {
      self.validate();
    }
  },

  detectType: function() {
    var self = this;
    var value = self.values[0];
    if (typeOf(value) === 'String') {
      self.type = 'String';
    } else if (typeOf(value) === 'Number') {
      self.type = 'Number';
    } else if (typeOf(value) === 'Binary') {
      self.type = 'Binary';
    } else {
      throw util.error(new Error(), {
        code: 'InvalidSetType',
        message: 'Sets can contain string, number, or binary values'
      });
    }
  },

  validate: function() {
    var self = this;
    var length = self.values.length;
    var values = self.values;
    for (var i = 0; i < length; i++) {
      if (typeOf(values[i]) !== self.type) {
        throw util.error(new Error(), {
          code: 'InvalidType',
          message: self.type + ' Set contains ' + typeOf(values[i]) + ' value'
        });
      }
    }
  }

});

module.exports = DynamoDBSet;

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sumomo-0.10.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.12 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.11 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.10 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.9 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js
sumomo-0.8.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/dynamodb/set.js