You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

schema-to-yup

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.10.8 to 1.10.9

2

dist/index.js

@@ -1,2 +0,2 @@

function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("yup"),n=t(require("uniq")),r=t(require("dashify")),i=t(require("uppercamelcase"));function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,h(t,e)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t,e){return(h=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function l(t,e,n){return(l=f()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&h(i,n.prototype),i}).apply(null,arguments)}function p(t){var e="function"==typeof Map?new Map:void 0;return(p=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return l(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),h(n,t)})(t)}var d={getProps:function(t){return t&&t.properties},getType:function(t){return t&&t.type},getName:function(t){return t&&(t.name||t.title)},getConstraints:function(t){return t},isString:function(t){return t&&"string"===t.type},isArray:function(t){return t&&"array"===t.type},isInteger:function(t){return t&&("integer"===t.type||"int"===t.type)},isBoolean:function(t){return t&&"boolean"===t.type},hasDateFormat:function(t){return t&&["date","date-time"].find(function(e){return e===t.format})},isDate:function(t){return t&&"string"===t.type&&d.hasDateFormat(t.format)},isNumber:function(t){return t&&("number"===t.type||d.isInteger(t))},isObject:function(t){return t&&"object"===t.type},isRequired:function(t){return t&&t.required}},y={getProps:function(t){return t.properties},getType:function(t){return t.type},getName:function(t){return t.name||t.title},getConstraints:function(t){return t},isString:function(t){return"string"===t.type&&!y.hasDateFormat(t)},isArray:function(t){return"array"===t.type},isBoolean:function(t){return"boolean"===t.type},isInteger:function(t){return"integer"===t.type},hasDateFormat:function(t){var e;return["date","date-time"].includes(null==t||null==(e=t.value)?void 0:e.format)},isDate:function(t){return"string"===t.type&&y.hasDateFormat(t)},isNumber:function(t){return"number"===t.type||y.isInteger(t)},isObject:function(t){return"object"===t.type},isRequired:function(t){return t.required}},m={getProps:function(t){return t&&t.fields},getType:function(t){return t&&t.type},getName:function(t){return t&&(t.name||t.title)},getConstraints:function(t){return t},isString:function(t){return t&&"string"===t.type},isArray:function(t){return t&&"array"===t.type},isInteger:function(t){return t&&"int"===t.type},isFloat:function(t){return t&&"float"===t.type},isDouble:function(t){return t&&"double"===t.type},isBoolean:function(t){return t&&"boolean"===t.type},isDate:function(t){return t&&"int"===t.type&&"date"===t.logicalType},isNumber:function(t){return t&&(m.isInteger(t)||m.isFloat(t)||m.isDouble(t))},isObject:function(t){return t&&"record"===t.type},isRequired:function(t){return t&&t.required}},v={"json-schema":d,"type-def":y,avro:m},g=function(t){function e(e){return void 0===e&&(e={}),t.call(this,e)||this}u(e,t);var n=e.prototype;return n.isNothing=function(t){return null==t},n.isPresent=function(t){return!this.isNothing(t)},n.toNumber=function(t){return Number(t)},n.isNumberLike=function(t){return!isNaN(this.toNumber(t))},n.isObjectType=function(t){return t===Object(t)},n.isArrayType=function(t){return Array.isArray(t)},n.isNumberType=function(t){return!isNaN(t)},n.isStringType=function(t){return"string"==typeof t},n.isFunctionType=function(t){return"function"==typeof t},n.isDateType=function(t){return t instanceof Date},e}(function(){function t(t){void 0===t&&(t={}),this.config=t;var e=t.log,n=t.error;this.enable=t.enable||{},this.log="function"==typeof e?e:console.log,this.err="function"==typeof n?n:console.error}var e=t.prototype;return e.error=function(t,e){if(!1!==this.enable.error)throw this.err&&(e?this.err(t,e):this.err(t)),t},e.warn=function(t,e){this.enable.warn&&this.logInfo("WARNING: "+t,e)},e.logInfo=function(t,e){this.enable.log&&this.log&&(e?this.log(t,e):this.log(t))},t}()),b=function(){function t(t,e){this.schemaParserMap=t,this.name=e}var e=t.prototype;return e.lookup=function(t){return void 0===t&&(t=this.name),this.schemaParserMap[t]},e.build=function(){var t=this.lookup();if(t.extends){var e=this.extend(t.extends);if(e)return e}return t},e.extend=function(t){var e=this.lookup(t);e&&(entry=o({},e,this.lookup()))},t}(),w=function(t){function e(e){var n;void 0===e&&(e={}),n=t.call(this,e)||this;var r,i,s=(e.createSchemaParserBuilder||(r=e.schemaParserMap||v,i=e.schemaType||"json-schema",new b(r,i))).build();return n.config=o({},s,e),n}return u(e,t),e.prototype.createSchemaParserBuilder=function(t,e){return new SchemaParserBuilder(t,e)},e}(g);function C(t){return t===Object(t)}var k=function(){function t(t,e){void 0===e&&(e={}),this.whenEntryObj=t;var n=e.properties,r=e.config,i=e.key,s=e.when,a=e.type;this.schema=e.schema,this.when=s,this.properties=n||{},this.key=i,this.type=a,this.config=r}var e=t.prototype;return e.validateAndConfigure=function(t){if(!C(t=t||this.whenEntryObj))return this.warn("invalid or missing when entry constraint object",t),!1;var e=Object.keys(t);return e.length<2?(this.warn("validateAndConfigure: when entry constraint must have at least 2 keys: "+e,t),!1):this.hasKey(e,"is")?!!this.hasKey(e,"then")||(this.warn("validateAndConfigure: when entry constraint missing 'then' or 'else' constraint: "+e,t),!1):(this.warn("validateAndConfigure: when entry constraint missing 'is' constraint: "+e,t),!1)},e.createYupSchemaEntry=function(t){return this.config.createYupSchemaEntry(t)},e.createValue=function(t,e){var n;return"string"==typeof t&&((n={})[t]=!0,t=n),C(t)||this.error("createValue: "+e+" must be a schema object"),o({key:this.key,type:this.type},t)},e.createEntryOpts=function(t,e){var n=this.createValue(t,e);return{schema:this.schema,properties:this.properties,key:this.key,type:this.type,value:n,config:this.config}},e.createEntry=function(t,e){var n=this.createEntryOpts(t,e);return this.createYupSchemaEntry(n)},e.hasKey=function(t,e){return t.find(function(t){return t===e})},e.hasAnyKey=function(t,e){return t.find(function(t){return e.includes(t)})},e.whenEntryFor=function(t,e,n){var r;if(n=n||e,"string"==typeof t&&((r={})[t]=!0,t=r),!C(t))throw"whenEntryFor: Invalid when object "+t;var i=o({},t[n]);return delete t[n],i?(t[e]=this.createEntry(i,e),t):t},e.calcEntryObj=function(){var t=o({},this.whenEntryObj);return"otherwise"in(t=this.whenEntryFor(t,"then"))&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t},e.warn=function(t,e){console.error("[WhenEntry] WARNING",t,e)},e.error=function(t,e){throw console.error("[WhenEntry] ERROR",t,e),t},a(t,[{key:"entryObj",get:function(){return this.validateAndConfigure()&&this.calcEntryObj()}}]),t}();function E(t){return t===Object(t)}var O=function(){function t(t){void 0===t&&(t={});var e=t.type,n=t.key,r=t.value,i=t.when,s=t.schema,a=t.properties,o=t.config;this.opts=t,this.when=i,this.key=n,this.type=e,this.value=r,this.schema=s,this.properties=a,this.config=o,this.validate()}var e=t.prototype;return e.validate=function(){"string"!=typeof this.type&&this.error("validate: invalid or mising type: "+this.type,this.opts),E(this.when)||this.error("validate: invalid or mising when: "+this.when,this.opts)},e.validateAndConfigure=function(t){if(!E(t=t||this.when))return this.warn("invalid or missing when constraint",t),!1;var e=Object.keys(t);return e.length<1?(this.warn("when constraint must have at least 1 key: "+e,t),!1):(this.whenKeys=e,!0)},e.createWhenEntry=function(t,e){return function(t,e){return void 0===e&&(e={}),new k(t,e)}(t,e)},e.accumulate=function(t,e){var n=this.when[e];if(!E(n))return this.warn("invalid when entry constraint object "+n+" for "+e),t;var r=this.createWhenEntry(n,{type:this.type,key:this.key,schema:this.schema,properties:this.properties,config:this.config}).entryObj;return r?t=Object.assign(t,r):t},e.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},e.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},a(t,[{key:"constraintObj",get:function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}}},{key:"keyVal",get:function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t}},{key:"constraintValue",get:function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]}},{key:"constraint",get:function(){return this.validateAndConfigure()&&this.constraintValue}}]),t}(),N=function(t){return new O(t)},M=function(t){function e(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).typeHandler=e,r.constraintsAdded={},r.delegators.map(function(t){r[t]=e[t]}),r}u(e,t);var n=e.prototype;return n.build=function(t,e){void 0===e&&(e={});var n=e.constraintName,r=e.constraintValue,i=e.method,s=e.yup,a=e.value,o=e.values,u=e.errName;if(s=s||this.base,this.isNothing(r=r||e.propValue||this.constraints[t]))return this.warn("no prop value"),!1;n=n||t;var c=this.aliasMap[i=i||n]||i;if(!s[c])return this.warn("Yup has no such API method: "+c),!1;for(var h,f=s[c].bind(s),l=this.valErrMessage(n),p=u&&this.valErrMessage(u),d={constraintName:n,yup:s,constraintFn:f,errFn:l||p},y=0,m=["multiValueConstraint","presentConstraintValue","nonPresentConstraintValue"];y<m.length&&!(h=this[m[y]](a||o,d));y++);return h?(this.base=h,h):(this.warn("buildConstraint: missing value or values options"),!1)},n.nonPresentConstraintValue=function(t,e){var n=e.constraintName,r=e.constraintFn,i=e.errFn;if(!this.isPresent(t))return this.onConstraintAdded({name:n}),r(i)},n.presentConstraintValue=function(t,e){var n=e.constraintName,r=e.constraintFn,i=e.errFn;if(this.isPresent(t))return this.onConstraintAdded({name:n,value:t}),this.isNoValueConstraint(n)?r(i):r(t,i)},n.multiValueConstraint=function(t,e){var n=e.constraintFn,r=e.constraintName,i=e.errFn;if(this.isPresent(t)){if(Array.isArray(t))return this.onConstraintAdded({name:r,value:t}),this.callConstraintFn(n,r,t,i);this.warn("buildConstraint: values option must be an array of arguments")}},n.callConstraintFn=function(t,e,n,r){return this.isMultiArgsCall(e)?t.apply(void 0,n.concat([r])):t(n,r)},n.isMultiArgsCall=function(t){return this.multiArgsValidatorMethods[t]},n.isNoValueConstraint=function(t){return this.noValueConstraints.includes(t)},n.addValueConstraint=function(t,e){var n=void 0===e?{}:e;return this.addConstraint(t,{constraintName:n.constraintName,value:!0,errName:n.errName})},n.addConstraint=function(t,e){var n=this.build(t,e);return!!n&&(this.typeHandler.base=n,n)},n.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this.typeHandler},n.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},a(e,[{key:"delegators",get:function(){return["errMessages","base","key","constraints","errorMessageHandler"]}},{key:"multiArgsValidatorMethods",get:function(){return this.config.multiArgsValidatorMethods||{when:!0}}},{key:"noValueConstraints",get:function(){return["required","email","url","format"]}},{key:"constraintsMap",get:function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}},{key:"aliasMap",get:function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}}}]),e}(g),T=function(t){function e(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).typeHandler=e,r.constraints=e.constraints,r.errMessages=e.errMessages,r.key=e.key,r.type=e.type,r}u(e,t);var n=e.prototype;return n.valErrMessage=function(t){var e=this.constraints,n=this.errMessageFor(t);return"function"==typeof n?n(e):n},n.errMessageFor=function(t){var e=this.errMessages,n=e[this.key];return n?n[t]:e["$"+t]},e}(g),x=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),S=function(t){function r(n){var r;void 0===n&&(n={}),r=t.call(this,n.config)||this;var i=n.schema,s=n.key,a=n.value,o=n.config;return o=o||{},i=i||{},r.validateOnCreate(s,a,n),r.yup=e,r.key=s,r.schema=i,r.properties=i.properties||{},r.value=a,r.constraints=r.getConstraints(),r.format=a.format||r.constraints.format,r.config=o||{},r.type="mixed",r.mixedConfig=r.config.mixed||{},r.typeConfig=r.config[r.type]||{},r.base=e.mixed(),r.errMessages=o.errMessages||{},r.configureTypeConfig(),r.constraintsAdded={},r}u(r,t);var i=r.prototype;return i.configureTypeConfig=function(){this.typeConfig.enabled||this.typeConfig.extends||this.typeConfig.convert&&(this.typeConfig.extends=Object.keys(this.typeConfig.convert))},i.isRequired=function(t){return!0===(t=t||this.value).required},i.disabledMode=function(t){var e=this.mode[t];return!!this.disableFlags.find(function(t){return e===t})},i.enabledMode=function(t){var e=this.mode[t];return!!this.enableFlags.find(function(t){return e===t})},i.preProcessedConstraintValue=function(t){return this.shouldPreProcessValue?this.isRequired(t)?t:o({},t,{notRequired:!0}):t},i.initHelpers=function(){var t=this.config;this.errorMessageHandler=(this.config.createErrorMessageHandler||this.createErrorMessageHandler)(this,t),this.constraintBuilder=(this.config.createConstraintBuilder||this.createConstraintBuilder)(this,t),this.rebind("addConstraint","addValueConstraint")},i.createConstraintBuilder=function(t,e){return void 0===e&&(e={}),new M(t,e)},i.createErrorMessageHandler=function(t,e){return void 0===e&&(e={}),new T(t,e)},i.rebind=function(){var t=this;[].slice.call(arguments).map(function(e){var n=t[e];t[e]=t.isFunctionType(n)?n.bind(t):n})},i.validateOnCreate=function(t,e,n){t||this.error("create: missing key "+JSON.stringify(n)),e||this.error("create: missing value "+JSON.stringify(n))},i.convertEnabled=function(){var t=this;this.enabled.map(function(e){var n=t.convertFnFor(e);n&&n(t)})},i.convertFnFor=function(t){return this.customConvertFnFor(t)||this.builtInConvertFnFor(t)},i.customConvertFnFor=function(t){return(this.typeConfig.convert||{})[t]},i.builtInConvertFnFor=function(t){return this[t].bind(this)},i.getConstraints=function(){return this.config.getConstraints(this.value)},i.createSchemaEntry=function(){return this.convert().base},i.convert=function(){return this.initHelpers(),this.addMappedConstraints(),this.convertEnabled(),this},i.addValueConstraint=function(t,e){var n=this.constraintBuilder.addValueConstraint(t,e);return n&&(this.base=n.base),this},i.addConstraint=function(t,e){if(!this.constraintBuilder)throw new Error("[YupMixed] addConstraint: Missing constraintBuilder in "+this.constructor.name);var n=this.constraintBuilder.addConstraint(t,e);return n&&(this.base=n),this},i.addMappedConstraints=function(){var t=Object.keys(this.constraintsMap),e=this.addMappedConstraint.bind(this);return t.map(e),this},i.addMappedConstraint=function(t){var e=this["value"===t?"addValueConstraint":"addConstraint"];this.constraintsMap[t].map(function(t){e(t)})},i.oneOf=function(){var t=this,e=this.constraints.enum||this.constraints.oneOf||this.constraints.anyOf;if(this.isNothing(e))return this;e=Array.isArray(e)?e:[e];var n=["oneOf","enum","anyOf"].find(function(e){return void 0!==t.constraints[e]});return this.addConstraint(n,{values:e})},i.notOneOf=function(){var t=this.constraints,e=t.not,n=t.notOneOf||e&&(e.enum||e.oneOf);return this.isNothing(n)?this:(n=Array.isArray(n)?n:[n],this.addConstraint("notOneOf",{values:n}))},i.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},i.createWhenConditionFor=function(t){return(this.config.createWhenCondition||N)({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})},i.when=function(){var t,e=this.constraints.when;if((t=e)!==Object(t))return this;var n=this.createWhenConditionFor(e).constraint;return n?(this.logInfo("Adding when constraint for "+this.key,n),this.addConstraint("when",{values:n,errName:"when"}),this):(this.warn("Invalid when constraint for: "+e),this)},i.isType=function(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this},i.nullable=function(){var t=this.constraints;return this.addConstraint("nullable",{value:t.nullable||t.isNullable,errName:"notOneOf"}),this},i.message=function(){return config.messages[this.key]||config.messages[this.type]||{}},i.errMessage=function(t){return void 0===t&&(t="default"),this.message[t]||"error"},i.toValidJSONSchema=function(){},i.normalize=function(){},i.deNormalize=function(){},i.errorMsg=function(t){this.throwError(t)},i.error=function(t,e){var n=["["+t+"]",e].join(" ");this.errorMsg(n)},i.throwError=function(t){throw t},a(r,[{key:"mode",get:function(){return this.config.mode||{}}},{key:"disableFlags",get:function(){return[!1,"disabled","no","off"]}},{key:"enableFlags",get:function(){return[!0,"enabled","yes","on"]}},{key:"shouldPreProcessValue",get:function(){return!this.disabledMode("notRequired")}},{key:"value",get:function(){return this._value},set:function(t){this._value=this.preProcessedConstraintValue(t)}},{key:"mixedEnabled",get:function(){return this.mixedConfig.enabled||["oneOf","notOneOf","when","nullable","isType"]}},{key:"typeEnabled",get:function(){return[]}},{key:"$typeExtends",get:function(){if(Array.isArray(this.typeConfig.extends))return n([].concat(this.typeConfig.extends,this.typeEnabled))}},{key:"configuredTypeEnabled",get:function(){return Array.isArray(this.typeConfig.enabled)?this.typeConfig.enabled:this.typeEnabled}},{key:"$typeEnabled",get:function(){return this.$typeExtends||this.configuredTypeEnabled}},{key:"enabled",get:function(){return[].concat(this.mixedEnabled,this.$typeEnabled)}},{key:"constraintsMap",get:function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}}]),r}(w),j=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],A={errMessages:function(t){return void 0===t&&(t=j),t.reduce(function(t,e){return t[e]=function(t){var e=t.value;return t.key+": invalid for "+(e.name||e.title)},t},{})}},V=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="array",n.base=n.yup.array(),n.createYupSchemaEntry=n.config.createYupSchemaEntry,n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.ensureItems=function(){return this.addConstraint("ensure")},n.compact=function(){return this.addConstraint("compact")},n.itemsOf=function(){var t=this.constraints,e=t.items||t.itemsOf||this.constraints.of;if(!this.isNothing(e))if(Array.isArray(e))this.error("itemsOf","does not (yet) support an Array of schemas");else if(this.isObjectType(e)){if(this.createYupSchemaEntry){try{var n=this.createYupSchemaEntry({key:this.key,value:e,config:this.config});return this.addConstraint("of",{constraintValue:n,propValue:e})}catch(t){this.error("itemsOf: Error",t)}return this}this.warn("missing createYupSchemaEntry in config, needed for recursive validation")}else this.error("itemsOf","must be a schema object, was "+typeof e)},n.maxItems=function(){var t=this.constraints,e=t.maxItems||t.max;if(!this.isNumberType(e))return this;if(!this.isValidSize(e))return this.handleInvalidSize("maxItems",e);var n=e&&this.base.max(e);return this.base=n||this.base,this},n.minItems=function(){var t=this.constraints,e=t.minItems||t.min;if(!this.isNumberType(e))return this;if(!this.isValidSize(e))return this.handleInvalidSize("minItems",e);var n=e&&this.base.min(e);return this.base=n||this.base,this},n.$items=function(){return this},n.$additionalItems=function(){return this},n.$uniqueItems=function(){return this},n.$contains=function(){return this},n.handleInvalidSize=function(t,e){var n="invalid array size constraint for "+t+", was "+e+". Must be a number >= 0";return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},n.isValidSize=function(t){return this.isNumberType(t)&&t>=0},a(e,[{key:"typeEnabled",get:function(){return["maxItems","minItems","ensureItems","compact","itemsOf"]}}]),e}(S),F=function(t){function e(e){return t.call(this,e)||this}u(e,t);var n=e.prototype;return n.isArray=function(t){return this.config.isArray||this.error("ArrayHandler: mising isArray in config",this.config),this.config.isArray(t)},n.handle=function(t){return this.isArray(t)&&V.create(t).createSchemaEntry()},e}(w);function P(t,e){return void 0===e&&(e={}),t&&new F(e).handle(t)}var R=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="boolean",n.base=n.yup.boolean(),n}return u(e,t),e.create=function(t){return new e(t)},e}(S),D=function(){function t(t){this.config=t}var e=t.prototype;return e.isBoolean=function(t){return this.config.isBoolean(t)},e.handle=function(t){return this.isBoolean(t)&&R.create(t).createSchemaEntry()},t}();function I(t,e){return void 0===e&&(e={}),t&&new D(e).handle(t)}var Y=function(t){function e(e){return t.call(this,e)||this}return u(e,t),a(e,[{key:"$map",get:function(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}}}]),e}(function(t){function e(e){return t.call(this,e)||this}u(e,t);var n=e.prototype;return n.transform=function(t){return this.typer.toNumber(t)},n.isValidConstraint=function(t){return this.typer.isNumberLike(t)},a(e,[{key:"explainConstraintValidMsg",get:function(){return"Must be a number or convertible to a number"}}]),e}(function(t){function e(e,n){var r;return(r=t.call(this,e.config)||this).map=n||r.$map||{},r.typer=e,r.delegates.map(function(t){var n=e[t];n||r.error("missing delegate: "+t,{typer:e}),r[t]=r.isFunctionType(n)?n.bind(e):n}),r}u(e,t);var n=e.prototype;return n.isStringType=function(t){return"string"==typeof t},n.add=function(){var t=this,e=this.map;Object.keys(e).map(function(n){var r=t.entryNames(e[n]);t.addConstraints(n,r)})},n.entryNames=function(t){return Array.isArray(t)?t:[t]},n.addConstraints=function(t,e){var n=this;return void 0===e&&(e=[]),e.map(function(e){var r=n.validateAndTransform(e);n.addConstraint(e,{method:t,value:r})}),this},n.validateAndTransform=function(t){var e=this.constraints[t];return this.validate(e),this.transform(e)},n.invalidMsg=function(t,e){return"invalid constraint for "+t+", was "+e+"."},n.invalidConstraintMsg=function(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")},n.validate=function(t){return this.isNothing(t)?this:this.isValidConstraint(t)?void 0:this.handleInvalidConstraint(name,t)},n.isValidConstraint=function(t){return!0},n.handleInvalidConstraint=function(t,e){var n=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},a(e,[{key:"delegates",get:function(){return["constraints","addConstraint","constraintsAdded"]}},{key:"explainConstraintValidMsg",get:function(){return""}}]),e}(g))),q=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.isValid=function(){return this.config.isNumber(this.obj)},e}(function(t){function e(e,n){var r;return(r=t.call(this,n)||this).obj=e,r}u(e,t);var n=e.prototype;return n.isValid=function(){return!1},n.verify=function(){return this.isPresent(this.obj)&&this.isValid(this.obj)},e}(w)),H=function(t,e){return void 0===e&&(e={}),function(t,e){return new q(t,e)}(t,e).verify()};function B(t,e){return void 0===e&&(e={}),H(t,e)&&function(t){return z.schemaEntryFor(t)}(t)}var z=function(t){function e(e){var n,r;return(n=t.call(this,e)||this).type=n.normalizeNumType(e.type),n.base=n.yup.number(),n.rangeConstraint=(r=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n),new Y(r)),n}u(e,t);var n=e.prototype;return n.normalizeNumType=function(t){return"int"===t?"integer":t},e.create=function(t){return new e(t)},e.schemaEntryFor=function(t){return e.create(t).createSchemaEntry()},n.convert=function(){return t.prototype.convert.call(this),this},n.range=function(){this.rangeConstraint.add()},n.truncate=function(){return this.addConstraint("truncate")},n.round=function(){var t=this.constraints.round;if(this.isNothing(t))return this;var e=this.isStringType(t)?t:"round";return t&&this.base.round(e),this},n.posNeg=function(){this.positive(),this.negative()},n.integer=function(){return this.isInteger&&this.addConstraint("integer"),this},n.positive=function(){return this.addConstraint("positive")},n.negative=function(){return this.addConstraint("negative")},n.normalize=function(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min},a(e,[{key:"typeEnabled",get:function(){return["range","posNeg","integer"]}},{key:"isInteger",get:function(){return this.config.isInteger(this.type)}},{key:"isNegative",get:function(){var t=this.constraints,e=t.exclusiveMaximum;return!!t.negative||void 0!==e&&0===e}},{key:"isPositive",get:function(){var t=this.constraints,e=t.exclusiveMinimum;return!!t.positive||void 0!==e&&0===e}}]),e}(S),L=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="object",n.base=n.yup.object(),n.properties=n.value.properties,n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){if(!this.properties)return this;t.prototype.convert.call(this);var e=this.value,n=this.config;if(e){n.buildYup||this.error("convert","Missing buildYup function from config",n);var r=this.config.buildYup(e,n);this.base=r}return this},n.camelCase=function(){return this.addConstraint("camelCase")},n.constantCase=function(){return this.addConstraint("constantCase")},n.noUnknown=function(){var t=this.value,e=t.noUnknown||t.propertyNames,n=e&&this.base.noUnknown(e,this.valErrMessage("propertyNames")||this.valErrMessage("noUnknown"));return this.base=n||this.base,this},a(e,[{key:"typeEnabled",get:function(){return["noUnknown","camelCase","constantCase"]}}]),e}(S),$=function(t){return t&&"object"===t.type},_=function(){function t(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||$,this.config=t,this.schema=t.schema}var e=t.prototype;return e.isObject=function(t){return this.config.isObject(t.value)},e.handle=function(t){return this.isObject(t)&&L.create(o({},t,{config:this.config})).createSchemaEntry()},t}();function K(t,e){return void 0===e&&(e={}),t&&new _(e).handle(t)}var U=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="string",n.base=n.yup.string(),n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.trim=function(){return this.addConstraint("trim")},n.lowercase=function(){return this.addConstraint("lowercase")},n.uppercase=function(){return this.addConstraint("uppercase")},n.genericFormat=function(){1!=!this.config.format&&this.yup.prototype[this.format]&&this.addConstraint(this.format)},n.email=function(){if(!this.isEmail)return this;var t=this.constraintNameFor("email","format");return this.addConstraint("email",{constraintValue:!0,constraintName:t,method:"email",errName:"email"}),this},n.constraintNameFor=function(){var t=this;return[].slice.call(arguments).find(function(e){return t.constraints[e]})},n.url=function(){if(!this.isUrl)return this;var t=this.constraintNameFor("url","format");return this.addConstraint("url",{constraintValue:!0,constraintName:t,method:"url",errName:"url"}),this},n.minLength=function(){var t=this.constraints.minLength,e=this.valErrMessage("minLength")||this.valErrMessage("min"),n=t&&this.base.min(t,e);return this.base=n||this.base,this},n.maxLength=function(){var t=this.constraints.maxLength,e=this.valErrMessage("maxLength")||this.valErrMessage("max"),n=t&&this.base.max(t,e);return this.base=n||this.base,this},n.pattern=function(){var t=this.constraints,e=t.pattern;if(!e)return this;var n=new RegExp(e,t.flags),r=this.valErrMessage("pattern")||this.valErrMessage("matches")||this.valErrMessage("regex"),i=n&&this.base.matches(n,r);return this.base=i||this.base,this},n.normalize=function(){this.constraints.pattern=this.constraints.pattern||this.constraints.matches||this.constraints.regex,this.constraints.maxLength=this.constraints.maxLength||this.constraints.max,this.constraints.minLength=this.constraints.minLength||this.constraints.min},a(e,[{key:"typeEnabled",get:function(){return["normalize","minLength","maxLength","pattern","lowercase","uppercase","email","url","genericFormat"]}},{key:"isEmail",get:function(){return this.constraints.email||"email"===this.format}},{key:"isUrl",get:function(){return this.constraints.url||"url"===this.format}}]),e}(S),W=function(){function t(t){this.config=t}var e=t.prototype;return e.isString=function(t){return this.config.isString(t)},e.handle=function(t){return this.isString(t)&&U.create(o({config:this.config},t)).createSchemaEntry()},t}();function J(t,e){return void 0===e&&(e={}),t&&new W(e).handle(t)}var G=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="date",n.base=n.yup.date(),n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.toDate=function(t){return new Date(t)},n.isValidDateType=function(t){return this.isStringType(t)||this.isDateType(t)},n.isValidDate=function(t){return!!this.isValidDateType(t)&&(!this.isStringType(t)||Boolean(Date.parse(t)))},n.transformToDate=function(t){return this.isNumberType(t)?new Date(t):t},n.minDate=function(){var t=this.constraints.minDate||this.constraints.min;if(this.isNothing(t))return this;var e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("minDate",e);var n=e&&this.base.min(this.toDate(e),this.valErrMessage("minDate")||this.valErrMessage("min"));return this.base=n||this.base,this},n.maxDate=function(){var t=this.constraints.maxDate||this.constraints.max;if(this.isNothing(t))return this;var e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("maxDate",e);var n=e&&this.base.max(this.toDate(e),this.valErrMessage("maxDate")||this.valErrMessage("max"));return this.base=n||this.base,this},n.handleInvalidDate=function(t,e){var n="invalid constraint for "+t+", was "+e+". Must be a number, string (valid date format) or a Date instance";return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},a(e,[{key:"typeEnabled",get:function(){return["minDate","maxDate"]}}]),e}(S),Q=function(){function t(t){this.config=t}var e=t.prototype;return e.isDate=function(t){return this.config.isDate(t)},e.handle=function(t){return this.isDate(t)&&G.create(t).createSchemaEntry()},t}();function X(t,e){return void 0===e&&(e={}),t&&new Q(e).handle(t)}var Z={__proto__:null,errValKeys:j,defaults:A,YupArray:V,toYupArray:P,YupBoolean:R,toYupBoolean:I,YupNumber:z,toYupNumberSchemaEntry:B,toYupNumber:function(t,e){return void 0===e&&(e={}),H(t,e)&&function(t){return z.create(t)}(t)},YupObject:L,toYupObject:K,YupString:U,toYupString:J,YupDate:G,toYupDate:X,YupMixed:S,ConvertYupSchemaError:x,Base:w},tt=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),et=function(t){function e(e,n){var r;r=t.call(this,n)||this;var i=e.value,s=e.type,a=e.kind,o=e.name,u=e.key,c=e.schema,h=e.types;return r.opts=e,r.kind=a,r.value=i,r.schema=c,r.key=u,r.value=i||{},r.name=o,r.type=s,r.types=h,r}u(e,t);var n=e.prototype;return n.error=function(t,e){var n,r,i=this.opts;throw e?(n=console).error.apply(n,[t,e].concat(i)):(r=console).error.apply(r,[t].concat(i)),new tt(t)},n.resolve=function(){throw"Must be implemented by subclass"},a(e,[{key:"obj",get:function(){return{schema:this.schema,key:this.key,value:this.value,type:this.type,kind:this.kind,config:this.config}}}]),e}(w),nt=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.resolve=function(){if(Array.isArray(this.value)){var t=this.config.toMultiType;return t?t(this):void 0}},e}(et),rt=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.resolve=function(){if(!Array.isArray(this.value)){var t=this.config.toSingleType;if(t)return t(this);for(var e,n=this.obj,r=this.config,i=0,s=Object.keys(this.types);i<s.length;i++){var a=this.types[s[i]];if(a&&(e=a(n,r)),e)break}return e}},e}(et),it=function(t,e){return new st(t,e)},st=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).initResolvers(),r}u(e,t);var n=e.prototype;return n.initResolvers=function(){var t=this.opts,e=this.config,n=e.createMultiTypeResolver||this.createMultiTypeResolver.bind(this);this.multiTypeResolver=n(t,e);var r=e.createSingleTypeResolver||this.createSingleTypeResolver.bind(this);this.singleTypeResolver=r(t,e)},n.createMultiTypeResolver=function(){return new nt(this.opts,this.config)},n.createSingleTypeResolver=function(){return new rt(this.opts,this.config)},n.resolve=function(){return this.toMultiType()||this.toSingleType()||this.toDefaultEntry()},n.toMultiType=function(){return(this.config.toMultiType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)},n.toSingleType=function(){return(this.config.toSingleType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)},n.toDefaultEntry=function(){return this.defaultType()},n.defaultType=function(){this.error("toEntry: unknown type",this.type)},e}(et),at=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),ot=function(t){function e(e){var n;n=t.call(this,e.config)||this;var r=e.schema,i=e.name,s=e.key,a=e.value,o=e.config;n.opts=e,n.schema=r,n.key=s,n.value=a||{},n.config=o||{},n.name=i;var u=Array.isArray(a)?"array":a.type;return n.kind="array"===u?"multi":"single",n.type=u,n.setTypeHandlers(),n.setPropertyHandler(),n}u(e,t);var n=e.prototype;return n.setPropertyHandler=function(){var t=this.config;this.propertyValueHandler=(t.createPropertyValueHandler||this.createPropertyValueHandler)({type:this.type,kind:this.kind,types:this.types,value:this.value,name:this.name,key:this.key,schema:this.schema},t)},n.createPropertyValueHandler=function(t,e){return it(t,e)},n.setTypeHandlers=function(){this.types=o({},this.defaultTypeHandlerMap,this.config.typeHandlers||{})},n.isValidSchema=function(){return this.isStringType(this.type)},n.error=function(t,e){var n,r,i=this.opts;throw e?(n=console).error.apply(n,[t,e].concat(i)):(r=console).error.apply(r,[t].concat(i)),new at(t)},n.toEntry=function(){if(!this.isValidSchema()){var t=JSON.stringify(this.schema);this.error("Not a valid schema: type "+this.type+" must be a string, was "+typeof this.type+" "+t)}return this.propertyValueHandler.resolve(this.opts,this.config)},a(e,[{key:"defaultTypeHandlerMap",get:function(){return{string:J,number:B,boolean:I,array:P,object:K,date:X}}}]),e}(w);function ut(t){return void 0===t&&(t={}),new ot(t).toEntry()}function ct(t,e){return void 0===e&&(e={}),new ft(t,e).yupSchema}function ht(t){return t===Object(t)}var ft=function(t){function n(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).init(e,n),r}u(n,t);var r=n.prototype;return r.init=function(t,n){n.buildYup=ct,n.createYupSchemaEntry=n.createYupSchemaEntry||ut,this.config=Object.assign(this.config,n),n.locale&&e.setLocale(n.locale),this.schema=t;var r=this.getType(t),i=this.getProps(t);if(this.type=r,this.properties=i,this.additionalProps=this.getAdditionalProperties(t),this.required=this.getRequired(t),("function"==typeof n.init?n.init:function(){}).bind(this)(t,n),function(t){return t&&"object"===t}(r))if(ht(i)){var s=this.getName(t),a=this.normalizeRequired(t),o=this.propsToShape({properties:a,name:s,config:n});this.shapeConfig=o,this.validSchema=!0}else{var u=JSON.stringify(a);this.error("invalid schema: must have a properties object: "+u)}else this.error('invalid schema: must be type: "object", was type: '+r)},r.getAdditionalProperties=function(t){return t.additionalProperties},r.getRequired=function(t){var e=this.config.getRequired;return e?e(t):t.required||[]},r.getProps=function(t){return this.config.getProps(t)},r.getType=function(t){return this.config.getType(t)},r.getName=function(t){return this.config.getName(t)},r.normalizeRequired=function(){var t=this,e=o({},this.properties),n=[].concat(this.required)||[];return Object.keys(e).reduce(function(r,i){var s=e[i],a=n.indexOf(i)>=0;return ht(s)?s.required=t.isRequired(s)||a:t.warn("Bad value: "+s+" must be an object"),r[i]=s,r},{})},r.isRequired=function(t){return this.config.isRequired(t)},r.propsToShape=function(t){void 0===t&&(t={});var e=this.objPropsToShape(t);return this.objPropsShape=e,this.addPropsShape=this.additionalPropsToShape(t,e),e},r.additionalPropsToShape=function(t,e){return e},r.objPropsToShape=function(t){var e=this,n=t.name,r=o({},this.properties);return Object.keys(r).reduce(function(t,i){var s=e.propToYupSchemaEntry({name:n,key:i,value:r[i]});return e.logInfo("propsToShape",{key:i,yupSchemaEntry:s}),t[i]=s,t},{})},r.propToYupSchemaEntry=function(t){var e=t.value;return this.createYupSchemaEntry({schema:this.schema,name:t.name,key:t.key,value:void 0===e?{}:e,config:this.config})},r.createYupSchemaEntry=function(t){var e=t.config;return e.createYupSchemaEntry({schema:t.schema,name:t.name,key:t.key,value:t.value,config:e})},a(n,[{key:"yupSchema",get:function(){return e.object().shape(this.shapeConfig)}}]),n}(w),lt={alphanumeric:{optsKey:"locale"},alpha:{optsKey:"locale"},ascii:{},byte:{},creditCard:{},currency:{opts:"currencyOpts"},dataUri:{},dateTime:{},date:{},domainName:{opts:"domainOpts"},hash:{opts:"hashAlgo"},hexColor:{},ipv4:{},ipv6:{},isbn:{},magnetUri:{},mimeType:{},mobilePhone:{},mongoId:{},postalCode:{},uuid:{}},pt={createValidatorName:function(t,e){return"is"+(t=(t=i(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")},createTestName:function(t,e){return r(t||e)}},dt={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};exports.ConstraintBuilder=M,exports.ErrorMessageHandler=T,exports.PropertyValueResolver=st,exports.YupBuilder=ft,exports.YupSchemaEntry=ot,exports.YupSchemaEntryError=at,exports.buildYup=ct,exports.createPropertyValueResolver=it,exports.createYupSchemaEntry=ut,exports.extendYupApi=function(t){var n,r=this,i=void 0===t?{}:t,s=i.constraints,a=i.override,u=void 0!==a&&a,c=i.validator,h=i.createValidatorName,f=i.createTestName;if(!c)throw"extendYupApi: missing validator option";Array.isArray(s)&&(void 0===n&&(n={}),s=s.reduce(function(t,e){if("string"!=typeof e&&!(e instanceof Object)){if(!1!==n.throws)throw"toConstraintsMap: invalid entry "+e;return t}if("string"==typeof e)t[name]={};else{if(!e.name){if(!1!==n.throws)throw"toConstraintsMap: invalid entry "+e+" missing name";return t}t[e.name]=e}return t},{})),s=u?s||lt:o({},lt,s||{}),h=h||pt.createValidatorName,f=f||pt.createTestName,Object.keys(s).map(function(t){var n=s[t],i=n.testName,a=n.optsKey,o=n.logging,u=h(n.validatorName,t);i=f(i,t),e.addMethod(e.string,t,function(n){void 0===n&&(n={});var s=n.message,h=n[a];return e.string().test(i,s,function(e){var n=r.path,a=r.createError,f=c[u];if("function"!=typeof(f=f||dt[u]))throw Error("No method named ${validatorName} on validator");var l=f(e,h);return!0===o&&console.log("Yup validator bridge",{key:t,fullValidatorName:u,testName:i,value:e,valid:l}),l||a({path:n,message:s})})})})},exports.types=Z;
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("yup"),n=t(require("uniq")),r=t(require("dashify")),i=t(require("uppercamelcase"));function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function a(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function u(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,h(t,e)}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function h(t,e){return(h=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function l(t,e,n){return(l=f()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var i=new(Function.bind.apply(t,r));return n&&h(i,n.prototype),i}).apply(null,arguments)}function p(t){var e="function"==typeof Map?new Map:void 0;return(p=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return l(t,arguments,c(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),h(n,t)})(t)}var d={getProps:function(t){return t&&t.properties},getType:function(t){return t&&t.type},getName:function(t){return t&&(t.name||t.title)},getConstraints:function(t){return t},isString:function(t){return t&&"string"===t.type},isArray:function(t){return t&&"array"===t.type},isInteger:function(t){return t&&("integer"===t.type||"int"===t.type)},isBoolean:function(t){return t&&"boolean"===t.type},hasDateFormat:function(t){return t&&["date","date-time"].find(function(e){return e===t.format})},isDate:function(t){return t&&"string"===t.type&&d.hasDateFormat(t.format)},isNumber:function(t){return t&&("number"===t.type||d.isInteger(t))},isObject:function(t){return t&&"object"===t.type},isRequired:function(t){return t&&t.required}},y={getProps:function(t){return t.properties},getType:function(t){return t.type},getName:function(t){return t.name||t.title},getConstraints:function(t){return t},isString:function(t){return"string"===t.type&&!y.hasDateFormat(t)},isArray:function(t){return"array"===t.type},isBoolean:function(t){return"boolean"===t.type},isInteger:function(t){return"integer"===t.type},hasDateFormat:function(t){var e;return["date","date-time"].includes(null==t||null==(e=t.value)?void 0:e.format)},isDate:function(t){return"string"===t.type&&y.hasDateFormat(t)},isNumber:function(t){return"number"===t.type||y.isInteger(t)},isObject:function(t){return"object"===t.type},isRequired:function(t){return t.required}},m={getProps:function(t){return t&&t.fields},getType:function(t){return t&&t.type},getName:function(t){return t&&(t.name||t.title)},getConstraints:function(t){return t},isString:function(t){return t&&"string"===t.type},isArray:function(t){return t&&"array"===t.type},isInteger:function(t){return t&&"int"===t.type},isFloat:function(t){return t&&"float"===t.type},isDouble:function(t){return t&&"double"===t.type},isBoolean:function(t){return t&&"boolean"===t.type},isDate:function(t){return t&&"int"===t.type&&"date"===t.logicalType},isNumber:function(t){return t&&(m.isInteger(t)||m.isFloat(t)||m.isDouble(t))},isObject:function(t){return t&&"record"===t.type},isRequired:function(t){return t&&t.required}},v={"json-schema":d,"type-def":y,avro:m},g=function(t){function e(e){return void 0===e&&(e={}),t.call(this,e)||this}u(e,t);var n=e.prototype;return n.isNothing=function(t){return null==t},n.isPresent=function(t){return!this.isNothing(t)},n.toNumber=function(t){return Number(t)},n.isNumberLike=function(t){return!isNaN(this.toNumber(t))},n.isObjectType=function(t){return t===Object(t)},n.isArrayType=function(t){return Array.isArray(t)},n.isNumberType=function(t){return!isNaN(t)},n.isStringType=function(t){return"string"==typeof t},n.isFunctionType=function(t){return"function"==typeof t},n.isDateType=function(t){return t instanceof Date},e}(function(){function t(t){void 0===t&&(t={}),this.config=t;var e=t.log,n=t.error;this.enable=t.enable||{},this.log="function"==typeof e?e:console.log,this.err="function"==typeof n?n:console.error}var e=t.prototype;return e.error=function(t,e){if(!1!==this.enable.error)throw this.err&&(e?this.err(t,e):this.err(t)),t},e.warn=function(t,e){this.enable.warn&&this.logInfo("WARNING: "+t,e)},e.logInfo=function(t,e){this.enable.log&&this.log&&(e?this.log(t,e):this.log(t))},t}()),b=function(){function t(t,e){this.schemaParserMap=t,this.name=e}var e=t.prototype;return e.lookup=function(t){return void 0===t&&(t=this.name),this.schemaParserMap[t]},e.build=function(){var t=this.lookup();if(t.extends){var e=this.extend(t.extends);if(e)return e}return t},e.extend=function(t){var e=this.lookup(t);e&&(entry=o({},e,this.lookup()))},t}(),w=function(t){function e(e){var n;void 0===e&&(e={}),n=t.call(this,e)||this;var r,i,s=(e.createSchemaParserBuilder||(r=e.schemaParserMap||v,i=e.schemaType||"json-schema",new b(r,i))).build();return n.config=o({},s,e),n}return u(e,t),e.prototype.createSchemaParserBuilder=function(t,e){return new SchemaParserBuilder(t,e)},e}(g);function C(t){return t===Object(t)}var k=function(){function t(t,e){void 0===e&&(e={}),this.whenEntryObj=t;var n=e.properties,r=e.config,i=e.key,s=e.when,a=e.type;this.schema=e.schema,this.when=s,this.properties=n||{},this.key=i,this.type=a,this.config=r}var e=t.prototype;return e.validateAndConfigure=function(t){if(!C(t=t||this.whenEntryObj))return this.warn("invalid or missing when entry constraint object",t),!1;var e=Object.keys(t);return e.length<2?(this.warn("validateAndConfigure: when entry constraint must have at least 2 keys: "+e,t),!1):this.hasKey(e,"is")?!!this.hasKey(e,"then")||(this.warn("validateAndConfigure: when entry constraint missing 'then' or 'else' constraint: "+e,t),!1):(this.warn("validateAndConfigure: when entry constraint missing 'is' constraint: "+e,t),!1)},e.createYupSchemaEntry=function(t){return this.config.createYupSchemaEntry(t)},e.createValue=function(t,e){var n;return"string"==typeof t&&((n={})[t]=!0,t=n),C(t)||this.error("createValue: "+e+" must be a schema object"),o({key:this.key,type:this.type},t)},e.createEntryOpts=function(t,e){var n=this.createValue(t,e);return{schema:this.schema,properties:this.properties,key:this.key,type:this.type,value:n,config:this.config}},e.createEntry=function(t,e){var n=this.createEntryOpts(t,e);return this.createYupSchemaEntry(n)},e.hasKey=function(t,e){return t.find(function(t){return t===e})},e.hasAnyKey=function(t,e){return t.find(function(t){return e.includes(t)})},e.whenEntryFor=function(t,e,n){var r;if(n=n||e,"string"==typeof t&&((r={})[t]=!0,t=r),!C(t))throw"whenEntryFor: Invalid when object "+t;var i=o({},t[n]);return delete t[n],i?(t[e]=this.createEntry(i,e),t):t},e.calcEntryObj=function(){var t=o({},this.whenEntryObj);return"otherwise"in(t=this.whenEntryFor(t,"then"))&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t},e.warn=function(t,e){console.error("[WhenEntry] WARNING",t,e)},e.error=function(t,e){throw console.error("[WhenEntry] ERROR",t,e),t},a(t,[{key:"entryObj",get:function(){return this.validateAndConfigure()&&this.calcEntryObj()}}]),t}();function E(t){return t===Object(t)}var O=function(){function t(t){void 0===t&&(t={});var e=t.type,n=t.key,r=t.value,i=t.when,s=t.schema,a=t.properties,o=t.config;this.opts=t,this.when=i,this.key=n,this.type=e,this.value=r,this.schema=s,this.properties=a,this.config=o,this.validate()}var e=t.prototype;return e.validate=function(){"string"!=typeof this.type&&this.error("validate: invalid or mising type: "+this.type,this.opts),E(this.when)||this.error("validate: invalid or mising when: "+this.when,this.opts)},e.validateAndConfigure=function(t){if(!E(t=t||this.when))return this.warn("invalid or missing when constraint",t),!1;var e=Object.keys(t);return e.length<1?(this.warn("when constraint must have at least 1 key: "+e,t),!1):(this.whenKeys=e,!0)},e.createWhenEntry=function(t,e){return function(t,e){return void 0===e&&(e={}),new k(t,e)}(t,e)},e.accumulate=function(t,e){var n=this.when[e];if(!E(n))return this.warn("invalid when entry constraint object "+n+" for "+e),t;var r=this.createWhenEntry(n,{type:this.type,key:this.key,schema:this.schema,properties:this.properties,config:this.config}).entryObj;return r?t=Object.assign(t,r):t},e.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},e.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},a(t,[{key:"constraintObj",get:function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}}},{key:"keyVal",get:function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t}},{key:"constraintValue",get:function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]}},{key:"constraint",get:function(){return this.validateAndConfigure()&&this.constraintValue}}]),t}(),N=function(t){return new O(t)},M=function(t){function e(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).typeHandler=e,r.constraintsAdded={},r.delegators.map(function(t){r[t]=e[t]}),r}u(e,t);var n=e.prototype;return n.build=function(t,e){void 0===e&&(e={});var n=e.constraintName,r=e.constraintValue,i=e.method,s=e.yup,a=e.value,o=e.values,u=e.errName;if(s=s||this.base,this.isNothing(r=r||e.propValue||this.constraints[t]))return this.warn("no prop value"),!1;n=n||t;var c=this.aliasMap[i=i||n]||i;if(!s[c])return this.warn("Yup has no such API method: "+c),!1;for(var h,f=s[c].bind(s),l=this.valErrMessage(n),p=u&&this.valErrMessage(u),d={constraintName:n,yup:s,constraintFn:f,errFn:l||p},y=0,m=["multiValueConstraint","presentConstraintValue","nonPresentConstraintValue"];y<m.length&&!(h=this[m[y]](a||o,d));y++);return h?(this.base=h,h):(this.warn("buildConstraint: missing value or values options"),!1)},n.nonPresentConstraintValue=function(t,e){var n=e.constraintName,r=e.constraintFn,i=e.errFn;if(!this.isPresent(t))return this.onConstraintAdded({name:n}),r(i)},n.presentConstraintValue=function(t,e){var n=e.constraintName,r=e.constraintFn,i=e.errFn;if(this.isPresent(t))return this.onConstraintAdded({name:n,value:t}),this.isNoValueConstraint(n)?r(i):r(t,i)},n.multiValueConstraint=function(t,e){var n=e.constraintFn,r=e.constraintName,i=e.errFn;if(this.isPresent(t)){if(Array.isArray(t))return this.onConstraintAdded({name:r,value:t}),this.callConstraintFn(n,r,t,i);this.warn("buildConstraint: values option must be an array of arguments")}},n.callConstraintFn=function(t,e,n,r){return this.isMultiArgsCall(e)?t.apply(void 0,n.concat([r])):t(n,r)},n.isMultiArgsCall=function(t){return this.multiArgsValidatorMethods[t]},n.isNoValueConstraint=function(t){return this.noValueConstraints.includes(t)},n.addValueConstraint=function(t,e){var n=void 0===e?{}:e;return this.addConstraint(t,{constraintName:n.constraintName,value:!0,errName:n.errName})},n.addConstraint=function(t,e){var n=this.build(t,e);return!!n&&(this.typeHandler.base=n,n)},n.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this.typeHandler},n.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},a(e,[{key:"delegators",get:function(){return["errMessages","base","key","constraints","errorMessageHandler"]}},{key:"multiArgsValidatorMethods",get:function(){return this.config.multiArgsValidatorMethods||{when:!0}}},{key:"noValueConstraints",get:function(){return["required","email","url","format"]}},{key:"constraintsMap",get:function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}},{key:"aliasMap",get:function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}}}]),e}(g),T=function(t){function e(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).typeHandler=e,r.constraints=e.constraints,r.errMessages=e.errMessages,r.key=e.key,r.type=e.type,r}u(e,t);var n=e.prototype;return n.valErrMessage=function(t){var e=this.constraints,n=this.errMessageFor(t);return"function"==typeof n?n(e):n},n.errMessageFor=function(t){var e=this.errMessages,n=e[this.key];return n?n[t]:e["$"+t]},e}(g),x=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),S=function(t){function r(n){var r;void 0===n&&(n={}),r=t.call(this,n.config)||this;var i=n.schema,s=n.key,a=n.value,o=n.config;return o=o||{},i=i||{},r.validateOnCreate(s,a,n),r.yup=e,r.key=s,r.schema=i,r.properties=i.properties||{},r.value=a,r.constraints=r.getConstraints(),r.format=a.format||r.constraints.format,r.config=o||{},r.type="mixed",r.mixedConfig=r.config.mixedEnabled||{},r.typeConfig=r.config[r.type]||{},r.base=e.mixed(),r.errMessages=o.errMessages||{},r.configureTypeConfig(),r.constraintsAdded={},r}u(r,t);var i=r.prototype;return i.configureTypeConfig=function(){this.typeConfig.enabled||this.typeConfig.extends||this.typeConfig.convert&&(this.typeConfig.extends=Object.keys(this.typeConfig.convert))},i.isRequired=function(t){return!0===(t=t||this.value).required},i.disabledMode=function(t){var e=this.mode[t];return!!this.disableFlags.find(function(t){return e===t})},i.enabledMode=function(t){var e=this.mode[t];return!!this.enableFlags.find(function(t){return e===t})},i.preProcessedConstraintValue=function(t){return this.shouldPreProcessValue?this.isRequired(t)?t:o({},t,{notRequired:!0}):t},i.initHelpers=function(){var t=this.config;this.errorMessageHandler=(this.config.createErrorMessageHandler||this.createErrorMessageHandler)(this,t),this.constraintBuilder=(this.config.createConstraintBuilder||this.createConstraintBuilder)(this,t),this.rebind("addConstraint","addValueConstraint")},i.createConstraintBuilder=function(t,e){return void 0===e&&(e={}),new M(t,e)},i.createErrorMessageHandler=function(t,e){return void 0===e&&(e={}),new T(t,e)},i.rebind=function(){var t=this;[].slice.call(arguments).map(function(e){var n=t[e];t[e]=t.isFunctionType(n)?n.bind(t):n})},i.validateOnCreate=function(t,e,n){t||this.error("create: missing key "+JSON.stringify(n)),e||this.error("create: missing value "+JSON.stringify(n))},i.convertEnabled=function(){var t=this;this.enabled.map(function(e){var n=t.convertFnFor(e);n&&n(t)})},i.convertFnFor=function(t){return this.customConvertFnFor(t,this)||this.builtInConvertFnFor(t)},i.customConvertFnFor=function(t){return(this.typeConfig.convert||{})[t]},i.builtInConvertFnFor=function(t){return this[t].bind(this)},i.getConstraints=function(){return this.config.getConstraints(this.value)},i.createSchemaEntry=function(){return this.convert().base},i.convert=function(){return this.initHelpers(),this.addMappedConstraints(),this.convertEnabled(),this},i.addValueConstraint=function(t,e){var n=this.constraintBuilder.addValueConstraint(t,e);return n&&(this.base=n.base),this},i.addConstraint=function(t,e){if(!this.constraintBuilder)throw new Error("[YupMixed] addConstraint: Missing constraintBuilder in "+this.constructor.name);var n=this.constraintBuilder.addConstraint(t,e);return n&&(this.base=n),this},i.addMappedConstraints=function(){var t=Object.keys(this.constraintsMap),e=this.addMappedConstraint.bind(this);return t.map(e),this},i.addMappedConstraint=function(t){var e=this["value"===t?"addValueConstraint":"addConstraint"];this.constraintsMap[t].map(function(t){e(t)})},i.oneOf=function(){var t=this,e=this.constraints.enum||this.constraints.oneOf||this.constraints.anyOf;if(this.isNothing(e))return this;e=Array.isArray(e)?e:[e];var n=["oneOf","enum","anyOf"].find(function(e){return void 0!==t.constraints[e]});return this.addConstraint(n,{values:e})},i.notOneOf=function(){var t=this.constraints,e=t.not,n=t.notOneOf||e&&(e.enum||e.oneOf);return this.isNothing(n)?this:(n=Array.isArray(n)?n:[n],this.addConstraint("notOneOf",{values:n}))},i.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},i.createWhenConditionFor=function(t){return(this.config.createWhenCondition||N)({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})},i.label=function(){var t=this.value,e=t.title||t.label;return this.base=e&&this.base.label(e)||this.base,this},i.when=function(){var t,e=this.constraints.when;if((t=e)!==Object(t))return this;var n=this.createWhenConditionFor(e).constraint;return n?(this.logInfo("Adding when constraint for "+this.key,n),this.addConstraint("when",{values:n,errName:"when"}),this):(this.warn("Invalid when constraint for: "+e),this)},i.isType=function(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this},i.nullable=function(){var t=this.constraints;return this.addConstraint("nullable",{value:t.nullable||t.isNullable,errName:"notOneOf"}),this},i.message=function(){return config.messages[this.key]||config.messages[this.type]||{}},i.errMessage=function(t){return void 0===t&&(t="default"),this.message[t]||"error"},i.toValidJSONSchema=function(){},i.normalize=function(){},i.deNormalize=function(){},i.errorMsg=function(t){this.throwError(t)},i.error=function(t,e){var n=["["+t+"]",e].join(" ");this.errorMsg(n)},i.throwError=function(t){throw t},a(r,[{key:"mode",get:function(){return this.config.mode||{}}},{key:"disableFlags",get:function(){return[!1,"disabled","no","off"]}},{key:"enableFlags",get:function(){return[!0,"enabled","yes","on"]}},{key:"shouldPreProcessValue",get:function(){return!this.disabledMode("notRequired")}},{key:"value",get:function(){return this._value},set:function(t){this._value=this.preProcessedConstraintValue(t)}},{key:"mixedEnabled",get:function(){return this.mixedConfig.enabled||["oneOf","notOneOf","when","nullable","isType","label"]}},{key:"typeEnabled",get:function(){return[]}},{key:"$typeExtends",get:function(){if(Array.isArray(this.typeConfig.extends))return n([].concat(this.typeConfig.extends,this.typeEnabled))}},{key:"configuredTypeEnabled",get:function(){return Array.isArray(this.typeConfig.enabled)?this.typeConfig.enabled:this.typeEnabled}},{key:"$typeEnabled",get:function(){return this.$typeExtends||this.configuredTypeEnabled}},{key:"enabled",get:function(){return[].concat(this.mixedEnabled,this.$typeEnabled)}},{key:"constraintsMap",get:function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}}]),r}(w),j=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],A={errMessages:function(t){return void 0===t&&(t=j),t.reduce(function(t,e){return t[e]=function(t){var e=t.value;return t.key+": invalid for "+(e.name||e.title)},t},{})}},V=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="array",n.base=n.yup.array(),n.createYupSchemaEntry=n.config.createYupSchemaEntry,n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.ensureItems=function(){return this.addConstraint("ensure")},n.compact=function(){return this.addConstraint("compact")},n.itemsOf=function(){var t=this.constraints,e=t.items||t.itemsOf||this.constraints.of;if(!this.isNothing(e))if(Array.isArray(e))this.error("itemsOf","does not (yet) support an Array of schemas");else if(this.isObjectType(e)){if(this.createYupSchemaEntry){try{var n=this.createYupSchemaEntry({key:this.key,value:e,config:this.config});return this.addConstraint("of",{constraintValue:n,propValue:e})}catch(t){this.error("itemsOf: Error",t)}return this}this.warn("missing createYupSchemaEntry in config, needed for recursive validation")}else this.error("itemsOf","must be a schema object, was "+typeof e)},n.maxItems=function(){var t=this.constraints,e=t.maxItems||t.max;if(!this.isNumberType(e))return this;if(!this.isValidSize(e))return this.handleInvalidSize("maxItems",e);var n=e&&this.base.max(e);return this.base=n||this.base,this},n.minItems=function(){var t=this.constraints,e=t.minItems||t.min;if(!this.isNumberType(e))return this;if(!this.isValidSize(e))return this.handleInvalidSize("minItems",e);var n=e&&this.base.min(e);return this.base=n||this.base,this},n.$items=function(){return this},n.$additionalItems=function(){return this},n.$uniqueItems=function(){return this},n.$contains=function(){return this},n.handleInvalidSize=function(t,e){var n="invalid array size constraint for "+t+", was "+e+". Must be a number >= 0";return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},n.isValidSize=function(t){return this.isNumberType(t)&&t>=0},a(e,[{key:"typeEnabled",get:function(){return["maxItems","minItems","ensureItems","compact","itemsOf"]}}]),e}(S),F=function(t){function e(e){return t.call(this,e)||this}u(e,t);var n=e.prototype;return n.isArray=function(t){return this.config.isArray||this.error("ArrayHandler: mising isArray in config",this.config),this.config.isArray(t)},n.handle=function(t){return this.isArray(t)&&V.create(t).createSchemaEntry()},e}(w);function P(t,e){return void 0===e&&(e={}),t&&new F(e).handle(t)}var R=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="boolean",n.base=n.yup.boolean(),n}return u(e,t),e.create=function(t){return new e(t)},e}(S),D=function(){function t(t){this.config=t}var e=t.prototype;return e.isBoolean=function(t){return this.config.isBoolean(t)},e.handle=function(t){return this.isBoolean(t)&&R.create(t).createSchemaEntry()},t}();function I(t,e){return void 0===e&&(e={}),t&&new D(e).handle(t)}var Y=function(t){function e(e){return t.call(this,e)||this}return u(e,t),a(e,[{key:"$map",get:function(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}}}]),e}(function(t){function e(e){return t.call(this,e)||this}u(e,t);var n=e.prototype;return n.transform=function(t){return this.typer.toNumber(t)},n.isValidConstraint=function(t){return this.typer.isNumberLike(t)},a(e,[{key:"explainConstraintValidMsg",get:function(){return"Must be a number or convertible to a number"}}]),e}(function(t){function e(e,n){var r;return(r=t.call(this,e.config)||this).map=n||r.$map||{},r.typer=e,r.delegates.map(function(t){var n=e[t];n||r.error("missing delegate: "+t,{typer:e}),r[t]=r.isFunctionType(n)?n.bind(e):n}),r}u(e,t);var n=e.prototype;return n.isStringType=function(t){return"string"==typeof t},n.add=function(){var t=this,e=this.map;Object.keys(e).map(function(n){var r=t.entryNames(e[n]);t.addConstraints(n,r)})},n.entryNames=function(t){return Array.isArray(t)?t:[t]},n.addConstraints=function(t,e){var n=this;return void 0===e&&(e=[]),e.map(function(e){var r=n.validateAndTransform(e);n.addConstraint(e,{method:t,value:r})}),this},n.validateAndTransform=function(t){var e=this.constraints[t];return this.validate(e),this.transform(e)},n.invalidMsg=function(t,e){return"invalid constraint for "+t+", was "+e+"."},n.invalidConstraintMsg=function(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")},n.validate=function(t){return this.isNothing(t)?this:this.isValidConstraint(t)?void 0:this.handleInvalidConstraint(name,t)},n.isValidConstraint=function(t){return!0},n.handleInvalidConstraint=function(t,e){var n=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},a(e,[{key:"delegates",get:function(){return["constraints","addConstraint","constraintsAdded"]}},{key:"explainConstraintValidMsg",get:function(){return""}}]),e}(g))),q=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.isValid=function(){return this.config.isNumber(this.obj)},e}(function(t){function e(e,n){var r;return(r=t.call(this,n)||this).obj=e,r}u(e,t);var n=e.prototype;return n.isValid=function(){return!1},n.verify=function(){return this.isPresent(this.obj)&&this.isValid(this.obj)},e}(w)),H=function(t,e){return void 0===e&&(e={}),function(t,e){return new q(t,e)}(t,e).verify()};function B(t,e){return void 0===e&&(e={}),H(t,e)&&function(t){return z.schemaEntryFor(t)}(t)}var z=function(t){function e(e){var n,r;return(n=t.call(this,e)||this).type=n.normalizeNumType(e.type),n.base=n.yup.number(),n.rangeConstraint=(r=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n),new Y(r)),n}u(e,t);var n=e.prototype;return n.normalizeNumType=function(t){return"int"===t?"integer":t},e.create=function(t){return new e(t)},e.schemaEntryFor=function(t){return e.create(t).createSchemaEntry()},n.convert=function(){return t.prototype.convert.call(this),this},n.range=function(){this.rangeConstraint.add()},n.truncate=function(){return this.addConstraint("truncate")},n.round=function(){var t=this.constraints.round;if(this.isNothing(t))return this;var e=this.isStringType(t)?t:"round";return t&&this.base.round(e),this},n.posNeg=function(){this.positive(),this.negative()},n.integer=function(){return this.isInteger&&this.addConstraint("integer"),this},n.positive=function(){return this.addConstraint("positive")},n.negative=function(){return this.addConstraint("negative")},n.normalize=function(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min},a(e,[{key:"typeEnabled",get:function(){return["range","posNeg","integer"]}},{key:"isInteger",get:function(){return this.config.isInteger(this.type)}},{key:"isNegative",get:function(){var t=this.constraints,e=t.exclusiveMaximum;return!!t.negative||void 0!==e&&0===e}},{key:"isPositive",get:function(){var t=this.constraints,e=t.exclusiveMinimum;return!!t.positive||void 0!==e&&0===e}}]),e}(S),L=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="object",n.base=n.yup.object(),n.properties=n.value.properties,n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){if(!this.properties)return this;t.prototype.convert.call(this);var e=this.value,n=this.config;if(e){n.buildYup||this.error("convert","Missing buildYup function from config",n);var r=this.config.buildYup(e,n);this.base=r}return this},n.camelCase=function(){return this.addConstraint("camelCase")},n.constantCase=function(){return this.addConstraint("constantCase")},n.noUnknown=function(){var t=this.value,e=t.noUnknown||t.propertyNames,n=e&&this.base.noUnknown(e,this.valErrMessage("propertyNames")||this.valErrMessage("noUnknown"));return this.base=n||this.base,this},a(e,[{key:"typeEnabled",get:function(){return["noUnknown","camelCase","constantCase"]}}]),e}(S),$=function(t){return t&&"object"===t.type},_=function(){function t(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||$,this.config=t,this.schema=t.schema}var e=t.prototype;return e.isObject=function(t){return this.config.isObject(t.value)},e.handle=function(t){return this.isObject(t)&&L.create(o({},t,{config:this.config})).createSchemaEntry()},t}();function K(t,e){return void 0===e&&(e={}),t&&new _(e).handle(t)}var U=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="string",n.base=n.yup.string(),n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.trim=function(){return this.addConstraint("trim")},n.lowercase=function(){return this.addConstraint("lowercase")},n.uppercase=function(){return this.addConstraint("uppercase")},n.genericFormat=function(){1!=!this.config.format&&this.yup.prototype[this.format]&&this.addConstraint(this.format)},n.email=function(){if(!this.isEmail)return this;var t=this.constraintNameFor("email","format");return this.addConstraint("email",{constraintValue:!0,constraintName:t,method:"email",errName:"email"}),this},n.constraintNameFor=function(){var t=this;return[].slice.call(arguments).find(function(e){return t.constraints[e]})},n.url=function(){if(!this.isUrl)return this;var t=this.constraintNameFor("url","format");return this.addConstraint("url",{constraintValue:!0,constraintName:t,method:"url",errName:"url"}),this},n.minLength=function(){var t=this.constraints.minLength,e=this.valErrMessage("minLength")||this.valErrMessage("min"),n=t&&this.base.min(t,e);return this.base=n||this.base,this},n.maxLength=function(){var t=this.constraints.maxLength,e=this.valErrMessage("maxLength")||this.valErrMessage("max"),n=t&&this.base.max(t,e);return this.base=n||this.base,this},n.pattern=function(){var t=this.constraints,e=t.pattern;if(!e)return this;var n=new RegExp(e,t.flags),r=this.valErrMessage("pattern")||this.valErrMessage("matches")||this.valErrMessage("regex"),i=n&&this.base.matches(n,r);return this.base=i||this.base,this},n.normalize=function(){this.constraints.pattern=this.constraints.pattern||this.constraints.matches||this.constraints.regex,this.constraints.maxLength=this.constraints.maxLength||this.constraints.max,this.constraints.minLength=this.constraints.minLength||this.constraints.min},a(e,[{key:"typeEnabled",get:function(){return["normalize","minLength","maxLength","pattern","lowercase","uppercase","email","url","genericFormat"]}},{key:"isEmail",get:function(){return this.constraints.email||"email"===this.format}},{key:"isUrl",get:function(){return this.constraints.url||"url"===this.format}}]),e}(S),W=function(){function t(t){this.config=t}var e=t.prototype;return e.isString=function(t){return this.config.isString(t)},e.handle=function(t){return this.isString(t)&&U.create(o({config:this.config},t)).createSchemaEntry()},t}();function J(t,e){return void 0===e&&(e={}),t&&new W(e).handle(t)}var G=function(t){function e(e){var n;return(n=t.call(this,e)||this).type="date",n.base=n.yup.date(),n}u(e,t),e.create=function(t){return new e(t)};var n=e.prototype;return n.convert=function(){return t.prototype.convert.call(this),this},n.toDate=function(t){return new Date(t)},n.isValidDateType=function(t){return this.isStringType(t)||this.isDateType(t)},n.isValidDate=function(t){return!!this.isValidDateType(t)&&(!this.isStringType(t)||Boolean(Date.parse(t)))},n.transformToDate=function(t){return this.isNumberType(t)?new Date(t):t},n.minDate=function(){var t=this.constraints.minDate||this.constraints.min;if(this.isNothing(t))return this;var e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("minDate",e);var n=e&&this.base.min(this.toDate(e),this.valErrMessage("minDate")||this.valErrMessage("min"));return this.base=n||this.base,this},n.maxDate=function(){var t=this.constraints.maxDate||this.constraints.max;if(this.isNothing(t))return this;var e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("maxDate",e);var n=e&&this.base.max(this.toDate(e),this.valErrMessage("maxDate")||this.valErrMessage("max"));return this.base=n||this.base,this},n.handleInvalidDate=function(t,e){var n="invalid constraint for "+t+", was "+e+". Must be a number, string (valid date format) or a Date instance";return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},a(e,[{key:"typeEnabled",get:function(){return["minDate","maxDate"]}}]),e}(S),Q=function(){function t(t){this.config=t}var e=t.prototype;return e.isDate=function(t){return this.config.isDate(t)},e.handle=function(t){return this.isDate(t)&&G.create(t).createSchemaEntry()},t}();function X(t,e){return void 0===e&&(e={}),t&&new Q(e).handle(t)}var Z={__proto__:null,errValKeys:j,defaults:A,YupArray:V,toYupArray:P,YupBoolean:R,toYupBoolean:I,YupNumber:z,toYupNumberSchemaEntry:B,toYupNumber:function(t,e){return void 0===e&&(e={}),H(t,e)&&function(t){return z.create(t)}(t)},YupObject:L,toYupObject:K,YupString:U,toYupString:J,YupDate:G,toYupDate:X,YupMixed:S,ConvertYupSchemaError:x,Base:w},tt=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),et=function(t){function e(e,n){var r;r=t.call(this,n)||this;var i=e.value,s=e.type,a=e.kind,o=e.name,u=e.key,c=e.schema,h=e.types;return r.opts=e,r.kind=a,r.value=i,r.schema=c,r.key=u,r.value=i||{},r.name=o,r.type=s,r.types=h,r}u(e,t);var n=e.prototype;return n.error=function(t,e){var n,r,i=this.opts;throw e?(n=console).error.apply(n,[t,e].concat(i)):(r=console).error.apply(r,[t].concat(i)),new tt(t)},n.resolve=function(){throw"Must be implemented by subclass"},a(e,[{key:"obj",get:function(){return{schema:this.schema,key:this.key,value:this.value,type:this.type,kind:this.kind,config:this.config}}}]),e}(w),nt=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.resolve=function(){if(Array.isArray(this.value)){var t=this.config.toMultiType;return t?t(this):void 0}},e}(et),rt=function(t){function e(e,n){return t.call(this,e,n)||this}return u(e,t),e.prototype.resolve=function(){if(!Array.isArray(this.value)){var t=this.config.toSingleType;if(t)return t(this);for(var e,n=this.obj,r=this.config,i=0,s=Object.keys(this.types);i<s.length;i++){var a=this.types[s[i]];if(a&&(e=a(n,r)),e)break}return e}},e}(et),it=function(t,e){return new st(t,e)},st=function(t){function e(e,n){var r;return(r=t.call(this,e,n)||this).initResolvers(),r}u(e,t);var n=e.prototype;return n.initResolvers=function(){var t=this.opts,e=this.config,n=e.createMultiTypeResolver||this.createMultiTypeResolver.bind(this);this.multiTypeResolver=n(t,e);var r=e.createSingleTypeResolver||this.createSingleTypeResolver.bind(this);this.singleTypeResolver=r(t,e)},n.createMultiTypeResolver=function(){return new nt(this.opts,this.config)},n.createSingleTypeResolver=function(){return new rt(this.opts,this.config)},n.resolve=function(){return this.toMultiType()||this.toSingleType()||this.toDefaultEntry()},n.toMultiType=function(){return(this.config.toMultiType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)},n.toSingleType=function(){return(this.config.toSingleType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)},n.toDefaultEntry=function(){return this.defaultType()},n.defaultType=function(){this.error("toEntry: unknown type",this.type)},e}(et),at=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e}(p(Error)),ot=function(t){function e(e){var n;n=t.call(this,e.config)||this;var r=e.schema,i=e.name,s=e.key,a=e.value,o=e.config;n.opts=e,n.schema=r,n.key=s,n.value=a||{},n.config=o||{},n.name=i;var u=Array.isArray(a)?"array":a.type;return n.kind="array"===u?"multi":"single",n.type=u,n.setTypeHandlers(),n.setPropertyHandler(),n}u(e,t);var n=e.prototype;return n.setPropertyHandler=function(){var t=this.config;this.propertyValueHandler=(t.createPropertyValueHandler||this.createPropertyValueHandler)({type:this.type,kind:this.kind,types:this.types,value:this.value,name:this.name,key:this.key,schema:this.schema},t)},n.createPropertyValueHandler=function(t,e){return it(t,e)},n.setTypeHandlers=function(){this.types=o({},this.defaultTypeHandlerMap,this.config.typeHandlers||{})},n.isValidSchema=function(){return this.isStringType(this.type)},n.error=function(t,e){var n,r,i=this.opts;throw e?(n=console).error.apply(n,[t,e].concat(i)):(r=console).error.apply(r,[t].concat(i)),new at(t)},n.toEntry=function(){if(!this.isValidSchema()){var t=JSON.stringify(this.schema);this.error("Not a valid schema: type "+this.type+" must be a string, was "+typeof this.type+" "+t)}return this.propertyValueHandler.resolve(this.opts,this.config)},a(e,[{key:"defaultTypeHandlerMap",get:function(){return{string:J,number:B,boolean:I,array:P,object:K,date:X}}}]),e}(w);function ut(t){return void 0===t&&(t={}),new ot(t).toEntry()}function ct(t,e){return void 0===e&&(e={}),new ft(t,e).yupSchema}function ht(t){return t===Object(t)}var ft=function(t){function n(e,n){var r;return void 0===n&&(n={}),(r=t.call(this,n)||this).init(e,n),r}u(n,t);var r=n.prototype;return r.init=function(t,n){n.buildYup=ct,n.createYupSchemaEntry=n.createYupSchemaEntry||ut,this.config=Object.assign(this.config,n),n.locale&&e.setLocale(n.locale),this.schema=t;var r=this.getType(t),i=this.getProps(t);if(this.type=r,this.properties=i,this.additionalProps=this.getAdditionalProperties(t),this.required=this.getRequired(t),("function"==typeof n.init?n.init:function(){}).bind(this)(t,n),function(t){return t&&"object"===t}(r))if(ht(i)){var s=this.getName(t),a=this.normalizeRequired(t),o=this.propsToShape({properties:a,name:s,config:n});this.shapeConfig=o,this.validSchema=!0}else{var u=JSON.stringify(a);this.error("invalid schema: must have a properties object: "+u)}else this.error('invalid schema: must be type: "object", was type: '+r)},r.getAdditionalProperties=function(t){return t.additionalProperties},r.getRequired=function(t){var e=this.config.getRequired;return e?e(t):t.required||[]},r.getProps=function(t){return this.config.getProps(t)},r.getType=function(t){return this.config.getType(t)},r.getName=function(t){return this.config.getName(t)},r.normalizeRequired=function(){var t=this,e=o({},this.properties),n=[].concat(this.required)||[];return Object.keys(e).reduce(function(r,i){var s=e[i],a=n.indexOf(i)>=0;return ht(s)?s.required=t.isRequired(s)||a:t.warn("Bad value: "+s+" must be an object"),r[i]=s,r},{})},r.isRequired=function(t){return this.config.isRequired(t)},r.propsToShape=function(t){void 0===t&&(t={});var e=this.objPropsToShape(t);return this.objPropsShape=e,this.addPropsShape=this.additionalPropsToShape(t,e),e},r.additionalPropsToShape=function(t,e){return e},r.objPropsToShape=function(t){var e=this,n=t.name,r=o({},this.properties);return Object.keys(r).reduce(function(t,i){var s=e.propToYupSchemaEntry({name:n,key:i,value:r[i]});return e.logInfo("propsToShape",{key:i,yupSchemaEntry:s}),t[i]=s,t},{})},r.propToYupSchemaEntry=function(t){var e=t.value;return this.createYupSchemaEntry({schema:this.schema,name:t.name,key:t.key,value:void 0===e?{}:e,config:this.config})},r.createYupSchemaEntry=function(t){var e=t.config;return e.createYupSchemaEntry({schema:t.schema,name:t.name,key:t.key,value:t.value,config:e})},a(n,[{key:"yupSchema",get:function(){return e.object().shape(this.shapeConfig)}}]),n}(w),lt={alphanumeric:{optsKey:"locale"},alpha:{optsKey:"locale"},ascii:{},byte:{},creditCard:{},currency:{opts:"currencyOpts"},dataUri:{},dateTime:{},date:{},domainName:{opts:"domainOpts"},hash:{opts:"hashAlgo"},hexColor:{},ipv4:{},ipv6:{},isbn:{},magnetUri:{},mimeType:{},mobilePhone:{},mongoId:{},postalCode:{},uuid:{}},pt={createValidatorName:function(t,e){return"is"+(t=(t=i(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")},createTestName:function(t,e){return r(t||e)}},dt={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};exports.ConstraintBuilder=M,exports.ErrorMessageHandler=T,exports.PropertyValueResolver=st,exports.YupBuilder=ft,exports.YupSchemaEntry=ot,exports.YupSchemaEntryError=at,exports.buildYup=ct,exports.createPropertyValueResolver=it,exports.createYupSchemaEntry=ut,exports.extendYupApi=function(t){var n,r=this,i=void 0===t?{}:t,s=i.constraints,a=i.override,u=void 0!==a&&a,c=i.validator,h=i.createValidatorName,f=i.createTestName;if(!c)throw"extendYupApi: missing validator option";Array.isArray(s)&&(void 0===n&&(n={}),s=s.reduce(function(t,e){if("string"!=typeof e&&!(e instanceof Object)){if(!1!==n.throws)throw"toConstraintsMap: invalid entry "+e;return t}if("string"==typeof e)t[name]={};else{if(!e.name){if(!1!==n.throws)throw"toConstraintsMap: invalid entry "+e+" missing name";return t}t[e.name]=e}return t},{})),s=u?s||lt:o({},lt,s||{}),h=h||pt.createValidatorName,f=f||pt.createTestName,Object.keys(s).map(function(t){var n=s[t],i=n.testName,a=n.optsKey,o=n.logging,u=h(n.validatorName,t);i=f(i,t),e.addMethod(e.string,t,function(n){void 0===n&&(n={});var s=n.message,h=n[a];return e.string().test(i,s,function(e){var n=r.path,a=r.createError,f=c[u];if("function"!=typeof(f=f||dt[u]))throw Error("No method named ${validatorName} on validator");var l=f(e,h);return!0===o&&console.log("Yup validator bridge",{key:t,fullValidatorName:u,testName:i,value:e,valid:l}),l||a({path:n,message:s})})})})},exports.types=Z;
//# sourceMappingURL=index.js.map
{
"name": "schema-to-yup",
"version": "1.10.8",
"version": "1.10.9",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

@@ -392,3 +392,3 @@ # Schema to Yup schema

You can also add custom custraint handler functions directly via the `config` object as follows:
You can add custom custraint handler functions directly via the `config` object.
This can be used to override built in constraints or extend with your own.

@@ -450,2 +450,31 @@

You can use this approach to add base level entry handlers via `mixed` which is the base handler for any specific type handler such as for `string` and `number`.
Here we are replacing the `label` handler with our custom handler implementation which uses `description` if available.
```js
const mixed = {
enabled: [
"oneOf",
"notOneOf",
"when",
"nullable",
"isType",
// "label", not enabled
// custom
"my-custom-label" // enabled
},
convert: {
"my-custom-label": (typeInst) =>
const value = typeInst.value;
const label = value.title || value.label || value.description;
typeInst.base = (label && this.base.label(label)) || this.base;
return typeInst;
}
}
}
const yupSchema = buildYup(jsonSchema, { mixedEnabled }
```
### Custom constraint builder

@@ -819,3 +848,3 @@

````js
```js
const mySchemaParserMap = {

@@ -840,3 +869,3 @@ "my-schema": {

const schema = buildYup(nameJsonSchema, { log: true });
````
```

@@ -1246,1 +1275,5 @@ You can also pass a log function in the `log` option to handle log messages and an `err` option with a custom error handler function.

MIT
```
```

@@ -31,3 +31,3 @@ import * as yup from "yup";

this.type = "mixed";
this.mixedConfig = this.config.mixed || {};
this.mixedConfig = this.config.mixedEnabled || {};
this.typeConfig = this.config[this.type] || {};

@@ -145,3 +145,4 @@ this.base = yup.mixed();

"nullable",
"isType"
"isType",
"label"
]

@@ -185,3 +186,3 @@ );

convertFnFor(name) {
return this.customConvertFnFor(name) || this.builtInConvertFnFor(name);
return this.customConvertFnFor(name, this) || this.builtInConvertFnFor(name);
}

@@ -304,2 +305,9 @@

label() {
const value = this.value
const label = value.title || value.label
this.base = (label && this.base.label(label)) || this.base
return this
}
when() {

@@ -306,0 +314,0 @@ const when = this.constraints.when;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc