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

@orion-js/schema

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@orion-js/schema - npm Package Compare versions

Comparing version 0.0.39 to 0.0.41

45

lib/getValidationErrors/getError/index.js

@@ -41,27 +41,28 @@ 'use strict';

if (!(0, _isNil2.default)(value)) {
_context.next = 8;
_context.next = 7;
break;
}
if (!(currentSchema.optional || options.omitRequired)) {
_context.next = 7;
if (!(!currentSchema.optional && !options.omitRequired)) {
_context.next = 5;
break;
}
return _context.abrupt('return', null);
return _context.abrupt('return', _Errors2.default.REQUIRED);
case 5:
_context.next = 14;
break;
case 7:
return _context.abrupt('return', _Errors2.default.REQUIRED);
case 8:
validatorKey = (0, _getFieldValidator2.default)(currentSchema.type);
validator = validatorKey === 'custom' ? currentSchema.type : _fieldTypes2.default[validatorKey];
_context.next = 12;
_context.next = 11;
return validator.validate.apply(validator, [value, info].concat(_toConsumableArray(args)));
case 12:
case 11:
error = _context.sent;
if (!error) {
_context.next = 15;
_context.next = 14;
break;

@@ -72,16 +73,16 @@ }

case 15:
case 14:
if (!currentSchema.custom) {
_context.next = 21;
_context.next = 20;
break;
}
_context.next = 18;
_context.next = 17;
return currentSchema.custom.apply(currentSchema, [value, info].concat(_toConsumableArray(args)));
case 18:
case 17:
customError = _context.sent;
if (!customError) {
_context.next = 21;
_context.next = 20;
break;

@@ -92,16 +93,16 @@ }

case 21:
case 20:
if (!currentSchema.type.__validate) {
_context.next = 27;
_context.next = 26;
break;
}
_context.next = 24;
_context.next = 23;
return (_currentSchema$type = currentSchema.type).__validate.apply(_currentSchema$type, [value, info].concat(_toConsumableArray(args)));
case 24:
case 23:
typeError = _context.sent;
if (!typeError) {
_context.next = 27;
_context.next = 26;
break;

@@ -112,6 +113,6 @@ }

case 27:
case 26:
return _context.abrupt('return', null);
case 28:
case 27:
case 'end':

@@ -118,0 +119,0 @@ return _context.stop();

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

test('can validate object type with custom validation', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
test('run custom validation when field is optional and no value is passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
var person, schema;

@@ -293,3 +293,7 @@ return regeneratorRuntime.wrap(function _callee8$(_context8) {

name: {
type: String
type: String,
optional: true,
custom: function custom(value) {
return 'No';
}
},

@@ -304,5 +308,10 @@ __validate: function __validate(value) {

case 0:
return _context7.abrupt('return', value.name === 'Nicolás' ? null : 'no');
if (value) {
_context7.next = 2;
break;
}
case 1:
return _context7.abrupt('return', 'No object');
case 2:
case 'end':

@@ -318,3 +327,10 @@ return _context7.stop();

person: {
type: person
type: person,
optional: true
},
number: {
type: Number,
custom: function custom() {
return 'No';
}
}

@@ -325,3 +341,3 @@ };

return (0, _index2.default)(schema, {
person: { name: 'Nicolás' }
person: { name: null }
});

@@ -331,17 +347,36 @@

_context8.t1 = _context8.sent;
(0, _context8.t0)(_context8.t1).toBeNull();
_context8.t2 = expect;
_context8.next = 10;
_context8.t2 = {
number: _Errors2.default.REQUIRED,
'person.name': 'No'
};
(0, _context8.t0)(_context8.t1).toEqual(_context8.t2);
_context8.t3 = expect;
_context8.next = 11;
return (0, _index2.default)(schema, {
person: { name: 'Joaquin' }
person: null,
number: null
});
case 10:
_context8.t3 = _context8.sent;
_context8.t4 = {
person: 'no'
case 11:
_context8.t4 = _context8.sent;
_context8.t5 = {
number: _Errors2.default.REQUIRED,
person: 'No object'
};
(0, _context8.t2)(_context8.t3).toEqual(_context8.t4);
(0, _context8.t3)(_context8.t4).toEqual(_context8.t5);
_context8.t6 = expect;
_context8.next = 17;
return (0, _index2.default)(schema, {
number: 123
});
case 13:
case 17:
_context8.t7 = _context8.sent;
_context8.t8 = {
number: 'No',
person: 'No object'
};
(0, _context8.t6)(_context8.t7).toEqual(_context8.t8);
case 20:
case 'end':

@@ -354,4 +389,4 @@ return _context8.stop();

test('skip child validation if specified', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
var person, schema, errors;
test('can validate object type with custom validation', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
var person, schema;
return regeneratorRuntime.wrap(function _callee10$(_context10) {

@@ -362,9 +397,6 @@ while (1) {

person = {
firstName: {
name: {
type: String
},
lastName: {
type: String
},
__skipChildValidation: function __skipChildValidation(value) {
__validate: function __validate(value) {
var _this2 = this;

@@ -377,3 +409,3 @@

case 0:
return _context9.abrupt('return', value.firstName === 'Nicolás');
return _context9.abrupt('return', value.name === 'Nicolás' ? null : 'no');

@@ -390,4 +422,4 @@ case 1:

schema = {
persons: {
type: [person]
person: {
type: person
}

@@ -398,3 +430,3 @@ };

return (0, _index2.default)(schema, {
persons: [{ firstName: 'Nicolás' }]
person: { name: 'Nicolás' }
});

@@ -405,4 +437,71 @@

(0, _context10.t0)(_context10.t1).toBeNull();
_context10.next = 9;
_context10.t2 = expect;
_context10.next = 10;
return (0, _index2.default)(schema, {
person: { name: 'Joaquin' }
});
case 10:
_context10.t3 = _context10.sent;
_context10.t4 = {
person: 'no'
};
(0, _context10.t2)(_context10.t3).toEqual(_context10.t4);
case 13:
case 'end':
return _context10.stop();
}
}
}, _callee10, undefined);
})));
test('skip child validation if specified', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
var person, schema, errors;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
person = {
firstName: {
type: String
},
lastName: {
type: String
},
__skipChildValidation: function __skipChildValidation(value) {
var _this3 = this;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
return _context11.abrupt('return', value.firstName === 'Nicolás');
case 1:
case 'end':
return _context11.stop();
}
}
}, _callee11, _this3);
}))();
}
};
schema = {
persons: {
type: [person]
}
};
_context12.t0 = expect;
_context12.next = 5;
return (0, _index2.default)(schema, {
persons: [{ firstName: 'Nicolás' }]
});
case 5:
_context12.t1 = _context12.sent;
(0, _context12.t0)(_context12.t1).toBeNull();
_context12.next = 9;
return (0, _index2.default)(schema, {
persons: [{ firstName: 'Joaquin' }]

@@ -412,3 +511,3 @@ });

case 9:
errors = _context10.sent;
errors = _context12.sent;

@@ -421,13 +520,13 @@ expect(errors).toEqual({

case 'end':
return _context10.stop();
return _context12.stop();
}
}
}, _callee10, undefined);
}, _callee12, undefined);
})));
test('pass currentDoc validating arrays', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
test('pass currentDoc validating arrays', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
var aItem, doc, item, schema;
return regeneratorRuntime.wrap(function _callee13$(_context13) {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context13.prev = _context13.next) {
switch (_context15.prev = _context15.next) {
case 0:

@@ -439,10 +538,10 @@ aItem = { name: 'Nicolás' };

type: String,
custom: function custom(name, _ref10) {
var _this3 = this;
custom: function custom(name, _ref11) {
var _this4 = this;
var currentDoc = _ref10.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
var currentDoc = _ref11.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context13.prev = _context13.next) {
case 0:

@@ -453,6 +552,6 @@ expect(currentDoc).toBe(aItem);

case 'end':
return _context11.stop();
return _context13.stop();
}
}
}, _callee11, _this3);
}, _callee13, _this4);
}))();

