mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added node-modules
This commit is contained in:
2
node_modules/mongoose-pureautoinc/.npmignore
generated
vendored
Normal file
2
node_modules/mongoose-pureautoinc/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
pre-commit
|
73
node_modules/mongoose-pureautoinc/README.md
generated
vendored
Normal file
73
node_modules/mongoose-pureautoinc/README.md
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
mongoose-pureautoinc
|
||||
====================
|
||||
|
||||
This plugin let you add an `auto increment` field to your schema.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
- [Node.js](http://nodejs.org/), a server-side JavaScript implementation,
|
||||
- [MongoDB](http://www.mongodb.org), a NoSQL database,
|
||||
- [Mongoose](http://mongoosejs.com), an elegant Object Document Mapper for MongoDB.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Install it from NPM as you always do it with other packages.
|
||||
~~~
|
||||
npm install mongoose-pureautoinc
|
||||
~~~
|
||||
|
||||
|
||||
## Available options
|
||||
|
||||
- `model` - required parameter, name of your Mongoose model
|
||||
- `field` - name of your field
|
||||
- `start` - first value of your field which will be used
|
||||
|
||||
|
||||
## How to use
|
||||
|
||||
You can run example using this command:
|
||||
~~~
|
||||
$ node examples/example.js
|
||||
~~~
|
||||
|
||||
Firstly, you need to `require` Mongoose and the plugin.
|
||||
~~~
|
||||
var mongoose = require('../node_modules/mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
db = mongoose.createConnection('127.0.0.1', 'yourDatabaseName'),
|
||||
pureautoinc = require('pureautoinc');
|
||||
~~~
|
||||
|
||||
Secondly, you need to initialize the plugin, define your schema and connect the plugin to it.
|
||||
~~~
|
||||
pureautoinc.init(db);
|
||||
|
||||
var schema = new Schema({
|
||||
email: String,
|
||||
text: String
|
||||
});
|
||||
|
||||
schema.plugin(pureautoinc, {
|
||||
model: 'Subscriber',
|
||||
field: 'recordNum'
|
||||
});
|
||||
~~~
|
||||
|
||||
After that you can create your model and use it as you wish.
|
||||
~~~
|
||||
var Subscriber = db.model('Subscriber', schema);
|
||||
~~~
|
||||
|
||||
|
||||
## For developers
|
||||
You should use Git pre-hook to validate your changes. Just copy `pre-commit` file into `./git/hooks/` directory.
|
||||
In order to run tests manually execute `$ vows --spec tests/*`
|
||||
In order to test performance of the plugin execute `$ node benchmarks/benchmark.js`
|
||||
|
||||
|
||||
## Copyright
|
||||
|
||||
© 2012 [MyLove Company, LLC](http://www.mylovecompany.com). Source code is distributed under [CDDL 1.0](http://opensource.org/licenses/CDDL-1.0) open source license.
|
86
node_modules/mongoose-pureautoinc/benchmarks/benchmark.js
generated
vendored
Normal file
86
node_modules/mongoose-pureautoinc/benchmarks/benchmark.js
generated
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* @author Dmitry Ilin @ MyLove Company, LLC <dmitry@mylovecompany.com>
|
||||
*/
|
||||
|
||||
var mongoose = require('../node_modules/mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
db = mongoose.createConnection('127.0.0.1', 'pureautoinc_benchmark'),
|
||||
pureautoinc = require('../index');
|
||||
|
||||
pureautoinc.init(db);
|
||||
|
||||
|
||||
var schema = new Schema({
|
||||
email: String,
|
||||
text: String
|
||||
});
|
||||
|
||||
schema.plugin(pureautoinc.plugin, {
|
||||
model: 'Subscriber',
|
||||
field: 'subscriberId'
|
||||
});
|
||||
var Subscriber = db.model('Subscriber', schema);
|
||||
|
||||
var time,
|
||||
i = 0,
|
||||
j = 0,
|
||||
tests = 5,
|
||||
iterations = 10000,
|
||||
results = [];
|
||||
|
||||
console.log('\nIterations per test: ' + iterations + '\n');
|
||||
|
||||
|
||||
function testsCompleted () {
|
||||
|
||||
mongoose.disconnect();
|
||||
|
||||
var sum = 0;
|
||||
for (var k = 0; k < results.length; k++)
|
||||
sum += results[k];
|
||||
|
||||
console.log('Average time: ' + (sum / tests).toFixed(0) + ' ms\n');
|
||||
}
|
||||
|
||||
function subscriberSaved (err, res) {
|
||||
|
||||
i++;
|
||||
if (i < iterations) {
|
||||
addSubscriber();
|
||||
} else {
|
||||
results.push(new Date().getTime() - time);
|
||||
|
||||
console.log((j + 1) + '. Time: ' + results[results.length - 1] + ' ms');
|
||||
|
||||
j++;
|
||||
if (j < tests)
|
||||
runTest();
|
||||
else
|
||||
Subscriber.collection.drop(testsCompleted);
|
||||
}
|
||||
}
|
||||
|
||||
function addSubscriber () {
|
||||
|
||||
var subscriber = new Subscriber({
|
||||
email: 'email@mail.ru',
|
||||
text: 'text'
|
||||
});
|
||||
|
||||
subscriber.save(subscriberSaved);
|
||||
}
|
||||
|
||||
function dataRemoved () {
|
||||
|
||||
time = new Date().getTime();
|
||||
i = 0;
|
||||
addSubscriber();
|
||||
}
|
||||
|
||||
function runTest () {
|
||||
|
||||
// Removing all subscribers before next test
|
||||
Subscriber.remove({}, dataRemoved);
|
||||
}
|
||||
|
||||
runTest();
|
40
node_modules/mongoose-pureautoinc/examples/example.js
generated
vendored
Normal file
40
node_modules/mongoose-pureautoinc/examples/example.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @author Dmitry Ilin @ MyLove Company, LLC <dmitry@mylovecompany.com>
|
||||
*/
|
||||
|
||||
var dbName = 'pureautoinc_example',
|
||||
mongoose = require('../node_modules/mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
db = mongoose.createConnection('127.0.0.1', dbName),
|
||||
pureautoinc = require('../index');
|
||||
|
||||
pureautoinc.init(db);
|
||||
|
||||
|
||||
var schema = new Schema({
|
||||
name: String,
|
||||
address: String
|
||||
});
|
||||
|
||||
schema.plugin(pureautoinc.plugin, {
|
||||
model: 'Person',
|
||||
field: 'filingNumber',
|
||||
start: 100
|
||||
});
|
||||
|
||||
var Person = db.model('Person', schema);
|
||||
|
||||
console.log('Database: ' + dbName);
|
||||
console.log('Collection: ' + Person.collection.name);
|
||||
|
||||
var person = new Person({
|
||||
name: 'Sherlock Holmes',
|
||||
address: '221b Baker St, Marylebone, London W1'
|
||||
});
|
||||
|
||||
person.save(function (err, res) {
|
||||
|
||||
console.log('New record added:');
|
||||
console.log(res);
|
||||
mongoose.disconnect();
|
||||
});
|
5
node_modules/mongoose-pureautoinc/index.js
generated
vendored
Normal file
5
node_modules/mongoose-pureautoinc/index.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @author Dmitry Ilin @ MyLove Company, LLC <dmitry@mylovecompany.com>
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/pureautoinc.js');
|
105
node_modules/mongoose-pureautoinc/lib/pureautoinc.js
generated
vendored
Normal file
105
node_modules/mongoose-pureautoinc/lib/pureautoinc.js
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* @author Dmitry Ilin @ MyLove Company, LLC <dmitry@mylovecompany.com>
|
||||
*/
|
||||
|
||||
module.exports = new (function () {
|
||||
|
||||
var db,
|
||||
Counter,
|
||||
mongoose,
|
||||
counterName;
|
||||
|
||||
this.plugin = function(schema, options) {
|
||||
|
||||
if (!options.model)
|
||||
throw new Error('Missing required parameter: model');
|
||||
|
||||
options.model = options.model.toLowerCase();
|
||||
options.field = options.field || 'sequenceNumber';
|
||||
options.start = (!isNaN(options.start)) ? options.start : 0;
|
||||
|
||||
var fields = {},
|
||||
ready = false;
|
||||
|
||||
// Adding new field into schema
|
||||
fields[options.field] = {
|
||||
type: Number,
|
||||
unique: true,
|
||||
require: true
|
||||
};
|
||||
schema.add(fields);
|
||||
|
||||
// Initializing of plugin
|
||||
Counter.findOne({
|
||||
model: options.model,
|
||||
field: options.field
|
||||
}, function (err, res) {
|
||||
if (!res)
|
||||
(new Counter({
|
||||
model: options.model,
|
||||
field: options.field,
|
||||
c: options.start
|
||||
})).save(function () {
|
||||
ready = true;
|
||||
});
|
||||
else
|
||||
ready = true;
|
||||
});
|
||||
|
||||
schema.pre('save', function (next) {
|
||||
|
||||
var doc = this;
|
||||
|
||||
// Delay before plugin will be sucessfully initialized
|
||||
function save () {
|
||||
|
||||
if (ready)
|
||||
Counter.collection.findAndModify({
|
||||
model: options.model,
|
||||
field: options.field
|
||||
}, [], {
|
||||
$inc: {
|
||||
c: 1
|
||||
}
|
||||
}, {
|
||||
'new': true,
|
||||
upsert: true
|
||||
}, function (err, res) {
|
||||
|
||||
if (!err)
|
||||
doc[options.field] = res.c - 1;
|
||||
next(err);
|
||||
});
|
||||
else
|
||||
setTimeout(save, 5);
|
||||
}
|
||||
save();
|
||||
});
|
||||
};
|
||||
|
||||
this.init = function (database, counter) {
|
||||
|
||||
db = database;
|
||||
mongoose = require('mongoose');
|
||||
counterName = counter || 'counter';
|
||||
|
||||
var schema = new mongoose.Schema({
|
||||
model: {
|
||||
type: String,
|
||||
require: true
|
||||
},
|
||||
field: {
|
||||
type: String,
|
||||
require: true
|
||||
},
|
||||
c: {
|
||||
type: Number,
|
||||
'default': 0
|
||||
}
|
||||
});
|
||||
schema.index({ field: 1, model: 1 }, { unique: true, required: true, index: -1 });
|
||||
|
||||
Counter = db.model(counterName, schema);
|
||||
};
|
||||
|
||||
})();
|
37
node_modules/mongoose-pureautoinc/package.json
generated
vendored
Normal file
37
node_modules/mongoose-pureautoinc/package.json
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "mongoose-pureautoinc",
|
||||
"description": "Creating of auto increment fields",
|
||||
"version": "2012.1.0",
|
||||
"author": {
|
||||
"name": "MyLove Company, LLC"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"mongoose": ">=3.0.0",
|
||||
"vows": "0.5.13"
|
||||
},
|
||||
"keywords": [
|
||||
"mongoose",
|
||||
"mongo",
|
||||
"mongodb",
|
||||
"auto-increment",
|
||||
"increment",
|
||||
"field"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mylovecompany/mongoose-pureautoinc.git"
|
||||
},
|
||||
"main": "./index.js",
|
||||
"readme": "mongoose-pureautoinc\n====================\n\nThis plugin let you add an `auto increment` field to your schema.\n\n\n## Requirements\n\n- [Node.js](http://nodejs.org/), a server-side JavaScript implementation,\n- [MongoDB](http://www.mongodb.org), a NoSQL database,\n- [Mongoose](http://mongoosejs.com), an elegant Object Document Mapper for MongoDB.\n\n\n## Installation\n\nInstall it from NPM as you always do it with other packages.\n~~~\nnpm install mongoose-pureautoinc\n~~~\n\n\n## Available options\n\n- `model` - required parameter, name of your Mongoose model\n- `field` - name of your field\n- `start` - first value of your field which will be used\n\n\n## How to use\n\nYou can run example using this command:\n~~~\n$ node examples/example.js\n~~~\n\nFirstly, you need to `require` Mongoose and the plugin.\n~~~\nvar mongoose = require('../node_modules/mongoose'),\n Schema = mongoose.Schema,\n db = mongoose.createConnection('127.0.0.1', 'yourDatabaseName'),\n pureautoinc = require('pureautoinc');\n~~~\n\nSecondly, you need to initialize the plugin, define your schema and connect the plugin to it.\n~~~\npureautoinc.init(db);\n\nvar schema = new Schema({\n email: String,\n text: String\n});\n\nschema.plugin(pureautoinc, {\n model: 'Subscriber',\n field: 'recordNum'\n});\n~~~\n\nAfter that you can create your model and use it as you wish.\n~~~\nvar Subscriber = db.model('Subscriber', schema);\n~~~\n\n\n## For developers\nYou should use Git pre-hook to validate your changes. Just copy `pre-commit` file into `./git/hooks/` directory. \nIn order to run tests manually execute `$ vows --spec tests/*` \nIn order to test performance of the plugin execute `$ node benchmarks/benchmark.js`\n\n\n## Copyright\n\n© 2012 [MyLove Company, LLC](http://www.mylovecompany.com). Source code is distributed under [CDDL 1.0](http://opensource.org/licenses/CDDL-1.0) open source license.",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "mongoose-pureautoinc@2012.1.0",
|
||||
"dist": {
|
||||
"shasum": "97c7346dcbfbe08f4b27efe688ad75cdbf65d850"
|
||||
},
|
||||
"_from": "mongoose-pureautoinc@",
|
||||
"_resolved": "https://registry.npmjs.org/mongoose-pureautoinc/-/mongoose-pureautoinc-2012.1.0.tgz"
|
||||
}
|
138
node_modules/mongoose-pureautoinc/tests/test.js
generated
vendored
Normal file
138
node_modules/mongoose-pureautoinc/tests/test.js
generated
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* @author Dmitry Ilin @ MyLove Company, LLC <dmitry@mylovecompany.com>
|
||||
*/
|
||||
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
events = require('events'),
|
||||
mongoose = require('../node_modules/mongoose'),
|
||||
pureautoinc = require('../index'),
|
||||
Schema = mongoose.Schema,
|
||||
db = mongoose.createConnection('127.0.0.1', 'pureautoinc_test');
|
||||
|
||||
pureautoinc.init(db);
|
||||
|
||||
|
||||
var suite = vows.describe('Testing Schema creation and auto incrementing');
|
||||
|
||||
suite.addBatch({
|
||||
|
||||
'After schema creation and plugin application': {
|
||||
|
||||
topic: function () {
|
||||
|
||||
var schema = new Schema({
|
||||
email: String,
|
||||
text: String
|
||||
});
|
||||
|
||||
var pluginParameters = {
|
||||
model: 'Subscriber',
|
||||
field: 'sequenceNumber'
|
||||
};
|
||||
|
||||
schema.plugin(pureautoinc.plugin, pluginParameters);
|
||||
|
||||
var Subscriber = db.model('Subscriber', schema);
|
||||
|
||||
var Test = {
|
||||
model: db.model('Subscriber'),
|
||||
pluginParameters: pluginParameters
|
||||
};
|
||||
|
||||
return Test;
|
||||
},
|
||||
|
||||
'schema gained auto increment field': function (topic) {
|
||||
|
||||
assert.ok(topic.model.schema.paths[topic.pluginParameters.field]);
|
||||
},
|
||||
|
||||
'and model created': {
|
||||
|
||||
topic: function (Model) {
|
||||
|
||||
var promise = new (events.EventEmitter);
|
||||
|
||||
var subscriber;
|
||||
var count = 5;
|
||||
|
||||
function save (counter) {
|
||||
|
||||
subscriber = new Model.model({
|
||||
email: 'useremail@emailserver.com',
|
||||
text: 'some text'
|
||||
});
|
||||
|
||||
subscriber.save(function (err, res) {
|
||||
|
||||
if (err)
|
||||
promise.emit('error', err, Model);
|
||||
else if (counter < count)
|
||||
save(++counter);
|
||||
else
|
||||
promise.emit('success', res, Model);
|
||||
});
|
||||
}
|
||||
save(1);
|
||||
|
||||
return promise;
|
||||
},
|
||||
|
||||
'data saved successfully': function (err, res, Model) {
|
||||
|
||||
assert.ok(res);
|
||||
},
|
||||
|
||||
'and if we look at indexes': {
|
||||
|
||||
topic: function (promise, Model) {
|
||||
|
||||
var promise = new (events.EventEmitter);
|
||||
|
||||
Model.model.collection.getIndexes(function (err, res) {
|
||||
if (err)
|
||||
promise.emit('error', err, Model);
|
||||
else
|
||||
promise.emit('success', res, Model);
|
||||
});
|
||||
|
||||
return promise;
|
||||
},
|
||||
|
||||
'index created successfully': function (err, res, Model) {
|
||||
|
||||
assert.ok(res[Model.pluginParameters.field + '_1']);
|
||||
},
|
||||
|
||||
'and after documents created': {
|
||||
|
||||
topic: function (promise, Model) {
|
||||
|
||||
var promise = new (events.EventEmitter);
|
||||
|
||||
Model.model.find({}, function (err, res) {
|
||||
|
||||
Model.model.collection.drop(function (err) { });
|
||||
|
||||
var counter = Model.pluginParameters.start;
|
||||
for (var i = 0; i < res.length; i++) {
|
||||
if (res[i][Model.pluginParameters.field] != counter)
|
||||
promise.emit('error', err, Model);
|
||||
counter++;
|
||||
}
|
||||
promise.emit('success', res, Model);
|
||||
});
|
||||
|
||||
return promise;
|
||||
},
|
||||
|
||||
'data contains right sequence numbers': function (err, res, Model) {
|
||||
|
||||
assert.ok(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
Reference in New Issue
Block a user