UNPKG

frexp

Version:
2 lines (1 loc) 3.36 kB
"use strict";var e=require("./_rollupPluginBabelHelpers-aESfU7SF.js");function r(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var t=r(require("zod")),n=["path","code"],a=function(){return e._createClass((function r(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:void 0;e._classCallCheck(this,r),e._defineProperty(this,"schema",void 0),e._defineProperty(this,"payload",void 0),e._defineProperty(this,"validated",void 0),e._defineProperty(this,"_error",void 0),t&&(this.schema=t),n&&(this.payload=n)}),[{key:"_validate",value:(o=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(){var a,o,i=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return a=i.length>0&&void 0!==i[0]?i[0]:void 0,r.prev=1,o=e._objectSpread2({},a),r.next=5,this.schema.parseAsync(this.payload,o);case 5:return this.validated=r.sent,r.abrupt("return",!1);case 9:return r.prev=9,r.t0=r.catch(1),r.t0 instanceof t.ZodError&&(this._error=r.t0.issues.reduce((function(r,t){var a,o=t.path,i=t.code,s=e._objectWithoutProperties(t,n);return[].concat(e._toConsumableArray(r),[e._objectSpread2({path:null!==(a=o.at(0))&&void 0!==a?a:"",type:i},s)])}),[])),r.abrupt("return",!0);case 14:case"end":return r.stop()}}),r,this,[[1,9]])}))),function(){return o.apply(this,arguments)})},{key:"fails",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:void 0;return this._validate(e)}},{key:"throwError",value:(a=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(){var t,n,a=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return t=a.length>0&&void 0!==a[0]?a[0]:void 0,r.prev=1,n=e._objectSpread2({abortEarly:!1,stripUnknown:!0},t),r.next=5,this.schema.validate(this.payload,n);case 5:this.validated=r.sent,r.next=11;break;case 8:throw r.prev=8,r.t0=r.catch(1),r.t0;case 11:case"end":return r.stop()}}),r,this,[[1,8]])}))),function(){return a.apply(this,arguments)})},{key:"validation",value:(r=e._asyncToGenerator(e._regeneratorRuntime().mark((function r(t){var n,a,o=arguments;return e._regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=o.length>1&&void 0!==o[1]?o[1]:void 0,r.prev=1,a=e._objectSpread2({},n),r.next=5,t.parseAsync(this.payload,a);case 5:return r.abrupt("return",r.sent);case 8:throw r.prev=8,r.t0=r.catch(1),r.t0;case 11:case"end":return r.stop()}}),r,this,[[1,8]])}))),function(e){return r.apply(this,arguments)})},{key:"errors",value:function(){return this._error}}],[{key:"body",value:function(r){return function(){var t=e._asyncToGenerator(e._regeneratorRuntime().mark((function t(n){var a,o,i=arguments;return e._regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=i.length>1&&void 0!==i[1]?i[1]:void 0,t.prev=1,o=e._objectSpread2({},a),t.next=5,n.parseAsync(r,o);case 5:return t.abrupt("return",t.sent);case 8:throw t.prev=8,t.t0=t.catch(1),t.t0;case 11:case"end":return t.stop()}}),t,null,[[1,8]])})));return function(e){return t.apply(this,arguments)}}()}}]);var r,a,o}();module.exports=a;