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

periodicjs.core.data

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

periodicjs.core.data - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

utility/filterqueries.js

4

adapters/loki.js

@@ -271,2 +271,6 @@ 'use strict';

}
if (options.fq) {
query[toplevel].push(...utility.filterqueries.getFilterQueries(options.fq, 'loki'));
}
options.query = query;

@@ -273,0 +277,0 @@ if (options.paginate) _QUERY_WITH_PAGINATION.call(this, options, cb);

389

adapters/mongo.js

@@ -6,3 +6,3 @@ 'use strict';

const flatten = require('flat');
const utility = require(path.join(__dirname, '../utility/index'));
const utility = require('../utility/index');
const xss_default_whitelist = require(path.join(__dirname, '../defaults/index')).xss_whitelist();

@@ -22,7 +22,7 @@

*/
const _QUERY = function (options, cb) {
const _QUERY = function(options, cb) {
try {
let Model = options.model || this.model;
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip',].reduce((result, key) => {
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip', ].reduce((result, key) => {
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]);

@@ -38,3 +38,3 @@ result[key] = options[key] || this[key];

.exec(cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -56,7 +56,7 @@ }

*/
const _STREAM = function (options, cb) {
const _STREAM = function(options, cb) {
try {
let Model = options.model || this.model;
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip',].reduce((result, key) => {
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip', ].reduce((result, key) => {
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]);

@@ -74,3 +74,3 @@ result[key] = options[key] || this[key];

cb(null, stream);
} catch (e) {
} catch (e) {
cb(e);

@@ -93,7 +93,7 @@ }

*/
const _QUERY_WITH_PAGINATION = function (options, cb) {
const _QUERY_WITH_PAGINATION = function(options, cb) {
try {
let Model = options.model || this.model;
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query',].reduce((result, key) => {
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query', ].reduce((result, key) => {
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]);

@@ -104,4 +104,4 @@ result[key] = options[key] || this[key];

let pages = {
total: 0,
total_pages: 0,
total: 0,
total_pages: 0,
};

@@ -112,33 +112,33 @@ let total = 0;

Promisie.parallel({
count: () => {
return new Promisie((resolve, reject) => {
Model.count(query, (err, count) => {
if (err) reject(err);
else resolve(count);
});
});
},
pagination: () => {
return Promisie.doWhilst(() => {
count: () => {
return new Promisie((resolve, reject) => {
_QUERY.call(this, { query, sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => {
Model.count(query, (err, count) => {
if (err) reject(err);
else {
skip += data.length;
total += data.length;
pages.total += data.length;
pages.total_pages++;
pages[index++] = {
documents: data,
count: data.length,
};
resolve(data.length);
}
else resolve(count);
});
});
}, current => (current === pagelength && total < limit))
.then(() => pages)
.catch(e => Promisie.reject(e));
}
})
},
pagination: () => {
return Promisie.doWhilst(() => {
return new Promisie((resolve, reject) => {
_QUERY.call(this, { query, sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => {
if (err) reject(err);
else {
skip += data.length;
total += data.length;
pages.total += data.length;
pages.total_pages++;
pages[index++] = {
documents: data,
count: data.length,
};
resolve(data.length);
}
});
});
}, current => (current === pagelength && total < limit))
.then(() => pages)
.catch(e => Promisie.reject(e));
}
})
.then(result => {

@@ -151,3 +151,3 @@ cb(null, Object.assign({}, result.pagination, {

.catch(cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -175,3 +175,3 @@ }

*/
const _SEARCH = function (options, cb) {
const _SEARCH = function(options, cb) {
try {

@@ -185,3 +185,5 @@ let query;

let toplevel = (options.inclusive) ? '$or' : '$and';
query = { [toplevel]: [], };
query = {
[toplevel]: [],
};
//Pushes options.query if it already a composed query object

@@ -199,3 +201,3 @@ if (options.query && typeof options.query === 'object') query[toplevel].push(options.query);

block.$or.push({
[ searchfields[ i ] ]: new RegExp(value, 'gi'),
[searchfields[i]]: new RegExp(value, 'gi'),
});

@@ -211,21 +213,30 @@ }

let isObjectIds = (split.filter(utility.isObjectId).length === split.length);
if (isObjectIds){ query[toplevel].push({ '_id': { $in: split, }, });}
else if(Array.isArray(docid)){
docid.forEach(d=>{
if(d==='_id'){
if(utility.isObjectId(options.query)){
query[toplevel].push({ [d] : { $in: split, }, });
if (isObjectIds) { query[toplevel].push({ '_id': { $in: split, }, }); } else if (Array.isArray(docid)) {
docid.forEach(d => {
if (d === '_id') {
if (utility.isObjectId(options.query)) {
query[toplevel].push({
[d]: { $in: split, },
});
}
} else {
query[toplevel].push({
[d]: { $in: split, },
});
}
} else{
query[toplevel].push({ [d] : { $in: split, }, });
}
});
} else{
query[toplevel].push({ [(docid) ? (docid) : '_id']: { $in: split, }, });
});
} else {
query[toplevel].push({
[(docid) ? (docid) : '_id']: { $in: split, },
});
}
}
if (options.fq) {
query[toplevel].push(...utility.filterqueries.getFilterQueries(options.fq));
}
// console.log({ query })
options.query = query;
if (options.paginate) _QUERY_WITH_PAGINATION.call(this, options, cb);
else _QUERY.call(this, options, cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -246,3 +257,3 @@ }

*/
const _LOAD = function (options, cb) {
const _LOAD = function(options, cb) {
try {

@@ -252,3 +263,3 @@ let Model = options.model || this.model;

//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid',].reduce((result, key) => {
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid', ].reduce((result, key) => {
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]);

@@ -258,17 +269,20 @@ result[key] = options[key] || this[key];

}, {});
if(options.query && typeof options.query === 'object') {
if (options.query && typeof options.query === 'object') {
query = options.query;
}
else if((Array.isArray(docid))){
query = { '$or':[], };
docid.forEach(d=>{
if(d==='_id'){
if(utility.isObjectId(options.query)){
query.$or.push({ [d] : options.query, });
} else if ((Array.isArray(docid))) {
query = { '$or': [], };
docid.forEach(d => {
if (d === '_id') {
if (utility.isObjectId(options.query)) {
query.$or.push({
[d]: options.query,
});
}
} else{
query.$or.push({ [d] : options.query, });
} else {
query.$or.push({
[d]: options.query,
});
}
});
} else{
} else {
query = {

@@ -284,3 +298,3 @@ [(utility.isObjectId(options.query)) ? '_id' : (docid || '_id')]: options.query,

.exec(cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -295,3 +309,3 @@ }

*/
const GENERATE_PATCH = function (data) {
const GENERATE_PATCH = function(data) {
delete data._id;

@@ -317,3 +331,3 @@ delete data.__v;

*/
const GENERATE_PUT = function (data) {
const GENERATE_PUT = function(data) {
delete data._id;

@@ -337,4 +351,5 @@ delete data.__v;

*/
const _UPDATE = function (options, cb) {
const _UPDATE = function(options, cb) {
try {
// console.log('_UPDATE', { options });
options.track_changes = (typeof options.track_changes === 'boolean') ? options.track_changes : this.track_changes;

@@ -373,5 +388,5 @@ if (!options.id) {

Promisie.parallel({
update: Promisie.promisify(Model.update, Model)({ _id: options.id, }, updateOperation),
changes: Promisie.promisify(generateChanges)(),
})
update: Promisie.promisify(Model.update, Model)({ _id: options.id, }, updateOperation),
changes: Promisie.promisify(generateChanges)(),
})
.then(result => {

@@ -381,3 +396,3 @@ if (options.ensure_changes) cb(null, result);

}, cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -400,3 +415,3 @@ }

*/
const _UPDATED = function (options, cb) {
const _UPDATED = function(options, cb) {
try {

@@ -407,3 +422,3 @@ _UPDATE.call(this, options, (err) => {

});
} catch (e) {
} catch (e) {
cb(e);

@@ -423,3 +438,3 @@ }

*/
const _UPDATE_ALL = function (options, cb) {
const _UPDATE_ALL = function(options, cb) {
try {

@@ -433,3 +448,3 @@ let Model = options.model || this.model;

Model.update(query, patch, { multi: true, }, cb);
} catch (e) {
} catch (e) {
cb(e);

@@ -450,3 +465,3 @@ }

*/
const _CREATE = function (options, cb) {
const _CREATE = function(options, cb) {
try {

@@ -458,8 +473,8 @@ let Model = options.model || this.model;

Promisie.map(newdoc, (doc) => {
return Promisie.promisify(Model.create, Model)(utility.enforceXSSRules(doc, xss_whitelist, options));
})
return Promisie.promisify(Model.create, Model)(utility.enforceXSSRules(doc, xss_whitelist, options));
})
.then(created => cb(null, created))
.catch(cb);
} else Model.create(utility.enforceXSSRules(newdoc, xss_whitelist, (options.newdoc) ? options : undefined), cb);
} catch (e) {
} else Model.create(utility.enforceXSSRules(newdoc, xss_whitelist, (options.newdoc) ? options : undefined), cb);
} catch (e) {
cb(e);

@@ -477,3 +492,3 @@ }

*/
const _DELETE = function (options, cb) {
const _DELETE = function(options, cb) {
try {

@@ -483,4 +498,4 @@ let Model = options.model || this.model;

if (typeof deleteid !== 'string') throw new Error('Must specify "deleteid" or "id" for delete');
Model.remove({ _id: deleteid, }, cb);
} catch (e) {
Model.remove({ _id: deleteid, }, cb);
} catch (e) {
cb(e);

@@ -498,3 +513,3 @@ }

*/
const _DELETED = function (options, cb) {
const _DELETED = function(options, cb) {
try {

@@ -510,3 +525,3 @@ _LOAD.call(this, { model: options.model, query: options.deleteid || options.id, }, (err1, loaded) => {

});
} catch (e) {
} catch (e) {
cb(e);

@@ -536,98 +551,98 @@ }

*/
constructor (options = {}) {
this.db_connection = options.db_connection || mongoose;
this.docid = options.docid; //previously docnamelookup
this.model = (typeof options.model === 'string') ? this.db_connection.model(options.model) : options.model;
this.sort = options.sort || '-createdat';
this.limit = options.limit || 500;
this.skip = options.skip || 0;
if (Array.isArray(options.search)) this.searchfields = options.search;
else if (typeof options.search === 'string') this.searchfields = options.search.split(',');
else this.searchfields = [];
this.population = options.population;
this.fields = options.fields;
this.pagelength = options.pagelength || 15;
this.cache = options.cache;
this.track_changes = (options.track_changes === false) ? false : true;
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;
this._useCache = (options.useCache && options.cache) ? true : false;
}
/**
* Query method for adapter see _QUERY and _QUERY_WITH_PAGINATION for more details
* @param {Object} [options={}] Configurable options for query
* @param {Boolean} options.paginate When true query will return data in a paginated form
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
query (options = {}, cb = false) {
let _query = (options && options.paginate) ? _QUERY_WITH_PAGINATION.bind(this) : _QUERY.bind(this);
if (typeof cb === 'function') _query(options, cb);
else return Promisie.promisify(_query)(options);
}
/**
* Search method for adapter see _SEARCH for more details
* @param {Object} [options={}] Configurable options for query
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
search (options = {}, cb = false) {
let _search = _SEARCH.bind(this);
if (typeof cb === 'function') _search(options, cb);
else return Promisie.promisify(_search)(options);
}
/**
* Stream method for adapter see _STREAM for more details
* @param {Object} [options={}] Configurable options for stream
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
stream (options = {}, cb = false) {
let _stream = _STREAM.bind(this);
if (typeof cb === 'function') _stream(options, cb);
else return Promisie.promisify(_stream)(options);
}
/**
* Load method for adapter see _LOAD for more details
* @param {Object} [options={}] Configurable options for load
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
load (options = {}, cb = false) {
let _load = _LOAD.bind(this);
if (typeof cb === 'function') _load(options, cb);
else return Promisie.promisify(_load)(options);
}
/**
* Update method for adapter see _UPDATE, _UPDATED and _UPDATE_ALL for more details
* @param {Object} [options={}] Configurable options for update
* @param {Boolean} options.return_updated If true update method will return the updated document instead of an update status message
* @param {Boolean} options.multi If true a multiple document update will be perfomed
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
update (options = {}, cb = false) {
let _update = (options.multi) ? _UPDATE_ALL.bind(this) : ((options.return_updated) ? _UPDATED.bind(this) : _UPDATE.bind(this));
if (typeof cb === 'function') _update(options, cb);
else return Promisie.promisify(_update)(options);
}
/**
* Create method for adapter see _CREATE for more details
* @param {Object} [options={}] Configurable options for create
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
create (options = {}, cb = false) {
let _create = _CREATE.bind(this);
if (typeof cb === 'function') _create(options, cb);
else return Promisie.promisify(_create)(options);
}
/**
* Delete method for adapter see _DELETE and _DELETED for more details
* @param {Object} [options={}] Configurable options for create
* @param {Boolean} options.return_deleted If true delete method will return the deleted document
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
delete (options = {}, cb = false) {
constructor(options = {}) {
this.db_connection = options.db_connection || mongoose;
this.docid = options.docid; //previously docnamelookup
this.model = (typeof options.model === 'string') ? this.db_connection.model(options.model) : options.model;
this.sort = options.sort || '-createdat';
this.limit = options.limit || 500;
this.skip = options.skip || 0;
if (Array.isArray(options.search)) this.searchfields = options.search;
else if (typeof options.search === 'string') this.searchfields = options.search.split(',');
else this.searchfields = [];
this.population = options.population;
this.fields = options.fields;
this.pagelength = options.pagelength || 15;
this.cache = options.cache;
this.track_changes = (options.track_changes === false) ? false : true;
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;
this._useCache = (options.useCache && options.cache) ? true : false;
}
/**
* Query method for adapter see _QUERY and _QUERY_WITH_PAGINATION for more details
* @param {Object} [options={}] Configurable options for query
* @param {Boolean} options.paginate When true query will return data in a paginated form
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
query(options = {}, cb = false) {
let _query = (options && options.paginate) ? _QUERY_WITH_PAGINATION.bind(this) : _QUERY.bind(this);
if (typeof cb === 'function') _query(options, cb);
else return Promisie.promisify(_query)(options);
}
/**
* Search method for adapter see _SEARCH for more details
* @param {Object} [options={}] Configurable options for query
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
search(options = {}, cb = false) {
let _search = _SEARCH.bind(this);
if (typeof cb === 'function') _search(options, cb);
else return Promisie.promisify(_search)(options);
}
/**
* Stream method for adapter see _STREAM for more details
* @param {Object} [options={}] Configurable options for stream
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
stream(options = {}, cb = false) {
let _stream = _STREAM.bind(this);
if (typeof cb === 'function') _stream(options, cb);
else return Promisie.promisify(_stream)(options);
}
/**
* Load method for adapter see _LOAD for more details
* @param {Object} [options={}] Configurable options for load
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
load(options = {}, cb = false) {
let _load = _LOAD.bind(this);
if (typeof cb === 'function') _load(options, cb);
else return Promisie.promisify(_load)(options);
}
/**
* Update method for adapter see _UPDATE, _UPDATED and _UPDATE_ALL for more details
* @param {Object} [options={}] Configurable options for update
* @param {Boolean} options.return_updated If true update method will return the updated document instead of an update status message
* @param {Boolean} options.multi If true a multiple document update will be perfomed
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
update(options = {}, cb = false) {
let _update = (options.multi) ? _UPDATE_ALL.bind(this) : ((options.return_updated) ? _UPDATED.bind(this) : _UPDATE.bind(this));
if (typeof cb === 'function') _update(options, cb);
else return Promisie.promisify(_update)(options);
}
/**
* Create method for adapter see _CREATE for more details
* @param {Object} [options={}] Configurable options for create
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
create(options = {}, cb = false) {
let _create = _CREATE.bind(this);
if (typeof cb === 'function') _create(options, cb);
else return Promisie.promisify(_create)(options);
}
/**
* Delete method for adapter see _DELETE and _DELETED for more details
* @param {Object} [options={}] Configurable options for create
* @param {Boolean} options.return_deleted If true delete method will return the deleted document
* @param {Function} [cb=false] Callback argument. When cb is not passed function returns a Promise
* @return {Object} Returns a Promise when cb argument is not passed
*/
delete(options = {}, cb = false) {
let _delete = (options.return_deleted) ? _DELETED.bind(this) : _DELETE.bind(this);

@@ -639,2 +654,2 @@ if (typeof cb === 'function') _delete(options, cb);

module.exports = MONGO_ADAPTER;
module.exports = MONGO_ADAPTER;

@@ -97,4 +97,4 @@ {

},
"version": "0.7.2",
"version": "0.7.3",
"license": "MIT"
}
'use strict';
const depopulate = require('./depopulate');
const diff = require('./diff');
const filterqueries = require('./filterqueries');
const isObjectId = require('./mongoid');

@@ -8,2 +9,2 @@ const enforceXSSRules = require('./xss_character_escape');

module.exports = { depopulate, diff, isObjectId, enforceXSSRules, Cursor };
module.exports = { depopulate, diff, isObjectId, enforceXSSRules, Cursor, filterqueries, };
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