New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@base-cms/db

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@base-cms/db - npm Package Compare versions

Comparing version 1.0.0-beta.7 to 1.0.0-beta.12

4

package.json
{
"name": "@base-cms/db",
"version": "1.0.0-beta.7",
"version": "1.0.0-beta.12",
"description": "The BaseCMS database driver. Requires direct MongoDB access.",

@@ -25,3 +25,3 @@ "main": "src/index.js",

},
"gitHead": "53471127f4132cb4d86ba3604efab9e23ab9a30e"
"gitHead": "612f16f6b72f67c0fce495e98301a74edd711f69"
}

@@ -31,4 +31,10 @@ const { ObjectID } = require('mongodb');

* @param {string} baseOpts.client The MongoClient instance to use.
* @param {object} baseOpts.context Context info to append as a comment to all queries.
*/
constructor({ tenant, client, logger } = {}) {
constructor({
tenant,
client,
logger,
context,
} = {}) {
if (!tenant) {

@@ -43,2 +49,3 @@ throw new Error('No tenant was provided.');

this.logger = logger;
this.context = context;
}

@@ -86,3 +93,3 @@

const coll = await this.collection(namespace, resource);
const doc = await coll.findOne(query, options);
const doc = await coll.findOne(query, this.appendContext(options));
this.log('findOne', start, { modelName, query, options });

@@ -136,3 +143,3 @@ return doc;

const coll = await this.collection(namespace, resource);
return coll.find(query, options);
return coll.find(query, this.appendContext(options));
}

@@ -472,3 +479,4 @@

const [secs, ns] = hrtime(start);
logger({ method, data, time: `${(secs * 1000) + (ns / 1000000)}ms` });
const time = (secs * 1000) + (ns / 1000000);
logger({ method, data, time });
}

@@ -489,2 +497,9 @@ }

appendContext(options = {}) {
const { context } = this;
const { comment } = options;
const comments = [context ? JSON.stringify(context) : null, comment];
return { ...options, comment: comments.filter(v => v).join('\n') || undefined };
}
/**

@@ -491,0 +506,0 @@ * Coerces a string ID to either a MongoDB ObjectID or an integer.

@@ -7,6 +7,26 @@ const { inspect } = require('util');

const logger = (obj) => {
log('');
Object.keys(obj).forEach(key => log(`${key}:`, inspect(obj[key], { colors: true, depth: 10 })));
log('');
const logger = () => {
let queries = 0;
let totalDbTime = 0;
const perMethod = {};
const perModel = {};
return (obj) => {
const { method, data, time } = obj;
const { modelName } = data;
perMethod[method] = perMethod[method] ? perMethod[method] + 1 : 1;
perModel[modelName] = perModel[modelName] ? perModel[modelName] + 1 : 1;
queries += 1;
totalDbTime += time;
log('');
Object.keys(obj).forEach(key => log(`${key}:`, inspect(obj[key], { colors: true, depth: 10 })));
log('');
log({
queries,
perMethod,
perModel,
totalDbTime,
});
log('');
};
};

@@ -20,6 +40,7 @@

module.exports = ({ tenant, client }) => new BaseDB({
module.exports = ({ tenant, client, context }) => new BaseDB({
tenant,
client,
logger: shouldLog() ? logger : undefined,
context,
logger: shouldLog() ? logger() : undefined,
});
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