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

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.4 to 1.9.5

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),e=t.then?"else":"otherwise";return t=this.whenEntryFor(t,"then"),this.whenEntryFor(t,"otherwise",e)},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 y=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()},l={constraintObj:{configurable:!0},keyVal:{configurable:!0},constraintValue:{configurable:!0},constraint:{configurable:!0}};y.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)},y.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)},y.prototype.createWhenEntry=function(t,e){return function(e,n){return void 0===n&&(n={}),new p(t,n)}(0,e)},y.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},l.constraintObj.get=function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}},l.keyVal.get=function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t},l.constraintValue.get=function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]},l.constraint.get=function(){return this.validateAndConfigure()&&this.constraintValue},y.prototype.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},y.prototype.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},Object.defineProperties(y.prototype,l);var m=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),d=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],g={errMessages:function(t){return void 0===t&&(t=d),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){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={},this.rebind("addConstraint","addValueConstraint")}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={enabled:{configurable:!0},constraintsMap:{configurable:!0}};return 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.addMappedConstraints(),this.oneOf().notOneOf(),this.when(),this.nullable().isType(),this},e.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.addConstraint(t,{constraintName:e.constraintName,value:!0,errName:e.errName})},e.prototype.buildConstraint=function(t,e){void 0===e&&(e={});var n=e.constraintName,r=e.propValue,i=e.method,o=e.yup,s=e.value,a=e.values,u=e.errName;if(o=o||this.base,this.isNothing(r=r||this.constraints[t]))return this.warn("no prop value"),o;if(n=n||t,!o[i=i||n])return this.warn("Yup has no such API method: "+i),this;var c=o[i];if(!c)return this.error("No such yup constrain method",{method:i});var p=c.bind(o),h=this.valErrMessage(n)||u&&this.valErrMessage(u);if(!this.isPresent(s)){var f=!0===s?r:s;return this.onConstraintAdded({name:n,value:f}),f?p(f,h):p(h)}return this.isPresent(s)?Array.isArray(a)?(this.onConstraintAdded({name:n,value:a}),p.apply(void 0,a.concat([h]))):(this.onConstraintAdded({name:n,value:s}),p([s],h)):(this.warn("buildConstraint: missing value or values options"),o)},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){e[n].map(t["value"===n?"addValueConstraint":"addConstraint"])}),this},n.constraintsMap.get=function(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}},e.prototype.oneOf=function(){var t=this.constraints.enum||this.constraints.oneOf||this.constraints.anyOf;return this.isNothing(t)?this:(t=Array.isArray(t)?t:[t],this.addConstraint("oneOf",{value:t,errName:"enum"}))},e.prototype.notOneOf=function(){var t=this.constraints,e=t.not,n=t.notOneOf||e&&(e.enum||e.oneOf);return n=Array.isArray(n)?n:[n],this.addConstraint("notOneOf",{value:n})},e.prototype.valErrMessage=function(t){var e=this.errMessages[this.key]?this.errMessages[this.key][t]:void 0;return"function"==typeof e?e(this.constraints):e},e.prototype.createWhenConditionFor=function(t){return function(t){return new y(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=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 O(t,e){return void 0===e&&(e={}),t&&new b(e).handle(t)}var 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",{value: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){this.config=t};function C(t,e){return void 0===e&&(e={}),t&&new j(e).handle(t)}j.prototype.isBoolean=function(t){return this.config.isBoolean(t)},j.prototype.handle=function(t){return this.isBoolean(t)&&N.create(t).createSchemaEntry()};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){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))),_=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)),x=function(t,e){return void 0===e&&(e={}),function(t,e){return new _(t,e)}(t,e).verify()};function S(t,e){return void 0===e&&(e={}),x(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.range=new E(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),T=function(t){return t&&"object"===t.type},M=function(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||T,this.config=t,this.schema=t.schema};function A(t,e){return void 0===e&&(e={}),t&&new M(e).handle(t)}M.prototype.isObject=function(t){return this.config.isObject(t.value)},M.prototype.handle=function(t){return this.isObject(t)&&I.create(Object.assign({},t,{config:this.config})).createSchemaEntry()};var I=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),D=function(t){this.config=t};function Y(t,e){return void 0===e&&(e={}),t&&new D(e).handle(t)}D.prototype.isString=function(t){return this.config.isString(t)},D.prototype.handle=function(t){return this.isString(t)&&V.create(Object.assign({},{config:this.config},t)).createSchemaEntry()};var V=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().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(){return this.isEmail&&this.addConstraint("email"),this},n.isEmail.get=function(){return this.constraints.email||"email"===this.format},e.prototype.url=function(){return this.isUrl&&this.addConstraint("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),R=function(t){this.config=t};function q(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)&&P.create(t).createSchemaEntry()};var P=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),z={errValKeys:d,defaults:g,YupArray:w,toYupArray:O,YupBoolean:N,toYupBoolean:C,YupNumber:k,toYupNumberSchemaEntry:S,toYupNumber:function(t,e){return void 0===e&&(e={}),x(t,e)&&function(t){return k.create(t)}(t)},YupObject:I,toYupObject:A,YupString:V,toYupString:Y,YupDate:P,toYupDate:q,YupMixed:v,ConvertYupSchemaError:m,Base:u},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.types={string:Y,number:S,boolean:C,array:O,object:A,date:q}}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={obj:{configurable:!0}};return 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)}var e=this.obj;return this.string(e)||this.number(e)||this.boolean(e)||this.array(e)||this.object(e)||this.date(e)||this.defaultType(e)},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}},e.prototype.string=function(t){return Y(t||this.obj,this.config)},e.prototype.number=function(t){return S(t||this.obj,this.config)},e.prototype.boolean=function(t){return C(t||this.obj,this.config)},e.prototype.array=function(t){return O(t||this.obj,this.config)},e.prototype.object=function(t){return A(t||this.obj,this.config)},e.prototype.date=function(t){return q(t||this.obj,this.config)},Object.defineProperties(e.prototype,n),e}(u);function F(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:{}},B={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)}},K={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};function W(t,e){return void 0===e&&(e={}),new G(t,e).yupSchema}function J(t){return t===Object(t)}var G=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),n.buildYup=W,n.createYupSchemaEntry=n.createYupSchemaEntry||F,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(J(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 J(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=W,exports.YupBuilder=G,exports.YupSchemaEntry=$,exports.YupSchemaEntryError=L,exports.types=z,exports.createYupSchemaEntry=F,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||B.createValidatorName,u=u||B.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||K[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("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),e=t.then?"else":"otherwise";return t=this.whenEntryFor(t,"then"),this.whenEntryFor(t,"otherwise",e)},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 y=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()},l={constraintObj:{configurable:!0},keyVal:{configurable:!0},constraintValue:{configurable:!0},constraint:{configurable:!0}};y.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)},y.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)},y.prototype.createWhenEntry=function(t,e){return function(e,n){return void 0===n&&(n={}),new p(t,n)}(0,e)},y.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},l.constraintObj.get=function(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}},l.keyVal.get=function(){var t=this.whenKeys||[];return 1===t.length?t[0]:t},l.constraintValue.get=function(){return!!this.keyVal&&[this.keyVal,this.constraintObj]},l.constraint.get=function(){return this.validateAndConfigure()&&this.constraintValue},y.prototype.warn=function(t,e){console.error("[WhenCondition] WARNING",t,e)},y.prototype.error=function(t,e){throw console.error("[WhenCondition] ERROR",t,e),t},Object.defineProperties(y.prototype,l);var m=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e}(Error),d=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],g={errMessages:function(t){return void 0===t&&(t=d),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){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={},this.rebind("addConstraint","addValueConstraint")}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={enabled:{configurable:!0},aliasMap:{configurable:!0},constraintsMap:{configurable:!0}};return 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.addMappedConstraints(),this.oneOf().notOneOf(),this.when(),this.nullable().isType(),this},e.prototype.addValueConstraint=function(t,e){return void 0===e&&(e={}),this.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){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)||a&&this.valErrMessage(a);return this.isPresent(r)?this.isPresent(s)?Array.isArray(s)?(this.onConstraintAdded({name:n,value:s}),c(s,p)):(this.warn("buildConstraint: values option must be an array of arguments"),o):this.isPresent(r)?(this.onConstraintAdded({name:n,value:r}),r?c(r,p):c(p)):(this.warn("buildConstraint: missing value or values options"),o):(this.onConstraintAdded({name:n}),c(p))},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){e[n].map(t["value"===n?"addValueConstraint":"addConstraint"])}),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){var e=this.errMessages[this.key]?this.errMessages[this.key][t]:void 0;return"function"==typeof e?e(this.constraints):e},e.prototype.createWhenConditionFor=function(t){return function(t){return new y(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=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 O(t,e){return void 0===e&&(e={}),t&&new b(e).handle(t)}var 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",{value: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){this.config=t};function C(t,e){return void 0===e&&(e={}),t&&new j(e).handle(t)}j.prototype.isBoolean=function(t){return this.config.isBoolean(t)},j.prototype.handle=function(t){return this.isBoolean(t)&&N.create(t).createSchemaEntry()};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){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))),_=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)),x=function(t,e){return void 0===e&&(e={}),function(t,e){return new _(t,e)}(t,e).verify()};function S(t,e){return void 0===e&&(e={}),x(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.range=new E(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),M=function(t){return t&&"object"===t.type},T=function(t){void 0===t&&(t={}),(t=t||{}).isObject=t.isObject||M,this.config=t,this.schema=t.schema};function A(t,e){return void 0===e&&(e={}),t&&new T(e).handle(t)}T.prototype.isObject=function(t){return this.config.isObject(t.value)},T.prototype.handle=function(t){return this.isObject(t)&&I.create(Object.assign({},t,{config:this.config})).createSchemaEntry()};var I=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),D=function(t){this.config=t};function Y(t,e){return void 0===e&&(e={}),t&&new D(e).handle(t)}D.prototype.isString=function(t){return this.config.isString(t)},D.prototype.handle=function(t){return this.isString(t)&&V.create(Object.assign({},{config:this.config},t)).createSchemaEntry()};var V=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().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(){return this.isEmail&&this.addConstraint("email"),this},n.isEmail.get=function(){return this.constraints.email||"email"===this.format},e.prototype.url=function(){return this.isUrl&&this.addConstraint("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),P=function(t){this.config=t};function R(t,e){return void 0===e&&(e={}),t&&new P(e).handle(t)}P.prototype.isDate=function(t){return this.config.isDate(t)},P.prototype.handle=function(t){return this.isDate(t)&&q.create(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),z={errValKeys:d,defaults:g,YupArray:w,toYupArray:O,YupBoolean:N,toYupBoolean:C,YupNumber:k,toYupNumberSchemaEntry:S,toYupNumber:function(t,e){return void 0===e&&(e={}),x(t,e)&&function(t){return k.create(t)}(t)},YupObject:I,toYupObject:A,YupString:V,toYupString:Y,YupDate:q,toYupDate:R,YupMixed:v,ConvertYupSchemaError:m,Base:u},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.types={string:Y,number:S,boolean:C,array:O,object:A,date:R}}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var n={obj:{configurable:!0}};return 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)}var e=this.obj;return this.string(e)||this.number(e)||this.boolean(e)||this.array(e)||this.object(e)||this.date(e)||this.defaultType(e)},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}},e.prototype.string=function(t){return Y(t||this.obj,this.config)},e.prototype.number=function(t){return S(t||this.obj,this.config)},e.prototype.boolean=function(t){return C(t||this.obj,this.config)},e.prototype.array=function(t){return O(t||this.obj,this.config)},e.prototype.object=function(t){return A(t||this.obj,this.config)},e.prototype.date=function(t){return R(t||this.obj,this.config)},Object.defineProperties(e.prototype,n),e}(u);function F(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:{}},B={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)}},K={isMagnetURI:function(t,e){return/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)}};function W(t,e){return void 0===e&&(e={}),new G(t,e).yupSchema}function J(t){return t===Object(t)}var G=function(t){function e(e,n){void 0===n&&(n={}),t.call(this,n),n.buildYup=W,n.createYupSchemaEntry=n.createYupSchemaEntry||F,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(J(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 J(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=W,exports.YupBuilder=G,exports.YupSchemaEntry=$,exports.YupSchemaEntryError=L,exports.types=z,exports.createYupSchemaEntry=F,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||B.createValidatorName,u=u||B.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||K[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})})})})};
//# sourceMappingURL=index.js.map
{
"name": "schema-to-yup",
"version": "1.9.4",
"version": "1.9.5",
"source": "src/index.js",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -126,5 +126,15 @@ import * as yup from "yup";

get aliasMap() {
return {
oneOf: "oneOf",
enum: "oneOf",
anyOf: "oneOf"
// ...
};
}
buildConstraint(propName, opts = {}) {
let {
constraintName,
constraintValue,
propValue,

@@ -138,5 +148,7 @@ method,

yup = yup || this.base;
propValue = propValue || this.constraints[propName];
constraintValue =
constraintValue || propValue || this.constraints[propName];
if (this.isNothing(propValue)) {
if (this.isNothing(constraintValue)) {
// console.log("no prop value", { constraints: this.constraints, propName });
this.warn("no prop value");

@@ -148,12 +160,11 @@ return yup;

if (!yup[method]) {
this.warn(`Yup has no such API method: ${method}`);
const yupConstraintMethodName = this.aliasMap[method] || method;
if (!yup[yupConstraintMethodName]) {
// console.log("no yup method", yupConstraintMethodName);
this.warn(`Yup has no such API method: ${yupConstraintMethodName}`);
return this;
}
const yupConstraintFn = yup[method];
if (!yupConstraintFn) {
return this.error("No such yup constrain method", { method });
}
const constraintFn = yupConstraintFn.bind(yup);
const constraintFn = yup[yupConstraintMethodName].bind(yup);
const errFn =

@@ -163,4 +174,5 @@ this.valErrMessage(constraintName) ||

// this.log("build constraint", {
// console.log("build constraint", {
// value,
// values,
// propName,

@@ -170,13 +182,11 @@ // constraints: this.constraints

if (!this.isPresent(value)) {
if (!this.isPresent(constraintValue)) {
// this.log("constraint - value not present", value);
// call yup constraint function with single value arguments (default)
const constraintValue = value === true ? propValue : value;
// constraintValue = value === true ? constraintValue : value;
this.onConstraintAdded({ name: constraintName, value: constraintValue });
this.onConstraintAdded({ name: constraintName });
const newBase = constraintValue
? constraintFn(constraintValue, errFn)
: constraintFn(errFn);
const newBase = constraintFn(errFn);

@@ -190,16 +200,11 @@ // this.log("built constraint", {

if (this.isPresent(value)) {
// this.log("constraint - value present", value);
if (this.isPresent(values)) {
// this.log("constraint - values present - add Array constraint", values);
// call yup constraint function with multiple arguments
if (!Array.isArray(values)) {
this.onConstraintAdded({ name: constraintName, value });
const newBase = constraintFn([value], errFn);
return newBase;
// this.warn(
// "buildConstraint: values option must be an array of arguments"
// );
// return yup;
this.warn(
"buildConstraint: values option must be an array of arguments"
);
return yup;
}

@@ -209,3 +214,3 @@

const newBase = constraintFn(...values, errFn);
const newBase = constraintFn(values, errFn);

@@ -218,2 +223,19 @@ // this.log("built constraint", {

}
if (this.isPresent(constraintValue)) {
// this.log("constraint - value not present", value);
this.onConstraintAdded({ name: constraintName, value: constraintValue });
const newBase = constraintValue
? constraintFn(constraintValue, errFn)
: constraintFn(errFn);
// this.log("built constraint", {
// yup: newBase
// });
return newBase;
}
this.warn("buildConstraint: missing value or values options");

@@ -224,2 +246,3 @@ return yup;

addConstraint(propName, opts) {
// console.log("addConstraint", propName, opts);
const contraint = this.buildConstraint(propName, opts);

@@ -254,7 +277,13 @@ this.base = contraint || this.base;

oneOf() {
let value =
let values =
this.constraints.enum || this.constraints.oneOf || this.constraints.anyOf;
if (this.isNothing(value)) return this;
value = Array.isArray(value) ? value : [value];
return this.addConstraint("oneOf", { value, errName: "enum" });
if (this.isNothing(values)) return this;
values = Array.isArray(values) ? values : [values];
// using alias
const alias = ["oneOf", "enum", "anyOf"].find(key => {
return this.constraints[key];
});
// TODO: pass value as constraintValue not value
return this.addConstraint(alias, { values });
}

@@ -264,5 +293,7 @@

const { not, notOneOf } = this.constraints;
let value = notOneOf || (not && (not.enum || not.oneOf));
value = Array.isArray(value) ? value : [value];
return this.addConstraint("notOneOf", { value });
let values = notOneOf || (not && (not.enum || not.oneOf));
if (this.isNothing(values)) return this;
values = Array.isArray(values) ? values : [values];
// TODO: pass value as constraintValue not value
return this.addConstraint("notOneOf", { values });
}

@@ -269,0 +300,0 @@

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

import { YupMixed } from './mixed';
import { YupMixed } from "./mixed";

@@ -132,6 +132,2 @@ class StringHandler {

export {
toYupString,
YupString,
StringHandler
};
export { toYupString, YupString, StringHandler };

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