function parseDynamoDBPropertyValue()

in lib/ddb-utils.js [62:120]


function parseDynamoDBPropertyValue(value) {
  if(value === null || value === undefined) {
    throw new Error("Can not process null or undefined properties");
  }
  var properties = Object.keys(value);
  if(properties.length === 0) {
    throw new Error("Can not process empty properties");
  }
  var dataType = properties[0];
  switch(dataType) {
    case "S": {
      return value.S;
    }
    case "B": {
      //return new Buffer(value.B, 'base64');
      return value.B; // Leave it as a base64 string for subsequent serialization
    }
    case "N": {
      return Number(value.N);
    }
    case "NULL": {
      return null;
    }
    case "BOOL": {
      return value.BOOL;
    }
    case "NS": {
      return value.NS.map(function(entry) {
        return Number(entry);
      });
    }
    case "SS": {
      return value.SS;
    }
    case "BS": {
      return value.BS.map(function(entry) {
        //return new Buffer(entry, 'base64');
        return entry; // Leave it as a base64 string for subsequent serialization
        return new Buffer(entry, 'base64');
      });
    }
    case "L": {
      return value.L.map(function(entry) {
        return parseDynamoDBPropertyValue(entry);
      });
    }
    case "M": {
      var result = {};
      var properties = Object.keys(value.M);
      properties.forEach(function(propertyName) {
        result[propertyName] = parseDynamoDBPropertyValue(value.M[propertyName]);
      });
      return result;
    }
    default: {
      throw new Error("Unknown property type " + dataType);
    }
  }
}