@@ -465,10 +564,10 @@ }

type: [item],
custom: function custom(items, _ref11) {
var _this4 = this;
custom: function custom(items, _ref12) {
var _this5 = this;
var currentDoc = _ref11.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
var currentDoc = _ref12.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context14.prev = _context14.next) {
case 0:

@@ -479,6 +578,6 @@ expect(currentDoc).toBe(doc);

case 'end':
return _context12.stop();
return _context14.stop();
}
}
}, _callee12, _this4);
}, _callee14, _this5);
}))();

@@ -491,3 +590,3 @@ }

expect.assertions(2);
_context13.next = 7;
_context15.next = 7;
return (0, _index2.default)(schema, doc);

@@ -497,13 +596,13 @@

case 'end':
return _context13.stop();
return _context15.stop();
}
}
}, _callee13, undefined);
}, _callee15, undefined);
})));
test('pass currentDoc validating complex schemas', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
test('pass currentDoc validating complex schemas', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23() {
var aCar, aMom, aItem, doc, car, mom, item, schema;
return regeneratorRuntime.wrap(function _callee21$(_context21) {
return regeneratorRuntime.wrap(function _callee23$(_context23) {
while (1) {
switch (_context21.prev = _context21.next) {
switch (_context23.prev = _context23.next) {
case 0:

@@ -517,10 +616,10 @@ aCar = { brand: 'Jeep' };

type: String,
custom: function custom(value, _ref13) {
var _this5 = this;
custom: function custom(value, _ref14) {
var _this6 = this;
var currentDoc = _ref13.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
var currentDoc = _ref14.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
return regeneratorRuntime.wrap(function _callee16$(_context16) {
while (1) {
switch (_context14.prev = _context14.next) {
switch (_context16.prev = _context16.next) {
case 0:

@@ -532,6 +631,6 @@ expect(value).toEqual(aCar.brand);

case 'end':
return _context14.stop();
return _context16.stop();
}
}
}, _callee14, _this5);
}, _callee16, _this6);
}))();

@@ -541,8 +640,8 @@ }

__validate: function __validate(value, info) {
var _this6 = this;
var _this7 = this;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context15.prev = _context15.next) {
switch (_context17.prev = _context17.next) {
case 0:

@@ -554,6 +653,6 @@ expect(value).toEqual(aMom.car);

case 'end':
return _context15.stop();
return _context17.stop();
}
}
}, _callee15, _this6);
}, _callee17, _this7);
}))();

