Comparing version 1.3.1 to 1.3.2
@@ -588,6 +588,6 @@ 'use strict'; | ||
entity[key] = this.nullToValue(meta.type, value); | ||
entity[key] = this.nullToValue(meta, value); | ||
} | ||
return error ? error : entity; | ||
return error || entity; | ||
}; | ||
@@ -611,3 +611,6 @@ | ||
// | ||
Schema.prototype.nullToValue = function (type, value) { | ||
Schema.prototype.nullToValue = function (meta, value) { | ||
var type = meta.type, | ||
self = this; | ||
if ((type === 'text' || type === 'ascii') && value === null) { | ||
@@ -628,3 +631,47 @@ // null text values will create tombstones in Cassandra | ||
} | ||
if (type === 'map') { | ||
return Object.keys(value).reduce(function reduce(memo, key) { | ||
memo[key] = self.nullToValue({ type: meta.mapType[1] }, value[key]); | ||
return memo; | ||
}, {}); | ||
} | ||
if (type === 'set') { | ||
// Sets are an odd edge case here, it can be an array or an object who's | ||
// values are sit in an add and/or remove property. This means we need to | ||
// a bit more work updating this data structure. | ||
if (this.type(value) === 'object') { | ||
['add', 'remove'].forEach(function each(method) { | ||
if (method in value) value[method] = value[method].map(function map(value) { | ||
return self.nullToValue({ type: meta.setType }, value); | ||
}); | ||
}); | ||
return value; | ||
} else { | ||
return value.map(function map(value) { | ||
return self.nullToValue({ type: meta.setType }, value); | ||
}); | ||
} | ||
} | ||
if (type === 'list') { | ||
if (this.type(value) === 'object') { | ||
['prepend', 'append', 'remove'].forEach(function each(method) { | ||
if (method in value) value[method] = value[method].map(function map(value) { | ||
return self.nullToValue({ type: meta.listType }, value); | ||
}); | ||
}); | ||
if (value.index && this.type(value.index) === 'object') { | ||
value.index = Object.keys(value.index).reduce(function (acc, idx) { | ||
acc[idx] = self.nullToValue({ type: meta.listType }, value.index[idx]); | ||
return acc; | ||
}, {}); | ||
} | ||
} else { | ||
return value.map(function map(value) { | ||
return self.nullToValue({ type: meta.setType }, value); | ||
}); | ||
} | ||
} | ||
return value; | ||
@@ -659,5 +706,25 @@ | ||
} | ||
if (this.type(value) === 'date' && value.getTime() === 0) { | ||
var type = this.type(value); | ||
if (type === 'date' && value.getTime() === 0) { | ||
return null; | ||
} | ||
if (type === 'array') { | ||
for (let i = 0; i < value.length; i++) { | ||
value[i] = this.valueToNull(value[i]); | ||
} | ||
return value; | ||
} | ||
if (type === 'object') { | ||
var keys = Object.keys(value); | ||
for (let i = 0; i < keys.length; i++) { | ||
value[keys[i]] = this.valueToNull(value[keys[i]]); | ||
} | ||
return value; | ||
} | ||
return value; | ||
@@ -664,0 +731,0 @@ }; |
{ | ||
"name": "datastar", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Now witness the power of this FULLY ARMED AND OPERATIONAL DATASTAR!", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
@@ -10,2 +10,3 @@ 'use strict'; | ||
schemas = require('../fixtures/schemas'), | ||
Datastar = require('../..'), | ||
datastarTestTools = require('datastar-test-tools'); | ||
@@ -23,3 +24,3 @@ | ||
assume(err).to.equal(null); | ||
datastar = helpers.connectDatastar({ config: data.cassandra }, null, done); | ||
datastar = helpers.connectDatastar({ config: data.cassandra }, Datastar, done); | ||
/* cassandra = new driver.Client({ | ||
@@ -118,3 +119,18 @@ contactPoints: data.cassandra.hosts, | ||
Artist.remove(entity, done); | ||
// | ||
// By passing a null we set the map value to null | ||
// | ||
Artist.update({ | ||
id: entity.id, | ||
metadata: { | ||
hello: null | ||
} | ||
}, function (err) { | ||
assume(err).is.falsey(); | ||
find(Artist, entity.id, function (_, result) { | ||
assume(result.metadata.hello).is.falsey(); | ||
Artist.remove(entity, done); | ||
}); | ||
}); | ||
}); | ||
@@ -130,3 +146,2 @@ }); | ||
type: 'all', | ||
fields: ['*'], | ||
conditions: { | ||
@@ -163,3 +178,2 @@ artistId: '00000000-0000-0000-0000-000000000002' | ||
type: 'all', | ||
fields: ['*'], | ||
conditions: { | ||
@@ -166,0 +180,0 @@ artistId: id |
190128
4806