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

simpl-schema

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simpl-schema - npm Package Compare versions

Comparing version 0.4.2 to 0.5.0

5

CHANGELOG.md

@@ -6,2 +6,3 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update -->

- [simpl-schema CHANGELOG](#simpl-schema-changelog)
- [0.5.0](#050)
- [0.4.2](#042)

@@ -25,2 +26,6 @@ - [0.4.1](#041)

## 0.5.0
- Remove underscore dependency in favor of seperated lodash modules
## 0.4.2

@@ -27,0 +32,0 @@

8

dist/clean.js

@@ -15,5 +15,5 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.isempty');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);

@@ -155,3 +155,3 @@ var _utility = require('./utility.js');

var value = mongoObject.getValueForPosition(removedPositionParent);
if (_underscore2.default.isEmpty(value)) mongoObject.removeValueForPosition(removedPositionParent);
if ((0, _lodash2.default)(value)) mongoObject.removeValueForPosition(removedPositionParent);
}

@@ -183,3 +183,3 @@ } catch (err) {

Object.keys(cleanDoc || {}).forEach(function (op) {
if (_underscore2.default.isEmpty(cleanDoc[op])) delete cleanDoc[op];
if ((0, _lodash2.default)(cleanDoc[op])) delete cleanDoc[op];
});

@@ -186,0 +186,0 @@ }

@@ -11,5 +11,5 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.foreach');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);

@@ -22,2 +22,6 @@ var _mongoObject = require('mongo-object');

var _lodash3 = require('lodash.includes');
var _lodash4 = _interopRequireDefault(_lodash3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -53,3 +57,3 @@

// If already called for this key, skip it
if (_underscore2.default.contains(doneKeys, affectedKey)) return;
if ((0, _lodash4.default)(doneKeys, affectedKey)) return;

@@ -60,3 +64,3 @@ var fieldParentName = (0, _utility.getParentOfKey)(affectedKey, true);

if (_underscore2.default.isArray(getFieldInfo(fieldParentName.slice(0, -1)).value)) {
if (Array.isArray(getFieldInfo(fieldParentName.slice(0, -1)).value)) {
if (isNaN(this.key.split('.').slice(-1).pop())) {

@@ -126,3 +130,3 @@ // parent is an array, but the key to be set is not an integer (see issue #80)

_underscore2.default.each(autoValueFunctions, function (_ref) {
(0, _lodash2.default)(autoValueFunctions, function (_ref) {
var func = _ref.func,

@@ -157,3 +161,3 @@ fieldName = _ref.fieldName,

}
currentPositions = _underscore2.default.map(currentPositions, function (position) {
currentPositions = currentPositions.map(function (position) {
position.key = position.key + '.' + lastPart;

@@ -190,3 +194,3 @@ position.position = position.position + '[' + lastPart.replace(/\./g, '][') + ']';

// has a value or that potentially should.
_underscore2.default.each(positions, function (position) {
(0, _lodash2.default)(positions, function (position) {
runAV.call(position, func, closestSubschemaFieldName);

@@ -193,0 +197,0 @@ });

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

var _underscore = require('underscore');
var _underscore2 = _interopRequireDefault(_underscore);
var _regExp = require('./regExp');

@@ -16,2 +12,6 @@

var _lodash = require('lodash.find');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -47,3 +47,3 @@

if (regExp) {
msgObj = _underscore2.default.find(regExpMessages, function (o) {
msgObj = (0, _lodash2.default)(regExpMessages, function (o) {
return o.exp && o.exp.toString() === regExp;

@@ -50,0 +50,0 @@ });

@@ -15,6 +15,22 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.foreach');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);
var _lodash3 = require('lodash.omit');
var _lodash4 = _interopRequireDefault(_lodash3);
var _lodash5 = require('lodash.isobject');
var _lodash6 = _interopRequireDefault(_lodash5);
var _lodash7 = require('lodash.union');
var _lodash8 = _interopRequireDefault(_lodash7);
var _lodash9 = require('lodash.includes');
var _lodash10 = _interopRequireDefault(_lodash9);
var _SimpleSchema = require('./SimpleSchema');

@@ -55,3 +71,3 @@

// First do some basic checks of the object, and throw errors if necessary
if (!_underscore2.default.isObject(obj)) {
if (!(0, _lodash6.default)(obj)) {
throw new Error('The first argument of validate() must be an object');

@@ -163,3 +179,3 @@ }

// If any return true, we're valid.
var fieldIsValid = _underscore2.default.some(def.type, function (typeDef) {
var fieldIsValid = def.type.some(function (typeDef) {
var finalValidatorContext = _extends({}, validatorContext, {

@@ -169,3 +185,3 @@

// and add them to inner props like "type" and "min"
definition: _extends({}, _underscore2.default.omit(def, 'type'), typeDef)
definition: _extends({}, (0, _lodash4.default)(def, 'type'), typeDef)
});

@@ -182,3 +198,3 @@

// functions after the first one returns false or an error string.
return _underscore2.default.every(fieldValidators, function (validator) {
return fieldValidators.every(function (validator) {
var result = validator.call(finalValidatorContext);

@@ -243,3 +259,3 @@

var shouldValidateKey = !keysToValidate || _underscore2.default.any(keysToValidate, function (keyToValidate) {
var shouldValidateKey = !keysToValidate || keysToValidate.some(function (keyToValidate) {
return keyToValidate === affectedKey || keyToValidate === affectedKeyGeneric || affectedKey.startsWith(keyToValidate + '.') || affectedKeyGeneric.startsWith(keyToValidate + '.');

@@ -267,3 +283,3 @@ });

if (Array.isArray(val)) {
_underscore2.default.each(val, function (v, i) {
(0, _lodash2.default)(val, function (v, i) {
checkObj({

@@ -284,3 +300,3 @@ val: v,

// any missing required keys, and to run any custom functions for other keys.
var keysToCheck = _underscore2.default.union(presentKeys, childKeys);
var keysToCheck = (0, _lodash8.default)(presentKeys, childKeys);

@@ -292,3 +308,3 @@ // If this object is within an array, make sure we check for

// Check all keys in the merged list
_underscore2.default.each(keysToCheck, function (key) {
(0, _lodash2.default)(keysToCheck, function (key) {
checkObj({

@@ -318,3 +334,3 @@ val: val[key],

// Loop through operators
_underscore2.default.each(mod, function (opObj, op) {
(0, _lodash2.default)(mod, function (opObj, op) {
// If non-operators are mixed in, throw error

@@ -330,3 +346,3 @@ if (op.slice(0, 1) !== '$') {

schema.objectKeys().forEach(function (schemaKey) {
if (!_underscore2.default.contains(presentKeys, schemaKey)) {
if (!(0, _lodash10.default)(presentKeys, schemaKey)) {
checkObj({

@@ -340,3 +356,3 @@ val: undefined,

}
_underscore2.default.each(opObj, function (v, k) {
(0, _lodash2.default)(opObj, function (v, k) {
if (op === '$push' || op === '$addToSet') {

@@ -375,7 +391,7 @@ if ((typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && '$each' in v) {

var addedFieldNames = [];
validationErrors = _underscore2.default.filter(validationErrors, function (errObj) {
validationErrors = validationErrors.filter(function (errObj) {
// Remove error types the user doesn't care about
if (_underscore2.default.contains(ignoreTypes, errObj.type)) return false;
if ((0, _lodash10.default)(ignoreTypes, errObj.type)) return false;
// Make sure there is only one error per fieldName
if (_underscore2.default.contains(addedFieldNames, errObj.name)) return false;
if ((0, _lodash10.default)(addedFieldNames, errObj.name)) return false;

@@ -382,0 +398,0 @@ addedFieldNames.push(errObj.name);

@@ -9,5 +9,5 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.foreach');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);

@@ -26,3 +26,3 @@ var _mongoObject = require('mongo-object');

_underscore2.default.each(schema, function (definition, key) {
(0, _lodash2.default)(schema, function (definition, key) {
// CASE 1: Not shorthand. Just clone

@@ -29,0 +29,0 @@ if (_mongoObject2.default.isBasicObject(definition)) {

@@ -20,6 +20,26 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.foreach');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);
var _lodash3 = require('lodash.without');
var _lodash4 = _interopRequireDefault(_lodash3);
var _lodash5 = require('lodash.omit');
var _lodash6 = _interopRequireDefault(_lodash5);
var _lodash7 = require('lodash.every');
var _lodash8 = _interopRequireDefault(_lodash7);
var _lodash9 = require('lodash.pick');
var _lodash10 = _interopRequireDefault(_lodash9);
var _lodash11 = require('lodash.uniq');
var _lodash12 = _interopRequireDefault(_lodash11);
var _messageBox = require('message-box');

@@ -29,2 +49,6 @@

var _lodash13 = require('lodash.includes');
var _lodash14 = _interopRequireDefault(_lodash13);
var _clone = require('clone');

@@ -188,3 +212,3 @@

_underscore2.default.each(this._schema, function (keySchema, key) {
(0, _lodash2.default)(this._schema, function (keySchema, key) {
mergedSchema[key] = keySchema;

@@ -194,3 +218,3 @@

if (!SimpleSchema.isSimpleSchema(typeDef.type)) return;
_underscore2.default.each(typeDef.type.mergedSchema(), function (subKeySchema, subKey) {
(0, _lodash2.default)(typeDef.type.mergedSchema(), function (subKeySchema, subKey) {
mergedSchema[key + '.' + subKey] = subKeySchema;

@@ -223,3 +247,3 @@ });

return function (val, prop) {
if (Array.isArray(propList) && !_underscore2.default.contains(propList, prop)) return;
if (Array.isArray(propList) && !(0, _lodash14.default)(propList, prop)) return;
// For any options that support specifying a function, evaluate the functions

@@ -237,3 +261,3 @@ if (propsThatCanBeFunction.indexOf(prop) > -1 && typeof val === 'function') {

var result = {};
_underscore2.default.each(defs, getPropIterator(result));
(0, _lodash2.default)(defs, getPropIterator(result));

@@ -245,3 +269,3 @@ // Resolve all the types and convert to a normal array to make it easier

var newTypeDef = {};
_underscore2.default.each(typeDef, getPropIterator(newTypeDef));
(0, _lodash2.default)(typeDef, getPropIterator(newTypeDef));
return newTypeDef;

@@ -319,3 +343,3 @@ });

_underscore2.default.each(this.mergedSchema(), function (val, k) {
(0, _lodash2.default)(this.mergedSchema(), function (val, k) {
if (k.indexOf(searchString) === 0) {

@@ -338,3 +362,3 @@ newSchemaDef[k.slice(searchString.length)] = val;

function addFuncs(autoValues, closestSubschemaFieldName) {
_underscore2.default.each(autoValues, function (func, fieldName) {
(0, _lodash2.default)(autoValues, function (func, fieldName) {
result.push({

@@ -350,3 +374,3 @@ func: func,

_underscore2.default.each(this._schema, function (keySchema, key) {
(0, _lodash2.default)(this._schema, function (keySchema, key) {
keySchema.type.definitions.forEach(function (typeDef) {

@@ -377,3 +401,3 @@ if (!SimpleSchema.isSimpleSchema(typeDef.type)) return;

var blackboxKeys = this._blackboxKeys;
_underscore2.default.each(this._schema, function (keySchema, key) {
(0, _lodash2.default)(this._schema, function (keySchema, key) {
keySchema.type.definitions.forEach(function (typeDef) {

@@ -386,3 +410,3 @@ if (!SimpleSchema.isSimpleSchema(typeDef.type)) return;

});
return _underscore2.default.uniq(blackboxKeys);
return (0, _lodash12.default)(blackboxKeys);
}

@@ -424,3 +448,3 @@

// Loop through all keys in the schema
return _underscore2.default.any(this._schemaKeys, function (loopKey) {
return this._schemaKeys.some(function (loopKey) {
// If the schema key is the test key, it's allowed.

@@ -499,3 +523,3 @@ if (loopKey === key) return true;

// Update all of the information cached on the instance
_underscore2.default.each(schemaObj, function (definition, fieldName) {
(0, _lodash2.default)(schemaObj, function (definition, fieldName) {
definition = (0, _clone2.default)(definition);

@@ -510,3 +534,3 @@ standardizeDefinition(definition);

}
_this5._schema[fieldName] = _extends({}, _this5._schema[fieldName], _underscore2.default.omit(definition, 'type'));
_this5._schema[fieldName] = _extends({}, _this5._schema[fieldName], (0, _lodash6.default)(definition, 'type'));
if (definition.type) _this5._schema[fieldName].type.extend(definition.type);

@@ -530,3 +554,4 @@ } else {

_underscore2.default.each(this._schema, function (definition, fieldName) {
// Update all of the information cached on the instance
(0, _lodash2.default)(this._schema, function (definition, fieldName) {
// Keep list of all keys for speedier checking

@@ -545,3 +570,3 @@ _this5._schemaKeys.push(fieldName);

// XXX For now if any oneOf type is blackbox, then the whole field is.
_underscore2.default.every(definition.type.definitions, function (oneOfDef) {
(0, _lodash8.default)(definition.type.definitions, function (oneOfDef) {
if (oneOfDef.blackbox === true) {

@@ -561,3 +586,3 @@ _this5._blackboxKeys.push(fieldName);

var setObjectKeys = function setObjectKeys(curSchema, schemaParentKey) {
_underscore2.default.each(curSchema, function (definition, fieldName) {
(0, _lodash2.default)(curSchema, function (definition, fieldName) {
fieldName = schemaParentKey ? schemaParentKey + '.' + fieldName : fieldName;

@@ -754,3 +779,3 @@ if (fieldName.indexOf('.') > -1 && fieldName.slice(-2) !== '.$') {

_underscore2.default.each(_labels, function (label, key) {
(0, _lodash2.default)(_labels, function (label, key) {
if (typeof label !== 'string' && typeof label !== 'function') return;

@@ -780,3 +805,3 @@ if (!_this9._schema.hasOwnProperty(key)) return;

var result = {};
_underscore2.default.each(this._schemaKeys, function (schemaKey) {
(0, _lodash2.default)(this._schemaKeys, function (schemaKey) {
result[schemaKey] = _this10.label(schemaKey);

@@ -813,3 +838,3 @@ });

if (_underscore2.default.contains(schemaDefinitionOptions, prop)) {
if ((0, _lodash14.default)(schemaDefinitionOptions, prop)) {
return def[prop];

@@ -968,7 +993,8 @@ }

function checkSchemaOverlap(schema) {
_underscore2.default.each(schema, function (val, key) {
_underscore2.default.each(val.type.definitions, function (def) {
(0, _lodash2.default)(schema, function (val, key) {
if (!val.type) throw new Error(key + ' key is missing "type"');
(0, _lodash2.default)(val.type.definitions, function (def) {
if (!SimpleSchema.isSimpleSchema(def.type)) return;
_underscore2.default.each(def.type._schema, function (subVal, subKey) {
(0, _lodash2.default)(def.type._schema, function (subVal, subKey) {
var newKey = key + '.' + subKey;

@@ -1016,6 +1042,6 @@ if (schema.hasOwnProperty(newKey)) {

if (def.type && !(def.type instanceof _SimpleSchemaGroup2.default)) {
def.type = new _SimpleSchemaGroup2.default(_underscore2.default.pick(def, oneOfProps));
def.type = new _SimpleSchemaGroup2.default((0, _lodash10.default)(def, oneOfProps));
}
_underscore2.default.without(oneOfProps, 'type').forEach(function (prop) {
(0, _lodash4.default)(oneOfProps, 'type').forEach(function (prop) {
delete def[prop];

@@ -1030,3 +1056,3 @@ });

// Validate the field definition
_underscore2.default.each(definition, function (val, key) {
(0, _lodash2.default)(definition, function (val, key) {
if (schemaDefinitionOptions.indexOf(key) === -1) {

@@ -1048,3 +1074,3 @@ throw new Error('Invalid definition for ' + fieldName + ' field: "' + key + '" is not a supported property');

if (SimpleSchema.isSimpleSchema(type)) {
_underscore2.default.each(type._schema, function (subVal, subKey) {
(0, _lodash2.default)(type._schema, function (subVal, subKey) {
var newKey = fieldName + '.' + subKey;

@@ -1119,6 +1145,6 @@ if (fullSchemaObj.hasOwnProperty(newKey)) {

var newSchema = {};
_underscore2.default.each(this._schema, function (value, key) {
(0, _lodash2.default)(this._schema, function (value, key) {
// Pick/omit it if it IS in the array of keys they want OR if it
// STARTS WITH something that is in the array plus a period
var includeIt = _underscore2.default.any(args, function (wantedField) {
var includeIt = args.some(function (wantedField) {
return key === wantedField || key.indexOf(wantedField + '.') === 0;

@@ -1125,0 +1151,0 @@ });

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

var _underscore = require('underscore');
var _SimpleSchema = require('../SimpleSchema');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash = require('lodash.includes');
var _SimpleSchema = require('../SimpleSchema');
var _lodash2 = _interopRequireDefault(_lodash);

@@ -22,3 +22,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var isAllowed = _underscore2.default.contains(allowedValues, this.value);
var isAllowed = (0, _lodash2.default)(allowedValues, this.value);
return isAllowed ? true : _SimpleSchema.SimpleSchema.ErrorTypes.VALUE_NOT_ALLOWED;

@@ -25,0 +25,0 @@ }

@@ -9,8 +9,2 @@ 'use strict';

var _underscore = require('underscore');
var _underscore2 = _interopRequireDefault(_underscore);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function doStringChecks(def, keyValue) {

@@ -40,3 +34,3 @@ // Is it a String?

var regExError = void 0;
_underscore2.default.every(def.regEx, function (re) {
def.regEx.every(function (re) {
if (!re.test(keyValue)) {

@@ -43,0 +37,0 @@ regExError = { type: _SimpleSchema.SimpleSchema.ErrorTypes.FAILED_REGULAR_EXPRESSION, regExp: re.toString() };

@@ -7,10 +7,4 @@ 'use strict';

var _underscore = require('underscore');
var _underscore2 = _interopRequireDefault(_underscore);
var _SimpleSchema = require('../SimpleSchema');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Check for missing required values. The general logic is this:

@@ -33,3 +27,3 @@ // * If the operator is $unset or $rename, it's invalid.

var setKeys = Object.keys(this.obj.$set || {}).concat(Object.keys(this.obj.$setOnInsert || {}));
var willBeCreatedAutomatically = _underscore2.default.some(setKeys, function (sk) {
var willBeCreatedAutomatically = setKeys.some(function (sk) {
return sk.slice(0, _this.key.length + 1) === _this.key + '.';

@@ -36,0 +30,0 @@ });

@@ -17,5 +17,5 @@ 'use strict';

var _underscore = require('underscore');
var _lodash = require('lodash.findwhere');
var _underscore2 = _interopRequireDefault(_underscore);
var _lodash2 = _interopRequireDefault(_lodash);

@@ -109,4 +109,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

value: function setValidationErrors(errors) {
var previousValidationErrors = _underscore2.default.pluck(this._validationErrors, 'name');
var newValidationErrors = _underscore2.default.pluck(errors, 'name');
var previousValidationErrors = this._validationErrors.map(function (o) {
return o.name;
});
var newValidationErrors = errors.map(function (o) {
return o.name;
});

@@ -122,3 +126,5 @@ this._validationErrors = errors;

value: function addValidationErrors(errors) {
var newValidationErrors = _underscore2.default.pluck(errors, 'name');
var newValidationErrors = errors.map(function (o) {
return o.name;
});

@@ -168,3 +174,3 @@ var _iteratorNormalCompletion3 = true;

var errors = this._validationErrors;
return _underscore2.default.findWhere(errors, { name: key }) || _underscore2.default.findWhere(errors, { name: genericKey });
return (0, _lodash2.default)(errors, { name: key }) || (0, _lodash2.default)(errors, { name: genericKey });
}

@@ -244,3 +250,3 @@ }, {

var wasValidated = _underscore2.default.any(keysToValidate, function (key) {
var wasValidated = keysToValidate.some(function (key) {
return key === error.name || error.name.startsWith(key + '.');

@@ -247,0 +253,0 @@ });

{
"name": "simpl-schema",
"version": "0.4.2",
"version": "0.5.0",
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.",

@@ -34,3 +34,14 @@ "author": "Eric Dobbertin <aldeed@gmail.com>",

"mongo-object": "^0.0.3",
"underscore": "^1.8.3"
"lodash.find": "^4.6.0",
"lodash.findwhere": "^3.1.0",
"lodash.foreach": "^4.5.0",
"lodash.every": "^4.6.0",
"lodash.includes": "^4.3.0",
"lodash.isempty": "^4.4.0",
"lodash.isobject": "^3.0.2",
"lodash.omit": "^4.5.0",
"lodash.without": "^4.4.0",
"lodash.pick": "^4.4.0",
"lodash.union": "^4.6.0",
"lodash.uniq": "^4.5.0"
},

@@ -37,0 +48,0 @@ "devDependencies": {

@@ -1182,1 +1182,3 @@ # simple-schema

- @Nemo64
- @DavidSichau
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