@@ -565,10 +664,10 @@ }

type: String,
custom: function custom(value, _ref14) {
var _this7 = this;
custom: function custom(value, _ref15) {
var _this8 = this;
var currentDoc = _ref14.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
return regeneratorRuntime.wrap(function _callee16$(_context16) {
var currentDoc = _ref15.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
return regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) {
switch (_context16.prev = _context16.next) {
switch (_context18.prev = _context18.next) {
case 0:

@@ -580,6 +679,6 @@ expect(value).toEqual(aMom.name);

case 'end':
return _context16.stop();
return _context18.stop();
}
}
}, _callee16, _this7);
}, _callee18, _this8);
}))();

@@ -590,11 +689,11 @@ }

type: car,
custom: function custom(value, _ref15) {
var _this8 = this;
custom: function custom(value, _ref16) {
var _this9 = this;
var currentDoc = _ref15.currentDoc,
doc = _ref15.doc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
var currentDoc = _ref16.currentDoc,
doc = _ref16.doc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
return regeneratorRuntime.wrap(function _callee19$(_context19) {
while (1) {
switch (_context17.prev = _context17.next) {
switch (_context19.prev = _context19.next) {
case 0:

@@ -606,6 +705,6 @@ expect(value).toEqual(aMom.car);

case 'end':
return _context17.stop();
return _context19.stop();
}
}
}, _callee17, _this8);
}, _callee19, _this9);
}))();

@@ -618,10 +717,10 @@ }

type: String,
custom: function custom(value, _ref16) {
var _this9 = this;
custom: function custom(value, _ref17) {
var _this10 = this;
var currentDoc = _ref16.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
return regeneratorRuntime.wrap(function _callee18$(_context18) {
var currentDoc = _ref17.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
return regeneratorRuntime.wrap(function _callee20$(_context20) {
while (1) {
switch (_context18.prev = _context18.next) {
switch (_context20.prev = _context20.next) {
case 0:

@@ -633,6 +732,6 @@ expect(value).toEqual(aItem.name);

case 'end':
return _context18.stop();
return _context20.stop();
}
}
}, _callee18, _this9);
}, _callee20, _this10);
}))();

@@ -643,10 +742,10 @@ }

type: mom,
custom: function custom(value, _ref17) {
var _this10 = this;
custom: function custom(value, _ref18) {
var _this11 = this;
var currentDoc = _ref17.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
return regeneratorRuntime.wrap(function _callee19$(_context19) {
var currentDoc = _ref18.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
return regeneratorRuntime.wrap(function _callee21$(_context21) {
while (1) {
switch (_context19.prev = _context19.next) {
switch (_context21.prev = _context21.next) {
case 0:

@@ -658,6 +757,6 @@ expect(value).toEqual(aItem.mom);

case 'end':
return _context19.stop();
return _context21.stop();
}
}
}, _callee19, _this10);
}, _callee21, _this11);
}))();

@@ -670,10 +769,10 @@ }

type: [item],
custom: function custom(value, _ref18) {
var _this11 = this;
custom: function custom(value, _ref19) {
var _this12 = this;
var currentDoc = _ref18.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
return regeneratorRuntime.wrap(function _callee20$(_context20) {
var currentDoc = _ref19.currentDoc;
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() {
return regeneratorRuntime.wrap(function _callee22$(_context22) {
while (1) {
switch (_context20.prev = _context20.next) {
switch (_context22.prev = _context22.next) {
case 0:

@@ -685,6 +784,6 @@ expect(value).toEqual(doc.items);

case 'end':
return _context20.stop();
return _context22.stop();
}
}
}, _callee20, _this11);
}, _callee22, _this12);
}))();

@@ -697,3 +796,3 @@ }

expect.assertions(14);
_context21.next = 11;
_context23.next = 11;
return (0, _index2.default)(schema, doc);

@@ -703,6 +802,6 @@

case 'end':
return _context21.stop();
return _context23.stop();
}
}
}, _callee21, undefined);
}, _callee23, undefined);
})));
{
"name": "@orion-js/schema",
"version": "0.0.39",
"version": "0.0.41",
"main": "index.js",

@@ -5,0 +5,0 @@ "author": "nicolaslopezj",

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