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.5.8 to 0.5.9

351

lib/getValidationErrors/index.test.js

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

test('gives error when a document field is not present in schema', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
test('omits required if specified', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
var errors;

@@ -114,2 +114,27 @@ return regeneratorRuntime.wrap(function _callee3$(_context3) {

_context3.next = 2;
return (0, _index2.default)(schema, {
lastName: 'López',
friends: [{}, { firstName: 'Joaquin' }]
}, { omitRequired: true });
case 2:
errors = _context3.sent;
expect(errors).toBeNull();
case 4:
case 'end':
return _context3.stop();
}
}
}, _callee3, undefined);
})));
test('gives error when a document field is not present in schema', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
var errors;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _index2.default)({

@@ -125,3 +150,3 @@ name: {

case 2:
errors = _context3.sent;
errors = _context4.sent;

@@ -134,13 +159,13 @@ expect(errors).toEqual({

case 'end':
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, undefined);
}, _callee4, undefined);
})));
test('dont give error when array is optional and its not passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
test('dont give error when array is optional and its not passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
var schema, errors;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:

@@ -156,3 +181,3 @@ schema = {

};
_context4.next = 3;
_context5.next = 3;
return (0, _index2.default)(schema, {

@@ -164,3 +189,3 @@ name: 'Nicolás López',

case 3:
errors = _context4.sent;
errors = _context5.sent;

@@ -171,15 +196,15 @@ expect(errors).toBeNull();

case 'end':
return _context4.stop();
return _context5.stop();
}
}
}, _callee4, undefined);
}, _callee5, undefined);
})));
test('gives an error if a optional object is present and has missing values', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
test('gives an error if a optional object is present and has missing values', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
var errors;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.next = 2;
_context6.next = 2;
return (0, _index2.default)(schema, {

@@ -195,3 +220,3 @@ firstName: 'Nicolás',

case 2:
errors = _context5.sent;
errors = _context6.sent;

@@ -204,13 +229,13 @@ expect(errors).toEqual({

case 'end':
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, undefined);
}, _callee6, undefined);
})));
test('can check errors in deeply nested keys', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
test('can check errors in deeply nested keys', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
var children, mother, family, deepSchema, errors;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:

@@ -253,3 +278,3 @@ children = {

};
_context6.next = 6;
_context7.next = 6;
return (0, _index2.default)(deepSchema, {

@@ -278,3 +303,3 @@ name: 'Nicolás',

case 6:
errors = _context6.sent;
errors = _context7.sent;

@@ -289,13 +314,13 @@ expect(errors).toEqual({

case 'end':
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, undefined);
}, _callee7, undefined);
})));
test('run custom validation when field is optional and no value is passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
test('run custom validation when field is optional and no value is passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
var person, schema;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:

@@ -313,20 +338,20 @@ person = {

return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
if (value) {
_context7.next = 2;
_context8.next = 2;
break;
}
return _context7.abrupt('return', 'No object');
return _context8.abrupt('return', 'No object');
case 2:
case 'end':
return _context7.stop();
return _context8.stop();
}
}
}, _callee7, _this);
}, _callee8, _this);
}))();

@@ -347,4 +372,4 @@ }

};
_context8.t0 = expect;
_context8.next = 5;
_context9.t0 = expect;
_context9.next = 5;
return (0, _index2.default)(schema, {

@@ -355,10 +380,10 @@ person: { name: null }

case 5:
_context8.t1 = _context8.sent;
_context8.t2 = {
_context9.t1 = _context9.sent;
_context9.t2 = {
number: _Errors2.default.REQUIRED,
'person.name': 'No'
};
(0, _context8.t0)(_context8.t1).toEqual(_context8.t2);
_context8.t3 = expect;
_context8.next = 11;
(0, _context9.t0)(_context9.t1).toEqual(_context9.t2);
_context9.t3 = expect;
_context9.next = 11;
return (0, _index2.default)(schema, {

@@ -370,10 +395,10 @@ person: null,

case 11:
_context8.t4 = _context8.sent;
_context8.t5 = {
_context9.t4 = _context9.sent;
_context9.t5 = {
number: _Errors2.default.REQUIRED,
person: 'No object'
};
(0, _context8.t3)(_context8.t4).toEqual(_context8.t5);
_context8.t6 = expect;
_context8.next = 17;
(0, _context9.t3)(_context9.t4).toEqual(_context9.t5);
_context9.t6 = expect;
_context9.next = 17;
return (0, _index2.default)(schema, {

@@ -384,22 +409,22 @@ number: 123

case 17:
_context8.t7 = _context8.sent;
_context8.t8 = {
_context9.t7 = _context9.sent;
_context9.t8 = {
number: 'No',
person: 'No object'
};
(0, _context8.t6)(_context8.t7).toEqual(_context8.t8);
(0, _context9.t6)(_context9.t7).toEqual(_context9.t8);
case 20:
case 'end':
return _context8.stop();
return _context9.stop();
}
}
}, _callee8, undefined);
}, _callee9, undefined);
})));
test('can validate object type with custom validation', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
test('can validate object type with custom validation', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
var person, schema;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:

@@ -413,15 +438,15 @@ person = {

return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
return _context9.abrupt('return', value.name === 'Nicolás' ? null : 'no');
return _context10.abrupt('return', value.name === 'Nicolás' ? null : 'no');
case 1:
case 'end':
return _context9.stop();
return _context10.stop();
}
}
}, _callee9, _this2);
}, _callee10, _this2);
}))();

