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

informa-db.js

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

informa-db.js - npm Package Compare versions

Comparing version 1.0.3 to 1.0.5

1

.eslintrc.js

@@ -19,4 +19,5 @@ module.exports = {

"no-console": "off",
"no-param-reassign": "off",
"no-underscore-dangle": "off",
},
};

50

index.js
const fs = require('fs');
let MongoClient;
let mongo;

@@ -8,4 +9,3 @@ class Db {

this.genProxy = (data) => new Proxy(data, {
set: (pObj, prop, val) => {
const obj = pObj;
set: (obj, prop, val) => {
obj[prop] = val;

@@ -30,6 +30,7 @@ if (this.saveOnChange) {

get: (obj, prop) => (typeof obj[prop] === 'object' || Array.isArray(obj[prop])
? this.genProxy(obj[prop].map((val) => { const v = val; delete v._id; return v; }))
? this.genProxy(obj[prop])
: obj[prop]),
});
if (!file) throw new Error('No path provided');
if (typeof file !== 'string') throw new Error('Provided path is not a string');
const dis = this;

@@ -40,3 +41,4 @@ return (async () => {

if (dis.isMongo) {
MongoClient = (await import('mongodb')).MongoClient;
mongo = (await import('mongodb')).default;
MongoClient = mongo.MongoClient;
dis.client = await MongoClient.connect(file, {

@@ -47,9 +49,23 @@ useNewUrlParser: true,

if (!db) {
if (!(await dis.client.db().admin().listDatabases()).databases.some((v) => v.name === 'infodbs')) {
throw new Error('\'infodbs\' is not a valid db.');
}
dis.collection = dis.client.db('infodbs');
} else {
if (
!(await dis.client.db().admin().listDatabases()).databases.some((v) => v.name === db)
) {
throw new Error(`'${db}' is not a valid db.`);
}
dis.collection = dis.client.db(db);
}
if (!collection) {
if (!(await (await dis.client.db(db || 'infodbs').listCollections()).toArray()).some((v) => v.name === 'db')) {
throw new Error('\'db\' is not a valid collection.');
}
dis.collection = dis.collection.collection('db');
} else {
if (!(await (await dis.client.db(db || 'infodbs').listCollections()).toArray()).some((v) => v.name === collection)) {
throw new Error(`'${collection}' is not a valid collection.`);
}
dis.collection = dis.collection.collection(collection);

@@ -65,3 +81,3 @@ }

process.on('exit', dis.client.close);
dis.value = dis.genProxy(dis.readOnlyValue);
// dis.value = dis.genProxy(dis.readOnlyValue);
} else {

@@ -76,3 +92,3 @@ if (!fs.existsSync(file)) {

dis.readOnlyValue = JSON.parse(fs.readFileSync(file, 'utf8'));
dis.value = dis.genProxy(dis.readOnlyValue);
// dis.value = dis.genProxy(dis.readOnlyValue);
}

@@ -96,5 +112,6 @@ dis.saveOnChange = true;

}
this.collection.drop();
this.rawContent.forEach(async (val) => {
await this.collection.deleteOne({ _id: new mongo.ObjectID(val._id) });
});
if (this.readOnlyValue.length > 0) this.collection.insertMany(this.readOnlyValue);
console.log(this.readOnlyValue, 'queue aire tit');
this.rawContent = JSON.parse(JSON.stringify(await this.collection.find({}).toArray()));

@@ -106,5 +123,3 @@ this.readOnlyValue = JSON.parse(

).map((val) => { const v = val; delete v._id; return v; });
console.log(this.readOnlyValue, 'ytreza');
this.value = this.genProxy(this.readOnlyValue);
console.log('azerty');
// this.value = this.genProxy(this.readOnlyValue);
return this.readOnlyValue;

@@ -137,2 +152,15 @@ }

}
set value(setTo) {
this.readOnlyValue = setTo;
if (this.saveOnChange) {
this.update();
}
return true;
}
get value() {
this.readOnlyValue = this.readOnlyValue.map((v) => { const r = v; delete r._id; return r; });
return this.genProxy(this.readOnlyValue);
}
}

@@ -139,0 +167,0 @@ module.exports = Db;

{
"name": "informa-db.js",
"version": "1.0.3",
"description": "",
"version": "1.0.5",
"description": "DataBases made easier",
"main": "index.js",
"scripts": {
"test": "node test.js"
},
"author": "InforMatheMusic",
"license": "ISC",
"repository": "https://github.com/informathemusic/informa-db.js",
"devDependencies": {

@@ -19,3 +17,6 @@ "eslint": "^6.8.0",

"eslint-plugin-react-hooks": "^2.5.0"
},
"dependencies": {
"mongodb": "^3.5.8"
}
}

@@ -40,3 +40,3 @@ # Informa-Db.js

Path to file or URI to mongodb server.
Will throw an error if none provided
Will throw an error if none provided or if type is incorrect
#### defaultString

@@ -49,2 +49,4 @@ Default string to write on file if it doesn't exist.

Defaults to true if the path starts with "mongodb", false otherwise.
Notice: If you need to interact with a mongodb server, you need to install mongodb yourself
#### db<String>

@@ -51,0 +53,0 @@ Database name, defaulting to "infodbs"

@@ -5,6 +5,6 @@ const Db = require('./index.js');

const test = await new Db(process.env.SERVER);
const ee = test.value.length;
test.value[ee] = { ee: 'ee' };
delete test.value[ee];
// const ee = test.value.length;
// test.value = [];
test.value[test.value.length] = { ee: 'eeeeee' };
console.log(test.value);
})();
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