Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

orm

Package Overview
Dependencies
Maintainers
2
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

orm - npm Package Compare versions

Comparing version 2.1.8 to 2.1.9

after-load.patch

5

Changelog.md

@@ -1,3 +0,4 @@

### v2.2.0 - (to do, in future)
- Fixes error code spelling: `PARAM_MISSMATCH` -> `PARAM_MISMATCH`
### v2.1.9 - 06 May 2014
- Add basic PostGIS support - (#456, #375)
- Allow mapping model properties to differently named columns (#273, #495)

@@ -4,0 +5,0 @@ ### v2.1.8 - 28 Apr 2014

@@ -38,3 +38,5 @@ var _ = require("lodash");

for (var k in props) {
props[k] = Property.normalize(props[k], {}, Model.settings);
props[k] = Property.normalize({
prop: props[k], name: k, customTypes: {}, settings: Model.settings
});
}

@@ -63,3 +65,2 @@ }

};
associations.push(association);

@@ -66,0 +67,0 @@

16

lib/Instance.js

@@ -154,7 +154,10 @@ var Property = require("./Property");

if (prop) {
if (prop.type === 'serial' && opts.data[k] == null) continue;
if (opts.data[k] == null && (prop.type == 'serial' || typeof prop.defaultValue == 'function')) {
continue;
}
data[k] = Property.validate(opts.data[k], prop);
if (opts.driver.propertyToValue) {
data[k] = opts.driver.propertyToValue(data[k], prop);
data[prop.mapsTo] = opts.driver.propertyToValue(opts.data[k], prop);
} else {
data[prop.mapsTo] = opts.data[k];
}

@@ -199,3 +202,3 @@ } else {

for (var i = 0; i < opts.id.length; i++) {
opts.data[opts.id[i]] = info.hasOwnProperty(opts.id[i]) ? info[opts.id[i]] : data[opts.id[i]];
opts.data[opts.id[i]] = info.hasOwnProperty(opts.id[i]) ? info[opts.id[i]] : data[opts.id[i]];
}

@@ -342,3 +345,3 @@ opts.is_new = false;

if (opts.extra[opts.extrachanges[i]]) {
data[opts.extrachanges[i]] = Property.validate(opts.data[opts.extrachanges[i]], opts.extra[opts.extrachanges[i]]);
data[opts.extrachanges[i]] = opts.data[opts.extrachanges[i]];
if (opts.driver.propertyToValue) {

@@ -400,4 +403,3 @@ data[opts.extrachanges[i]] = opts.driver.propertyToValue(data[opts.extrachanges[i]], opts.extra[opts.extrachanges[i]]);

if (Model.properties[key]) {
changes[key] = Property.validate(changes[key], Model.properties[key]);
if (opts.driver.propertyToValue) {
if (opts.driver.propertyToValue) {
changes[key] = opts.driver.propertyToValue(changes[key], Model.properties[key]);

@@ -404,0 +406,0 @@ }

@@ -36,2 +36,3 @@ var ChainFind = require("./ChainFind");

var model_fields = [];
var fieldToPropertyMap = {};
var allProperties = {};

@@ -146,2 +147,14 @@

var mapDatastoreFieldsToProperties = function (dataIn) {
var k, prop;
var dataOut = {};
for (k in dataIn) {
prop = fieldToPropertyMap[k];
if (!prop) dataOut[k] = dataIn[k];
else dataOut[prop.name] = dataIn[k];
}
return dataOut;
}
var model = function () {

@@ -288,5 +301,7 @@ var instance, i;

if (data.length === 0) {
return cb(new ORMError("Not found", 'NOT_FOUND', { model: opts.table }));
return cb(new ORMError("Not found", 'NOT_FOUND', { model: opts.table }));
}
data = mapDatastoreFieldsToProperties(data[0]);
var uid = opts.driver.uid + "/" + opts.table + "/" + ids.join("/");

@@ -298,3 +313,3 @@

}, function (cb) {
return createInstance(data[0], {
return createInstance(data, {
uid : uid,

@@ -637,16 +652,28 @@ autoSave : options.autoSave,

var currFields = {}, cType;
// standardize properties
for (k in opts.properties) {
opts.properties[k] = Property.normalize(opts.properties[k], opts.db.customTypes, opts.settings);
opts.properties[k].klass = 'primary';
allProperties[k] = opts.properties[k];
var prop = opts.properties[k] = Property.normalize({
prop: opts.properties[k], name: k,
customTypes: opts.db.customTypes, settings: opts.settings
});
prop.klass = 'primary';
allProperties[k] = prop;
fieldToPropertyMap[prop.mapsTo] = prop;
if (opts.id.indexOf(k) != -1) {
opts.properties[k].key = true;
prop.key = true;
}
if (opts.properties[k].lazyload !== true && model_fields.indexOf(k) == -1) {
model_fields.push(k);
if (prop.lazyload !== true && !currFields[k]) {
currFields[k] = true;
if ((cType = opts.db.customTypes[prop.type]) && cType.datastoreGet) {
model_fields.push({
a: prop.mapsTo, sql: cType.datastoreGet(prop, opts.db.driver.query)
});
} else {
model_fields.push(prop.mapsTo);
}
}
if (opts.properties[k].required) {
if (prop.required) {
// Prepend `required` validation

@@ -663,5 +690,7 @@ if(opts.validations.hasOwnProperty(k)) {

k = opts.id[i];
allProperties[k] = opts.properties[k] || {
type: 'serial', key: true, klass: 'key'
};
allProperties[k] = opts.properties[k] || Property.normalize({
prop: { type: 'serial', key: true, klass: 'key' },
name: k, customTypes: opts.db.customTypes, settings: opts.settings
});
fieldToPropertyMap[allProperties[k].mapsTo] = allProperties[k];
}

@@ -668,0 +697,0 @@ model_fields = opts.id.concat(model_fields);

@@ -0,1 +1,2 @@

var _ = require('lodash');
var ORMError = require("./Error");

@@ -6,57 +7,61 @@

"binary", "point", "serial"
]
];
exports.normalize = function (prop, customTypes, Settings) {
if (typeof prop === "function") {
switch (prop.name) {
exports.normalize = function (opts) {
if (typeof opts.prop === "function") {
switch (opts.prop.name) {
case "String":
prop = { type: "text" };
opts.prop = { type: "text" };
break;
case "Number":
prop = { type: "number" };
opts.prop = { type: "number" };
break;
case "Boolean":
prop = { type: "boolean" };
opts.prop = { type: "boolean" };
break;
case "Date":
prop = { type: "date" };
opts.prop = { type: "date" };
break;
case "Object":
prop = { type: "object" };
opts.prop = { type: "object" };
break;
case "Buffer":
prop = { type: "binary" };
opts.prop = { type: "binary" };
break;
}
} else if (typeof prop === "string") {
var tmp = prop;
prop = {};
prop.type = tmp;
} else if (Array.isArray(prop)) {
prop = { type: "enum", values: prop };
} else if (typeof opts.prop === "string") {
var tmp = opts.prop;
opts.prop = {};
opts.prop.type = tmp;
} else if (Array.isArray(opts.prop)) {
opts.prop = { type: "enum", values: opts.prop };
} else {
opts.prop = _.cloneDeep(opts.prop);
}
if (KNOWN_TYPES.indexOf(prop.type) === -1 && !(prop.type in customTypes)) {
throw new ORMError("Unknown property type: " + prop.type, 'NO_SUPPORT');
}
if (KNOWN_TYPES.indexOf(opts.prop.type) === -1 && !(opts.prop.type in opts.customTypes)) {
throw new ORMError("Unknown property type: " + opts.prop.type, 'NO_SUPPORT');
}
if (!prop.hasOwnProperty("required") && Settings.get("properties.required")) {
prop.required = true;
if (!opts.prop.hasOwnProperty("required") && opts.settings.get("properties.required")) {
opts.prop.required = true;
}
// Defaults to true. Rational means floating point here.
if (prop.type == "number" && prop.rational === undefined) {
prop.rational = true;
if (opts.prop.type == "number" && opts.prop.rational === undefined) {
opts.prop.rational = true;
}
if (prop.type == "number" && prop.rational === false) {
prop.type = "integer";
delete prop.rational;
if (!('mapsTo' in opts.prop)) {
opts.prop.mapsTo = opts.name
}
return prop;
};
if (opts.prop.type == "number" && opts.prop.rational === false) {
opts.prop.type = "integer";
delete opts.prop.rational;
}
exports.validate = function (value, prop) {
return value;
opts.prop.name = opts.name;
return opts.prop;
};

@@ -0,1 +1,3 @@

_ = require('lodash')
/**

@@ -179,4 +181,9 @@ * Order should be a String (with the property name assumed ascending)

new_obj[obj] = alternatives[obj] || alternatives[model.id[0]] || { type: 'number', unsigned: true, rational: false };
new_obj[obj] = _.cloneDeep(
alternatives[obj] || alternatives[model.id[0]] || { type: 'number', unsigned: true, rational: false }
);
new_obj[obj].name = obj;
new_obj[obj].mapsTo = obj;
return new_obj;

@@ -210,3 +217,5 @@ };

values : p.values || null,
required : required
required : required,
name : field_name,
mapsTo : field_name
};

@@ -218,3 +227,5 @@ } else {

size : 4,
required : required
required : required,
name : field_name,
mapsTo : field_name
};

@@ -221,0 +232,0 @@ }

@@ -15,3 +15,3 @@ {

],
"version" : "2.1.8",
"version" : "2.1.9",
"license" : "MIT",

@@ -41,4 +41,4 @@ "homepage" : "http://dresende.github.io/node-orm2",

"enforce" : "0.1.2",
"sql-query" : "0.1.16",
"sql-ddl-sync" : "git://github.com/dresende/node-sql-ddl-sync.git#v0.3.0",
"sql-query" : "git://github.com/dresende/node-sql-query.git#v0.1.17",
"sql-ddl-sync" : "git://github.com/dresende/node-sql-ddl-sync.git#v0.3.3",
"hat" : "0.0.3",

@@ -45,0 +45,0 @@ "lodash" : "2.4.1"

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