@@ -435,4 +460,4 @@ }

};
_context10.t0 = expect;
_context10.next = 5;
_context11.t0 = expect;
_context11.next = 5;
return (0, _index2.default)(schema, {

@@ -443,6 +468,6 @@ person: { name: 'Nicolás' }

case 5:
_context10.t1 = _context10.sent;
(0, _context10.t0)(_context10.t1).toBeNull();
_context10.t2 = expect;
_context10.next = 10;
_context11.t1 = _context11.sent;
(0, _context11.t0)(_context11.t1).toBeNull();
_context11.t2 = expect;
_context11.next = 10;
return (0, _index2.default)(schema, {

@@ -453,21 +478,21 @@ person: { name: 'Joaquin' }

case 10:
_context10.t3 = _context10.sent;
_context10.t4 = {
_context11.t3 = _context11.sent;
_context11.t4 = {
person: 'no'
};
(0, _context10.t2)(_context10.t3).toEqual(_context10.t4);
(0, _context11.t2)(_context11.t3).toEqual(_context11.t4);
case 13:
case 'end':
return _context10.stop();
return _context11.stop();
}
}
}, _callee10, undefined);
}, _callee11, undefined);
})));
test('skip child validation if specified', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
test('skip child validation if specified', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
var person, schema, errors;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context13.prev = _context13.next) {
case 0:

@@ -484,15 +509,15 @@ person = {

return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context12.prev = _context12.next) {
case 0:
return _context11.abrupt('return', value.firstName === 'Nicolás');
return _context12.abrupt('return', value.firstName === 'Nicolás');
case 1:
case 'end':
return _context11.stop();
return _context12.stop();
}
}
}, _callee11, _this3);
}, _callee12, _this3);
}))();

@@ -506,4 +531,4 @@ }

};
_context12.t0 = expect;
_context12.next = 5;
_context13.t0 = expect;
_context13.next = 5;
return (0, _index2.default)(schema, {

@@ -514,5 +539,5 @@ persons: [{ firstName: 'Nicolás' }]

case 5:
_context12.t1 = _context12.sent;
(0, _context12.t0)(_context12.t1).toBeNull();
_context12.next = 9;
_context13.t1 = _context13.sent;
(0, _context13.t0)(_context13.t1).toBeNull();
_context13.next = 9;
return (0, _index2.default)(schema, {

@@ -523,3 +548,3 @@ persons: [{ firstName: 'Joaquin' }]

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

@@ -532,13 +557,13 @@ expect(errors).toEqual({

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

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

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

@@ -564,6 +589,6 @@ expect(currentDoc).toBe(aItem);

case 'end':
return _context13.stop();
return _context14.stop();
}
}
}, _callee13, _this4);
}, _callee14, _this4);
}))();

@@ -576,10 +601,10 @@ }

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

@@ -590,6 +615,6 @@ expect(currentDoc).toBe(doc);

case 'end':
return _context14.stop();
return _context15.stop();
}
}
}, _callee14, _this5);
}, _callee15, _this5);
}))();

@@ -602,3 +627,3 @@ }

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

@@ -608,13 +633,13 @@

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

@@ -628,10 +653,10 @@ aCar = { brand: 'Jeep' };

type: String,
custom: function custom(value, _ref14) {
custom: function custom(value, _ref15) {
var _this6 = 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 _callee17() {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
while (1) {
switch (_context16.prev = _context16.next) {
switch (_context17.prev = _context17.next) {
case 0:

@@ -643,6 +668,6 @@ expect(value).toEqual(aCar.brand);

case 'end':
return _context16.stop();
return _context17.stop();
}
}
}, _callee16, _this6);
}, _callee17, _this6);
}))();

@@ -654,6 +679,6 @@ }

return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
return regeneratorRuntime.wrap(function _callee17$(_context17) {
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
return regeneratorRuntime.wrap(function _callee18$(_context18) {
while (1) {
switch (_context17.prev = _context17.next) {
switch (_context18.prev = _context18.next) {
case 0:

@@ -665,6 +690,6 @@ expect(value).toEqual(aMom.car);

case 'end':
return _context17.stop();
return _context18.stop();
}
}
}, _callee17, _this7);
}, _callee18, _this7);
}))();

@@ -676,10 +701,10 @@ }

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

@@ -691,6 +716,6 @@ expect(value).toEqual(aMom.name);

case 'end':
return _context18.stop();
return _context19.stop();
}
}
}, _callee18, _this8);
}, _callee19, _this8);
}))();

@@ -701,11 +726,11 @@ }

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

@@ -717,6 +742,6 @@ expect(value).toEqual(aMom.car);

case 'end':
return _context19.stop();
return _context20.stop();
}
}
}, _callee19, _this9);
}, _callee20, _this9);
}))();

@@ -729,10 +754,10 @@ }

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

@@ -744,6 +769,6 @@ expect(value).toEqual(aItem.name);

case 'end':
return _context20.stop();
return _context21.stop();
}
}
}, _callee20, _this10);
}, _callee21, _this10);
}))();

@@ -754,10 +779,10 @@ }

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

@@ -769,6 +794,6 @@ expect(value).toEqual(aItem.mom);

case 'end':
return _context21.stop();
return _context22.stop();
}
}
}, _callee21, _this11);
}, _callee22, _this11);
}))();

@@ -781,10 +806,10 @@ }

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

@@ -796,6 +821,6 @@ expect(value).toEqual(doc.items);

case 'end':
return _context22.stop();
return _context23.stop();
}
}
}, _callee22, _this12);
}, _callee23, _this12);
}))();

@@ -808,3 +833,3 @@ }

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

@@ -814,6 +839,6 @@

case 'end':
return _context23.stop();
return _context24.stop();
}
}
}, _callee23, undefined);
}, _callee24, undefined);
})));
{
"name": "@orion-js/schema",
"version": "0.5.8",
"version": "0.5.9",
"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