simpl-schema
Advanced tools
Comparing version 1.5.7 to 1.5.8
@@ -140,2 +140,5 @@ "use strict"; | ||
var fieldIsValid = def.type.some(function (typeDef) { | ||
// If the type is SimpleSchema.Any, then it is valid: | ||
if (typeDef === _SimpleSchema.SimpleSchema.Any) return true; | ||
var finalValidatorContext = _objectSpread({}, validatorContext, { | ||
@@ -142,0 +145,0 @@ // Take outer definition props like "optional" and "label" |
@@ -586,3 +586,4 @@ "use strict"; | ||
(0, _lodash["default"])(definition.type.definitions, function (oneOfDef) { | ||
if (oneOfDef.blackbox === true) { | ||
// XXX If the type is SS.Any, also consider it a blackbox | ||
if (oneOfDef.blackbox === true || oneOfDef.type === SimpleSchema.Any) { | ||
_this8._blackboxKeys.push(fieldName); | ||
@@ -960,2 +961,4 @@ | ||
_defineProperty(SimpleSchema, "Any", '___Any___'); | ||
_defineProperty(SimpleSchema, "RegEx", _regExp["default"]); | ||
@@ -962,0 +965,0 @@ |
@@ -9,3 +9,3 @@ "use strict"; | ||
var _expectValid = _interopRequireDefault(require("./testHelpers/expectValid")); | ||
var _expectValid4 = _interopRequireDefault(require("./testHelpers/expectValid")); | ||
@@ -16,2 +16,12 @@ var _expectErrorOfTypeLength = _interopRequireDefault(require("./testHelpers/expectErrorOfTypeLength")); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } 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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -606,3 +616,3 @@ | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
names: [] | ||
@@ -631,3 +641,3 @@ }); | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
test: null | ||
@@ -676,6 +686,6 @@ }); | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
foo: 'bar' | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
foo: 'bar' | ||
@@ -685,3 +695,3 @@ }, { | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
foo: 'bar' | ||
@@ -695,3 +705,3 @@ }, { | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
bar: 'foo' | ||
@@ -701,3 +711,3 @@ }, { | ||
}); | ||
(0, _expectValid["default"])(schema, { | ||
(0, _expectValid4["default"])(schema, { | ||
bar: 'foo' | ||
@@ -1040,2 +1050,154 @@ }, { | ||
}); | ||
describe('SimpleSchema.Any', function () { | ||
var schema = new _SimpleSchema.SimpleSchema({ | ||
testAny: _SimpleSchema.SimpleSchema.Any | ||
}); | ||
describe('can be used to allow a key with type', function () { | ||
var dataTypes = [["String 'string'", 'string'], ['Number 42', 42], ['Number 3.1415', 3.1415], ['Array []', []], ["Array ['string']", ['string']], ['Object { }', {}], ['Object { test: true }', { | ||
test: true | ||
}], ['Number NaN', NaN], ['Date new Date()', new Date()], ['Boolean true', true], ['Boolean false', false]]; | ||
dataTypes.forEach(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
label = _ref2[0], | ||
type = _ref2[1]; | ||
describe(label, function () { | ||
it("on it's own", function () { | ||
(0, _expectValid4["default"])(schema, { | ||
testAny: type | ||
}); | ||
}); | ||
it('as a nested key', function () { | ||
(0, _expectValid4["default"])(new _SimpleSchema.SimpleSchema({ | ||
testNested: schema | ||
}), { | ||
testNested: { | ||
testAny: { | ||
test: type | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('with modifiers', function () { | ||
var shouldBeValidModifiers = ['$set', '$setOnInsert', '$inc', '$dec', '$min', '$max', '$mul', '$pop', '$pull', '$pullAll']; | ||
shouldBeValidModifiers.forEach(function (mod) { | ||
describe(mod, function () { | ||
it("can be used for ".concat(mod, " modifiers"), function () { | ||
(0, _expectValid4["default"])(schema, _defineProperty({}, mod, { | ||
testAny: 3.1415 | ||
}), { | ||
modifier: true | ||
}); | ||
}); | ||
it("can be used for nested ".concat(mod, " modifiers"), function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectValid4["default"])(parentSchema, _defineProperty({}, mod, { | ||
parent: { | ||
testAny: 3.1415 | ||
} | ||
}), { | ||
modifier: true | ||
}); | ||
}); | ||
it("can be used for nested ".concat(mod, " modifiers with dot notation"), function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectValid4["default"])(parentSchema, _defineProperty({}, mod, { | ||
'parent.testAny': 3.1415 | ||
}), { | ||
modifier: true | ||
}); | ||
}); | ||
}); | ||
}); // Special cases where we don't expect it to work like the rest: | ||
describe('$unset', function () { | ||
it('can be used for $unset modifiers', function () { | ||
(0, _expectErrorOfTypeLength["default"])(_SimpleSchema.SimpleSchema.ErrorTypes.REQUIRED, schema, { | ||
$unset: { | ||
testAny: 1 | ||
} | ||
}, { | ||
modifier: true | ||
}).toEqual(1); | ||
}); | ||
it('can be used for nested $unset modifiers', function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectErrorOfTypeLength["default"])(_SimpleSchema.SimpleSchema.ErrorTypes.REQUIRED, parentSchema, { | ||
$unset: { | ||
parent: 1 | ||
} | ||
}, { | ||
modifier: true | ||
}).toEqual(1); | ||
}); | ||
it('can be used for nested $unset modifiers with dot notation', function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectErrorOfTypeLength["default"])(_SimpleSchema.SimpleSchema.ErrorTypes.REQUIRED, parentSchema, { | ||
$unset: { | ||
'parent.testAny': 1 | ||
} | ||
}, { | ||
modifier: true | ||
}).toEqual(1); | ||
}); | ||
}); | ||
describe('$addToSet', function () { | ||
it('can be used for $addToSet modifiers', function () { | ||
(0, _expectValid4["default"])(schema, { | ||
$addToSet: { | ||
testAny: 1 | ||
} | ||
}, { | ||
modifier: true | ||
}); | ||
}); | ||
it('can be used for nested $addToSet modifiers with dot notation', function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectValid4["default"])(parentSchema, { | ||
$addToSet: { | ||
'parent.testAny': 3.1415 | ||
} | ||
}, { | ||
modifier: true | ||
}); | ||
}); | ||
}); | ||
describe('$push', function () { | ||
it('can be used for $push modifiers', function () { | ||
(0, _expectValid4["default"])(schema, { | ||
$push: { | ||
testAny: 1 | ||
} | ||
}, { | ||
modifier: true | ||
}); | ||
}); | ||
it('can be used for nested $push modifiers with dot notation', function () { | ||
var parentSchema = new _SimpleSchema.SimpleSchema({ | ||
parent: schema | ||
}); | ||
(0, _expectValid4["default"])(parentSchema, { | ||
$push: { | ||
'parent.testAny': 3.1415 | ||
} | ||
}, { | ||
modifier: true | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "simpl-schema", | ||
"version": "1.5.7", | ||
"version": "1.5.8", | ||
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.", | ||
@@ -63,3 +63,3 @@ "author": "Eric Dobbertin <aldeed@gmail.com>", | ||
"expect": "^1.20.1", | ||
"mocha": "^7.0.1" | ||
"mocha": "^7.1.1" | ||
}, | ||
@@ -66,0 +66,0 @@ "babel": { |
@@ -1238,11 +1238,11 @@ # SimpleSchema (simpl-schema NPM package) | ||
case (SimpleSchema.RegEx.Url.toString()): | ||
return "Cette URL is invalide"; | ||
return "Cette URL est invalide"; | ||
case (SimpleSchema.RegEx.Id.toString()): | ||
return "Cet identifiant alphanumérique est invalide"; | ||
case (SimpleSchema.RegEx.ZipCode.toString()): | ||
return "Ce code ZIP est invalide"; | ||
return "Ce code postal est invalide"; | ||
case (SimpleSchema.RegEx.Phone.toString()): | ||
return "Ce numéro de téléphone est invalide"; | ||
default: | ||
return "Ce champ a échoué la validation par Regex"; | ||
return "Ce champ n'a pas passé la validation Regex"; | ||
} | ||
@@ -1249,0 +1249,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
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
476097
12648