Comparing version 1.16.0 to 1.16.1
@@ -71,2 +71,7 @@ var schemaUtil = require(__dirname+'/schema.js'); | ||
// Atom feed | ||
this._active = false; | ||
this._feed = null; | ||
// Add customized methods of the model on this document. | ||
@@ -1668,3 +1673,43 @@ util.loopKeys(model._methods, function(methods, key) { | ||
/** | ||
* Set the atom feed and update the document for each change | ||
*/ | ||
Document.prototype._setFeed = function(feed) { | ||
var self = this; | ||
self.__proto__._feed = feed; | ||
self.__proto__._active = true; | ||
feed.each(function(err, change) { | ||
if (err) { | ||
self.__proto__._active = false; | ||
self.emit('error', err); | ||
} | ||
else { | ||
if (change.new_val === null) { | ||
// Delete all the fields | ||
self._merge({}); | ||
self._setOldValue(change.old_val); | ||
self._setUnSaved(); | ||
self.emit('change', self); | ||
} | ||
else { | ||
self._merge(change.new_val); | ||
self._setOldValue(change.old_val); | ||
self.setSaved(); | ||
self.emit('change', self); | ||
} | ||
} | ||
}); | ||
}; | ||
Document.prototype.getFeed = function() { | ||
return this.__proto__._feed; | ||
} | ||
Document.prototype.closeFeed = function() { | ||
return this.__proto__._feed.close(); | ||
} | ||
module.exports = Document; |
@@ -5,2 +5,3 @@ var Promise = require('bluebird'); | ||
var schemaUtil = require(__dirname+'/schema.js'); | ||
var Feed = require(__dirname+'/feed.js'); | ||
@@ -118,2 +119,3 @@ | ||
self._query.run(fullOptions).then(function(result) { | ||
// Expect a write result from RethinkDB | ||
if (self._postValidation === true) { | ||
@@ -213,2 +215,15 @@ var error = null; | ||
} | ||
else if ((typeof result.getType === 'function') && (result.getType() === 'feed')) { | ||
var feed = new Feed(result, self._model); | ||
resolve(feed); | ||
} | ||
else if ((typeof result.getType === 'function') && (result.getType() === 'atomFeed')) { | ||
result.next().then(function(initial) { | ||
var value = initial.new_val || {}; | ||
self._model._parse(value).then(function(doc) { | ||
doc._setFeed(result); | ||
resolve(doc); | ||
}).error(reject); | ||
}); | ||
} | ||
else { | ||
@@ -470,2 +485,14 @@ if (parse === true) { | ||
} | ||
else if (key === 'changes') { | ||
(function(key) { | ||
Query.prototype[key] = function() { | ||
// In case of `get().changes()` we want to remove the default(r.errror(...)) | ||
// TODO: Do not hardcode this? | ||
if ((typeof this._query === 'function') && (this._query._query[0] === 92)) { | ||
this._query._query = this._query._query[1][0]; | ||
} | ||
return new Query(this._model, this._query[key].apply(this._query, arguments)); | ||
} | ||
})(key); | ||
} | ||
else { | ||
@@ -472,0 +499,0 @@ (function(key) { |
@@ -326,2 +326,7 @@ var util = require('util'); | ||
function toArray(args) { | ||
return Array.prototype.slice.call(args); | ||
} | ||
util.toArray = toArray; | ||
module.exports = util; |
{ | ||
"name": "thinky", | ||
"version": "1.16.0", | ||
"version": "1.16.1", | ||
"description": "RethinkDB ORM for Node.js", | ||
@@ -27,3 +27,3 @@ "main": "lib/thinky.js", | ||
"dependencies":{ | ||
"rethinkdbdash": "~1.16.0", | ||
"rethinkdbdash": "~1.16.3", | ||
"bluebird": "~2.1.3", | ||
@@ -30,0 +30,0 @@ "validator": "~ 3.22.1" |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
195030
22
5255
39
Updatedrethinkdbdash@~1.16.3