Comparing version 0.0.1 to 0.0.3
@@ -117,5 +117,5 @@ var util = require('util'), | ||
} | ||
if (hasValue && field.type.toLowerCase() !== typeof(value).toLowerCase()) { | ||
if (hasValue && field.type.toLowerCase() !== (typeof value).toLowerCase()) { | ||
if (!this.validateCoersiveTypes(field,name,value)) { | ||
throw new ValidationError(name,"invalid type ("+typeof(value)+") for field: "+name+". Should be "+field.type+". Value was: "+util.inspect(value)); | ||
throw new ValidationError(name,"invalid type ("+(typeof value)+") for field: "+name+". Should be "+field.type+". Value was: "+util.inspect(value)); | ||
} | ||
@@ -175,2 +175,14 @@ } | ||
Instance.prototype.toPayload = function toPayload() { | ||
var obj = {}, | ||
fields = this._model.fields, | ||
values = this.values(); | ||
for (var key in values) { | ||
if (values.hasOwnProperty(key) && values[key] !== null) { | ||
obj[fields[key].name || key] = values[key]; | ||
} | ||
} | ||
return obj; | ||
}; | ||
Instance.prototype.isUnsaved = function isUnsaved() { | ||
@@ -234,3 +246,3 @@ return this._dirty; | ||
// see if we have a field remapping | ||
if (!skipNotFound && name in this._fieldmap) { | ||
if (name in this._fieldmap) { | ||
name = this._fieldmap[name]; | ||
@@ -237,0 +249,0 @@ } |
@@ -413,3 +413,6 @@ var util = require('util'), | ||
catch(err) { | ||
// Oh well, carry on! | ||
if (key === 'where') { | ||
err.message = 'Failed to parse "where" as JSON: ' + err.message; | ||
throw err; | ||
} | ||
} | ||
@@ -416,0 +419,0 @@ } |
{ | ||
"name": "api-orm", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"description": "API Builder ORM", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -92,2 +92,31 @@ var should = require('should'), | ||
it('should be able get payloads for servers',function(callback){ | ||
var Connector = new orm.MemoryConnector(); | ||
var User = orm.Model.define('user',{ | ||
fields: { | ||
name: { | ||
name: 'internalName', | ||
type: String, | ||
default: 'Jeff' | ||
}, | ||
age: { | ||
type: Number, | ||
default: 10 | ||
} | ||
}, | ||
connector: Connector | ||
}); | ||
User.create(function(err,instance){ | ||
should(err).be.not.ok; | ||
should(instance).be.an.Object; | ||
var payload = instance.toPayload(); | ||
should(payload).be.an.Object; | ||
should(payload.internalName).be.ok; | ||
should(payload.age).be.ok; | ||
callback(); | ||
}); | ||
}); | ||
it('should be able to create with defaults',function(callback){ | ||
@@ -94,0 +123,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
94060
2947
1