simpl-schema
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -20,22 +20,18 @@ 'use strict'; | ||
var _lodash = require('lodash.without'); | ||
var _lodash = require('lodash.omit'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _lodash3 = require('lodash.omit'); | ||
var _lodash3 = require('lodash.every'); | ||
var _lodash4 = _interopRequireDefault(_lodash3); | ||
var _lodash5 = require('lodash.every'); | ||
var _lodash5 = require('lodash.pick'); | ||
var _lodash6 = _interopRequireDefault(_lodash5); | ||
var _lodash7 = require('lodash.pick'); | ||
var _lodash7 = require('lodash.uniq'); | ||
var _lodash8 = _interopRequireDefault(_lodash7); | ||
var _lodash9 = require('lodash.uniq'); | ||
var _lodash10 = _interopRequireDefault(_lodash9); | ||
var _messageBox = require('message-box'); | ||
@@ -45,5 +41,5 @@ | ||
var _lodash11 = require('lodash.includes'); | ||
var _lodash9 = require('lodash.includes'); | ||
var _lodash12 = _interopRequireDefault(_lodash11); | ||
var _lodash10 = _interopRequireDefault(_lodash9); | ||
@@ -129,2 +125,3 @@ var _clone = require('clone'); | ||
this._schema = {}; | ||
this._depsLabels = {}; | ||
this.extend(schema); | ||
@@ -168,6 +165,34 @@ | ||
}, { | ||
key: 'schema', | ||
key: 'reactiveLabelDependency', | ||
/** | ||
* For Meteor apps, add a reactive dependency on the label | ||
* for a key. | ||
*/ | ||
value: function reactiveLabelDependency(key) { | ||
var tracker = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._constructorOptions.tracker; | ||
if (!key || !tracker) return; | ||
var genericKey = _mongoObject2.default.makeKeyGeneric(key); | ||
// If in this schema | ||
if (this._schema[genericKey]) { | ||
if (!this._depsLabels[genericKey]) { | ||
this._depsLabels[genericKey] = new tracker.Dependency(); | ||
} | ||
this._depsLabels[genericKey].depend(); | ||
return; | ||
} | ||
// If in subschema | ||
this.findFirstAncestorSimpleSchema(key, function (simpleSchema, ancestor, subSchemaKey) { | ||
// Pass tracker down so that we get reactivity even if the subschema | ||
// didn't have tracker option set | ||
simpleSchema.reactiveLabelDependency(subSchemaKey, tracker); | ||
}); | ||
} | ||
/** | ||
* @param {String} [key] One specific or generic key for which to get the schema. | ||
@@ -180,2 +205,5 @@ * @returns {Object} The entire schema object or just the definition for one key. | ||
*/ | ||
}, { | ||
key: 'schema', | ||
value: function schema(key) { | ||
@@ -248,3 +276,3 @@ if (!key) return this._schema; | ||
return function (prop) { | ||
if (Array.isArray(propList) && !(0, _lodash12.default)(propList, prop)) return; | ||
if (Array.isArray(propList) && !(0, _lodash10.default)(propList, prop)) return; | ||
var val = obj[prop]; | ||
@@ -350,3 +378,3 @@ // For any options that support specifying a function, evaluate the functions | ||
return new SimpleSchema(newSchemaDef); | ||
return new SimpleSchema(newSchemaDef, this._constructorOptions); | ||
} | ||
@@ -412,3 +440,3 @@ | ||
}); | ||
return (0, _lodash10.default)(blackboxKeys); | ||
return (0, _lodash8.default)(blackboxKeys); | ||
} | ||
@@ -516,7 +544,6 @@ | ||
schemaObj = schema._schema; | ||
// Merge the validators | ||
this._validators = this._validators.concat(schema._validators); | ||
this._docValidators = this._docValidators.concat(schema._docValidators); | ||
// Merge the clean options | ||
this._cleanOptions = (0, _extend3.default)(true, {}, this._cleanOptions, schema._cleanOptions); | ||
this._cleanOptions = (0, _extend3.default)(true, this._cleanOptions, schema._cleanOptions); | ||
this._constructorOptions = (0, _extend3.default)(true, this._constructorOptions, schema._constructorOptions); | ||
} else { | ||
@@ -536,3 +563,3 @@ schemaObj = (0, _expandShorthand2.default)(schema); | ||
} | ||
_this8._schema[fieldName] = _extends({}, _this8._schema[fieldName], (0, _lodash4.default)(definition, 'type')); | ||
_this8._schema[fieldName] = _extends({}, _this8._schema[fieldName], (0, _lodash2.default)(definition, 'type')); | ||
if (definition.type) _this8._schema[fieldName].type.extend(definition.type); | ||
@@ -553,3 +580,2 @@ } else { | ||
this._firstLevelSchemaKeys = []; | ||
this._depsLabels = {}; | ||
this._objectKeys = {}; | ||
@@ -567,10 +593,5 @@ | ||
// Initialize label reactive dependency (Meteor only) | ||
if (_this8._constructorOptions.tracker) { | ||
_this8._depsLabels[fieldName] = new _this8._constructorOptions.tracker.Dependency(); | ||
} | ||
// Keep list of all blackbox keys for passing to MongoObject constructor | ||
// XXX For now if any oneOf type is blackbox, then the whole field is. | ||
(0, _lodash6.default)(definition.type.definitions, function (oneOfDef) { | ||
(0, _lodash4.default)(definition.type.definitions, function (oneOfDef) { | ||
if (oneOfDef.blackbox === true) { | ||
@@ -819,4 +840,3 @@ _this8._blackboxKeys.push(fieldName); | ||
var genericKey = _mongoObject2.default.makeKeyGeneric(key); | ||
this._depsLabels[genericKey] && this._depsLabels[genericKey].depend(); | ||
this.reactiveLabelDependency(key); | ||
return def.label; | ||
@@ -842,3 +862,3 @@ } | ||
if ((0, _lodash12.default)(schemaDefinitionOptions, prop)) { | ||
if ((0, _lodash10.default)(schemaDefinitionOptions, prop)) { | ||
return def[prop]; | ||
@@ -1047,3 +1067,3 @@ } | ||
function standardizeDefinition(def) { | ||
def = (0, _clone2.default)(def); | ||
var standardizedDef = (0, _lodash2.default)(def, oneOfProps); | ||
@@ -1053,11 +1073,10 @@ // Internally, all definition types are stored as groups for simplicity of access. | ||
// it will be added later when the two SimpleSchemaGroups are merged. | ||
if (!def.type || !(def.type instanceof _SimpleSchemaGroup2.default)) { | ||
def.type = new _SimpleSchemaGroup2.default((0, _lodash8.default)(def, oneOfProps)); | ||
if (def.type && def.type instanceof _SimpleSchemaGroup2.default) { | ||
standardizedDef.type = def.type; | ||
} else { | ||
var groupProps = (0, _lodash6.default)(def, oneOfProps); | ||
standardizedDef.type = new _SimpleSchemaGroup2.default(groupProps); | ||
} | ||
(0, _lodash2.default)(oneOfProps, 'type').forEach(function (prop) { | ||
delete def[prop]; | ||
}); | ||
return def; | ||
return standardizedDef; | ||
} | ||
@@ -1064,0 +1083,0 @@ |
{ | ||
"name": "simpl-schema", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.", | ||
@@ -24,3 +24,3 @@ "author": "Eric Dobbertin <aldeed@gmail.com>", | ||
"lint": "eslint .", | ||
"prepare": "npm run lint && npm test && npm run build", | ||
"prepare": "npm run lint && npm test && npm run build && (cd ../tests/meteor-app && meteor npm i && npm test)", | ||
"test": "mocha --compilers js:babel-core/register --recursive \"lib/**/*.tests.js\"", | ||
@@ -42,3 +42,2 @@ "test:watch": "npm test -- --watch" | ||
"lodash.uniq": "^4.5.0", | ||
"lodash.without": "^4.4.0", | ||
"message-box": "^0.1.1", | ||
@@ -61,3 +60,27 @@ "mongo-object": "^0.1.1" | ||
"mocha": "^2.5.3" | ||
}, | ||
"babel": { | ||
"presets": ["es2015", "stage-0"] | ||
}, | ||
"eslintConfig": { | ||
"extends": "airbnb", | ||
"parser": "babel-eslint", | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"arrow-body-style": 0, | ||
"consistent-return": 0, | ||
"max-len": 0, | ||
"no-param-reassign": 0, | ||
"no-underscore-dangle": 0, | ||
"no-use-before-define": [2, "nofunc"], | ||
"no-unused-expressions": 0, | ||
"no-console": 0, | ||
"space-before-function-paren": 0, | ||
"react/prefer-stateless-function": 0, | ||
"react/no-multi-comp": 0 | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14
2541
115402
24
1
0
- Removedlodash.without@^4.4.0
- Removedlodash.without@4.4.0(transitive)