periodicjs.core.data
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -413,2 +413,3 @@ 'use strict'; | ||
* @param {Object|string} [options.sort="-createdat"] Specifies default sort logic for .query and .search queries | ||
* @param {Object} [options.db_connection=mongoose] A custom mongoose db instance if connecting to a different mongoose instance. Will default to cached mongoose connection if not passed. If this option is defined the changeset scheam will be registered on this instance. | ||
* @param {number} [options.limit=500] Specifies a default limit to the total documents returned in a .query and .search queries | ||
@@ -420,8 +421,8 @@ * @param {number} [options.skip=0] Specifies a default amount of documents to skip in a .query and .search queries | ||
* @param {Boolean} [options.track_changes=true] Sets default track changes behavior for udpates | ||
* @param {Object} [options.changeset] Overwrites default changeset model should have a custom create method if using a custom schema | ||
* @param {string[]} [options.xss_whitelist=false] Configuration for XSS whitelist package. If false XSS whitelisting will be ignored | ||
*/ | ||
constructor (options = {}) { | ||
this.db_connection = options.db_connection || mongoose; | ||
this.docid = options.docid; //previously docnamelookup | ||
this.model = (typeof options.model === 'string') ? mongoose.model(options.model) : options.model; | ||
this.model = (typeof options.model === 'string') ? this.db_connection.model(options.model) : options.model; | ||
this.sort = options.sort || '-createdat'; | ||
@@ -438,3 +439,3 @@ this.limit = options.limit || 500; | ||
this.track_changes = (options.track_changes === false) ? false : true; | ||
this.changeset = options.changeset || require(path.join(__dirname, '../changeset/index')).mongo; | ||
this.changeset = (options.db_connection) ? require(path.join(__dirname, '../changeset/index')).mongo(this.db_connection) : require(path.join(__dirname, '../changeset/index')).mongo_default; | ||
this.xss_whitelist = options.xss_whitelist || xss_default_whitelist; | ||
@@ -441,0 +442,0 @@ this._useCache = (options.useCache && options.cache) ? true : false; |
'use strict'; | ||
const DEFAULTS = require('./defaults/index'); | ||
const mongo = require('./mongo'); | ||
module.exports = { | ||
mongo: mongo.Changes | ||
mongo_default: DEFAULTS.mongo, | ||
mongo | ||
}; |
'use strict'; | ||
const mongoose = require('mongoose'); | ||
const path = require('path'); | ||
const Mongo_Adapter = require(path.join(__dirname, '../adapters/mongo')); | ||
@@ -34,12 +35,18 @@ /** | ||
/** | ||
* Exports the changeset model as a singleton | ||
* @return {Object} Returns a mongo adapter with changeset as its model property | ||
* Registers a changeset schema to a custom mongoose instance | ||
* @param {Object} db_connection A mongoose connection where the changeset collection should be registered | ||
* @return {Object} Returns an instance of a Mongo_Adapter that has been configured for the changeset collection | ||
*/ | ||
module.exports = (function (Mongo_Adapter) { | ||
let ChangeSet = mongoose.model('Changeset', CHANGESET); | ||
let Changes = new Mongo_Adapter({ | ||
model: ChangeSet, | ||
module.exports = function register_changeset (db_connection) { | ||
let ChangeSet; | ||
try { | ||
ChangeSet = db_connection.model('Changeset', CHANGESET); | ||
} | ||
catch (e) { | ||
ChangeSet = db_connection.model('Changeset'); | ||
} | ||
return new Mongo_Adapter({ | ||
model: ChangeSet, | ||
track_changes: false | ||
}); | ||
return { Changes }; | ||
})(require(path.join(__dirname, '../adapters/mongo'))); | ||
}); | ||
}; |
@@ -88,2 +88,3 @@ ## Classes | ||
| [options.sort] | <code>Object</code> | <code>string</code> | <code>"-createdat"</code> | Specifies default sort logic for .query and .search queries | | ||
| [options.db_connection] | <code>Object</code> | <code>mongoose</code> | A custom mongoose db instance if connecting to a different mongoose instance. Will default to cached mongoose connection if not passed. If this option is defined the changeset scheam will be registered on this instance. | | ||
| [options.limit] | <code>number</code> | <code>500</code> | Specifies a default limit to the total documents returned in a .query and .search queries | | ||
@@ -95,3 +96,2 @@ | [options.skip] | <code>number</code> | <code>0</code> | Specifies a default amount of documents to skip in a .query and .search queries | | ||
| [options.track_changes] | <code>Boolean</code> | <code>true</code> | Sets default track changes behavior for udpates | | ||
| [options.changeset] | <code>Object</code> | | Overwrites default changeset model should have a custom create method if using a custom schema | | ||
| [options.xss_whitelist] | <code>Array.<string></code> | <code>false</code> | Configuration for XSS whitelist package. If false XSS whitelisting will be ignored | | ||
@@ -98,0 +98,0 @@ |
@@ -92,4 +92,4 @@ { | ||
}, | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"license": "MIT" | ||
} |
@@ -12,6 +12,7 @@ 'use strict'; | ||
var Example; | ||
var db; | ||
var connectDB = function () { | ||
return new Promisie((resolve, reject) => { | ||
mongoose.connect('mongodb://localhost/test_core_data'); | ||
let db = mongoose.connection; | ||
db = mongoose.connection; | ||
db.on('error', reject) | ||
@@ -53,2 +54,24 @@ .once('open', resolve); | ||
}); | ||
describe('Custom mongoose instance testing', () => { | ||
let CustomInstanceAdapter; | ||
before(() => { | ||
CustomInstanceAdapter = AdapterInterface.create({ adapter: 'mongo', model: Example, db_connection: db }); | ||
}); | ||
let person = { | ||
contact: { | ||
first_name: 'ADistinctName', | ||
last_name: 'World', | ||
dob: moment('12/02/1990', 'MM/DD/YYYY').format() | ||
} | ||
}; | ||
it('Should be able to create a document when creating an adapter with a custom db connection', done => { | ||
CustomInstanceAdapter.create({ newdoc: Object.assign({}, person), skip_xss: true }) | ||
.try(result => { | ||
expect(result.contact.first_name).to.equal('ADistinctName'); | ||
expect(result._id).to.be.ok; | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); | ||
describe('Adapter .create method testing', () => { | ||
@@ -55,0 +78,0 @@ let person = { |
@@ -8,2 +8,4 @@ 'use strict'; | ||
const utility = require(path.join(__dirname, '../utility/index')); | ||
const MongoAdapter = require(path.join(__dirname, '../adapters/mongo')); | ||
const createChangeset = require(path.join(__dirname, '../changeset/mongo')); | ||
@@ -103,2 +105,8 @@ var generateObjectId = function () { | ||
}); | ||
describe('Mongo Changset on custom mongoose instance', function () { | ||
it('Should register the Changeset schema and create an adapter', () => { | ||
let adapter = createChangeset(mongoose); | ||
expect(adapter instanceof MongoAdapter).to.be.true; | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
1287109
66
2125
18