aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mongo-factory
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/mongo-factory')
-rw-r--r--node_modules/mongo-factory/.npmignore28
-rw-r--r--node_modules/mongo-factory/.travis.yml13
-rw-r--r--node_modules/mongo-factory/LICENSE21
-rw-r--r--node_modules/mongo-factory/README.md43
-rw-r--r--node_modules/mongo-factory/index.js68
-rw-r--r--node_modules/mongo-factory/package.json97
-rw-r--r--node_modules/mongo-factory/test/test.js94
7 files changed, 364 insertions, 0 deletions
diff --git a/node_modules/mongo-factory/.npmignore b/node_modules/mongo-factory/.npmignore
new file mode 100644
index 0000000..262b5dc
--- /dev/null
+++ b/node_modules/mongo-factory/.npmignore
@@ -0,0 +1,28 @@
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# Deployed apps should consider commenting this line out:
+# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
+node_modules
+
+# Web Storm project files
+.idea
diff --git a/node_modules/mongo-factory/.travis.yml b/node_modules/mongo-factory/.travis.yml
new file mode 100644
index 0000000..ffdc2aa
--- /dev/null
+++ b/node_modules/mongo-factory/.travis.yml
@@ -0,0 +1,13 @@
+language: node_js
+node_js:
+ - "5"
+ - "4"
+ - "0.12"
+ - "0.11"
+ - "0.10"
+addons:
+ code_climate:
+ repo_token: 0bc1060eb2c8897c6d192e530449d2a6ab83338bbe3e94510531bf010c05b562
+after_script:
+ - cat ./coverage/lcov.info | codeclimate
+services: mongodb
diff --git a/node_modules/mongo-factory/LICENSE b/node_modules/mongo-factory/LICENSE
new file mode 100644
index 0000000..11e0047
--- /dev/null
+++ b/node_modules/mongo-factory/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Tom Caflisch
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/node_modules/mongo-factory/README.md b/node_modules/mongo-factory/README.md
new file mode 100644
index 0000000..81433b5
--- /dev/null
+++ b/node_modules/mongo-factory/README.md
@@ -0,0 +1,43 @@
+#mongo-factory
+[![Build Status](https://travis-ci.org/toymachiner62/mongo-factory.svg?branch=master)](https://travis-ci.org/toymachiner62/mongo-factory)
+[![Code Climate](https://codeclimate.com/github/toymachiner62/mongo-factory/badges/gpa.svg)](https://codeclimate.com/github/toymachiner62/mongo-factory)
+
+> The purpose of this module is to manage mongo connection pools without creating a new connection pool in every file.
+>
+> You can require this module in as many files as you want and every time you call `mongoFactory.getConnection` it returns
+> a connection if one exists for the connection string passed in, or it instantiates the connection pool and
+> then returns a connection.
+
+## Usage
+
+```js
+var mongoFactory = require('mongo-factory');
+
+mongoFactory.getConnection('mongodb://localhost:27017')
+ .then(function(db) {
+ // Use mongo's "db" object as you normally would.
+ db.collection.find()...
+ })
+ .catch(function(err) {
+ console.error(err);
+ });
+```
+
+## API
+
+#### `getConnection(mongodbConnectionString)`
+
+The only parameter is a connection string for a MongoDB connection.
+
+#### `ObjectId`
+
+Exposes the MongoDB [ObjectID](http://mongodb.github.io/node-mongodb-native/2.0/tutorials/objectid/) function.
+
+## Contributing
+
+1. Clone project and run `npm install`
+2. Add feature(s)
+3. Add tests for it
+4. Submit pull request
+
+Enjoy!
diff --git a/node_modules/mongo-factory/index.js b/node_modules/mongo-factory/index.js
new file mode 100644
index 0000000..085c25c
--- /dev/null
+++ b/node_modules/mongo-factory/index.js
@@ -0,0 +1,68 @@
+/**
+ * Creates and manages the Mongo connection pool
+ *
+ * @type {exports}
+ */
+var Promise = require('es6-promise').Promise;
+var mongo = require('mongodb');
+var MongoClient = mongo.MongoClient;
+var _ = require('underscore');
+
+// Store all instantiated connections.
+var connections = [];
+
+module.exports = function() {
+
+ return {
+
+ /**
+ * Gets a Mongo connection from the pool.
+ *
+ * If the connection pool has not been instantiated yet, it is first
+ * instantiated and a connection is returned.
+ *
+ * @returns {Promise|Db} - A promise object that resolves to a Mongo db object.
+ */
+ getConnection: function getConnection(connectionString) {
+ return new Promise(function(resolve, reject) {
+ // If connectionString is null or undefined, return an error.
+ if (_.isEmpty(connectionString)) {
+ return reject('getConnection must be called with a mongo connection string');
+ }
+
+ // Check if a connection already exists for the provided connectionString.
+ var pool = _.findWhere(connections, { connectionString: connectionString });
+
+ // If a connection pool was found, resolve the promise with it.
+ if (pool) {
+ return resolve(pool.db);
+ }
+
+ // If the connection pool has not been instantiated,
+ // instantiate it and return the connection.
+ MongoClient.connect(connectionString, function(err, database) {
+ if (err) {
+ return reject(err);
+ }
+
+ // Store the connection in the connections array.
+ connections.push({
+ connectionString: connectionString,
+ db: database
+ });
+
+ return resolve(database);
+ });
+ });
+ },
+
+ /**
+ * Exposes Mongo ObjectID function.
+ *
+ * @returns {Function} - Mongo ObjectID function
+ */
+ ObjectID: function() {
+ return mongo.ObjectID();
+ }
+ };
+}();
diff --git a/node_modules/mongo-factory/package.json b/node_modules/mongo-factory/package.json
new file mode 100644
index 0000000..877f20c
--- /dev/null
+++ b/node_modules/mongo-factory/package.json
@@ -0,0 +1,97 @@
+{
+ "_args": [
+ [
+ {
+ "name": "mongo-factory",
+ "raw": "mongo-factory",
+ "rawSpec": "",
+ "scope": null,
+ "spec": "latest",
+ "type": "tag"
+ },
+ "/Users/warefhaque/CSC309/solutions_repo"
+ ]
+ ],
+ "_from": "mongo-factory@latest",
+ "_id": "mongo-factory@1.0.0",
+ "_inCache": true,
+ "_installable": true,
+ "_location": "/mongo-factory",
+ "_nodeVersion": "5.1.0",
+ "_npmUser": {
+ "email": "tomcaflisch@gmail.com",
+ "name": "toymachiner62"
+ },
+ "_npmVersion": "3.3.12",
+ "_phantomChildren": {},
+ "_requested": {
+ "name": "mongo-factory",
+ "raw": "mongo-factory",
+ "rawSpec": "",
+ "scope": null,
+ "spec": "latest",
+ "type": "tag"
+ },
+ "_requiredBy": [
+ "/"
+ ],
+ "_resolved": "https://registry.npmjs.org/mongo-factory/-/mongo-factory-1.0.0.tgz",
+ "_shasum": "fade3ee31336c9d13029b2168c0538520be589db",
+ "_shrinkwrap": null,
+ "_spec": "mongo-factory",
+ "_where": "/Users/warefhaque/CSC309/solutions_repo",
+ "author": {
+ "name": "Tom Caflisch"
+ },
+ "bugs": {
+ "url": "https://github.com/toymachiner62/mongoFactory/issues"
+ },
+ "dependencies": {
+ "es6-promise": "^3.0.2",
+ "underscore": "^1.8.3"
+ },
+ "description": "A very simple mongo connection pool manager",
+ "devDependencies": {
+ "chai": "^3.4.1",
+ "chai-as-promised": "^5.2.0",
+ "chai-spies": "^0.7.1",
+ "codeclimate-test-reporter": "0.1.1",
+ "mocha": "^2.3.4",
+ "mongodb": "*"
+ },
+ "directories": {},
+ "dist": {
+ "shasum": "fade3ee31336c9d13029b2168c0538520be589db",
+ "tarball": "https://registry.npmjs.org/mongo-factory/-/mongo-factory-1.0.0.tgz"
+ },
+ "gitHead": "a080b957cdda8e6969ea600e89afe74a09248419",
+ "homepage": "https://github.com/toymachiner62/mongoFactory",
+ "keywords": [
+ "mongo",
+ "node",
+ "connection",
+ "pool"
+ ],
+ "license": "MIT",
+ "main": "mongoFactory.js",
+ "maintainers": [
+ {
+ "email": "tomcaflisch@gmail.com",
+ "name": "toymachiner62"
+ }
+ ],
+ "name": "mongo-factory",
+ "optionalDependencies": {},
+ "peerDependencies": {
+ "mongodb": "*"
+ },
+ "readme": "ERROR: No README data found!",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/toymachiner62/mongoFactory.git"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "version": "1.0.0"
+}
diff --git a/node_modules/mongo-factory/test/test.js b/node_modules/mongo-factory/test/test.js
new file mode 100644
index 0000000..9ac91c3
--- /dev/null
+++ b/node_modules/mongo-factory/test/test.js
@@ -0,0 +1,94 @@
+var chai = require('chai');
+var expect = chai.expect;
+var mongo = require('mongodb');
+
+describe('mongoFactory', function() {
+ var mongoFactory;
+
+ beforeEach(function() {
+ mongoFactory = require('../');
+ });
+
+ it('can be required without blowing up', function(done) {
+ var mongoFactory = require('../');
+ expect(mongoFactory).to.exist;
+ done();
+ });
+
+ describe('getConnection()', function() {
+ describe('with no parameters', function() {
+ it('should fulfill the promise', function(done) {
+ var conn = mongoFactory.getConnection();
+ expect(conn).to.be.fulfilled;
+ done();
+ });
+
+ it('should reject the promise', function(done) {
+ var conn = mongoFactory.getConnection();
+ expect(conn).to.be.rejected;
+ done();
+ });
+ });
+
+ describe('with a null parameter', function() {
+ it('should reject the promise', function(done) {
+ var conn = mongoFactory.getConnection(null);
+ expect(conn).to.be.rejected;
+ done();
+ });
+ });
+
+ describe('with a valid mongo string parameter', function() {
+ describe('needing to create the pool the first time', function() {
+ it('should return a fulfilled promise', function(done) {
+ var conn = mongoFactory.getConnection('mongodb://localhost:27017').then(function(db) {
+ expect(conn).to.be.fulfilled;
+ expect(conn).to.not.be.rejected;
+ done();
+ });
+ });
+ });
+
+ describe('after a pool is already instantiated', function() {
+ it('should return a fulfilled promise', function(done) {
+ var conn1 = mongoFactory.getConnection('mongodb://localhost:27017').then(function() {
+ var conn = mongoFactory.getConnection('mongodb://localhost:27017').then(function() {
+ expect(conn).to.be.fulfilled;
+ expect(conn).to.not.be.rejected;
+ done();
+ });
+ });
+ });
+ });
+ });
+ });
+
+ describe('ObjectID', function() {
+ it('should return mongo\'s ObjectID method', function() {
+ var oid = mongoFactory.ObjectID;
+ expect(oid).to.be.a.function;
+ });
+
+ it('should allow you to create a new ObjectID', function() {
+ var oid = new mongoFactory.ObjectID;
+ expect(oid.toHexString().length).to.equal(24);
+ });
+
+ it('should allow you to compare ObjectIDs', function() {
+ var oid1 = new mongoFactory.ObjectID;
+ var oid2 = new mongoFactory.ObjectID(oid1.id);
+ var oid3 = new mongoFactory.ObjectID;
+ expect(oid1.equals(oid2));
+ expect(!oid1.equals(oid3));
+ });
+
+ it('should allow you to create a new ObjectID with a specific timestamp', function() {
+ // Get a timestamp in seconds
+ var timestamp = Math.floor(new Date().getTime()/1000);
+ // Create a date with the timestamp
+ var timestampDate = new Date(timestamp*1000);
+ var oid = new mongoFactory.ObjectID(timestamp);
+ expect(oid.getTimestamp().toString()).to.equal(timestampDate.toString());
+ });
+ });
+});