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

schema-to-yup - npm Package Compare versions

Comparing version 1.9.18 to 1.9.19

src/constraint-builder.js

2

dist/index.js

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

function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=t(require("dashify")),n=t(require("uppercamelcase")),r=require("yup"),i={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&&i.hasDateFormat(t.format)},isNumber:function(t){return t&&("number"===t.type||i.isInteger(t))},isObject:function(t){return t&&"object"===t.type},isRequired:function(t){return t&&t.required}},o={"json-schema":i,"type-def":{getProps:function(t){return t&&t.fields},getType:function(t){return t&&t.type},getName:function(t){return t&&t.name},getConstraints:function(t){return t&&(t.directives||{}).constraints||{}},isString:function(t){return t&&"String"===t.type},isArray:function(t){return t&&t.isList},isInteger:function(t){return t&&"Int"===t.type},isBoolean:function(t){return t&&"Boolean"===t.type},isDate:function(t){return t&&"Date"===t.type||t.directives.date},isNumber:function(t){return t&&"Int"===t.type||"Float"===t.type},isObject:function(t){return t&&"Object"===t.type},isRequired:function(t){return t&&!t.isNullable}}},s=function(t){void 0===t&&(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};s.prototype.error=function(t,e){if(!1!==this.enable.error)throw this.err&&(e?this.err(t,e):this.err(t)),t},s.prototype.warn=function(t,e){this.enable.warn&&this.logInfo("WARNING: "+t,e)},s.prototype.logInfo=function(t,e){this.enable.log&&this.log&&(e?this.log(t,e):this.log(t))};var a=function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isNothing=function(t){return null==t},e.prototype.isPresent=function(t){return!this.isNothing(t)},e.prototype.toNumber=function(t){return Number(t)},e.prototype.isNumberLike=function(t){return!isNaN(this.toNumber(t))},e.prototype.isObjectType=function(t){return t===Object(t)},e.prototype.isNumberType=function(t){return!isNaN(t)},e.prototype.isStringType=function(t){return"string"==typeof t},e.prototype.isFunctionType=function(t){return"function"==typeof t},e.prototype.isDateType=function(t){return t instanceof Date},e}(s),u=function(t){function e(e){void 0===e&&(e={}),t.call(this,e),this.config=Object.assign({},o[e.schemaType||"json-schema"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(a);function c(t){return t===Object(t)}var p=function(t,e){void 0===e&&(e={}),this.whenEntryObj=t;var n=e.properties,r=e.config,i=e.key,o=e.when,s=e.type;this.schema=e.schema,this.when=o,this.properties=n||{},this.key=i,this.type=s,this.config=r},h={entryObj:{configurable:!0}};function f(t){return t===Object(t)}p.prototype.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)},p.prototype.createYupSchemaEntry=function(t){return this.config.createYupSchemaEntry(t)},p.prototype.createValue=function(t,e){return"string"==typeof t&&((t={})[t]=!0),c(t)||this.error("createValue: "+e+" must be a schema object"),Object.assign({},{key:this.key,type:this.type},t)},p.prototype.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}},p.prototype.createEntry=function(t,e){var n=this.createEntryOpts(t,e);return this.createYupSchemaEntry(n)},p.prototype.hasKey=function(t,e){return t.find(function(t){return t===e})},p.prototype.hasAnyKey=function(t,e){return t.find(function(t){return e.includes(t)})},p.prototype.whenEntryFor=function(t,e,n){if(n=n||e,"string"==typeof t&&((t={})[t]=!0),!c(t))throw"whenEntryFor: Invalid when object "+t;var r=Object.assign({},t[n]);return delete t[n],r?(t[e]=this.createEntry(r,e),t):t},p.prototype.calcEntryObj=function(){var t=Object.assign({},this.whenEntryObj);return"otherwise"in(t=this.whenEntryFor(t,"then"))&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t},h.entryObj.get=function(){return this.validateAndConfigure()&&this.calcEntryObj()},p.prototype.warn=function(t,e){console.error("[WhenEntry] WARNING",t,e)},p.prototype.error=function(t,e){throw console.error("[WhenEntry] ERROR",t,e),t},Object.defineProperties(p.prototype,h);var l=function(t){void 0===t&&(t={});var e=t.type,n=t.key,r=t.value,i=t.when,o=t.schema,s=t.properties,a=t.config;this.opts=t,this.when=i,this.key=n,this.type=e,this.value=r,this.schema=o,this.properties=s,this.config=a,this.validate()},y={constraintObj:{configurable:!0},keyVal:{configurable:!0},constraintValue:{configurable:!0},constraint:{configurable:!0}};l.prototype.validate=function(){"string"!=typeof this.type&&this.error("validate: invalid or mising type: "+this.type,this.opts),f(this.when)||this.error("validate: invalid or mising when: "+this.when,this.opts)},l.prototype.validateAndConfigure=function(t){if(!f(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)},l.prototype.createWhenEntry=function(t,e){return function(e,n){return void 0===n&&(n={}),new p(t,n)}(0,e)},l.prototype.accumulate=function(t,e){var n=this.when[e];if(!f(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},y.constraintObj.get=function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}},y.keyVal.get=function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t},y.constraintValue.get=function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]},y.constraint.get=function(){return this.validateAndConfigure()&&this.constraintValue},l.prototype.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},l.prototype.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},Object.defineProperties(l.prototype,y);var d=function(t){function e(e,n){var r=this;void 0===n&&(n={}),t.call(this,n),this.typeHandler=e,this.constraintsAdded={},this.delegators.map(function(t){r[t]=e[t]})}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={delegators:{configurable:!0},noValueConstraints:{configurable:!0},constraintsMap:{configurable:!0},aliasMap:{configurable:!0}};return n.delegators.get=function(){return["errMessages","base","key","constraints","errorMessageHandler"]},e.prototype.build=function(t,e){void 0===e&&(e={});var n=e.constraintName,r=e.constraintValue,i=e.method,o=e.yup,s=e.values,a=e.errName;if(o=o||this.base,this.isNothing(r=r||e.propValue||this.constraints[t]))return this.warn("no prop value"),o;n=n||t;var u=this.aliasMap[i=i||n]||i;if(!o[u])return this.warn("Yup has no such API method: "+u),this;var c=o[u].bind(o),p=this.valErrMessage(n),h=a&&this.valErrMessage(a),f={constraintName:n,yup:o,constraintFn:c,errFn:p||h};return this.multiValueConstraint(s,f)||this.presentConstraintValue(r,f)||this.nonPresentConstraintValue(r,f)||(this.warn("buildConstraint: missing value or values options"),o)},e.prototype.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)},e.prototype.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)},e.prototype.multiValueConstraint=function(t,e){var n=e.constraintFn,r=e.constraintName,i=e.yup,o=e.errFn;if(this.isPresent(t))return Array.isArray(t)?(this.onConstraintAdded({name:r,value:t}),n.apply(void 0,t.concat([o]))):(this.warn("buildConstraint: values option must be an array of arguments"),i)},e.prototype.isNoValueConstraint=function(t){return this.noValueConstraints.includes(t)},n.noValueConstraints.get=function(){return["required","email","url","format"]},e.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.addConstraint(t,{constraintName:e.constraintName,value:!0,errName:e.errName})},e.prototype.addConstraint=function(t,e){var n=this.build(t,e);return this.base=n||this.base,this.typeHandler},e.prototype.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this.typeHandler},n.constraintsMap.get=function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}},e.prototype.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},n.aliasMap.get=function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}},Object.defineProperties(e.prototype,n),e}(a),m=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),this.typeHandler=e,this.constraints=e.constraints,this.errMessages=e.errMessages,this.key=e.key,this.type=e.type}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.valErrMessage=function(t){var e=this.constraints,n=this.errMessageFor(t);return"function"==typeof n?n(e):n},e.prototype.errMessageFor=function(t){var e=this.errMessages,n=e[this.key];return n?n[t]:e["$"+t]},e}(a),g=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),v=function(t){function e(e){void 0===e&&(e={}),t.call(this,e.config);var n=e.schema,i=e.key,o=e.value,s=e.config;s=s||{},n=n||{},this.validateOnCreate(i,o,e),this.yup=r,this.key=i,this.schema=n,this.properties=n.properties||{},this.value=o,this.constraints=this.getConstraints(),this.format=o.format||this.constraints.format,this.config=s||{},this.type="mixed",this.base=r.mixed(),this.errMessages=s.errMessages||{},this.constraintsAdded={}}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={mode:{configurable:!0},disableFlags:{configurable:!0},enableFlags:{configurable:!0},shouldPreProcessValue:{configurable:!0},value:{configurable:!0},enabled:{configurable:!0},aliasMap:{configurable:!0},constraintsMap:{configurable:!0}};return e.prototype.isRequired=function(t){return!0===(t=t||this.value).required},n.mode.get=function(){return this.config.mode||{}},n.disableFlags.get=function(){return[!1,"disabled","no","off"]},n.enableFlags.get=function(){return[!0,"enabled","yes","on"]},e.prototype.disabledMode=function(t){var e=this.mode[t];return!!this.disableFlags.find(function(t){return e===t})},e.prototype.enabledMode=function(t){var e=this.mode[t];return!!this.enableFlags.find(function(t){return e===t})},n.shouldPreProcessValue.get=function(){return!this.disabledMode("notRequired")},e.prototype.preProcessedConstraintValue=function(t){return this.shouldPreProcessValue?this.isRequired(t)?t:Object.assign({},t,{notRequired:!0}):t},n.value.set=function(t){this._value=this.preProcessedConstraintValue(t)},n.value.get=function(){return this._value},e.prototype.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")},e.prototype.createConstraintBuilder=function(t,e){return void 0===e&&(e={}),new d(t,e)},e.prototype.createErrorMessageHandler=function(t,e){return void 0===e&&(e={}),new m(t,e)},e.prototype.rebind=function(){for(var t=this,e=[],n=arguments.length;n--;)e[n]=arguments[n];e.map(function(e){var n=t[e];t[e]=t.isFunctionType(n)?n.bind(t):n})},e.prototype.validateOnCreate=function(t,e,n){t||this.error("create: missing key "+JSON.stringify(n)),e||this.error("create: missing value "+JSON.stringify(n))},n.enabled.get=function(){},e.prototype.convertEnabled=function(){var t=this;this.enabled.map(function(e){t[e]&&t[e]()})},e.prototype.getConstraints=function(){return this.config.getConstraints(this.value)},e.prototype.createSchemaEntry=function(){return this.convert().base},e.prototype.convert=function(){return this.initHelpers(),this.addMappedConstraints(),this.oneOf().notOneOf(),this.when(),this.nullable().isType(),this},e.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.constraintBuilder.addConstraint(t,{constraintName:e.constraintName,value:!0,errName:e.errName})},n.aliasMap.get=function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}},e.prototype.buildConstraint=function(t,e){return void 0===e&&(e={}),this.constraintBuilder.build(t,e)},e.prototype.addConstraint=function(t,e){var n=this.buildConstraint(t,e);return this.base=n||this.base,this},e.prototype.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this},e.prototype.addMappedConstraints=function(){var t=this,e=this.constraintsMap;return Object.keys(e).map(function(n){var r=t["value"===n?"addValueConstraint":"addConstraint"];e[n].map(function(t){r(t)})}),this},n.constraintsMap.get=function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}},e.prototype.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 t.constraints[e]});return this.addConstraint(n,{values:e})},e.prototype.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}))},e.prototype.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},e.prototype.createWhenConditionFor=function(t){return(this.config.createWhenCondition||function(t){return new l(t)})({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})},e.prototype.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)},e.prototype.isType=function(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this},e.prototype.nullable=function(){var t=this.constraints;return this.addConstraint("nullable",{value:t.nullable||t.isNullable,errName:"notOneOf"}),this},e.prototype.$const=function(){return this},e.prototype.$allOf=function(){return this},e.prototype.$anyOf=function(){return this},e.prototype.$oneOf=function(){return this},e.prototype.$if=function(){return this},e.prototype.$then=function(){return this},e.prototype.$else=function(){return this},e.prototype.message=function(){return config.messages[this.key]||config.messages[this.type]||{}},e.prototype.errMessage=function(t){return void 0===t&&(t="default"),this.message[t]||"error"},e.prototype.toValidJSONSchema=function(){},e.prototype.normalize=function(){},e.prototype.deNormalize=function(){},e.prototype.errorMsg=function(t){this.throwError(t)},e.prototype.error=function(t,e){var n=["["+t+"]",e].join(" ");this.errorMsg(n)},e.prototype.throwError=function(t){throw t},Object.defineProperties(e.prototype,n),e}(u),b=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],O={errMessages:function(t){return void 0===t&&(t=b),t.reduce(function(t,e){return t[e]=function(t){var e=t.value;return t.key+": invalid for "+(e.name||e.title)},t},{})}},w=function(t){function e(e){t.call(this,e),this.type="array",this.base=this.yup.array(),this.createYupSchemaEntry=this.config.createYupSchemaEntry}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.create=function(t){return new e(t)},e.prototype.convert=function(){return this.maxItems(),this.minItems(),this.ensureItems(),this.compact(),this.itemsOf(),t.prototype.convert.call(this),this},e.prototype.ensureItems=function(){return this.addConstraint("ensure")},e.prototype.compact=function(){return this.addConstraint("compact")},e.prototype.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)},e.prototype.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},e.prototype.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},e.prototype.$items=function(){return this},e.prototype.$additionalItems=function(){return this},e.prototype.$uniqueItems=function(){return this},e.prototype.$contains=function(){return this},e.prototype.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)},e.prototype.isValidSize=function(t){return this.isNumberType(t)&&t>=0},e}(v),j=function(t){function e(e){t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isArray=function(t){return this.config.isArray||this.error("ArrayHandler: mising isArray in config",this.config),this.config.isArray(t)},e.prototype.handle=function(t){return this.isArray(t)&&w.create(t).createSchemaEntry()},e}(u);function C(t,e){return void 0===e&&(e={}),t&&new j(e).handle(t)}var N=function(t){function e(e){t.call(this,e),this.type="boolean",this.base=this.yup.boolean()}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.create=function(t){return new e(t)},e}(v),E=function(t){this.config=t};function _(t,e){return void 0===e&&(e={}),t&&new E(e).handle(t)}E.prototype.isBoolean=function(t){return this.config.isBoolean(t)},E.prototype.handle=function(t){return this.isBoolean(t)&&N.create(t).createSchemaEntry()};var M=function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={$map:{configurable:!0}};return n.$map.get=function(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}},Object.defineProperties(e.prototype,n),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={explainConstraintValidMsg:{configurable:!0}};return e.prototype.transform=function(t){return this.typer.toNumber(t)},e.prototype.isValidConstraint=function(t){return this.typer.isNumberLike(t)},n.explainConstraintValidMsg.get=function(){return"Must be a number or convertible to a number"},Object.defineProperties(e.prototype,n),e}(function(t){function e(e,n){var r=this;t.call(this,e.config),this.map=n||this.$map||{},this.typer=e,this.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})}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={delegates:{configurable:!0},explainConstraintValidMsg:{configurable:!0}};return e.prototype.isStringType=function(t){return"string"==typeof t},n.delegates.get=function(){return["constraints","addConstraint","constraintsAdded"]},e.prototype.add=function(){var t=this,e=this.map;Object.keys(e).map(function(n){var r=t.entryNames(e[n]);t.addConstraints(n,r)})},e.prototype.entryNames=function(t){return Array.isArray(t)?t:[t]},e.prototype.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},e.prototype.validateAndTransform=function(t){var e=this.constraints[t];return this.validate(e),this.transform(e)},e.prototype.invalidMsg=function(t,e){return"invalid constraint for "+t+", was "+e+"."},n.explainConstraintValidMsg.get=function(){return""},e.prototype.invalidConstraintMsg=function(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")},e.prototype.validate=function(t){return this.isNothing(t)?this:this.isValidConstraint(t)?void 0:this.handleInvalidConstraint(name,t)},e.prototype.isValidConstraint=function(t){return!0},e.prototype.handleInvalidConstraint=function(t,e){var n=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},Object.defineProperties(e.prototype,n),e}(a))),x=function(t){function e(e,n){t.call(this,e,n)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isValid=function(){return this.config.isNumber(this.obj)},e}(function(t){function e(e,n){t.call(this,n),this.obj=e}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isValid=function(){return!1},e.prototype.verify=function(){return this.isPresent(this.obj)&&this.isValid(this.obj)},e}(u)),S=function(t,e){return void 0===e&&(e={}),function(t,e){return new x(t,e)}(t,e).verify()};function V(t,e){return void 0===e&&(e={}),S(t,e)&&function(t){return T.schemaEntryFor(t)}(t)}var T=function(t){function e(e){t.call(this,e),this.type=this.normalizeNumType(e.type),this.base=this.yup.number(),this.range=new M(this)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={enabled:{configurable:!0},isInteger:{configurable:!0},isNegative:{configurable:!0},isPositive:{configurable:!0}};return e.prototype.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.enabled.get=function(){return["range","posNeg","integer"]},e.prototype.convert=function(){var e=this;return this.enabled.map(function(t){return e.processConstraint(t)}),t.prototype.convert.call(this),this},e.prototype.processConstraint=function(t){var e=this[t];e&&"function"==typeof e?e.bind(this)():e.add()},e.prototype.truncate=function(){return this.addConstraint("truncate")},e.prototype.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},e.prototype.posNeg=function(){this.positive(),this.negative()},e.prototype.integer=function(){return this.isInteger&&this.addConstraint("integer"),this},n.isInteger.get=function(){return this.config.isInteger(this.type)},e.prototype.positive=function(){return this.addConstraint("positive")},e.prototype.negative=function(){return this.addConstraint("negative")},n.isNegative.get=function(){var t=this.constraints,e=t.exclusiveMaximum;return!!t.negative||void 0!==e&&0===e},n.isPositive.get=function(){var t=this.constraints,e=t.exclusiveMinimum;return!!t.positive||void 0!==e&&0===e},e.prototype.normalize=function(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min},Object.defineProperties(e.prototype,n),e}(v),k=function(t){function e(e){t.call(this,e),this.type="object",this.base=this.yup.object(),this.properties=this.value.properties}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.create=function(t){return new e(t)},e.prototype.convert=function(){if(!this.properties)return this;this.noUnknown(),this.camelCase().constantCase();var t=this.value,e=this.config;if(t){e.buildYup||this.error("convert","Missing buildYup function from config",e);var n=this.config.buildYup(t,e);this.base=n}return this},e.prototype.camelCase=function(){return this.addConstraint("camelCase")},e.prototype.constantCase=function(){return this.addConstraint("constantCase")},e.prototype.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},e}(v),A=function(t){return t&&"object"===t.type},I=function(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||A,this.config=t,this.schema=t.schema};function D(t,e){return void 0===e&&(e={}),t&&new I(e).handle(t)}I.prototype.isObject=function(t){return this.config.isObject(t.value)},I.prototype.handle=function(t){return this.isObject(t)&&k.create(Object.assign({},t,{config:this.config})).createSchemaEntry()};var Y=function(t){function e(e){t.call(this,e),this.type="string",this.base=this.yup.string()}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={isEmail:{configurable:!0},isUrl:{configurable:!0}};return e.create=function(t){return new e(t)},e.prototype.convert=function(){return t.prototype.convert.call(this),this.normalize(),this.minLength().maxLength().pattern(),this.lowercase(),this.uppercase(),this.email(),this.url(),this.genericFormat(),this},e.prototype.trim=function(){return this.addConstraint("trim")},e.prototype.lowercase=function(){return this.addConstraint("lowercase")},e.prototype.uppercase=function(){return this.addConstraint("uppercase")},e.prototype.genericFormat=function(){1!=!this.config.format&&this.yup.prototype[this.format]&&this.addConstraint(this.format)},e.prototype.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},e.prototype.constraintNameFor=function(){for(var t=this,e=[],n=arguments.length;n--;)e[n]=arguments[n];return e.find(function(e){return t.constraints[e]})},n.isEmail.get=function(){return this.constraints.email||"email"===this.format},e.prototype.url=function(){if(!this.isUrl)return this;var t=this.constraintNameFor("url","format");return this.addConstraint("email",{constraintValue:!0,constraintName:t,method:"url",errName:"url"}),this},n.isUrl.get=function(){return this.constraints.url||"url"===this.format},e.prototype.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},e.prototype.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},e.prototype.pattern=function(){var t=this.constraints.pattern;if(!t)return this;var e=new RegExp(t),n=this.valErrMessage("pattern")||this.valErrMessage("matches")||this.valErrMessage("regex"),r=e&&this.base.matches(e,n);return this.base=r||this.base,this},e.prototype.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},Object.defineProperties(e.prototype,n),e}(v),F=function(t){this.config=t};function P(t,e){return void 0===e&&(e={}),t&&new F(e).handle(t)}F.prototype.isString=function(t){return this.config.isString(t)},F.prototype.handle=function(t){return this.isString(t)&&Y.create(Object.assign({},{config:this.config},t)).createSchemaEntry()};var q=function(t){function e(e){t.call(this,e),this.type="date",this.base=this.yup.date()}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.create=function(t){return new e(t)},e.prototype.convert=function(){return this.minDate().maxDate(),t.prototype.convert.call(this),this},e.prototype.toDate=function(t){return new Date(t)},e.prototype.isValidDateType=function(t){return this.isStringType(t)||this.isDateType(t)},e.prototype.isValidDate=function(t){return!!this.isValidDateType(t)&&(!this.isStringType(t)||Boolean(Date.parse(t)))},e.prototype.transformToDate=function(t){return this.isNumberType(t)?new Date(t):t},e.prototype.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},e.prototype.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},e.prototype.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)},e}(v),R=function(t){this.config=t};function H(t,e){return void 0===e&&(e={}),t&&new R(e).handle(t)}R.prototype.isDate=function(t){return this.config.isDate(t)},R.prototype.handle=function(t){return this.isDate(t)&&q.create(t).createSchemaEntry()};var z={errValKeys:b,defaults:O,YupArray:w,toYupArray:C,YupBoolean:N,toYupBoolean:_,YupNumber:T,toYupNumberSchemaEntry:V,toYupNumber:function(t,e){return void 0===e&&(e={}),S(t,e)&&function(t){return T.create(t)}(t)},YupObject:k,toYupObject:D,YupString:Y,toYupString:P,YupDate:q,toYupDate:H,YupMixed:v,ConvertYupSchemaError:g,Base:u},B=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),$=function(t){function e(e){var n=e.schema,r=e.name,i=e.key,o=e.value,s=e.config;t.call(this,s),this.schema=n,this.key=i,this.value=o||{},this.config=s||{},this.name=r,this.type=o.type,this.setTypeHandlers()}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={defaultTypeHandlerMap:{configurable:!0},obj:{configurable:!0}};return n.defaultTypeHandlerMap.get=function(){return{string:P,number:V,boolean:_,array:C,object:D,date:H}},e.prototype.setTypeHandlers=function(){this.types=Object.assign({},this.defaultTypeHandlerMap,this.config.typeHandlers||{})},e.prototype.isValidSchema=function(){return"string"==typeof this.type},e.prototype.error=function(t){throw new B(t)},e.prototype.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)}for(var e=this.obj,n=this.config,r=0,i=Object.keys(this.types);r<i.length;r+=1){var o=(0,this.types[i[r]])(e,n);if(o)return o}return this.defaultType(n)},e.prototype.defaultType=function(t){this.error("toEntry: unknown type",t)},n.obj.get=function(){return{schema:this.schema,key:this.key,value:this.value,type:this.type,config:this.config}},Object.defineProperties(e.prototype,n),e}(u);function L(t){return void 0===t&&(t={}),new $(t).toEntry()}var U={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:{}},K={createValidatorName:function(t,e){return"is"+(t=(t=n(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")},createTestName:function(t,n){return e(t||n)}},W={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};function J(t,e){return void 0===e&&(e={}),new Q(t,e).yupSchema}function G(t){return t===Object(t)}var Q=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),n.buildYup=J,n.createYupSchemaEntry=n.createYupSchemaEntry||L,this.config=Object.assign(this.config,n),this.schema=e;var r=this.getType(e),i=this.getProps(e);if(this.type=r,this.properties=i,this.required=this.getRequired(e),function(t){return t&&"object"===t}(r))if(G(i)){var o=this.getName(e),s=this.normalizeRequired(e),a=this.propsToShape({properties:s,name:o,config:n});this.shapeConfig=a,this.validSchema=!0}else{var u=JSON.stringify(s);this.error("invalid schema: must have a properties object: "+u)}else this.error('invalid schema: must be type: "object", was type: '+r)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={yupSchema:{configurable:!0}};return e.prototype.getRequired=function(t){var e=this.config.getRequired;return e?e(t):t.required||[]},e.prototype.getProps=function(t){return this.config.getProps(t)},e.prototype.getType=function(t){return this.config.getType(t)},e.prototype.getName=function(t){return this.config.getName(t)},n.yupSchema.get=function(){return r.object().shape(this.shapeConfig)},e.prototype.normalizeRequired=function(){var t=this,e=Object.assign({},this.properties),n=[].concat(this.required)||[];return Object.keys(e).reduce(function(r,i){var o=e[i],s=n.indexOf(i)>=0;return G(o)?o.required=t.isRequired(o)||s:t.warn("Bad value: "+o+" must be an object"),r[i]=o,r},{})},e.prototype.isRequired=function(t){return this.config.isRequired(t)},e.prototype.propsToShape=function(t){var e=this,n=t.name,r=Object.assign({},this.properties);return Object.keys(r).reduce(function(t,i){var o=e.propToYupSchemaEntry({name:n,key:i,value:r[i]});return e.logInfo("propsToShape",{key:i,yupSchemaEntry:o}),t[i]=o,t},{})},e.prototype.propToYupSchemaEntry=function(t){var e=t.value;return void 0===e&&(e={}),(this.createYupSchemaEntry||this.config.createYupSchemaEntry)({schema:this.schema,name:t.name,key:t.key,value:e,config:this.config})},e.prototype.createYupSchemaEntry=function(t){var e=t.config;return e.createYupSchemaEntry({schema:t.schema,name:t.name,key:t.key,value:t.value,config:e})},Object.defineProperties(e.prototype,n),e}(u);exports.buildYup=J,exports.YupBuilder=Q,exports.YupSchemaEntry=$,exports.YupSchemaEntryError=B,exports.types=z,exports.createYupSchemaEntry=L,exports.extendYupApi=function(t){var e=this;void 0===t&&(t={});var n=t.constraints,i=t.override;void 0===i&&(i=!1);var o,s=t.validator,a=t.createValidatorName,u=t.createTestName;if(!s)throw"extendYupApi: missing validator option";Array.isArray(n)&&(void 0===o&&(o={}),n=n.reduce(function(t,e){if("string"!=typeof e&&!(e instanceof Object)){if(!1!==o.throws)throw"toConstraintsMap: invalid entry "+e;return t}if("string"==typeof e)t[name]={};else{if(!e.name){if(!1!==o.throws)throw"toConstraintsMap: invalid entry "+e+" missing name";return t}t[e.name]=e}return t},{})),n=i?n||U:Object.assign({},U,n||{}),a=a||K.createValidatorName,u=u||K.createTestName,Object.keys(n).map(function(t){var i=n[t],o=i.testName,c=i.optsKey,p=i.logging,h=a(i.validatorName,t);o=u(o,t),r.addMethod(r.string,t,function(n){void 0===n&&(n={});var i=n.message,a=n[c];return r.string().test(o,i,function(n){var r=e.path,u=e.createError,c=s[h];if("function"!=typeof(c=c||W[h]))throw Error("No method named ${validatorName} on validator");var f=c(n,a);return!0===p&&console.log("Yup validator bridge",{key:t,fullValidatorName:h,testName:o,value:n,valid:f}),f||u({path:r,message:i})})})})};
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=t(require("uniq")),n=t(require("dashify")),r=t(require("uppercamelcase")),i=require("yup"),o={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&&o.hasDateFormat(t.format)},isNumber:function(t){return t&&("number"===t.type||o.isInteger(t))},isObject:function(t){return t&&"object"===t.type},isRequired:function(t){return t&&t.required}},s={"json-schema":o,"type-def":{getProps:function(t){return t&&t.fields},getType:function(t){return t&&t.type},getName:function(t){return t&&t.name},getConstraints:function(t){return t&&(t.directives||{}).constraints||{}},isString:function(t){return t&&"String"===t.type},isArray:function(t){return t&&t.isList},isInteger:function(t){return t&&"Int"===t.type},isBoolean:function(t){return t&&"Boolean"===t.type},isDate:function(t){return t&&"Date"===t.type||t.directives.date},isNumber:function(t){return t&&"Int"===t.type||"Float"===t.type},isObject:function(t){return t&&"Object"===t.type},isRequired:function(t){return t&&!t.isNullable}}},a=function(t){void 0===t&&(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};a.prototype.error=function(t,e){if(!1!==this.enable.error)throw this.err&&(e?this.err(t,e):this.err(t)),t},a.prototype.warn=function(t,e){this.enable.warn&&this.logInfo("WARNING: "+t,e)},a.prototype.logInfo=function(t,e){this.enable.log&&this.log&&(e?this.log(t,e):this.log(t))};var u=function(t){function e(e){void 0===e&&(e={}),t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isNothing=function(t){return null==t},e.prototype.isPresent=function(t){return!this.isNothing(t)},e.prototype.toNumber=function(t){return Number(t)},e.prototype.isNumberLike=function(t){return!isNaN(this.toNumber(t))},e.prototype.isObjectType=function(t){return t===Object(t)},e.prototype.isNumberType=function(t){return!isNaN(t)},e.prototype.isStringType=function(t){return"string"==typeof t},e.prototype.isFunctionType=function(t){return"function"==typeof t},e.prototype.isDateType=function(t){return t instanceof Date},e}(a),c=function(t){function e(e){void 0===e&&(e={}),t.call(this,e),this.config=Object.assign({},s[e.schemaType||"json-schema"],e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(u);function p(t){return t===Object(t)}var h=function(t,e){void 0===e&&(e={}),this.whenEntryObj=t;var n=e.properties,r=e.config,i=e.key,o=e.when,s=e.type;this.schema=e.schema,this.when=o,this.properties=n||{},this.key=i,this.type=s,this.config=r},f={entryObj:{configurable:!0}};function y(t){return t===Object(t)}h.prototype.validateAndConfigure=function(t){if(!p(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)},h.prototype.createYupSchemaEntry=function(t){return this.config.createYupSchemaEntry(t)},h.prototype.createValue=function(t,e){return"string"==typeof t&&((t={})[t]=!0),p(t)||this.error("createValue: "+e+" must be a schema object"),Object.assign({},{key:this.key,type:this.type},t)},h.prototype.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}},h.prototype.createEntry=function(t,e){var n=this.createEntryOpts(t,e);return this.createYupSchemaEntry(n)},h.prototype.hasKey=function(t,e){return t.find(function(t){return t===e})},h.prototype.hasAnyKey=function(t,e){return t.find(function(t){return e.includes(t)})},h.prototype.whenEntryFor=function(t,e,n){if(n=n||e,"string"==typeof t&&((t={})[t]=!0),!p(t))throw"whenEntryFor: Invalid when object "+t;var r=Object.assign({},t[n]);return delete t[n],r?(t[e]=this.createEntry(r,e),t):t},h.prototype.calcEntryObj=function(){var t=Object.assign({},this.whenEntryObj);return"otherwise"in(t=this.whenEntryFor(t,"then"))&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t},f.entryObj.get=function(){return this.validateAndConfigure()&&this.calcEntryObj()},h.prototype.warn=function(t,e){console.error("[WhenEntry] WARNING",t,e)},h.prototype.error=function(t,e){throw console.error("[WhenEntry] ERROR",t,e),t},Object.defineProperties(h.prototype,f);var l=function(t){void 0===t&&(t={});var e=t.type,n=t.key,r=t.value,i=t.when,o=t.schema,s=t.properties,a=t.config;this.opts=t,this.when=i,this.key=n,this.type=e,this.value=r,this.schema=o,this.properties=s,this.config=a,this.validate()},d={constraintObj:{configurable:!0},keyVal:{configurable:!0},constraintValue:{configurable:!0},constraint:{configurable:!0}};l.prototype.validate=function(){"string"!=typeof this.type&&this.error("validate: invalid or mising type: "+this.type,this.opts),y(this.when)||this.error("validate: invalid or mising when: "+this.when,this.opts)},l.prototype.validateAndConfigure=function(t){if(!y(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)},l.prototype.createWhenEntry=function(t,e){return function(e,n){return void 0===n&&(n={}),new h(t,n)}(0,e)},l.prototype.accumulate=function(t,e){var n=this.when[e];if(!y(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},d.constraintObj.get=function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}},d.keyVal.get=function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t},d.constraintValue.get=function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]},d.constraint.get=function(){return this.validateAndConfigure()&&this.constraintValue},l.prototype.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},l.prototype.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},Object.defineProperties(l.prototype,d);var m=function(t){function e(e,n){var r=this;void 0===n&&(n={}),t.call(this,n),this.typeHandler=e,this.constraintsAdded={},this.delegators.map(function(t){r[t]=e[t]})}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={delegators:{configurable:!0},noValueConstraints:{configurable:!0},constraintsMap:{configurable:!0},aliasMap:{configurable:!0}};return n.delegators.get=function(){return["errMessages","base","key","constraints","errorMessageHandler"]},e.prototype.build=function(t,e){void 0===e&&(e={});var n=e.constraintName,r=e.constraintValue,i=e.method,o=e.yup,s=e.values,a=e.errName;if(o=o||this.base,this.isNothing(r=r||e.propValue||this.constraints[t]))return this.warn("no prop value"),o;n=n||t;var u=this.aliasMap[i=i||n]||i;if(!o[u])return this.warn("Yup has no such API method: "+u),this;var c=o[u].bind(o),p=this.valErrMessage(n),h=a&&this.valErrMessage(a),f={constraintName:n,yup:o,constraintFn:c,errFn:p||h};return this.multiValueConstraint(s,f)||this.presentConstraintValue(r,f)||this.nonPresentConstraintValue(r,f)||(this.warn("buildConstraint: missing value or values options"),o)},e.prototype.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)},e.prototype.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)},e.prototype.multiValueConstraint=function(t,e){var n=e.constraintFn,r=e.constraintName,i=e.yup,o=e.errFn;if(this.isPresent(t))return Array.isArray(t)?(this.onConstraintAdded({name:r,value:t}),n.apply(void 0,t.concat([o]))):(this.warn("buildConstraint: values option must be an array of arguments"),i)},e.prototype.isNoValueConstraint=function(t){return this.noValueConstraints.includes(t)},n.noValueConstraints.get=function(){return["required","email","url","format"]},e.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.addConstraint(t,{constraintName:e.constraintName,value:!0,errName:e.errName})},e.prototype.addConstraint=function(t,e){var n=this.build(t,e);return this.base=n||this.base,this.typeHandler},e.prototype.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this.typeHandler},n.constraintsMap.get=function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}},e.prototype.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},n.aliasMap.get=function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}},Object.defineProperties(e.prototype,n),e}(u),g=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),this.typeHandler=e,this.constraints=e.constraints,this.errMessages=e.errMessages,this.key=e.key,this.type=e.type}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.valErrMessage=function(t){var e=this.constraints,n=this.errMessageFor(t);return"function"==typeof n?n(e):n},e.prototype.errMessageFor=function(t){var e=this.errMessages,n=e[this.key];return n?n[t]:e["$"+t]},e}(u),v=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),b=function(t){function n(e){void 0===e&&(e={}),t.call(this,e.config);var n=e.schema,r=e.key,o=e.value,s=e.config;s=s||{},n=n||{},this.validateOnCreate(r,o,e),this.yup=i,this.key=r,this.schema=n,this.properties=n.properties||{},this.value=o,this.constraints=this.getConstraints(),this.format=o.format||this.constraints.format,this.config=s||{},this.type="mixed",this.mixedConfig=this.config.mixed||{},this.typeConfig=this.config[this.type]||{},this.base=i.mixed(),this.errMessages=s.errMessages||{},this.configureTypeConfig(),this.constraintsAdded={}}t&&(n.__proto__=t),(n.prototype=Object.create(t&&t.prototype)).constructor=n;var r={mode:{configurable:!0},disableFlags:{configurable:!0},enableFlags:{configurable:!0},shouldPreProcessValue:{configurable:!0},value:{configurable:!0},mixedEnabled:{configurable:!0},typeEnabled:{configurable:!0},$typeExtends:{configurable:!0},configuredTypeEnabled:{configurable:!0},$typeEnabled:{configurable:!0},enabled:{configurable:!0},aliasMap:{configurable:!0},constraintsMap:{configurable:!0}};return n.prototype.configureTypeConfig=function(){this.typeConfig.enabled||this.typeConfig.extends||this.typeConfig.convert&&(this.typeConfig.extends=Object.keys(this.typeConfig.convert))},n.prototype.isRequired=function(t){return!0===(t=t||this.value).required},r.mode.get=function(){return this.config.mode||{}},r.disableFlags.get=function(){return[!1,"disabled","no","off"]},r.enableFlags.get=function(){return[!0,"enabled","yes","on"]},n.prototype.disabledMode=function(t){var e=this.mode[t];return!!this.disableFlags.find(function(t){return e===t})},n.prototype.enabledMode=function(t){var e=this.mode[t];return!!this.enableFlags.find(function(t){return e===t})},r.shouldPreProcessValue.get=function(){return!this.disabledMode("notRequired")},n.prototype.preProcessedConstraintValue=function(t){return this.shouldPreProcessValue?this.isRequired(t)?t:Object.assign({},t,{notRequired:!0}):t},r.value.set=function(t){this._value=this.preProcessedConstraintValue(t)},r.value.get=function(){return this._value},n.prototype.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")},n.prototype.createConstraintBuilder=function(t,e){return void 0===e&&(e={}),new m(t,e)},n.prototype.createErrorMessageHandler=function(t,e){return void 0===e&&(e={}),new g(t,e)},n.prototype.rebind=function(){for(var t=this,e=[],n=arguments.length;n--;)e[n]=arguments[n];e.map(function(e){var n=t[e];t[e]=t.isFunctionType(n)?n.bind(t):n})},n.prototype.validateOnCreate=function(t,e,n){t||this.error("create: missing key "+JSON.stringify(n)),e||this.error("create: missing value "+JSON.stringify(n))},r.mixedEnabled.get=function(){return this.mixedConfig.enabled||["oneOf","notOneOf","when","nullable","isType"]},r.typeEnabled.get=function(){return[]},r.$typeExtends.get=function(){if(Array.isArray(this.typeConfig.extends))return e(this.typeConfig.extends.concat(this.typeEnabled))},r.configuredTypeEnabled.get=function(){return Array.isArray(this.typeConfig.enabled)?this.typeConfig.enabled:this.typeEnabled},r.$typeEnabled.get=function(){return this.$typeExtends||this.configuredTypeEnabled},r.enabled.get=function(){return this.mixedEnabled.concat(this.$typeEnabled)},n.prototype.convertEnabled=function(){var t=this;this.enabled.map(function(e){var n=t.convertFnFor(e);n&&n(t)})},n.prototype.convertFnFor=function(t){return this.customConvertFnFor(t)||this.builtInConvertFnFor(t)},n.prototype.customConvertFnFor=function(t){return(this.typeConfig.convert||{})[t]},n.prototype.builtInConvertFnFor=function(t){return this[t].bind(this)},n.prototype.getConstraints=function(){return this.config.getConstraints(this.value)},n.prototype.createSchemaEntry=function(){return this.convert().base},n.prototype.convert=function(){return this.initHelpers(),this.addMappedConstraints(),this.convertEnabled(),this},n.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.constraintBuilder.addConstraint(t,{constraintName:e.constraintName,value:!0,errName:e.errName})},r.aliasMap.get=function(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}},n.prototype.buildConstraint=function(t,e){return void 0===e&&(e={}),this.constraintBuilder.build(t,e)},n.prototype.addConstraint=function(t,e){var n=this.buildConstraint(t,e);return this.base=n||this.base,this},n.prototype.onConstraintAdded=function(t){return this.constraintsAdded[t.name]=t.value,this},n.prototype.addMappedConstraints=function(){var t=Object.keys(this.constraintsMap),e=this.addMappedConstraint.bind(this);return t.map(e),this},n.prototype.addMappedConstraint=function(t){var e=this["value"===t?"addValueConstraint":"addConstraint"];this.constraintsMap[t].map(function(t){e(t)})},r.constraintsMap.get=function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}},n.prototype.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 t.constraints[e]});return this.addConstraint(n,{values:e})},n.prototype.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}))},n.prototype.valErrMessage=function(t){return this.errorMessageHandler.valErrMessage(t)},n.prototype.createWhenConditionFor=function(t){return(this.config.createWhenCondition||function(t){return new l(t)})({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})},n.prototype.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)},n.prototype.isType=function(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this},n.prototype.nullable=function(){var t=this.constraints;return this.addConstraint("nullable",{value:t.nullable||t.isNullable,errName:"notOneOf"}),this},n.prototype.message=function(){return config.messages[this.key]||config.messages[this.type]||{}},n.prototype.errMessage=function(t){return void 0===t&&(t="default"),this.message[t]||"error"},n.prototype.toValidJSONSchema=function(){},n.prototype.normalize=function(){},n.prototype.deNormalize=function(){},n.prototype.errorMsg=function(t){this.throwError(t)},n.prototype.error=function(t,e){var n=["["+t+"]",e].join(" ");this.errorMsg(n)},n.prototype.throwError=function(t){throw t},Object.defineProperties(n.prototype,r),n}(c),O=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],C={errMessages:function(t){return void 0===t&&(t=O),t.reduce(function(t,e){return t[e]=function(t){var e=t.value;return t.key+": invalid for "+(e.name||e.title)},t},{})}},E=function(t){function e(e){t.call(this,e),this.type="array",this.base=this.yup.array(),this.createYupSchemaEntry=this.config.createYupSchemaEntry}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={typeEnabled:{configurable:!0}};return e.create=function(t){return new e(t)},e.prototype.convert=function(){return t.prototype.convert.call(this),this},n.typeEnabled.get=function(){return["maxItems","minItems","ensureItems","compact","itemsOf"]},e.prototype.ensureItems=function(){return this.addConstraint("ensure")},e.prototype.compact=function(){return this.addConstraint("compact")},e.prototype.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)},e.prototype.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},e.prototype.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},e.prototype.$items=function(){return this},e.prototype.$additionalItems=function(){return this},e.prototype.$uniqueItems=function(){return this},e.prototype.$contains=function(){return this},e.prototype.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)},e.prototype.isValidSize=function(t){return this.isNumberType(t)&&t>=0},Object.defineProperties(e.prototype,n),e}(b),w=function(t){function e(e){t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isArray=function(t){return this.config.isArray||this.error("ArrayHandler: mising isArray in config",this.config),this.config.isArray(t)},e.prototype.handle=function(t){return this.isArray(t)&&E.create(t).createSchemaEntry()},e}(c);function j(t,e){return void 0===e&&(e={}),t&&new w(e).handle(t)}var N=function(t){function e(e){t.call(this,e),this.type="boolean",this.base=this.yup.boolean()}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.create=function(t){return new e(t)},e}(b),_=function(t){this.config=t};function M(t,e){return void 0===e&&(e={}),t&&new _(e).handle(t)}_.prototype.isBoolean=function(t){return this.config.isBoolean(t)},_.prototype.handle=function(t){return this.isBoolean(t)&&N.create(t).createSchemaEntry()};var x=function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={$map:{configurable:!0}};return n.$map.get=function(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}},Object.defineProperties(e.prototype,n),e}(function(t){function e(e){t.call(this,e)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={explainConstraintValidMsg:{configurable:!0}};return e.prototype.transform=function(t){return this.typer.toNumber(t)},e.prototype.isValidConstraint=function(t){return this.typer.isNumberLike(t)},n.explainConstraintValidMsg.get=function(){return"Must be a number or convertible to a number"},Object.defineProperties(e.prototype,n),e}(function(t){function e(e,n){var r=this;t.call(this,e.config),this.map=n||this.$map||{},this.typer=e,this.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})}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={delegates:{configurable:!0},explainConstraintValidMsg:{configurable:!0}};return e.prototype.isStringType=function(t){return"string"==typeof t},n.delegates.get=function(){return["constraints","addConstraint","constraintsAdded"]},e.prototype.add=function(){var t=this,e=this.map;Object.keys(e).map(function(n){var r=t.entryNames(e[n]);t.addConstraints(n,r)})},e.prototype.entryNames=function(t){return Array.isArray(t)?t:[t]},e.prototype.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},e.prototype.validateAndTransform=function(t){var e=this.constraints[t];return this.validate(e),this.transform(e)},e.prototype.invalidMsg=function(t,e){return"invalid constraint for "+t+", was "+e+"."},n.explainConstraintValidMsg.get=function(){return""},e.prototype.invalidConstraintMsg=function(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")},e.prototype.validate=function(t){return this.isNothing(t)?this:this.isValidConstraint(t)?void 0:this.handleInvalidConstraint(name,t)},e.prototype.isValidConstraint=function(t){return!0},e.prototype.handleInvalidConstraint=function(t,e){var n=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(n),this):(this.error(n,e),this)},Object.defineProperties(e.prototype,n),e}(u))),T=function(t){function e(e,n){t.call(this,e,n)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isValid=function(){return this.config.isNumber(this.obj)},e}(function(t){function e(e,n){t.call(this,n),this.obj=e}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.isValid=function(){return!1},e.prototype.verify=function(){return this.isPresent(this.obj)&&this.isValid(this.obj)},e}(c)),S=function(t,e){return void 0===e&&(e={}),function(t,e){return new T(t,e)}(t,e).verify()};function V(t,e){return void 0===e&&(e={}),S(t,e)&&function(t){return k.schemaEntryFor(t)}(t)}var k=function(t){function e(e){t.call(this,e),this.type=this.normalizeNumType(e.type),this.base=this.yup.number(),this.rangeConstraint=new x(this)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={typeEnabled:{configurable:!0},isInteger:{configurable:!0},isNegative:{configurable:!0},isPositive:{configurable:!0}};return e.prototype.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.typeEnabled.get=function(){return["range","posNeg","integer"]},e.prototype.convert=function(){return t.prototype.convert.call(this),this},e.prototype.range=function(){this.rangeConstraint.add()},e.prototype.truncate=function(){return this.addConstraint("truncate")},e.prototype.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},e.prototype.posNeg=function(){this.positive(),this.negative()},e.prototype.integer=function(){return this.isInteger&&this.addConstraint("integer"),this},n.isInteger.get=function(){return this.config.isInteger(this.type)},e.prototype.positive=function(){return this.addConstraint("positive")},e.prototype.negative=function(){return this.addConstraint("negative")},n.isNegative.get=function(){var t=this.constraints,e=t.exclusiveMaximum;return!!t.negative||void 0!==e&&0===e},n.isPositive.get=function(){var t=this.constraints,e=t.exclusiveMinimum;return!!t.positive||void 0!==e&&0===e},e.prototype.normalize=function(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min},Object.defineProperties(e.prototype,n),e}(b),A=function(t){function e(e){t.call(this,e),this.type="object",this.base=this.yup.object(),this.properties=this.value.properties}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={typeEnabled:{configurable:!0}};return e.create=function(t){return new e(t)},n.typeEnabled.get=function(){return["noUnknown","camelCase","constantCase"]},e.prototype.convert=function(){if(!this.properties)return this;this.convertEnabled();var t=this.value,e=this.config;if(t){e.buildYup||this.error("convert","Missing buildYup function from config",e);var n=this.config.buildYup(t,e);this.base=n}return this},e.prototype.camelCase=function(){return this.addConstraint("camelCase")},e.prototype.constantCase=function(){return this.addConstraint("constantCase")},e.prototype.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},Object.defineProperties(e.prototype,n),e}(b),I=function(t){return t&&"object"===t.type},F=function(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||I,this.config=t,this.schema=t.schema};function D(t,e){return void 0===e&&(e={}),t&&new F(e).handle(t)}F.prototype.isObject=function(t){return this.config.isObject(t.value)},F.prototype.handle=function(t){return this.isObject(t)&&A.create(Object.assign({},t,{config:this.config})).createSchemaEntry()};var Y=function(t){function e(e){t.call(this,e),this.type="string",this.base=this.yup.string()}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={typeEnabled:{configurable:!0},isEmail:{configurable:!0},isUrl:{configurable:!0}};return e.create=function(t){return new e(t)},e.prototype.convert=function(){return t.prototype.convert.call(this),this},n.typeEnabled.get=function(){return["normalize","minLength","maxLength","pattern","lowercase","uppercase","email","url","genericFormat"]},e.prototype.trim=function(){return this.addConstraint("trim")},e.prototype.lowercase=function(){return this.addConstraint("lowercase")},e.prototype.uppercase=function(){return this.addConstraint("uppercase")},e.prototype.genericFormat=function(){1!=!this.config.format&&this.yup.prototype[this.format]&&this.addConstraint(this.format)},e.prototype.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},e.prototype.constraintNameFor=function(){for(var t=this,e=[],n=arguments.length;n--;)e[n]=arguments[n];return e.find(function(e){return t.constraints[e]})},n.isEmail.get=function(){return this.constraints.email||"email"===this.format},e.prototype.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.isUrl.get=function(){return this.constraints.url||"url"===this.format},e.prototype.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},e.prototype.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},e.prototype.pattern=function(){var t=this.constraints.pattern;if(!t)return this;var e=new RegExp(t),n=this.valErrMessage("pattern")||this.valErrMessage("matches")||this.valErrMessage("regex"),r=e&&this.base.matches(e,n);return this.base=r||this.base,this},e.prototype.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},Object.defineProperties(e.prototype,n),e}(b),P=function(t){this.config=t};function q(t,e){return void 0===e&&(e={}),t&&new P(e).handle(t)}P.prototype.isString=function(t){return this.config.isString(t)},P.prototype.handle=function(t){return this.isString(t)&&Y.create(Object.assign({},{config:this.config},t)).createSchemaEntry()};var R=function(t){function e(e){t.call(this,e),this.type="date",this.base=this.yup.date()}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={typeEnabled:{configurable:!0}};return e.create=function(t){return new e(t)},n.typeEnabled.get=function(){return["minDate","maxDate"]},e.prototype.convert=function(){return t.prototype.convert.call(this),this},e.prototype.toDate=function(t){return new Date(t)},e.prototype.isValidDateType=function(t){return this.isStringType(t)||this.isDateType(t)},e.prototype.isValidDate=function(t){return!!this.isValidDateType(t)&&(!this.isStringType(t)||Boolean(Date.parse(t)))},e.prototype.transformToDate=function(t){return this.isNumberType(t)?new Date(t):t},e.prototype.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},e.prototype.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},e.prototype.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)},Object.defineProperties(e.prototype,n),e}(b),H=function(t){this.config=t};function B(t,e){return void 0===e&&(e={}),t&&new H(e).handle(t)}H.prototype.isDate=function(t){return this.config.isDate(t)},H.prototype.handle=function(t){return this.isDate(t)&&R.create(t).createSchemaEntry()};var z={errValKeys:O,defaults:C,YupArray:E,toYupArray:j,YupBoolean:N,toYupBoolean:M,YupNumber:k,toYupNumberSchemaEntry:V,toYupNumber:function(t,e){return void 0===e&&(e={}),S(t,e)&&function(t){return k.create(t)}(t)},YupObject:A,toYupObject:D,YupString:Y,toYupString:q,YupDate:R,toYupDate:B,YupMixed:b,ConvertYupSchemaError:v,Base:c},L=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),$=function(t){function e(e){var n=e.schema,r=e.name,i=e.key,o=e.value,s=e.config;t.call(this,s),this.schema=n,this.key=i,this.value=o||{},this.config=s||{},this.name=r,this.type=o.type,this.setTypeHandlers()}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={defaultTypeHandlerMap:{configurable:!0},obj:{configurable:!0}};return n.defaultTypeHandlerMap.get=function(){return{string:q,number:V,boolean:M,array:j,object:D,date:B}},e.prototype.setTypeHandlers=function(){this.types=Object.assign({},this.defaultTypeHandlerMap,this.config.typeHandlers||{})},e.prototype.isValidSchema=function(){return"string"==typeof this.type},e.prototype.error=function(t){throw new L(t)},e.prototype.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)}for(var e=this.obj,n=this.config,r=0,i=Object.keys(this.types);r<i.length;r+=1){var o=(0,this.types[i[r]])(e,n);if(o)return o}return this.defaultType(n)},e.prototype.defaultType=function(t){this.error("toEntry: unknown type",t)},n.obj.get=function(){return{schema:this.schema,key:this.key,value:this.value,type:this.type,config:this.config}},Object.defineProperties(e.prototype,n),e}(c);function U(t){return void 0===t&&(t={}),new $(t).toEntry()}var K={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:{}},W={createValidatorName:function(t,e){return"is"+(t=(t=r(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")},createTestName:function(t,e){return n(t||e)}},J={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};function G(t,e){return void 0===e&&(e={}),new X(t,e).yupSchema}function Q(t){return t===Object(t)}var X=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),n.buildYup=G,n.createYupSchemaEntry=n.createYupSchemaEntry||U,this.config=Object.assign(this.config,n),this.schema=e;var r=this.getType(e),i=this.getProps(e);if(this.type=r,this.properties=i,this.required=this.getRequired(e),function(t){return t&&"object"===t}(r))if(Q(i)){var o=this.getName(e),s=this.normalizeRequired(e),a=this.propsToShape({properties:s,name:o,config:n});this.shapeConfig=a,this.validSchema=!0}else{var u=JSON.stringify(s);this.error("invalid schema: must have a properties object: "+u)}else this.error('invalid schema: must be type: "object", was type: '+r)}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={yupSchema:{configurable:!0}};return e.prototype.getRequired=function(t){var e=this.config.getRequired;return e?e(t):t.required||[]},e.prototype.getProps=function(t){return this.config.getProps(t)},e.prototype.getType=function(t){return this.config.getType(t)},e.prototype.getName=function(t){return this.config.getName(t)},n.yupSchema.get=function(){return i.object().shape(this.shapeConfig)},e.prototype.normalizeRequired=function(){var t=this,e=Object.assign({},this.properties),n=[].concat(this.required)||[];return Object.keys(e).reduce(function(r,i){var o=e[i],s=n.indexOf(i)>=0;return Q(o)?o.required=t.isRequired(o)||s:t.warn("Bad value: "+o+" must be an object"),r[i]=o,r},{})},e.prototype.isRequired=function(t){return this.config.isRequired(t)},e.prototype.propsToShape=function(t){var e=this,n=t.name,r=Object.assign({},this.properties);return Object.keys(r).reduce(function(t,i){var o=e.propToYupSchemaEntry({name:n,key:i,value:r[i]});return e.logInfo("propsToShape",{key:i,yupSchemaEntry:o}),t[i]=o,t},{})},e.prototype.propToYupSchemaEntry=function(t){var e=t.value;return void 0===e&&(e={}),(this.createYupSchemaEntry||this.config.createYupSchemaEntry)({schema:this.schema,name:t.name,key:t.key,value:e,config:this.config})},e.prototype.createYupSchemaEntry=function(t){var e=t.config;return e.createYupSchemaEntry({schema:t.schema,name:t.name,key:t.key,value:t.value,config:e})},Object.defineProperties(e.prototype,n),e}(c);exports.buildYup=G,exports.YupBuilder=X,exports.YupSchemaEntry=$,exports.YupSchemaEntryError=L,exports.types=z,exports.createYupSchemaEntry=U,exports.extendYupApi=function(t){var e=this;void 0===t&&(t={});var n=t.constraints,r=t.override;void 0===r&&(r=!1);var o,s=t.validator,a=t.createValidatorName,u=t.createTestName;if(!s)throw"extendYupApi: missing validator option";Array.isArray(n)&&(void 0===o&&(o={}),n=n.reduce(function(t,e){if("string"!=typeof e&&!(e instanceof Object)){if(!1!==o.throws)throw"toConstraintsMap: invalid entry "+e;return t}if("string"==typeof e)t[name]={};else{if(!e.name){if(!1!==o.throws)throw"toConstraintsMap: invalid entry "+e+" missing name";return t}t[e.name]=e}return t},{})),n=r?n||K:Object.assign({},K,n||{}),a=a||W.createValidatorName,u=u||W.createTestName,Object.keys(n).map(function(t){var r=n[t],o=r.testName,c=r.optsKey,p=r.logging,h=a(r.validatorName,t);o=u(o,t),i.addMethod(i.string,t,function(n){void 0===n&&(n={});var r=n.message,a=n[c];return i.string().test(o,r,function(n){var i=e.path,u=e.createError,c=s[h];if("function"!=typeof(c=c||J[h]))throw Error("No method named ${validatorName} on validator");var f=c(n,a);return!0===p&&console.log("Yup validator bridge",{key:t,fullValidatorName:h,testName:o,value:n,valid:f}),f||u({path:i,message:r})})})})},exports.ErrorMessageHandler=g,exports.ConstraintBuilder=m;
//# sourceMappingURL=index.js.map
{
"name": "schema-to-yup",
"version": "1.9.18",
"version": "1.9.19",
"source": "src/index.js",

@@ -21,2 +21,3 @@ "main": "dist/index.js",

"dashify": "^2.0.0",
"uniq": "^1.0.1",
"uppercamelcase": "^3.0.0",

@@ -23,0 +24,0 @@ "yup": "^0.27.0"

@@ -208,4 +208,71 @@ # Schema to Yup schema

Release `2.0` will likely include a much improved infrastructure of suitable building blocks to easily customize behavior and extend the functionality etc.
To control which constraints are enabled (executed), simply edit the `typeEnabled` getter on your type handler class. Here is the default `typeEnabled` getter for the `YupDate` (Date) type handler, which is configured to execute constraint handler functions: `minDate` and `maxDate`.
```js
get typeEnabled() {
return ["minDate", "maxDate"];
}
```
This can also be used to add custom handlers as described in the next section.
### Custom constraint handler functions
You can also add custom custraint handler functions directly via the `config` object as follows:
This can be used to override built in constraints or extend with your own.
A custom handler to validate a string formatted as a valid `ip` address might look something like this (presuming such a method is available on `yup` string). You can also use this with [yup schema type extensions](https://github.com/jquense/yup#extending-schema-types).
```js
// takes the typehandler (such as YupString) instance as argument
const ipHandler = th => {
const constraintName = th.constraintNameFor("ip", "format");
const method = "ip";
th.addConstraint("ip", {
constraintValue: true,
constraintName,
method,
errName: method
});
};
const config = {
string: {
convert: {
ip: ipHandler
},
enabled: [
"ip", // custom
// built in
"normalize",
"minLength",
"maxLength",
"pattern",
"lowercase",
"uppercase",
"email",
"url",
"genericFormat"
]
}
// ... more configuration
};
buildYup(jsonSchema, config);
```
Instead of using enabled with the full list, you can also use `extends`
```js
extends: [
// custom additions
"ip",
// built in handlers all included automatically
]
```
Note that if `convert` has entries and `extends` for the type configuration is not set (and no `enabled` list of constraints defined either) it will use all the entries in `convert` by default (ie. `extends` set to all keys).
We welcome feedback on how to better structure the `config` object to make it easy and intuitive to add run-time configuration to suit your needs.
### Custom constraint builder

@@ -216,2 +283,4 @@

```js
import { ConstraintBuilder } from "schema-to-yup";
class MyConstraintBuilder extends ConstraintBuilder {

@@ -715,2 +784,4 @@ constructor(typeHandler, opts = {}) {

```js
import { ErrorMessageHandler } from "schema-to-yup";
class MyErrorMessageHandler extends ErrorMessageHandler {

@@ -717,0 +788,0 @@ // ...

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

import * as types from "./types";
// import { createYupSchemaEntry } from "./create-entry";
export { ErrorMessageHandler } from "./error-message-handler";
export { ConstraintBuilder } from "./constraint-builder";

@@ -156,0 +157,0 @@ export {

@@ -19,13 +19,2 @@ // See:

convert() {
this.maxItems();
this.minItems();
this.ensureItems();
this.compact();
// this.$uniqueItems()
// .$contains()
// .$additionalItems()
// .$items();
this.itemsOf();
super.convert();

@@ -35,2 +24,6 @@ return this;

get typeEnabled() {
return ["maxItems", "minItems", "ensureItems", "compact", "itemsOf"];
}
ensureItems() {

@@ -37,0 +30,0 @@ return this.addConstraint("ensure");

@@ -14,4 +14,7 @@ import { YupMixed } from "../mixed";

get typeEnabled() {
return ["minDate", "maxDate"];
}
convert() {
this.minDate().maxDate();
super.convert();

@@ -18,0 +21,0 @@ return this;

import * as yup from "yup";
import uniq from "uniq";

@@ -11,4 +12,4 @@ class ConvertYupSchemaError extends Error {}

import { createWhenCondition } from "../../conditions";
import { ConstraintBuilder } from "../constraint_builder";
import { ErrorMessageHandler } from "./error-message-handler";
import { ConstraintBuilder } from "../../constraint-builder";
import { ErrorMessageHandler } from "../../error-message-handler";

@@ -31,7 +32,16 @@ class YupMixed extends Base {

this.type = "mixed";
this.mixedConfig = this.config.mixed || {};
this.typeConfig = this.config[this.type] || {};
this.base = yup.mixed();
this.errMessages = config.errMessages || {};
this.configureTypeConfig();
this.constraintsAdded = {};
}
configureTypeConfig() {
if (this.typeConfig.enabled || this.typeConfig.extends) return;
if (!this.typeConfig.convert) return;
this.typeConfig.extends = Object.keys(this.typeConfig.convert);
}
isRequired(value) {

@@ -128,4 +138,37 @@ value = value || this.value;

// override for each type
get mixedEnabled() {
return (
this.mixedConfig.enabled || [
"oneOf",
"notOneOf",
"when",
"nullable",
"isType"
]
);
}
// override for each type
get typeEnabled() {
return [];
}
get $typeExtends() {
if (!Array.isArray(this.typeConfig.extends)) return;
return uniq([...this.typeConfig.extends, ...this.typeEnabled]);
}
get configuredTypeEnabled() {
return Array.isArray(this.typeConfig.enabled)
? this.typeConfig.enabled
: this.typeEnabled;
}
get $typeEnabled() {
return this.$typeExtends || this.configuredTypeEnabled;
}
get enabled() {
[];
return [...this.mixedEnabled, ...this.$typeEnabled];
}

@@ -135,4 +178,5 @@

this.enabled.map(name => {
if (this[name]) {
this[name]();
const convertFn = this.convertFnFor(name);
if (convertFn) {
convertFn(this);
}

@@ -142,2 +186,15 @@ });

convertFnFor(name) {
return this.customConvertFnFor(name) || this.builtInConvertFnFor(name);
}
customConvertFnFor(name) {
const typeConvertMap = this.typeConfig.convert || {};
return typeConvertMap[name];
}
builtInConvertFnFor(name) {
return this[name].bind(this);
}
getConstraints() {

@@ -154,5 +211,3 @@ return this.config.getConstraints(this.value);

this.addMappedConstraints();
this.oneOf().notOneOf();
this.when();
this.nullable().isType();
this.convertEnabled();
return this;

@@ -195,15 +250,18 @@ }

// contains different types of constraints (ie. name -> yup constraint function calls)
const $map = this.constraintsMap;
const keys = Object.keys($map);
keys.map(key => {
const constraintNames = $map[key];
const fnName = key === "value" ? "addValueConstraint" : "addConstraint";
const fn = this[fnName];
constraintNames.map(constraintName => {
fn(constraintName);
});
});
const keys = Object.keys(this.constraintsMap);
const fn = this.addMappedConstraint.bind(this);
keys.map(fn);
return this;
}
addMappedConstraint(key) {
const { constraintsMap } = this;
const constraintNames = constraintsMap[key];
const fnName = key === "value" ? "addValueConstraint" : "addConstraint";
const fn = this[fnName];
constraintNames.map(constraintName => {
fn(constraintName);
});
}
get constraintsMap() {

@@ -290,39 +348,2 @@ return {

$const() {
return this;
}
// boolean https: //ajv.js.org/keywords.html#allof
$allOf() {
return this;
}
// https://ajv.js.org/keywords.html#anyof
$anyOf() {
return this;
}
// https: //ajv.js.org/keywords.html#oneof
$oneOf() {
return this;
}
$if() {
const $if = this.constraints.if;
// TODO: translate to when?
return this;
}
$then() {
const $then = this.constraints.then;
// TODO: use with if translated to when?
return this;
}
$else() {
const $else = this.constraints.else;
// TODO: use with if translated to when?
return this;
}
message() {

@@ -329,0 +350,0 @@ return config.messages[this.key] || config.messages[this.type] || {};

@@ -30,3 +30,3 @@ import { YupMixed } from "../mixed";

this.base = this.yup.number();
this.range = createRangeConstraint(this);
this.rangeConstraint = createRangeConstraint(this);
}

@@ -46,3 +46,3 @@

get enabled() {
get typeEnabled() {
return ["range", "posNeg", "integer"];

@@ -52,3 +52,2 @@ }

convert() {
this.enabled.map(name => this.processConstraint(name));
super.convert();

@@ -58,5 +57,4 @@ return this;

processConstraint(name) {
const fn = this[name];
fn && typeof fn === "function" ? fn.bind(this)() : fn.add();
range() {
this.rangeConstraint.add();
}

@@ -63,0 +61,0 @@

@@ -16,6 +16,9 @@ import { YupMixed } from "../mixed";

get typeEnabled() {
return ["noUnknown", "camelCase", "constantCase"];
}
convert() {
if (!this.properties) return this;
this.noUnknown();
this.camelCase().constantCase();
this.convertEnabled();

@@ -22,0 +25,0 @@ const schema = this.value;

@@ -16,14 +16,19 @@ import { YupMixed } from "../mixed";

super.convert();
this.normalize();
this.minLength()
.maxLength()
.pattern();
this.lowercase();
this.uppercase();
this.email();
this.url();
this.genericFormat();
return this;
}
get typeEnabled() {
return [
"normalize",
"minLength",
"maxLength",
"pattern",
"lowercase",
"uppercase",
"email",
"url",
"genericFormat"
];
}
trim() {

@@ -74,3 +79,3 @@ return this.addConstraint("trim");

const method = "url";
this.addConstraint("email", {
this.addConstraint("url", {
constraintValue: true,

@@ -77,0 +82,0 @@ constraintName,

Sorry, the diff of this file is not supported yet

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