cormo
Advanced tools
Comparing version 0.8.0 to 0.8.1
@@ -1,3 +0,6 @@ | ||
module.exports = process.env.TEST_COV | ||
? require('./lib-cov') | ||
: require('./lib') | ||
if(process.env.CORMO_COVERAGE==='true') { | ||
require('coffee-coverage').register({path: 'relative', basePath: __dirname + '/src'}); | ||
module.exports = require('./src'); | ||
} else { | ||
module.exports = require('./lib'); | ||
} |
@@ -55,6 +55,4 @@ // Generated by CoffeeScript 1.7.1 | ||
AdapterBase.prototype._refineRawInstance = function(model, data, selected_columns) { | ||
var column, dont_eliminate_null, id, instance, parts, property, schema, support_nested, value, _i, _len; | ||
dont_eliminate_null = !this._connection.models[model].eliminate_null; | ||
schema = this._connection.models[model]._schema; | ||
AdapterBase.prototype.setValuesFromDB = function(instance, data, schema, selected_columns) { | ||
var column, parts, property, support_nested, value, _i, _len, _results; | ||
if (!selected_columns) { | ||
@@ -64,4 +62,3 @@ selected_columns = Object.keys(schema); | ||
support_nested = this.support_nested; | ||
id = this._getModelID(data); | ||
instance = {}; | ||
_results = []; | ||
for (_i = 0, _len = selected_columns.length; _i < _len; _i++) { | ||
@@ -77,6 +74,13 @@ column = selected_columns[_i]; | ||
} | ||
if ((value != null) || dont_eliminate_null) { | ||
util.setPropertyOfPath(instance, parts, value); | ||
} | ||
_results.push(util.setPropertyOfPath(instance, parts, value)); | ||
} | ||
return _results; | ||
}; | ||
AdapterBase.prototype._refineRawInstance = function(model, data, selected_columns, selected_columns_raw) { | ||
var instance; | ||
model = this._connection.models[model]; | ||
instance = {}; | ||
this.setValuesFromDB(instance, data, model._schema, selected_columns); | ||
model._collapseNestedNulls(instance, selected_columns_raw, null); | ||
Object.defineProperty(instance, 'id', { | ||
@@ -86,3 +90,3 @@ configurable: false, | ||
writable: false, | ||
value: id | ||
value: this._getModelID(data) | ||
}); | ||
@@ -92,7 +96,7 @@ return instance; | ||
AdapterBase.prototype._convertToModelInstance = function(model, data, selected_columns) { | ||
AdapterBase.prototype._convertToModelInstance = function(model, data, selected_columns, selected_columns_raw) { | ||
var id, modelClass; | ||
id = this._getModelID(data); | ||
modelClass = this._connection.models[model]; | ||
return new modelClass(data, id, selected_columns); | ||
return new modelClass(data, id, selected_columns, selected_columns_raw); | ||
}; | ||
@@ -99,0 +103,0 @@ |
@@ -581,5 +581,5 @@ // Generated by CoffeeScript 1.7.1 | ||
if (options.lean) { | ||
return callback(null, _this._refineRawInstance(model, result, options.select)); | ||
return callback(null, _this._refineRawInstance(model, result, options.select, options.select_raw)); | ||
} else { | ||
return callback(null, _this._convertToModelInstance(model, result, options.select)); | ||
return callback(null, _this._convertToModelInstance(model, result, options.select, options.select_raw)); | ||
} | ||
@@ -719,7 +719,7 @@ }; | ||
return callback(null, result.map(function(record) { | ||
return _this._refineRawInstance(model, record, options.select); | ||
return _this._refineRawInstance(model, record, options.select, options.select_raw); | ||
})); | ||
} else { | ||
return callback(null, result.map(function(record) { | ||
return _this._convertToModelInstance(model, record, options.select); | ||
return _this._convertToModelInstance(model, record, options.select, options.select_raw); | ||
})); | ||
@@ -726,0 +726,0 @@ } |
@@ -336,5 +336,5 @@ // Generated by CoffeeScript 1.7.1 | ||
if (options.lean) { | ||
return callback(null, _this._refineRawInstance(model, result[0], options.select)); | ||
return callback(null, _this._refineRawInstance(model, result[0], options.select, options.select_raw)); | ||
} else { | ||
return callback(null, _this._convertToModelInstance(model, result[0], options.select)); | ||
return callback(null, _this._convertToModelInstance(model, result[0], options.select, options.select_raw)); | ||
} | ||
@@ -417,7 +417,7 @@ } else if ((result != null ? result.length : void 0) > 1) { | ||
return callback(null, result.map(function(record) { | ||
return _this._refineRawInstance(model, record, options.select); | ||
return _this._refineRawInstance(model, record, options.select, options.select_raw); | ||
})); | ||
} else { | ||
return callback(null, result.map(function(record) { | ||
return _this._convertToModelInstance(model, record, options.select); | ||
return _this._convertToModelInstance(model, record, options.select, options.select_raw); | ||
})); | ||
@@ -424,0 +424,0 @@ } |
@@ -333,5 +333,5 @@ // Generated by CoffeeScript 1.7.1 | ||
if (options.lean) { | ||
return callback(null, _this._refineRawInstance(model, rows[0], options.select)); | ||
return callback(null, _this._refineRawInstance(model, rows[0], options.select, options.select_raw)); | ||
} else { | ||
return callback(null, _this._convertToModelInstance(model, rows[0], options.select)); | ||
return callback(null, _this._convertToModelInstance(model, rows[0], options.select, options.select_raw)); | ||
} | ||
@@ -408,7 +408,7 @@ } else if ((rows != null ? rows.length : void 0) > 1) { | ||
return callback(null, rows.map(function(record) { | ||
return _this._refineRawInstance(model, record, options.select); | ||
return _this._refineRawInstance(model, record, options.select, options.select_raw); | ||
})); | ||
} else { | ||
return callback(null, rows.map(function(record) { | ||
return _this._convertToModelInstance(model, record, options.select); | ||
return _this._convertToModelInstance(model, record, options.select, options.select_raw); | ||
})); | ||
@@ -415,0 +415,0 @@ } |
@@ -200,5 +200,5 @@ // Generated by CoffeeScript 1.7.1 | ||
if (options.lean) { | ||
return callback(null, _this._refineRawInstance(model, result, options.select)); | ||
return callback(null, _this._refineRawInstance(model, result, options.select, options.select_raw)); | ||
} else { | ||
return callback(null, _this._convertToModelInstance(model, result, options.select)); | ||
return callback(null, _this._convertToModelInstance(model, result, options.select, options.select_raw)); | ||
} | ||
@@ -230,7 +230,7 @@ } else { | ||
return callback(null, records.map(function(record) { | ||
return _this._refineRawInstance(model, record, options.select); | ||
return _this._refineRawInstance(model, record, options.select, options.select_raw); | ||
})); | ||
} else { | ||
return callback(null, records.map(function(record) { | ||
return _this._convertToModelInstance(model, record, options.select); | ||
return _this._convertToModelInstance(model, record, options.select, options.select_raw); | ||
})); | ||
@@ -237,0 +237,0 @@ } |
@@ -280,5 +280,5 @@ // Generated by CoffeeScript 1.7.1 | ||
if (options.lean) { | ||
return callback(null, _this._refineRawInstance(model, result[0], options.select)); | ||
return callback(null, _this._refineRawInstance(model, result[0], options.select, options.select_raw)); | ||
} else { | ||
return callback(null, _this._convertToModelInstance(model, result[0], options.select)); | ||
return callback(null, _this._convertToModelInstance(model, result[0], options.select, options.select_raw)); | ||
} | ||
@@ -353,7 +353,7 @@ } else if ((result != null ? result.length : void 0) > 1) { | ||
return callback(null, result.map(function(record) { | ||
return _this._refineRawInstance(model, record, options.select); | ||
return _this._refineRawInstance(model, record, options.select, options.select_raw); | ||
})); | ||
} else { | ||
return callback(null, result.map(function(record) { | ||
return _this._convertToModelInstance(model, record, options.select); | ||
return _this._convertToModelInstance(model, record, options.select, options.select_raw); | ||
})); | ||
@@ -360,0 +360,0 @@ } |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Connection, EventEmitter, Model, Promise, async, bindDomain, inspect, redis, _, _use, | ||
var Connection, EventEmitter, Model, Promise, bindDomain, inspect, redis, _, _use, | ||
__hasProp = {}.hasOwnProperty, | ||
@@ -13,4 +13,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
async = require('async'); | ||
bindDomain = require('./util').bindDomain; | ||
@@ -40,4 +38,4 @@ | ||
this._schema_changed = false; | ||
this._adapter = require(__dirname + '/adapters/' + adapter_name)(this); | ||
this._promise_connection = Promise.promisify(this._adapter.connect, this._adapter)(settings).then(function() { | ||
this._adapter = Promise.promisifyAll(require(__dirname + '/adapters/' + adapter_name)(this)); | ||
this._promise_connection = this._adapter.connectAsync(settings).then(function() { | ||
return this.connected = true; | ||
@@ -119,3 +117,3 @@ })["catch"](function(error) { | ||
} | ||
return Promise.promisify(_this._adapter.applySchema, _this._adapter)(model).then(function() { | ||
return _this._adapter.applySchemaAsync(model).then(function() { | ||
return modelClass._schema_changed = false; | ||
@@ -122,0 +120,0 @@ }); |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var ConnectionAssociation, Promise, async, bindDomain, inflector, types, _; | ||
var ConnectionAssociation, Promise, bindDomain, inflector, types, _; | ||
_ = require('underscore'); | ||
async = require('async'); | ||
bindDomain = require('../util').bindDomain; | ||
@@ -10,0 +8,0 @@ |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var ConnectionManipulate, Promise, async, bindDomain, inflector, types; | ||
var ConnectionManipulate, Promise, bindDomain, inflector, types; | ||
async = require('async'); | ||
bindDomain = require('../util').bindDomain; | ||
@@ -8,0 +6,0 @@ |
@@ -47,4 +47,2 @@ // Generated by CoffeeScript 1.7.1 | ||
Model.eliminate_null = false; | ||
Model.archive = false; | ||
@@ -202,3 +200,3 @@ | ||
return function() { | ||
return Promise.promisify(_this._adapter.drop, _this._adapter)(_this._name); | ||
return _this._adapter.dropAsync(_this._name); | ||
}; | ||
@@ -218,3 +216,3 @@ })(this))["finally"]((function(_this) { | ||
function Model(data) { | ||
var adapter, column, ctor, dont_eliminate_null, id, last, obj, parts, path, property, schema, selected_columns, support_nested, value, _i, _len, _ref, _ref1, _ref2; | ||
var adapter, column, ctor, id, last, obj, parts, path, property, schema, selected_columns, selected_columns_raw, value, _i, _len, _ref, _ref1, _ref2; | ||
data = data || {}; | ||
@@ -224,3 +222,2 @@ ctor = this.constructor; | ||
adapter = ctor._adapter; | ||
dont_eliminate_null = !ctor.eliminate_null; | ||
Object.defineProperty(this, '_prev_attributes', { | ||
@@ -271,22 +268,5 @@ writable: true, | ||
selected_columns = arguments[2]; | ||
support_nested = adapter.support_nested; | ||
for (column in schema) { | ||
property = schema[column]; | ||
if (selected_columns && selected_columns.indexOf(column) === -1) { | ||
continue; | ||
} | ||
parts = property._parts; | ||
value = support_nested ? util.getPropertyOfPath(data, parts) : data[property._dbname]; | ||
if (value != null) { | ||
value = adapter.valueToModel(value, property); | ||
} else { | ||
value = null; | ||
} | ||
if ((value != null) || dont_eliminate_null) { | ||
util.setPropertyOfPath(this, parts, value); | ||
} | ||
} | ||
if (dont_eliminate_null) { | ||
this._collapseNestedNulls(selected_columns); | ||
} | ||
selected_columns_raw = arguments[3]; | ||
adapter.setValuesFromDB(this, data, schema, selected_columns); | ||
ctor._collapseNestedNulls(this, selected_columns_raw, ctor.dirty_tracking ? this._intermediates : void 0); | ||
Object.defineProperty(this, 'id', { | ||
@@ -307,9 +287,5 @@ configurable: false, | ||
} | ||
if ((value != null) || dont_eliminate_null) { | ||
util.setPropertyOfPath(this, parts, value); | ||
} | ||
util.setPropertyOfPath(this, parts, value); | ||
} | ||
if (dont_eliminate_null) { | ||
this._collapseNestedNulls(); | ||
} | ||
ctor._collapseNestedNulls(this, null, ctor.dirty_tracking ? this._intermediates : void 0); | ||
Object.defineProperty(this, 'id', { | ||
@@ -325,17 +301,16 @@ configurable: true, | ||
Model.prototype._collapseNestedNulls = function(selected_columns) { | ||
var ctor, has_non_null, key, last, obj, path, value, _i, _len, _ref, _ref1, _ref2, _results; | ||
ctor = this.constructor; | ||
_ref = Object.keys(ctor._intermediate_paths); | ||
Model._collapseNestedNulls = function(instance, selected_columns_raw, intermediates) { | ||
var has_non_null, key, last, obj, path, value, _i, _len, _ref, _ref1, _ref2, _results; | ||
_ref = Object.keys(this._intermediate_paths); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
path = _ref[_i]; | ||
if (selected_columns && selected_columns.indexOf(path) === -1) { | ||
if (selected_columns_raw && selected_columns_raw.indexOf(path) === -1) { | ||
continue; | ||
} | ||
if (ctor.dirty_tracking) { | ||
obj = this._intermediates; | ||
if (intermediates) { | ||
obj = intermediates; | ||
last = path; | ||
} else { | ||
_ref1 = util.getLeafOfPath(this, path), obj = _ref1[0], last = _ref1[1]; | ||
_ref1 = util.getLeafOfPath(instance, path), obj = _ref1[0], last = _ref1[1]; | ||
} | ||
@@ -397,4 +372,3 @@ has_non_null = false; | ||
Model.prototype.set = function(path, value) { | ||
var eliminate_null, k, last, obj, parts, prev_value, v, _ref, _ref1, _results, _results1; | ||
eliminate_null = this.constructor.eliminate_null; | ||
var k, last, obj, parts, prev_value, v, _ref, _ref1, _results, _results1; | ||
if (this._intermediates.hasOwnProperty(path)) { | ||
@@ -421,9 +395,3 @@ obj = this._intermediates[path]; | ||
_ref = util.getLeafOfPath(this, parts), obj = _ref[0], last = _ref[1]; | ||
if (eliminate_null) { | ||
if (eliminate_null || prev_value === void 0) { | ||
this._defineProperty(obj, last, path, value != null); | ||
} | ||
} else if (prev_value === void 0) { | ||
this._defineProperty(obj, last, path, true); | ||
} | ||
this._defineProperty(obj, last, path, true); | ||
util.setPropertyOfPath(this._attributes, parts, value); | ||
@@ -430,0 +398,0 @@ _results1 = []; |
@@ -21,9 +21,16 @@ // Generated by CoffeeScript 1.7.1 | ||
key = 'CC.' + tableize(_this._name) + ':' + key; | ||
return Promise.promisify(redis.get, redis)(key); | ||
return new Promise(function(resolve, reject) { | ||
return redis.get(key, function(error, value) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(value); | ||
}); | ||
}); | ||
}; | ||
})(this)).then(function(data) { | ||
if (data == null) { | ||
})(this)).then(function(value) { | ||
if (value == null) { | ||
return Promise.reject(new Error('error')); | ||
} | ||
return Promise.resolve(JSON.parse(data)); | ||
return Promise.resolve(JSON.parse(value)); | ||
}); | ||
@@ -36,3 +43,10 @@ }; | ||
key = 'CC.' + tableize(_this._name) + ':' + key; | ||
return Promise.promisify(redis.setex, redis)(key, ttl, JSON.stringify(data)); | ||
return new Promise(function(resolve, reject) { | ||
return redis.setex(key, ttl, JSON.stringify(data), function(error) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(); | ||
}); | ||
}); | ||
}; | ||
@@ -46,3 +60,7 @@ })(this)); | ||
key = 'CC.' + tableize(_this._name) + ':' + key; | ||
return Promise.promisify(redis.del, redis)(key)["catch"](function(error) {}); | ||
return new Promise(function(resolve, reject) { | ||
return redis.del(key, function(error, count) { | ||
return resolve(); | ||
}); | ||
}); | ||
}; | ||
@@ -49,0 +67,0 @@ })(this)).nodeify(bindDomain(callback)); |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var ModelPersistence, Promise, async, inflector, util, _; | ||
var ModelPersistence, Promise, inflector, util, _; | ||
_ = require('underscore'); | ||
async = require('async'); | ||
inflector = require('../inflector'); | ||
@@ -112,3 +110,3 @@ | ||
} | ||
return Promise.promisify(ctor._adapter.create, ctor._adapter)(ctor._name, data).then((function(_this) { | ||
return ctor._adapter.createAsync(ctor._name, data).then((function(_this) { | ||
return function(id) { | ||
@@ -155,3 +153,3 @@ var foreign_key, promises; | ||
this._connection.log(this._name, 'createBulk', data_array); | ||
return Promise.promisify(this._adapter.createBulk, this._adapter)(this._name, data_array).then(function(ids) { | ||
return this._adapter.createBulkAsync(this._name, data_array).then(function(ids) { | ||
records.forEach(function(record, i) { | ||
@@ -190,3 +188,3 @@ return Object.defineProperty(record, 'id', { | ||
} | ||
return Promise.promisify(adapter.updatePartial, adapter)(ctor._name, data, { | ||
return adapter.updatePartialAsync(ctor._name, data, { | ||
id: this.id | ||
@@ -208,3 +206,3 @@ }, {}).then((function(_this) { | ||
} | ||
return Promise.promisify(ctor._adapter.update, ctor._adapter)(ctor._name, data).then((function(_this) { | ||
return ctor._adapter.updateAsync(ctor._name, data).then((function(_this) { | ||
return function() { | ||
@@ -211,0 +209,0 @@ return _this._prev_attributes = {}; |
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Promise, Query, async, bindDomain, _; | ||
var Promise, Query, bindDomain, _; | ||
_ = require('underscore'); | ||
async = require('async'); | ||
bindDomain = require('./util').bindDomain; | ||
@@ -76,4 +74,5 @@ | ||
Query.prototype.select = function(columns) { | ||
var intermediate_paths, schema_columns, select; | ||
var intermediate_paths, schema_columns, select, select_raw; | ||
this._options.select = null; | ||
this._options.select_raw = null; | ||
if (typeof columns === 'string') { | ||
@@ -83,6 +82,9 @@ schema_columns = Object.keys(this._model._schema); | ||
select = []; | ||
select_raw = []; | ||
columns.split(/\s+/).forEach(function(column) { | ||
if (schema_columns.indexOf(column) >= 0) { | ||
return select.push(column); | ||
select.push(column); | ||
return select_raw.push(column); | ||
} else if (intermediate_paths[column]) { | ||
select_raw.push(column); | ||
column += '.'; | ||
@@ -97,2 +99,3 @@ return schema_columns.forEach(function(sc) { | ||
this._options.select = select; | ||
this._options.select_raw = select_raw; | ||
} | ||
@@ -189,3 +192,3 @@ return this; | ||
} | ||
return Promise.promisify(this._adapter.findById, this._adapter)(this._name, this._id, this._options)["catch"](function(error) { | ||
return this._adapter.findByIdAsync(this._name, this._id, this._options)["catch"](function(error) { | ||
return Promise.reject(new Error('not found')); | ||
@@ -224,3 +227,3 @@ }).then(function(record) { | ||
} | ||
return Promise.promisify(this._adapter.find, this._adapter)(this._name, this._conditions, this._options).then((function(_this) { | ||
return this._adapter.findAsync(this._name, this._conditions, this._options).then((function(_this) { | ||
return function(records) { | ||
@@ -304,3 +307,3 @@ if (expected_count != null) { | ||
} | ||
return Promise.promisify(_this._adapter.count, _this._adapter)(_this._name, _this._conditions); | ||
return _this._adapter.countAsync(_this._name, _this._conditions); | ||
}; | ||
@@ -364,3 +367,3 @@ })(this)).nodeify(bindDomain(callback)); | ||
}); | ||
return Promise.promisify(_this._adapter.updatePartial, _this._adapter)(_this._name, data, _this._conditions, _this._options); | ||
return _this._adapter.updatePartialAsync(_this._name, data, _this._conditions, _this._options); | ||
}; | ||
@@ -472,3 +475,3 @@ })(this)).nodeify(bindDomain(callback)); | ||
return _this._doArchiveAndIntegrity(options).then(function() { | ||
return Promise.promisify(_this._adapter["delete"], _this._adapter)(_this._name, _this._conditions); | ||
return _this._adapter.deleteAsync(_this._name, _this._conditions); | ||
}); | ||
@@ -475,0 +478,0 @@ }; |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"keywords": [ | ||
@@ -35,2 +35,3 @@ "orm", | ||
"chai": "~1.9.0", | ||
"coffee-coverage": "~0.4.2", | ||
"coffee-script": "~1.7.1", | ||
@@ -37,0 +38,0 @@ "crojsdoc": "~0.6.5", |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
235297
13
47
5453