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.6.1 to 0.6.2

8

CHANGELOG.md

@@ -35,2 +35,9 @@ ## [Unreleased]

## [0.6.2] - 2018-01-03
### Changed
* Now is possible to have Mongo ObjectId type field in the Schema without refferencing any model.
* Improoved way of validating payload on schemas and payloads
## [0.6.1] - 2018-01-03

@@ -282,2 +289,3 @@

[0.6.2]: https://github.com/Yonirt/moltyjs/compare/v0.6.1...v0.6.2
[0.6.1]: https://github.com/Yonirt/moltyjs/compare/v0.6.0...v0.6.1

@@ -284,0 +292,0 @@ [0.6.0]: https://github.com/Yonirt/moltyjs/compare/v0.5.1...v0.6.0

57

lib/model.js

@@ -224,11 +224,20 @@ 'use strict';

for (var _iterator = Object.keys(schema)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
const key = _step.value;
let key = _step.value;
// Objects nested
if (!schema[key].type && isObject(schema[key])) {
try {
yield _this2._validatePayloadFieldValues(payload[key], schema[key], tenant, parentPayload);
continue;
} catch (error) {
throw error;
}
}
// No required values
if (payload[key] === undefined && !schema[key].required) continue;
if ((!payload || payload[key] === undefined) && !schema[key].required) continue;
// Objects nested
if (!schema[key].type && isObject(payload[key])) {
_this2._validatePayloadFieldValues(payload[key], schema[key], tenant, parentPayload);
continue;
// Is required validation
if (schema[key].required && (!payload || isEmptyValue(payload[key]))) {
throw new Error('Key ' + key + ' is required');
}

@@ -315,6 +324,16 @@

Object.keys(schema).forEach(key => {
// Objects nested
if (!schema[key].type && isObject(schema[key])) {
payload[key] = this._normalizePayload(payload[key], schema[key]);
return;
}
// Default values
if (payload[key] === undefined && 'default' in schema[key]) {
const defaultValue = schema[key].default;
payload[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
if ((!payload || payload[key] === undefined) && 'default' in schema[key]) {
const defaultValue = typeof schema[key].default === 'function' ? schema[key].default() : schema[key].default;
if (!payload) payload = {
[key]: defaultValue
};else payload[key] = defaultValue;
return;

@@ -325,19 +344,13 @@ }

// to keep record of it in the database
if (schema[key].ref && isEmptyValue(payload[key])) {
payload[key] = isArray(schema[key].type) ? [] : null;
}
if (schema[key].ref && (!payload || isEmptyValue(payload[key]))) {
const refNormalValue = isArray(schema[key].type) ? [] : null;
if (!payload) payload = {
[key]: refNormalValue
};else payload[key] = refNormalValue;
// No required values
if (payload[key] === undefined && !schema[key].required) return;
// Objects nested
if (!schema[key].type && isObject(payload[key])) {
payload[key] = this._normalizePayload(payload[key], schema[key]);
return;
}
// Is required validation
if (schema[key].required && isEmptyValue(payload[key])) {
throw new Error('Key ' + key + ' is required' + ', but got ' + payload[key]);
}
// No required values
if ((!payload || payload[key] === undefined) && !schema[key].required) return;
});

@@ -344,0 +357,0 @@

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

if (schema[key].type === ObjectId && isEmptyValue(schema[key].ref)) {
throw new Error('Unsupported type or bad variable, ref property is missing: ', key);
}
// If the properties of the schema field are not allowed

@@ -80,0 +76,0 @@ if (schema[key].type && Object.keys(schema[key]).length > 1) {

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

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

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