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

mongojs-hooks

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongojs-hooks - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

15

mongojs-hooks.js

@@ -17,8 +17,9 @@ var mongojs = require("mongojs");

//Tenancy helper
mongojs.Database.prototype.tenant = function () {
mongojs.Database.prototype.tenant = function (tenantName) {
var db = this;
var tenant = mongojs.Database.prototype.collection.apply(this, arguments);
tenant.collection = function (name) {
tenant.collection = function (collName) {
//'this' currently refers to the collection returned as 'tenant' and not the db
return mongojs.Database.prototype.collection.call(this, name);
return mongojs.Database.prototype.collection.call(db, tenantName + "." + collName, collName);
};

@@ -45,9 +46,9 @@

mongojs.Database.prototype.collection = _.wrap(mongojs.Database.prototype.collection, function (fn, name) {
mongojs.Database.prototype.collection = _.wrap(mongojs.Database.prototype.collection, function (fn, name, collName) {
//Create a parent mongojs collection to setup _name and _get fields
var collection = fn.call(this, name);
//Now if a pre-defined collection exists, call it with the internal fields retrieved above
if (colls[name])
collection = new colls[name](collection._name, collection._get);
//Now if a pre-defined collection exists (use tenent-less name if it exists), call it with the internal fields retrieved above
if (colls[collName || name])
collection = new colls[collName || name](collection._name, collection._get);

@@ -54,0 +55,0 @@ return collection;

{
"name": "mongojs-hooks",
"description": "Wrap monogjs in pre and post hooks",
"version": "0.1.0",
"version": "0.1.1",
"main": "./mongojs-hooks",

@@ -6,0 +6,0 @@ "author": {

@@ -29,2 +29,13 @@ require("should");

});
//This test doesn't need to assert anything, because if we mock out the call and test to
//see if it executes, then we don't evaluate the lazy loading and won't know if it called
//correctly. Instead, this test will fail by throwing an exception.
it("tenant().collection().find() - with tenant name - should not throw an exception", function (done) {
var collection = db.tenant("tenant").collection("tests");
collection.find(function () {
done();
});
});
});
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