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

moltyjs

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moltyjs - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

14

lib/clients/mongoClient.js
'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

@@ -55,2 +55,6 @@

addModel(model) {
if (this._connectionManager === null) throw new Error('You must first connect to the DB before creating a model.');
if (this._models[model._modelName] && !model._discriminator) throw new Error('There is already a model with the same name');
const schema = model._schemaNormalized;

@@ -65,5 +69,5 @@ let indexes = [];

this._models[model._modelName] = {
indexes: indexes
};
this._models[model._modelName] = _extends({}, this._models[model._modelName], {
indexes
});

@@ -70,0 +74,0 @@ if (model._discriminator) {

@@ -13,8 +13,7 @@ 'use strict';

this.Schema = Schema;
this.Model = Model;
this.models = {};
this.connection = null;
// Binding methods
this.Model = this.Model.bind(this);
this.connect = this.connect.bind(this);

@@ -24,20 +23,2 @@ }

/**
* Model(): Create a new model associated to a schema with an specifyc name.
* Used as a model contructor of the Model class.
* @param {Schema} schema
* @param {String} modelName
*
* @returns {Model}
*/
Model(schema, modelName) {
if (this.connection === null) throw new Error('You must first connect to the DB before creating a model.');
if (this.models[modelName]) throw new Error('There is already a model with the same name');
this.models[modelName] = new Model(schema, modelName);
return this.models[modelName];
}
/**
* connect(): Connect to a database through the DBClient

@@ -44,0 +25,0 @@ *

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

*/
constructor(schema, modelName, discriminator) {
constructor(schema, modelName, discriminator = null) {
if (arguments.length < 1) throw new Error('Schema is missing');

@@ -45,3 +45,3 @@

this._discriminator = discriminator ? discriminator : null;
this._discriminator = discriminator;

@@ -48,0 +48,0 @@ mongoClient.addModel(this);

MIT License
Copyright (c) 2017 Mario Lemes
Copyright (c) 2017 Mario Lemes Medina (mariolemesmedina@gmail.com) [@mario_lemes]

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "moltyjs",
"version": "0.1.1",
"version": "0.1.2",
"description": "A tiny ODM for MongoDB with multy tenancy support.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -113,3 +113,3 @@ # What is moltyjs?

const TestModel = model(newSchema, 'TestModel');
const TestModel = new Model(newSchema, 'TestModel');
```

@@ -155,2 +155,18 @@

## Create a new document
Once we have already set up the Schema and registered the Model with it we can start creating document from that Model as follow:
```javascript
const { Model } = require('moltys');
const TestModel = new Model(newSchema, 'TestModel');
newDoc = TestModel.new({
email: 'test@moltyjs.com',
password: '1321321',
name: 'Mario Lemes',
});
```
## Hooks middleware (Work in progress)

@@ -157,0 +173,0 @@

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