co-rethinkdb
Advanced tools
Comparing version 0.1.1 to 0.2.0
39
index.js
@@ -0,8 +1,40 @@ | ||
// When installing co-rethinkdb for an application that uses the same version | ||
// of rethinkdb, they share the same installation of rethinkdb: | ||
// - your application | ||
// |- node_modules | ||
// |- rethinkdb | ||
// |- co-rethinkdb | ||
// |- * no node_modules/rethinkdb because it uses the parent one | ||
// | ||
// Therefore, the following workaround is used to not overwrite the parents | ||
// rethinkdb behavior. | ||
var toReset = ['rethinkdb', 'rethinkdb/ast', 'rethinkdb/net', 'rethinkdb/cursor'].map(function(name) { | ||
return require.resolve(name) | ||
}) | ||
// remove parts of rethinkdb from cache | ||
var cache = toReset.map(function(path) { | ||
var cache = require.cache[path] | ||
delete require.cache[path] | ||
return cache | ||
}) | ||
var r = require('rethinkdb') | ||
, co = require('co') | ||
// restore cache | ||
toReset.forEach(function(path, i) { | ||
require.cache[path] = cache[i] | ||
}) | ||
var co = require('co') | ||
// Object, most of rethinkdb's objects inherit from | ||
var RDBOp = r.table('mock').constructor.__super__.constructor | ||
// the original run method | ||
var run = RDBOp.prototype.run | ||
// Since every rethinkdb method call, e.g., r.table('...') retuns a | ||
// function, `co` is going to call their `.call()` method making it | ||
// the perfect place to execute the `.run()` method instead. | ||
RDBOp.prototype.call = function(_, done) { | ||
@@ -16,2 +48,3 @@ var query = this | ||
// Wrap the original `.run()` method. | ||
RDBOp.prototype.run = function(conn) { | ||
@@ -24,2 +57,3 @@ var query = this | ||
// Wrap the original `.connect()` method. | ||
var connect = r.connect | ||
@@ -32,2 +66,3 @@ r.connect = function(opts) { | ||
// Wrap the original `.next()` method. | ||
var next = Cursor.prototype.next | ||
@@ -38,2 +73,3 @@ Cursor.prototype.next = function() { | ||
// Wrap the original `.each()` method. | ||
var each = Cursor.prototype.each | ||
@@ -45,2 +81,3 @@ Cursor.prototype.each = function(cb) { | ||
// Wrap the original `.toArray()` method. | ||
var toArray = Cursor.prototype.toArray | ||
@@ -47,0 +84,0 @@ Cursor.prototype.toArray = function() { |
{ | ||
"name": "co-rethinkdb", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": "Markus Ast <npm.m@rkusa.st>", | ||
@@ -5,0 +5,0 @@ "description": "Generator based querying goodness for RethinkDB", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6248
73
1