Socket
Socket
Sign inDemoInstall

cormo

Package Overview
Dependencies
Maintainers
1
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cormo - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

lib/connection/manipulate.js

4

lib/adapters/base.js

@@ -42,3 +42,3 @@ // Generated by CoffeeScript 1.4.0

AdapterBase.prototype.valueToDB = function(value, column, property) {
if (property.type === types.Object) {
if (property.type === types.Object || property.array) {
return JSON.stringify(value);

@@ -57,3 +57,3 @@ } else if (value != null) {

AdapterBase.prototype.valueToModel = function(value, column, property) {
if (property.type === types.Object) {
if (property.type === types.Object || property.array) {
return JSON.parse(value);

@@ -60,0 +60,0 @@ } else {

@@ -25,2 +25,5 @@ // Generated by CoffeeScript 1.4.0

_typeToSQL = function(property) {
if (property.array) {
return 'VARCHAR(255)';
}
switch (property.type) {

@@ -130,3 +133,3 @@ case types.String:

MySQLAdapter.prototype.valueToModel = function(value, column, property) {
if (property.type === types.Object) {
if (property.type === types.Object || property.array) {
return JSON.parse(value);

@@ -133,0 +136,0 @@ } else if (property.type === types.GeoPoint) {

@@ -25,2 +25,5 @@ // Generated by CoffeeScript 1.4.0

_typeToSQL = function(property) {
if (property.array) {
return 'VARCHAR(255)';
}
switch (property.type) {

@@ -27,0 +30,0 @@ case types.String:

@@ -25,2 +25,5 @@ // Generated by CoffeeScript 1.4.0

_typeToSQL = function(property) {
if (property.array) {
return 'VARCHAR(255)';
}
switch (property.type) {

@@ -115,3 +118,3 @@ case types.String:

SQLite3Adapter.prototype.valueToModel = function(value, column, property) {
if (property.type === types.Object) {
if (property.type === types.Object || property.array) {
return JSON.parse(value);

@@ -118,0 +121,0 @@ } else if (property.type === types.Date) {

@@ -126,4 +126,6 @@ // Generated by CoffeeScript 1.4.0

_use('manipulate');
module.exports = Connection;
}).call(this);

@@ -107,3 +107,3 @@ // Generated by CoffeeScript 1.4.0

var i, parts, subcolumn, subproperty, type, _i, _ref;
if (typeof property === 'object' && (!property.type || property.type.type)) {
if (typeof property === 'object' && !Array.isArray(property) && (!property.type || property.type.type)) {
for (subcolumn in property) {

@@ -118,3 +118,3 @@ subproperty = property[subcolumn];

}
if (typeof property === 'function' || typeof property === 'string') {
if (typeof property === 'function' || typeof property === 'string' || Array.isArray(property)) {
property = {

@@ -124,2 +124,6 @@ type: property

}
if (Array.isArray(property.type)) {
property.array = true;
property.type = property.type[0];
}
type = types._toCORMOType(property.type);

@@ -126,0 +130,0 @@ if (type === types.RecordID) {

@@ -13,48 +13,61 @@ // Generated by CoffeeScript 1.4.0

ModelValidate._validateType = function(column, type, value) {
switch (type) {
case types.Number:
value = Number(value);
if (isNaN(value)) {
throw "'" + column + "' is not a number";
}
break;
case types.Boolean:
if (typeof value !== 'boolean') {
throw "'" + column + "' is not a boolean";
}
break;
case types.Integer:
value = Number(value);
if (isNaN(value) || (value >> 0) !== value) {
throw "'" + column + "' is not an integer";
}
break;
case types.GeoPoint:
if (!(Array.isArray(value) && value.length === 2)) {
throw "'" + column + "' is not a geo point";
} else {
value[0] = Number(value[0]);
value[1] = Number(value[1]);
}
break;
case types.Date:
value = new Date(value);
if (isNaN(value.getTime())) {
throw "'" + column + "' is not a date";
}
}
return value;
};
ModelValidate._validateColumn = function(data, column, property) {
var last, obj, value, _ref;
var i, last, obj, v, value, _i, _len, _ref;
_ref = util.getLeafOfPath(data, property._parts, false), obj = _ref[0], last = _ref[1];
value = obj != null ? obj[last] : void 0;
if (value != null) {
switch (property.type) {
case types.Number:
value = Number(value);
if (isNaN(value)) {
return "'" + column + "' is not a number";
} else {
obj[last] = value;
if (property.array) {
if (!Array.isArray(value)) {
throw "'" + column + "' is not an array";
}
try {
for (i = _i = 0, _len = value.length; _i < _len; i = ++_i) {
v = value[i];
value[i] = this._validateType(column, property.type, v);
}
break;
case types.Boolean:
if (typeof value !== 'boolean') {
return "'" + column + "' is not a boolean";
}
break;
case types.Integer:
value = Number(value);
if (isNaN(value) || (value >> 0) !== value) {
return "'" + column + "' is not an integer";
} else {
obj[last] = value;
}
break;
case types.GeoPoint:
if (!(Array.isArray(value) && value.length === 2)) {
return "'" + column + "' is not a geo point";
} else {
value[0] = Number(value[0]);
value[1] = Number(value[1]);
}
break;
case types.Date:
value = new Date(value);
if (isNaN(value.getTime())) {
return "'" + column + "' is not a date";
} else {
obj[last] = value;
}
} catch (error) {
throw "'" + column + "' is not an array";
}
} else {
obj[last] = this._validateType(column, property.type, value);
}
} else {
if (property.required) {
return "'" + column + "' is required";
throw "'" + column + "' is required";
}

@@ -65,3 +78,3 @@ }

ModelValidate.prototype.validate = function(callback) {
var column, ctor, error, errors, property, schema,
var column, ctor, errors, property, schema,
_this = this;

@@ -74,3 +87,5 @@ this._runCallbacks('validate', 'before');

property = schema[column];
if (error = ctor._validateColumn(this, column, property)) {
try {
ctor._validateColumn(this, column, property);
} catch (error) {
errors.push(error);

@@ -77,0 +92,0 @@ }

@@ -183,3 +183,3 @@ // Generated by CoffeeScript 1.4.0

Query.prototype._validateAndBuildSaveData = function(errors, data, updates, path, object) {
var column, error, model, property, schema, _results;
var column, model, property, schema, _results;
model = this._model;

@@ -191,3 +191,5 @@ schema = model._schema;

if (property) {
if (error = model._validateColumn(updates, path + column, property)) {
try {
model._validateColumn(updates, path + column, property);
} catch (error) {
errors.push(error);

@@ -194,0 +196,0 @@ }

{
"name": "cormo",
"description": "ORM framework for Node.js",
"version": "0.3.3",
"version": "0.3.4",
"keywords": [

@@ -6,0 +6,0 @@ "orm",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc