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

schema-to-yup

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.12.6 to 1.12.7

1

__config.d.ts

@@ -25,2 +25,3 @@ export interface TypeHandlerConfig {

format?: boolean;
dependenciesMap?: object;
schemaParserMap?: object;

@@ -27,0 +28,0 @@ messages?: object;

2

dist/index.js

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

var t=require("yup"),e=require("uniq"),s=require("dashify"),r=require("uppercamelcase");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,r.get?r:{enumerable:!0,get:function(){return t[s]}})}}),e.default=t,e}var a=/*#__PURE__*/n(t),o=/*#__PURE__*/i(e),h=/*#__PURE__*/i(s),l=/*#__PURE__*/i(r);const c={getProps:t=>t&&t.properties,getType:t=>t&&t.type,getName:t=>t&&(t.name||t.title),getConstraints:t=>t,isString:t=>t&&"string"===t.type,isArray:t=>t&&"array"===t.type,isInteger:t=>t&&("integer"===t.type||"int"===t.type),isBoolean:t=>t&&"boolean"===t.type,hasDateFormat:t=>t&&["date","date-time"].find(e=>e===t.format),isDate:t=>t&&"string"===t.type&&c.hasDateFormat(t.format),isNumber:t=>t&&("number"===t.type||c.isInteger(t)),isObject:t=>t&&"object"===t.type,isRequired:t=>t&&t.required},u={getProps:t=>t.properties,getType:t=>t.type,getName:t=>t.name||t.title,getConstraints:t=>t,isString:t=>"string"===t.type&&!u.hasDateFormat(t),isArray:t=>"array"===t.type,isBoolean:t=>"boolean"===t.type,isInteger:t=>"integer"===t.type,hasDateFormat:t=>t&&["date","date-time"].find(e=>e===t.format),isDate:t=>"string"===t.type&&u.hasDateFormat(t),isNumber:t=>"number"===t.type||u.isInteger(t),isObject:t=>"object"===t.type,isRequired:t=>t.required},d={getProps:t=>t&&t.fields,getType:t=>t&&t.type,getName:t=>t&&(t.name||t.title),getConstraints:t=>t,isString:t=>t&&"string"===t.type,isArray:t=>t&&"array"===t.type,isInteger:t=>t&&"int"===t.type,isFloat:t=>t&&"float"===t.type,isDouble:t=>t&&"double"===t.type,isBoolean:t=>t&&"boolean"===t.type,isDate:t=>t&&"int"===t.type&&"date"===t.logicalType,isNumber:t=>t&&(d.isInteger(t)||d.isFloat(t)||d.isDouble(t)),isObject:t=>t&&"record"===t.type,isRequired:t=>t&&t.required},p={"json-schema":c,"type-def":u,avro:d};class y extends class{constructor(t={}){this.config=t;const{log:e,error:s}=t,r=t.enable||{};!0===t.logging&&(r.log=!0),!1===t.logging&&(r.log=!1),this.enable=r,this.log="function"==typeof e?e:console.log,this.err="function"==typeof s?s:console.error}error(t){var e=[].slice.call(arguments,1);if(!1!==this.enable.error&&this.err)throw e&&e.length?this.err(t,...e):this.err(t),t}warn(t){this.enable.warn&&this.logInfo("WARNING: "+t,...[].slice.call(arguments,1))}logTypeInfo(t){if(!this.enable.log)return;if(!this.log)return;const e=this.config.logTypes||[];e.length&&e.find(t=>this.type===t)&&logInfo(t,...[].slice.call(arguments,1))}logDetails(t,e){const s=this.config.logDetailed||[];s.length&&s.find(t=>!(t.key&&e.key!==t.key||t.constraintName&&e.constraintName!==t.constraintName||t.propName&&e.propName!==t.propName||t.method&&e.method!==t.method))&&this.logInfo(t,e,...[].slice.call(arguments,2))}logInfo(t){var e=[].slice.call(arguments,1);this.enable.log&&this.log&&(e&&e.length?this.log(t,...e):this.log(t))}}{constructor(t={}){super(t)}isNothing(t){return null==t}isPresent(t){return!this.isNothing(t)}hasKey(t,e){if(this.isObjectType(t))return Object.keys(t).includes(e)}toNumber(t){return Number(t)}isNumberLike(t){return!isNaN(this.toNumber(t))}isObjectType(t){return t===Object(t)}isArrayType(t){return Array.isArray(t)}isNumberType(t){return!isNaN(t)}isStringType(t){return"string"==typeof t}isFunctionType(t){return"function"==typeof t}isDateType(t){return t instanceof Date}}class g{constructor(t,e){this.schemaParserMap=t,this.name=e}lookup(t=this.name){return this.schemaParserMap[t]}build(){const t=this.lookup();if(t.extends){const e=this.extend(t.extends);if(e)return e}return t}extend(t){const e=this.lookup(t);e&&(entry={...e,...this.lookup()})}}class m extends y{constructor(t={}){super(t);const e=(t.createSchemaParserBuilder||new g(t.schemaParserMap||p,t.schemaType||"json-schema")).build();this.config={...e,...t}}createSchemaParserBuilder(t,e){return new SchemaParserBuilder(t,e)}}function f(t){return t===Object(t)}class b{constructor(t,e={}){this.whenEntryObj=t;const{schema:s,properties:r,config:i,key:n,when:a,type:o}=e;this.schema=s,this.when=a,this.properties=r||{},this.key=n,this.type=o,this.config=i}validateAndConfigure(t){if(!f(t=t||this.whenEntryObj))return this.warn("invalid or missing when entry constraint object",t),!1;const 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)}createYupSchemaEntry(t){return this.config.createYupSchemaEntry(t)}createValue(t,e){return"string"==typeof t&&(t={[t]:!0}),f(t)||this.error(`createValue: ${e} must be a schema object`),{key:this.key,type:this.type,...t}}createEntryOpts(t,e){const s=this.createValue(t,e);return{schema:this.schema,properties:this.properties,key:this.key,type:this.type,value:s,config:this.config}}createEntry(t,e){const s=this.createEntryOpts(t,e);return this.createYupSchemaEntry(s)}hasKey(t,e){return t.find(t=>t===e)}hasAnyKey(t,e){return t.find(t=>e.includes(t))}whenEntryFor(t,e,s){if(s=s||e,"string"==typeof t&&(t={[t]:!0}),!f(t))throw`whenEntryFor: Invalid when object ${t}`;const r={...t[s]};return delete t[s],r?(t[e]=this.createEntry(r,e),t):t}calcEntryObj(){let t={...this.whenEntryObj};return t=this.whenEntryFor(t,"then"),"otherwise"in t&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t}get entryObj(){return this.validateAndConfigure()&&this.calcEntryObj()}warn(t,e){console.error("[WhenEntry] WARNING",t,e)}error(t,e){throw console.error("[WhenEntry] ERROR",t,e),t}}function v(t){return t===Object(t)}class C{constructor(t={}){const{type:e,key:s,value:r,when:i,schema:n,properties:a,config:o}=t;this.opts=t,this.when=i,this.key=s,this.type=e,this.value=r,this.schema=n,this.properties=a,this.config=o,this.validate()}validate(){"string"!=typeof this.type&&this.error(`validate: invalid or mising type: ${this.type}`,this.opts),v(this.when)||this.error(`validate: invalid or mising when: ${this.when}`,this.opts)}validateAndConfigure(t){if(!v(t=t||this.when))return this.warn("invalid or missing when constraint",t),!1;const 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)}createWhenEntry(t,e){return((t,e={})=>new b(t,e))(t,e)}accumulate(t,e){let s=this.when[e];if(!v(s))return this.warn(`invalid when entry constraint object ${s} for ${e}`),t;const r={type:this.type,key:this.key,schema:this.schema,properties:this.properties,config:this.config},{entryObj:i}=this.createWhenEntry(s,r);return i?t=Object.assign(t,i):t}get constraintObj(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}}get keyVal(){const t=this.whenKeys||[];return 1===t.length?t[0]:t}get constraintValue(){return!!this.keyVal&&[this.keyVal,this.constraintObj]}get constraint(){return this.validateAndConfigure()&&this.constraintValue}warn(t,e){console.error("[WhenCondition] WARNING",t,e)}error(t,e){throw console.error("[WhenCondition] ERROR",t,e),t}}const N=t=>new C(t);class w extends y{constructor(t,e={}){super(e),this.typeHandler=t,this.type=t.type,this.builder=t.builder,this.constraintsAdded={},this.delegators.map(e=>{this[e]=t[e]})}get delegators(){return["errMessages","base","key","type","constraints","errorMessageHandler","logInfo","warn"]}build(t,e={}){let{constraintName:s,constraintValue:r,propValue:i,method:n,yup:a,value:o,values:h,errName:l}=e;if(a=a||this.base,r=this.getFirstValue([r,i,this.constraints[t]]),s=s||t,n=n||s,this.idObj={propName:t,method:n,constraintName:s,key:this.key},this.logDetailed("build",e,{resolved:{constraintValue:r,constraintName:s}}),this.isNothing(r))return this.warn("no prop value",{constraintValue:r}),!1;const c=this.aliasMap[n]||n;if(!a[c])return this.warn(`Yup has no such API method: ${c}`),!1;const u=a[c].bind(a),d=this.validationErrorMessage(s),p=l&&this.validationErrorMessage(l),y={constraintName:s,yup:a,constraintFn:u,errFn:d||p},g=["multiValueConstraint","presentConstraintValue","nonPresentConstraintValue"];let m;const f=this.type;for(let t of g)if(m=this[t].bind(this)(this.getFirstValue([o,h,r],{constraintName:s,type:f}),y),m)break;return m?(this.base=m,m):(this.warn("buildConstraint: missing value or values options"),!1)}yupRefMap(){return{string:["length","min","max"],number:["min","max","lessThan","moreThan"],date:["min","max"],array:["length","min","max"]}}getFirstValue(t,e={}){const{constraintName:s,type:r}=e,i=this.isPresent.bind(this),n=this.yupRefMap[r],o=t.filter(i)[0];return n&&n.includes(s)&&this.isStringType(o)?a.ref(o):o}nonPresentConstraintValue(t,{constraintName:e,constraintFn:s,errFn:r}){if(!this.isPresent(t))return this.logInfo("nonPresentConstraintValue",{constraintValue:t}),this.onConstraintAdded({method:"nonPresentConstraintValue",name:e}),s(r)}presentConstraintValue(t,{constraintName:e,constraintFn:s,errFn:r}){if(this.isPresent(t))return this.logInfo("presentConstraintValue",{constraintName:e,constraintValue:t}),this.onConstraintAdded({method:"presentConstraintValue",name:e,value:t}),this.isNoValueConstraint(e)?(this.logInfo("isNoValueConstraint",{constraintName:e}),s(r)):(this.logInfo("presentConstraintValue: apply validator function",{constraintName:e,constraintValue:t}),s(t,r));this.logInfo("presentConstraintValue: value not present",{constraintName:e,constraintValue:t})}multiValueConstraint(t,{constraintFn:e,constraintName:s,errFn:r}){if(this.isPresent(t)){if(this.logInfo("multiValueConstraint",{constraintName:s,values:t}),Array.isArray(t))return this.onConstraintAdded({method:"multiValueConstraint",name:s,value:t}),this.logInfo("multiValueConstraint: apply validator function",{constraintName:s,value:t}),this.callConstraintFn(e,s,t,r);this.warn("buildConstraint: values option must be an array of arguments")}}callConstraintFn(t,e,s,r){return this.isMultiArgsCall(e)?t(...s,r):t(s,r)}isMultiArgsCall(t){return this.multiArgsValidatorMethods[t]}get multiArgsValidatorMethods(){return this.config.multiArgsValidatorMethods||{when:!0}}isNoValueConstraint(t){return this.noValueConstraints.includes(t)}get noValueConstraints(){return["required","email","url","format"]}addTrueValueConstraint(t,{constraintName:e,errName:s}={}){return this.addConstraint(t,{constraintName:e,value:!0,errName:s})}addConstraint(t,e){const s=this.build(t,e);return!!s&&(this.typeHandler.base=s,s)}onConstraintAdded({method:t,name:e,value:s}){if(this.constraintsAdded[e]=s,this.builder)return this.builder.onConstraintAdded({type:this.type,method:t,name:e,value:s}),this.typeHandler;this.logInfo("no builder set to notify in ConstraintBuilder")}get constraintsMap(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}logDetailed(t){this.logDetails(t,this.idObj,...[].slice.call(arguments,1))}validationErrorMessage(t){return this.errorMessageHandler.validationErrorMessage(t)}get aliasMap(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}}}class E extends y{constructor(t,e={}){super(e),this.typeHandler=t,this.init()}init(){const{typeHandler:t}=this;this.constraints=t.constraints,this.errMessages=t.errMessages,this.key=t.key,this.value=t.value,this.constraints=t.constraints,this.parentNode=t.parentNode,this.keyPath=t.keyPath,this.type=t.type,this.description=t.description,this.title=t.title,this.setErrMessage()}errMessageMap(t={}){return t[this.errMessagesMapKey]||this.errMessages}get errMessageKey(){return this.config.errMessageKey||"errMessage"}get errMessagesMapKey(){return this.config.errMessagesMapKey||"errMessages"}setErrMessage(){const{typeHandler:t}=this,{value:e}=t;if(!e.errMessage)return;const s=this.errMessageKey,r=this.errMessageMap(e);return r[this.key]=e[s]||r[this.key],this}validationErrorMessage(t){const{constraints:e,key:s,description:r,title:i,typeHandler:n,keyPath:a,parentNode:o}=this,h=this.errMessageFor(t);return"function"==typeof h?h(e,{key:s,title:i,description:r,typeHandler:n,parentNode:o,keyPath:a}):h}errMessageFor(t){const{errMessages:e,key:s}=this,r=e[s];return r?r[t]:e[`$${t}`]}}class O extends Error{}class T extends m{constructor(t={}){super(t.config),this.init(t)}init(t){let{schema:e,key:s,value:r,config:i,entryHandler:n,parentNode:a}=t;i=i||{},e=e||{},this.parentNode=a||n?.parentNode,this.validateOnCreate(s,r,t),this.opts=t,this.entryHandler=n,this.validator=this.getValidator(),this.key=s,this.schema=e,this.properties=e.properties||{},this.value=r,this.title=r.title,this.description=r.description,this.constraints=this.getConstraints(),this.format=r.format||this.constraints.format,this.config=i||{},this.type=this.baseType,this.mixedConfig=this.config.mixedEnabled||{};const o=this.config[this.type]||{},h=this.config.mixed||{};this.mixedConfig=h,this.typeConfig={...h,...o},this.errMessages=i.errMessages||{},this.configureTypeConfig(),this.constraintsAdded={},this.base=this.getBase()}get keyPath(){return this._keyPath=this._keyPath||this.calcKeyPath(),this._keyPath}calcKeyPath(){let t,e=this,s=[];for(;(t=e.parentNode)&&t;)s.push(t.key),e=e.parentNode;return s.join(".")}get builder(){return this.entryHandler&&this.entryHandler.builder}getBase(){return this.customBaseValidator||this.validatorInstance}get customBaseValidator(){return this.config.validatorFor&&this.config.validatorFor(this.type)}getValidator(){return this.opts.validator||this.config.validator||this.builder&&this.builder.validator||a}get baseType(){return"mixed"}get validatorInstance(){return this.validator.mixed()}configureTypeConfig(){this.typeConfig.enabled||this.typeConfig.extends||this.typeConfig.convert&&(this.typeConfig.extends=Object.keys(this.typeConfig.convert))}isRequired(t){return!0===(t=t||this.value).required}get mode(){return this.config.mode||{}}get disableFlags(){return[!1,"disabled","no","off"]}get enableFlags(){return[!0,"enabled","yes","on"]}disabledMode(t){const e=this.mode[t];return!!this.disableFlags.find(t=>e===t)}enabledMode(t){const e=this.mode[t];return!!this.enableFlags.find(t=>e===t)}get shouldPreProcessValue(){return!this.disabledMode("notRequired")}preProcessedConstraintValue(t){return this.shouldPreProcessValue?this.isRequired(t)?t:{...t,notRequired:!0}:t}set value(t){this._value=this.preProcessedConstraintValue(t)}get value(){return this._value}initHelpers(){const{config:t}=this;this.errorMessageHandler=(this.config.createErrorMessageHandler||this.createErrorMessageHandler)(this,t),this.constraintBuilder=(this.config.createConstraintBuilder||this.createConstraintBuilder)(this,t),this.rebind("addConstraint","addTrueValueConstraint")}createConstraintBuilder(t,e={}){return new w(t,e)}createErrorMessageHandler(t,e={}){return new E(t,e)}rebind(){[].slice.call(arguments).map(t=>{const e=this[t];this[t]=this.isFunctionType(e)?e.bind(this):e})}validateOnCreate(t,e,s){t||this.error(`create: missing key ${JSON.stringify(s)}`),e||this.error(`create: missing value ${JSON.stringify(s)}`)}get mixedEnabled(){return this.mixedConfig.enabled||["oneOf","notOneOf","when","nullable","isType","label","const","refValueFor"]}get typeEnabled(){return[]}get $typeExtends(){if(Array.isArray(this.typeConfig.extends))return o.default([...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]}convertEnabled(){this.enabled.map(t=>{const e=this.convertFnFor(t);e&&e(this)})}convertFnFor(t){return this.customConvertFnFor(t,this)||this.builtInConvertFnFor(t)}customConvertFnFor(t){return(this.typeConfig.convert||{})[t]}builtInConvertFnFor(t){return this[t].bind(this)}getConstraints(){return this.config.getConstraints(this.value)}createSchemaEntry(){return this.preConvert(),this.convert(),this.postConvert(),this.base}preConvert(){const{preConvert:t}=this.config,e=t&&t.bind(this);e&&e(this)}postConvert(){const{postConvert:t}=this.config,e=t&&t.bind(this);e&&e(this)}convert(){return this.initHelpers(),this.addMappedConstraints(),this.convertEnabled(),this}apply(t){var e=[].slice.call(arguments,1);if("string"!=typeof t)throw new TypeError("[Mixed] apply must take a method name available on the validator instance as first argument");return this.base=e&&e.length&&this.base[t](...e)||this.base,this}applyArr(t,e){if("string"!=typeof t)throw new TypeError("[Mixed] apply must take a method name available on the validator instance as first argument");return this.base=e&&e.length&&this.base[t](e)||this.base,this}addTrueValueConstraint(t,e){const s=this.constraintBuilder.addTrueValueConstraint(t,e);if(s){const{base:t}=s;this.base=t}return this}addConstraint(t,e){if(!this.constraintBuilder)throw new Error(`[YupMixed] addConstraint: Missing constraintBuilder in ${this.constructor.name}`);const s=this.constraintBuilder.addConstraint(t,e);return s&&(this.base=s),this}addMappedConstraints(){const t=Object.keys(this.constraintsMap),e=this.addMappedConstraint.bind(this);return t.map(e),this}addMappedConstraint(t){const{constraintsMap:e}=this,s=this["trueValue"===t?"addTrueValueConstraint":"addConstraint"],r=this.constraints[t];e[t].map(t=>{s(t,{value:r})})}get constraintsMap(){return{simple:["default","required","notRequired","nullable"],trueValue:["strict"]}}refValueFor(){let t=this.constraints.refValueFor;return this.isNothing(t)?this:(this.logInfo("refValueFor",{propRefName:t}),this.apply("when",(e,s)=>e?s.required().oneOf([a.ref(t)]):s))}normalizeValues(t){return Array.isArray(t)?t:[t]}get oneOfValues(){return this.constraints.enum||this.constraints.oneOf||this.constraints.anyOf}get oneOfAliases(){return["oneOf","enum","anyOf"]}get oneOfAlias(){return this.oneOfAliases.find(t=>void 0!==this.constraints[t])}oneOf(){let t=this.oneOfValues;if(this.isNothing(t))return this;t=this.normalizeValues(t);const e=this.resolveValues(t),s=this.oneOfAlias;return this.logDetails("type",{constraintName:s,method:"oneOf",key:this.key,type:this.type},t,e),this.addConstraint(s,{values:e})}oneOfConditional(){let{config:t,parentNode:e,isObject:s,value:r,key:i}=this;const n=r;this.base=this.base.test(i,(r,i)=>{for(let i in n){if(!s(i))return r===i;if(t.buildYup(i,t,e).validate())return!0}return!1})}notOneOfConditional(){let{config:t,parentNode:e,isObject:s,value:r,key:i}=this;const n=r;this.base=this.base.test(i,(r,i)=>{for(let i in n){if(!s(i))return r!==i;if(t.buildYup(i,t,e).validate())return!1}return!0})}logDetailed(t,e){this.logDetails(t,e,...[].slice.call(arguments,2))}get notOneOfValues(){const{not:t,notOneOf:e}=this.constraints;return e||t&&(t.enum||t.oneOf)}notOneOf(){let t=this.oneOfValues;if(this.isNothing(t))return this;t=this.normalizeValues(t);const e=this.resolveValues(t);return this.logDetails("type",{constraintName:"notOneOf",method:"notOneOf",key:this.key,type:this.type},t,e),this.addConstraint("notOneOf",{values:e})}resolveValues(t){return t.map(t=>this.isObjectType(t)?this.resolveValue(t):t)}const(){let t=this.constraints.const;if(this.isNothing(t))return this;if(this.isDataRef(t)){const e=this.normalizeDataRefPath(t);t=a.ref(e)}return this.addConstraint("oneOf",{values:[t]})}normalizeDataRefPath(t){return(t=t.$data||t).split("/").shift().join("/")}isDataRef(t){return this.isPresent(t.$data)}isConst(t){return this.hasKey(t,"const")}resolveValue(t){return this.isConst(t)?t.const:(0,this.config.createYupSchemaEntry)({schema:this.schema,key:this.key,value:t,config:this.config})}validationErrorMessage(t){const e=this.errorMessageHandler.validationErrorMessage.bind(this.errorMessageHandler);return(this.config.validationErrorMessage||e)(t,this)}createWhenConditionFor(t){return(this.config.createWhenCondition||N)({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})}label(){const t=this.value,e=t.title||t.label;return this.base=e&&this.base.label(e)||this.base,this}when(){const t=this.constraints.when;if((e=t)!==Object(e))return this;var e;const{constraint:s}=this.createWhenConditionFor(t);return s?(this.logInfo(`Adding when constraint for ${this.key}`,s),this.addConstraint("when",{values:s,errName:"when"}),this):(this.warn(`Invalid when constraint for: ${t}`),this)}isType(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this}nullable(){const{nullable:t,isNullable:e}=this.constraints;return this.addConstraint("nullable",{value:t||e,errName:"notOneOf"}),this}message(){return config.messages[this.key]||config.messages[this.type]||{}}errMessage(t="default"){return this.message[t]||"error"}toValidJSONSchema(){}normalize(){}deNormalize(){}errorMsg(t){this.throwError(t)}error(t,e){const s=[`[${t}]`,e].join(" ");this.errorMsg(s)}throwError(t){throw t}}const x=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],M={errMessages:(t=x)=>t.reduce((t,e)=>(t[e]=({key:t,value:e})=>`${t}: invalid for ${e.name||e.title}`,t),{})};class V extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.createYupSchemaEntry=this.config.createYupSchemaEntry}get baseType(){return"array"}get validatorInstance(){return this.validator.array()}static create(t){return new V(t)}convert(){return super.convert(),this}get typeEnabled(){return["itemsOf","maxItems","minItems","ensureItems","compact"]}ensureItems(){return this.addConstraint("ensure")}compact(){return this.addConstraint("compact")}itemsOf(){const{items:t,itemsOf:e}=this.constraints,s=t||e||this.constraints.of;if(!this.isNothing(s))if(Array.isArray(s))this.error("itemsOf","does not (yet) support an Array of schemas");else if(this.isObjectType(s)){if(this.createYupSchemaEntry){try{const t=s,e={key:this.key,value:t,config:this.config};this.logTypeInfo("array:of",{schemaConf:e});const r=this.createYupSchemaEntry(e);return this.logTypeInfo("array:of",{schemaEntry:r}),this.addConstraint("of",{constraintValue:r,propValue:t,value:r})}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 s)}maxItems(){const{maxItems:t,max:e}=this.constraints,s=t||e;if(!this.isNumberType(s))return this;if(!this.isValidSize(s))return this.handleInvalidSize("maxItems",s);const r=this.validationErrorMessage("maxItems"),i=s&&this.base.max(s,r);return this.base=i||this.base,this}minItems(){const{minItems:t,min:e}=this.constraints,s=t||e;if(!this.isNumberType(s))return this;if(!this.isValidSize(s))return this.handleInvalidSize("minItems",s);const r=this.validationErrorMessage("minItems"),i=s&&this.base.min(s,r);return this.base=i||this.base,this}$items(){return this}$additionalItems(){return this}$uniqueItems(){return this}$contains(){return this}handleInvalidSize(t,e){const s=`invalid array size constraint for ${t}, was ${e}. Must be a number >= 0`;return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}isValidSize(t){return this.isNumberType(t)&&t>=0}}class k extends m{constructor(t){super(t)}isArray(t){return this.config.isArray||this.error("ArrayHandler: missing isArray in config",this.config),this.config.isArray(t)}handle(t){return this.isArray(t)&&V.create(t).createSchemaEntry()}}function S(t,e={}){return t&&new k(e).handle(t)}class j extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"boolean"}get validatorInstance(){return this.validator.boolean()}static create(t){return new j(t)}}class I{constructor(t){this.config=t}isBoolean(t){return this.config.isBoolean(t)}handle(t){return this.isBoolean(t)&&j.create(t).createSchemaEntry()}}function A(t,e={}){return t&&new I(e).handle(t)}class P extends y{constructor(t,e){super(t.config),this.map=e||this.$map||{},this.typeHandler=t,this.delegates.map(e=>{const s=t[e];s||this.error(`missing delegate: ${e}`,{typeHandler:t}),this[e]=this.isFunctionType(s)?s.bind(t):s})}isStringType(t){return"string"==typeof t}get delegates(){return["constraints","addConstraint","constraintsAdded"]}add(){const t=this.map;Object.keys(t).map(e=>{const s=this.entryNames(t[e]);this.addConstraints(e,s)})}entryNames(t){return Array.isArray(t)?t:[t]}addConstraints(t,e=[]){return e.map(e=>{const s=this.validateAndTransform(e);this.addConstraint(e,{method:t,value:s})}),this}validateAndTransform(t){const e=this.constraints[t];return this.validate(t,e),this.transform(e)}invalidMsg(t,e){return`invalid constraint for ${t}, was ${e}.`}get explainConstraintValidMsg(){return""}invalidConstraintMsg(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")}validate(t,e){return this.isNothing(e)?this:this.isValidConstraint(e)?void 0:this.handleInvalidConstraint(t,e)}isValidConstraint(t){return!0}handleInvalidConstraint(t,e){const s=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}}class D extends P{constructor(t){super(t)}transform(t){return this.typeHandler.toNumber(t)}isValidConstraint(t){return this.typeHandler.isNumberLike(t)||this.typeHandler.isStringType(t)}get explainConstraintValidMsg(){return"Must be a number or convertible to a number"}}class F extends D{constructor(t){super(t)}get $map(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}}}class R extends m{constructor(t,e){super(e),this.obj=t}isValid(){return!1}verify(){return this.isPresent(this.obj)&&this.isValid(this.obj)}}class H extends R{constructor(t,e){super(t,e)}isValid(){return this.config.isNumber(this.obj)}}const $=(t,e={})=>function(t,e){return new H(t,e)}(t,e).verify();function Y(t,e={}){return $(t,e)&&function(t){return q.schemaEntryFor(t)}(t)}class q extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.rangeConstraint=new F(this)}get baseType(){return this.normalizeNumType(this.opts.type)}get validatorInstance(){return this.validator.number()}normalizeNumType(t){return"int"===t?"integer":t}static create(t){return new q(t)}static schemaEntryFor(t){return q.create(t).createSchemaEntry()}get typeEnabled(){return["range","posNeg","integer"]}convert(){return super.convert(),this}range(){this.rangeConstraint.add()}truncate(){return this.addConstraint("truncate")}round(){const{round:t}=this.constraints;if(this.isNothing(t))return this;const e=this.isStringType(t)?t:"round";return t&&this.base.round(e),this}posNeg(){this.positive(),this.negative()}integer(){return this.isInteger&&this.addConstraint("integer"),this}get isInteger(){return this.config.isInteger(this.type)}positive(){return this.addConstraint("positive")}negative(){return this.addConstraint("negative")}get isNegative(){const{exclusiveMaximum:t,negative:e}=this.constraints;return!!e||void 0!==t&&0===t}get isPositive(){const{exclusiveMinimum:t,positive:e}=this.constraints;return!!e||void 0!==t&&0===t}normalize(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min}}class B extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.properties=this.value.properties}get baseType(){return"object"}get validatorInstance(){return this.validator.object()}static create(t){return new B(t)}get typeEnabled(){return["noUnknown","camelCase","constantCase"]}convert(){if(!this.properties)return this;super.convert();const t=this.value,e=this.config;if(t){e.buildYup||this.error("convert","Missing buildYup function from config",e);const s={key:this.key,...this.value,parentNode:this.parentNode},r=this.config.buildYup(t,e,s);this.base=r}return this}camelCase(){return this.addConstraint("camelCase")}constantCase(){return this.addConstraint("constantCase")}noUnknown(){const{noUnknown:t,propertyNames:e}=this.value,s=t||e,r=s&&this.base.noUnknown(s,this.validationErrorMessage("propertyNames")||this.validationErrorMessage("noUnknown"));return this.base=r||this.base,this}}const K=t=>t&&"object"===t.type;class z{constructor(t={}){(t=t||{}).isObject=t.isObject||K,this.config=t,this.schema=t.schema}isObject(t){return this.config.isObject(t.value)}handle(t){return this.isObject(t)&&B.create({...t,config:this.config}).createSchemaEntry()}}function L(t,e={}){return t&&function(t={}){return new z(t)}(e).handle(t)}class U extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"string"}get validatorInstance(){return this.validator.string()}static create(t){return new U(t)}convert(){return super.convert(),this}get typeEnabled(){return["normalize","minLength","maxLength","pattern","lowercase","uppercase","email","url","genericFormat"]}trim(){return this.addConstraint("trim")}lowercase(){return this.addConstraint("lowercase")}uppercase(){return this.addConstraint("uppercase")}genericFormat(){1!=!this.config.format&&this.validator.prototype[this.format]&&this.addConstraint(this.format)}email(){if(!this.isEmail)return this;const t=this.constraintNameFor("email","format"),e="email";return this.addConstraint("email",{constraintValue:!0,constraintName:t,method:e,errName:e}),this}constraintNameFor(){return[].slice.call(arguments).find(t=>this.constraints[t])}get isEmail(){return this.constraints.email||"email"===this.format}url(){if(!this.isUrl)return this;const t=this.constraintNameFor("url","format");return this.addConstraint("url",{constraintValue:!0,constraintName:t,method:"url",errName:"url"}),this}get isUrl(){return this.constraints.url||"url"===this.format}minLength(){const{minLength:t}=this.constraints,e=this.validationErrorMessage("minLength")||this.validationErrorMessage("min"),s=t&&this.base.min(t,e);return this.base=s||this.base,this}maxLength(){const{maxLength:t}=this.constraints,e=this.validationErrorMessage("maxLength")||this.validationErrorMessage("max"),s=t&&this.base.max(t,e);return this.base=s||this.base,this}pattern(){const{pattern:t,flags:e,excludeEmptyString:s}=this.constraints;if(!t)return this;const r=new RegExp(t,e),i=this.validationErrorMessage("pattern")||this.validationErrorMessage("matches")||this.validationErrorMessage("regex"),n=r&&this.base.matches(r,{message:i,excludeEmptyString:s});return this.base=n||this.base,this}normalize(){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}}class W{constructor(t){this.config=t}isString(t){return this.config.isString(t)}handle(t){return this.isString(t)&&U.create({config:this.config,...t}).createSchemaEntry()}}function _(t,e={}){return t&&new W(e).handle(t)}class J extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"date"}get validatorInstance(){return this.validator.date()}static create(t){return new J(t)}get typeEnabled(){return["minDate","maxDate"]}convert(){return super.convert(),this}toDate(t){return this.isStringType(t)&&!this.isValidDateFormat(t)?a.ref(t):new Date(t)}isValidDateType(t){return this.isStringType(t)||this.isDateType(t)}isValidDate(t){return!!this.isValidDateType(t)}isValidDateFormat(t){try{const e=Date.parse(t);return Boolean(e)}catch(t){return!1}}transformToDate(t){return this.isNumberType(t)?new Date(t):t}minDate(){const t=this.constraints.minDate||this.constraints.min;if(this.isNothing(t))return this;const e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("minDate",e);const s=e&&this.base.min(this.toDate(e),this.validationErrorMessage("minDate")||this.validationErrorMessage("min"));return this.base=s||this.base,this}maxDate(){const t=this.constraints.maxDate||this.constraints.max;if(this.isNothing(t))return this;const e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("maxDate",e);const s=e&&this.base.max(this.toDate(e),this.validationErrorMessage("maxDate")||this.validationErrorMessage("max"));return this.base=s||this.base,this}handleInvalidDate(t,e){const s=`invalid constraint for ${t}, was ${e}. Must be a number, string (valid date format) or a Date instance`;return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}}class G{constructor(t){this.config=t}isDate(t){return this.config.isDate(t)}isDateCompatible(t){return this.config.isString(t)}handle(t){return J.create(t).createSchemaEntry()}}function Q(t,e={}){return t&&new G(e).handle(t)}var X={__proto__:null,errValKeys:x,defaults:M,YupArray:V,toYupArray:S,YupBoolean:j,toYupBoolean:A,YupNumber:q,toYupNumberSchemaEntry:Y,toYupNumber:function(t,e={}){return $(t,e)&&function(t){return q.create(t)}(t)},YupObject:B,toYupObject:L,YupString:U,toYupString:_,YupDate:J,toYupDate:Q,YupMixed:T,ConvertYupSchemaError:O,Base:m};class Z extends Error{}class tt extends m{constructor(t,e,s){super(e);const{value:r,type:i,kind:n,name:a,key:o,schema:h,types:l,parentNode:c}=t;this.entryHandler=s||t.entryHandler,this.parentNode=c,this.builder=t.builder,this.opts=t,this.kind=n,this.value=r,this.schema=h,this.key=o,this.value=r||{},this.name=a,this.type=i,this.types=l}get validator(){return this.builder.validator}error(t,e){let{opts:s}=this;throw s=s||{},s=e?{data:e,...s}:s,console.error(t,...s),new Z(t)}resolve(){throw"Must be implemented by subclass"}get obj(){const{schema:t,key:e,value:s,type:r,kind:i,config:n,entryHandler:a,parentNode:o}=this;return{schema:t,parentNode:o,key:e,value:s,type:r,kind:i,config:n,entryHandler:a}}}class et extends tt{constructor(t,e,s){super(t,e,s)}resolve(){const{value:t}=this;if(!Array.isArray(t))return;const e=this.config.toMultiType;return e?e(this):this.oneOf()}oneOf(){const t=this.value,e=this.createEntry.bind(this),s=t.map(e);return this.mixed().oneOf(s)}notOneOf(){const t=this.value,e=this.createEntry.bind(this),s=t.map(e);return this.mixed().notOneOf(s)}createEntry(t){const{createYupSchemaEntry:e}=this.config;return t=normalizedValue(t),e({schema:this.schema,key:this.key,value:t,config:this.config})}normalizedValue(t){return"string"==typeof t?{type:t}:t}mixed(){return this.validator.mixed()}}class st extends tt{constructor(t,e,s){super(t,e,s)}resolve(){const{value:t}=this;if(Array.isArray(t))return;const e=this.config.toSingleType;if(e)return e(this);const{obj:s,config:r,entryHandler:i}=this,n=Object.keys(this.types);let a;for(let t of n){const e=this.types[t];if(e&&(a=e(s,r,i)),a)break}return a}}const rt=(t,e,s)=>new it(t,e,s);class it extends tt{constructor(t,e,s){super(t,e,s),this.initResolvers()}initResolvers(){const{opts:t,config:e,entryHandler:s}=this,r=e.createMultiTypeResolver||this.createMultiTypeResolver.bind(this);this.multiTypeResolver=r(t,e,s);const i=e.createSingleTypeResolver||this.createSingleTypeResolver.bind(this);this.singleTypeResolver=i(t,e,s)}createMultiTypeResolver(){const{opts:t,config:e,entryHandler:s}=this;return new et(t,e,s)}createSingleTypeResolver(){const{opts:t,config:e,entryHandler:s}=this;return new st(t,e,s)}resolve(){return this.toMultiType()||this.toSingleType()||this.toDefaultEntry()}toMultiType(){return(this.config.toMultiType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)}toSingleType(){return(this.config.toSingleType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)}toDefaultEntry(){return this.defaultType()}defaultType(){return this.error("toEntry: unknown type",this.type),!1}}class nt extends Error{}class at extends m{constructor(t){super(t.config);const{schema:e,name:s,key:r,value:i,config:n,builder:a,parentNode:o}=t;this.parentNode=o,this.builder=a,this.opts=t,this.schema=e,this.key=r,this.value=i||{},this.config=n||{},this.name=s,this.init()}get calcType(){const{value:t}=this;return Array.isArray(t)?"array":t.type}get calcKind(){return"array"===this.type?"multi":"single"}createNew(t){return new at(t).toEntry()}init(){this.type=this.calcType,this.kind=this.calcKind,this.setTypeHandlers(),this.setPropertyHandler()}get validator(){return this.builder&&this.builder.validator}setPropertyHandler(){const{config:t}=this;this.propertyValueHandler=(t.createPropertyValueHandler||this.createPropertyValueHandler)(this.propertyHandlerOpts,t)}get propertyHandlerOpts(){const{types:t,value:e,name:s,key:r,type:i,kind:n,schema:a,parentNode:o}=this;return{type:i,parentNode:o,kind:n,types:t,value:e,name:s,key:r,schema:a,entryHandler:this}}createPropertyValueHandler(t,e){return rt(t,e,this)}get defaultTypeHandlerMap(){return{string:_,number:Y,boolean:A,array:S,object:L,date:Q}}setTypeHandlers(){this.types=this.config.types||this.typeHandlers}get typeHandlers(){return{...this.defaultTypeHandlerMap,...this.config.typeHandlers||{}}}isValidSchema(){const{type:t}=this;return this.isStringType(t)}error(t,e){const{opts:s}=this;throw e?console.error(t,e,...s):console.error(t,...s),new nt(t)}toEntry(){if(!this.isValidSchema()){const t=JSON.stringify(this.schema);this.error(`Not a valid schema: type ${this.type} must be a string, was ${typeof this.type} ${t}`)}const{opts:t,config:e}=this;return this.propertyValueHandler.resolve(t,e)}}function ot(t={}){return new at(t).toEntry()}function ht(t,e={},s){return new ct(t,{...e},s).yupSchema}function lt(t){return t===Object(t)}class ct extends m{constructor(t,e={},s){super(e),this.init(t,e,s)}init(t,e,s){e.buildYup=ht,e.createYupSchemaEntry=e.createYupSchemaEntry||ot,this.config=Object.assign(this.config,e),this.schema=t;const r=this.getType(t),i=this.getProps(t);if(this.parentNode=s,this.type=r,this.properties={...i},this.additionalProps=this.getAdditionalProperties(t),this.required=this.getRequired(t),this.setLocale(),("function"==typeof e.init?e.init:()=>{}).bind(this)(t,e),!function(t){return t&&"object"===t}(r))return void this.error(`invalid schema: must be type: "object", was type: ${r}`);if(!lt(i)){const t=JSON.stringify(a);return void this.error(`invalid schema: must have a properties object: ${t}`)}const n=this.getName(t),a=(e.buildProperties||this.buildProperties).bind(this)(t,this),o=this.propsToShape({properties:a,name:n,config:e});this.shapeConfig=o,this.validSchema=!0}get validator(){return a}setLocale(){this.config.locale&&a.setLocale(this.config.locale)}getAdditionalProperties(t){return t.additionalProperties}getRequired(t){const{getRequired:e}=this.config;return e?e(t):t.required||[]}getProps(t){return this.config.getProps(t)}getType(t){return this.config.getType(t)}getName(t){return this.config.getName(t)}get yupSchema(){return a.object().shape(this.shapeConfig)}buildProperties(){const t=Object.keys(this.properties),e=(this.config.buildProp||this.buildProp).bind(this);return t.reduce(e,{})}getRequiredPropsList(){return Array.isArray(this.required)?[...this.required]:[]}buildProp(t,e){const s=this.properties[e],r=this.getRequiredPropsList();return(this.config.setRequired||this.setRequired).bind(this)(s,e,r),(this.config.setPropEntry||this.setPropEntry).bind(this)(t,e,s),t}setRequired(t,e,s){const r=s.indexOf(e)>=0;return lt(t)||this.warn(`Bad property value: ${t} must be an object`),t.required=this.isRequired(t)||r,t}setPropEntry(t,e,s){t[e]={required:s.required,...s}}isRequired(t){return this.config.isRequired(t)}propsToShape(t={}){const e=this.objPropsToShape(t);return this.objPropsShape=e,this.addPropsShape=this.additionalPropsToShape(e,t),e}additionalPropsToShape(t,e={}){return t}objPropsToShape({name:t}={}){const e={...this.properties},s=Object.keys(e),r=this.reducePropToShape.bind(this);return s.reduce((s,i)=>r(s,i,{name:t,key:i,value:e[i]}),{})}reducePropToShape(t,e,s){const r=this.propToYupSchemaEntry(s);return this.logInfo("propToShape",{...s,yupSchemaEntry:r}),r&&(t[e]=r),t}propToYupSchemaEntry({name:t,key:e,value:s={}}){return this.createYupSchemaEntry({schema:this.schema,parentNode:this.parentNode||this,name:t,key:e,value:s,config:this.config,builder:this})}createYupSchemaEntry(t={}){return this.config.createYupSchemaEntry(t)}onConstraintAdded(t){this.logInfo("Constraint Added",t)}}const ut={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:{}},dt={createValidatorName:(t,e)=>`is${t=(t=(t=l.default(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")}`,createTestName:(t,e)=>h.default(t||e)},pt={isMagnetURI:(t,e)=>/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)};exports.ConstraintBuilder=w,exports.ErrorMessageHandler=E,exports.PropertyValueResolver=it,exports.YupBuilder=ct,exports.YupSchemaEntry=at,exports.YupSchemaEntryError=nt,exports.buildYup=ht,exports.createPropertyValueResolver=rt,exports.createYupSchemaEntry=ot,exports.extendYupApi=function({constraints:e,override:s=!1,validator:r,createValidatorName:i,createTestName:n}={}){if(!r)throw"extendYupApi: missing validator option";Array.isArray(e)&&(e=((t,e={})=>t.reduce((t,s)=>{if("string"!=typeof s&&!(s instanceof Object)){if(!1!==e.throws)throw`toConstraintsMap: invalid entry ${s}`;return t}if("string"==typeof s)t[name]={};else{if(!s.name){if(!1!==e.throws)throw`toConstraintsMap: invalid entry ${s} missing name`;return t}t[s.name]=s}return t},{}))(e)),e=s?e||ut:{...ut,...e||{}},i=i||dt.createValidatorName,n=n||dt.createTestName,Object.keys(e).map(s=>{let{testName:a,optsKey:o,validatorName:h,logging:l}=e[s];const c=i(h,s);a=n(a,s),t.addMethod(t.string,s,(e={})=>{const{message:i}=e,n=e[o];return t.string().test(a,i,t=>{const{path:e,createError:o}=this;let h=r[c];if(h=h||pt[c],"function"!=typeof h)throw Error("No method named ${validatorName} on validator");const u=h(t,n);return!0===l&&console.log("Yup validator bridge",{key:s,fullValidatorName:c,testName:a,value:t,valid:u}),u||o({path:e,message:i})})})})},exports.types=X;
var t=require("yup"),e=require("uniq"),s=require("dashify"),r=require("uppercamelcase");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach(function(s){if("default"!==s){var r=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,r.get?r:{enumerable:!0,get:function(){return t[s]}})}}),e.default=t,e}var a=/*#__PURE__*/n(t),o=/*#__PURE__*/i(e),h=/*#__PURE__*/i(s),l=/*#__PURE__*/i(r);const c={getProps:t=>t&&t.properties,getType:t=>t&&t.type,getName:t=>t&&(t.name||t.title),getConstraints:t=>t,isString:t=>t&&"string"===t.type,isArray:t=>t&&"array"===t.type,isInteger:t=>t&&("integer"===t.type||"int"===t.type),isBoolean:t=>t&&"boolean"===t.type,hasDateFormat:t=>t&&["date","date-time"].find(e=>e===t.format),isDate:t=>t&&"string"===t.type&&c.hasDateFormat(t.format),isNumber:t=>t&&("number"===t.type||c.isInteger(t)),isObject:t=>t&&"object"===t.type,isRequired:t=>t&&t.required},u={getProps:t=>t.properties,getType:t=>t.type,getName:t=>t.name||t.title,getConstraints:t=>t,isString:t=>"string"===t.type&&!u.hasDateFormat(t),isArray:t=>"array"===t.type,isBoolean:t=>"boolean"===t.type,isInteger:t=>"integer"===t.type,hasDateFormat:t=>t&&["date","date-time"].find(e=>e===t.format),isDate:t=>"string"===t.type&&u.hasDateFormat(t),isNumber:t=>"number"===t.type||u.isInteger(t),isObject:t=>"object"===t.type,isRequired:t=>t.required},d={getProps:t=>t&&t.fields,getType:t=>t&&t.type,getName:t=>t&&(t.name||t.title),getConstraints:t=>t,isString:t=>t&&"string"===t.type,isArray:t=>t&&"array"===t.type,isInteger:t=>t&&"int"===t.type,isFloat:t=>t&&"float"===t.type,isDouble:t=>t&&"double"===t.type,isBoolean:t=>t&&"boolean"===t.type,isDate:t=>t&&"int"===t.type&&"date"===t.logicalType,isNumber:t=>t&&(d.isInteger(t)||d.isFloat(t)||d.isDouble(t)),isObject:t=>t&&"record"===t.type,isRequired:t=>t&&t.required},p={"json-schema":c,"type-def":u,avro:d};class y extends class{constructor(t={}){this.config=t;const{log:e,error:s}=t,r=t.enable||{};!0===t.logging&&(r.log=!0),!1===t.logging&&(r.log=!1),this.enable=r,this.log="function"==typeof e?e:console.log,this.err="function"==typeof s?s:console.error}error(t){var e=[].slice.call(arguments,1);if(!1!==this.enable.error&&this.err)throw e&&e.length?this.err(t,...e):this.err(t),t}warn(t){this.enable.warn&&this.logInfo("WARNING: "+t,...[].slice.call(arguments,1))}logTypeInfo(t){if(!this.enable.log)return;if(!this.log)return;const e=this.config.logTypes||[];e.length&&e.find(t=>this.type===t)&&logInfo(t,...[].slice.call(arguments,1))}logDetails(t,e){const s=this.config.logDetailed||[];s.length&&s.find(t=>!(t.key&&e.key!==t.key||t.constraintName&&e.constraintName!==t.constraintName||t.propName&&e.propName!==t.propName||t.method&&e.method!==t.method))&&this.logInfo(t,e,...[].slice.call(arguments,2))}logInfo(t){var e=[].slice.call(arguments,1);this.enable.log&&this.log&&(e&&e.length?this.log(t,...e):this.log(t))}}{constructor(t={}){super(t)}isNothing(t){return null==t}isPresent(t){return!this.isNothing(t)}hasKey(t,e){if(this.isObjectType(t))return Object.keys(t).includes(e)}toNumber(t){return Number(t)}isNumberLike(t){return!isNaN(this.toNumber(t))}isObjectType(t){return t===Object(t)}isArrayType(t){return Array.isArray(t)}isNumberType(t){return!isNaN(t)}isStringType(t){return"string"==typeof t}isFunctionType(t){return"function"==typeof t}isDateType(t){return t instanceof Date}}class g{constructor(t,e){this.schemaParserMap=t,this.name=e}lookup(t=this.name){return this.schemaParserMap[t]}build(){const t=this.lookup();if(t.extends){const e=this.extend(t.extends);if(e)return e}return t}extend(t){const e=this.lookup(t);e&&(entry={...e,...this.lookup()})}}class m extends y{constructor(t={}){super(t);const e=(t.createSchemaParserBuilder||new g(t.schemaParserMap||p,t.schemaType||"json-schema")).build();this.config={...e,...t}}createSchemaParserBuilder(t,e){return new SchemaParserBuilder(t,e)}}function f(t){return t===Object(t)}class b{constructor(t,e={}){this.whenEntryObj=t;const{schema:s,properties:r,config:i,key:n,when:a,type:o}=e;this.schema=s,this.when=a,this.properties=r||{},this.key=n,this.type=o,this.config=i}validateAndConfigure(t){if(!f(t=t||this.whenEntryObj))return this.warn("invalid or missing when entry constraint object",t),!1;const 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)}createYupSchemaEntry(t){return this.config.createYupSchemaEntry(t)}createValue(t,e){return"string"==typeof t&&(t={[t]:!0}),f(t)||this.error(`createValue: ${e} must be a schema object`),{key:this.key,type:this.type,...t}}createEntryOpts(t,e){const s=this.createValue(t,e);return{schema:this.schema,properties:this.properties,key:this.key,type:this.type,value:s,config:this.config}}createEntry(t,e){const s=this.createEntryOpts(t,e);return this.createYupSchemaEntry(s)}hasKey(t,e){return t.find(t=>t===e)}hasAnyKey(t,e){return t.find(t=>e.includes(t))}whenEntryFor(t,e,s){if(s=s||e,"string"==typeof t&&(t={[t]:!0}),!f(t))throw`whenEntryFor: Invalid when object ${t}`;const r={...t[s]};return delete t[s],r?(t[e]=this.createEntry(r,e),t):t}calcEntryObj(){let t={...this.whenEntryObj};return t=this.whenEntryFor(t,"then"),"otherwise"in t&&(t=this.whenEntryFor(t,"otherwise")),"else"in t&&(t=this.whenEntryFor(t,"else")),t}get entryObj(){return this.validateAndConfigure()&&this.calcEntryObj()}warn(t,e){console.error("[WhenEntry] WARNING",t,e)}error(t,e){throw console.error("[WhenEntry] ERROR",t,e),t}}function v(t){return t===Object(t)}class C{constructor(t={}){const{type:e,key:s,value:r,when:i,schema:n,properties:a,config:o}=t;this.opts=t,this.when=i,this.key=s,this.type=e,this.value=r,this.schema=n,this.properties=a,this.config=o,this.validate()}validate(){"string"!=typeof this.type&&this.error(`validate: invalid or mising type: ${this.type}`,this.opts),v(this.when)||this.error(`validate: invalid or mising when: ${this.when}`,this.opts)}validateAndConfigure(t){if(!v(t=t||this.when))return this.warn("invalid or missing when constraint",t),!1;const 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)}createWhenEntry(t,e){return((t,e={})=>new b(t,e))(t,e)}accumulate(t,e){let s=this.when[e];if(!v(s))return this.warn(`invalid when entry constraint object ${s} for ${e}`),t;const r={type:this.type,key:this.key,schema:this.schema,properties:this.properties,config:this.config},{entryObj:i}=this.createWhenEntry(s,r);return i?t=Object.assign(t,i):t}get constraintObj(){return this.whenKeys?this.whenKeys.reduce(this.accumulate.bind(this),{}):{}}get keyVal(){const t=this.whenKeys||[];return 1===t.length?t[0]:t}get constraintValue(){return!!this.keyVal&&[this.keyVal,this.constraintObj]}get constraint(){return this.validateAndConfigure()&&this.constraintValue}warn(t,e){console.error("[WhenCondition] WARNING",t,e)}error(t,e){throw console.error("[WhenCondition] ERROR",t,e),t}}const N=t=>new C(t);class w extends y{constructor(t,e={}){super(e),this.typeHandler=t,this.type=t.type,this.builder=t.builder,this.constraintsAdded={},this.delegators.map(e=>{this[e]=t[e]})}get delegators(){return["errMessages","base","key","type","constraints","errorMessageHandler","logInfo","warn"]}build(t,e={}){let{constraintName:s,constraintValue:r,propValue:i,method:n,yup:a,value:o,values:h,errName:l}=e;if(a=a||this.base,r=this.getFirstValue([r,i,this.constraints[t]]),s=s||t,n=n||s,this.idObj={propName:t,method:n,constraintName:s,key:this.key},this.logDetailed("build",e,{resolved:{constraintValue:r,constraintName:s}}),this.isNothing(r))return this.warn("no prop value",{constraintValue:r}),!1;const c=this.aliasMap[n]||n;if(!a[c])return this.warn(`Yup has no such API method: ${c}`),!1;const u=a[c].bind(a),d=this.validationErrorMessage(s),p=l&&this.validationErrorMessage(l),y={constraintName:s,yup:a,constraintFn:u,errFn:d||p},g=["multiValueConstraint","presentConstraintValue","nonPresentConstraintValue"];let m;const f=this.type;for(let t of g)if(m=this[t].bind(this)(this.getFirstValue([o,h,r],{constraintName:s,type:f}),y),m)break;return m?(this.base=m,m):(this.warn("buildConstraint: missing value or values options"),!1)}yupRefMap(){return{string:["length","min","max"],number:["min","max","lessThan","moreThan"],date:["min","max"],array:["length","min","max"]}}getFirstValue(t,e={}){const{constraintName:s,type:r}=e,i=this.isPresent.bind(this),n=this.yupRefMap[r],o=t.filter(i)[0];return n&&n.includes(s)&&this.isStringType(o)?a.ref(o):o}nonPresentConstraintValue(t,{constraintName:e,constraintFn:s,errFn:r}){if(!this.isPresent(t))return this.logInfo("nonPresentConstraintValue",{constraintValue:t}),this.onConstraintAdded({method:"nonPresentConstraintValue",name:e}),s(r)}presentConstraintValue(t,{constraintName:e,constraintFn:s,errFn:r}){if(this.isPresent(t))return this.logInfo("presentConstraintValue",{constraintName:e,constraintValue:t}),this.onConstraintAdded({method:"presentConstraintValue",name:e,value:t}),this.isNoValueConstraint(e)?(this.logInfo("isNoValueConstraint",{constraintName:e}),s(r)):(this.logInfo("presentConstraintValue: apply validator function",{constraintName:e,constraintValue:t}),s(t,r));this.logInfo("presentConstraintValue: value not present",{constraintName:e,constraintValue:t})}multiValueConstraint(t,{constraintFn:e,constraintName:s,errFn:r}){if(this.isPresent(t)){if(this.logInfo("multiValueConstraint",{constraintName:s,values:t}),Array.isArray(t))return this.onConstraintAdded({method:"multiValueConstraint",name:s,value:t}),this.logInfo("multiValueConstraint: apply validator function",{constraintName:s,value:t}),this.callConstraintFn(e,s,t,r);this.warn("buildConstraint: values option must be an array of arguments")}}callConstraintFn(t,e,s,r){return this.isMultiArgsCall(e)?t(...s,r):t(s,r)}isMultiArgsCall(t){return this.multiArgsValidatorMethods[t]}get multiArgsValidatorMethods(){return this.config.multiArgsValidatorMethods||{when:!0}}isNoValueConstraint(t){return this.noValueConstraints.includes(t)}get noValueConstraints(){return["required","email","url","format"]}addTrueValueConstraint(t,{constraintName:e,errName:s}={}){return this.addConstraint(t,{constraintName:e,value:!0,errName:s})}addConstraint(t,e){const s=this.build(t,e);return!!s&&(this.typeHandler.base=s,s)}onConstraintAdded({method:t,name:e,value:s}){if(this.constraintsAdded[e]=s,this.builder)return this.builder.onConstraintAdded({type:this.type,method:t,name:e,value:s}),this.typeHandler;this.logInfo("no builder set to notify in ConstraintBuilder")}get constraintsMap(){return{simple:["required","notRequired","nullable"],value:["default","strict"]}}logDetailed(t){this.logDetails(t,this.idObj,...[].slice.call(arguments,1))}validationErrorMessage(t){return this.errorMessageHandler.validationErrorMessage(t)}get aliasMap(){return{oneOf:"oneOf",enum:"oneOf",anyOf:"oneOf"}}}class E extends y{constructor(t,e={}){super(e),this.typeHandler=t,this.init()}init(){const{typeHandler:t}=this;this.constraints=t.constraints,this.errMessages=t.errMessages,this.key=t.key,this.value=t.value,this.constraints=t.constraints,this.parentNode=t.parentNode,this.keyPath=t.keyPath,this.type=t.type,this.description=t.description,this.title=t.title,this.setErrMessage()}errMessageMap(t={}){return t[this.errMessagesMapKey]||this.errMessages}get errMessageKey(){return this.config.errMessageKey||"errMessage"}get errMessagesMapKey(){return this.config.errMessagesMapKey||"errMessages"}setErrMessage(){const{typeHandler:t}=this,{value:e}=t;if(!e.errMessage)return;const s=this.errMessageKey,r=this.errMessageMap(e);return r[this.key]=e[s]||r[this.key],this}validationErrorMessage(t){const{constraints:e,key:s,description:r,title:i,typeHandler:n,keyPath:a,parentNode:o}=this,h=this.errMessageFor(t);return"function"==typeof h?h(e,{key:s,title:i,description:r,typeHandler:n,parentNode:o,keyPath:a}):h}errMessageFor(t){const{errMessages:e,key:s}=this,r=e[s];return r?r[t]:e[`$${t}`]}}class O extends Error{}class T extends m{constructor(t={}){super(t.config),this.init(t)}init(t){let{schema:e,key:s,value:r,config:i,entryHandler:n,parentNode:a}=t;i=i||{},e=e||{},this.parentNode=a||n?.parentNode,this.validateOnCreate(s,r,t),this.opts=t,this.entryHandler=n,this.validator=this.getValidator(),this.key=s,this.schema=e,this.properties=e.properties||{},this.value=r,this.title=r.title,this.description=r.description,this.constraints=this.getConstraints(),this.format=r.format||this.constraints.format,this.config=i||{},this.type=this.baseType,this.mixedConfig=this.config.mixedEnabled||{};const o=this.config[this.type]||{},h=this.config.mixed||{};this.mixedConfig=h,this.typeConfig={...h,...o},this.errMessages=i.errMessages||{},this.configureTypeConfig(),this.constraintsAdded={},this.base=this.getBase()}get keyPath(){return this._keyPath=this._keyPath||this.calcKeyPath(),this._keyPath}calcKeyPath(){let t,e=this,s=[];for(;(t=e.parentNode)&&t;)s.push(t.key),e=e.parentNode;return s.join(".")}get builder(){return this.entryHandler&&this.entryHandler.builder}getBase(){return this.customBaseValidator||this.validatorInstance}get customBaseValidator(){return this.config.validatorFor&&this.config.validatorFor(this.type)}getValidator(){return this.opts.validator||this.config.validator||this.builder&&this.builder.validator||a}get baseType(){return"mixed"}get validatorInstance(){return this.validator.mixed()}configureTypeConfig(){this.typeConfig.enabled||this.typeConfig.extends||this.typeConfig.convert&&(this.typeConfig.extends=Object.keys(this.typeConfig.convert))}isRequired(t){return!0===(t=t||this.value).required}get mode(){return this.config.mode||{}}get disableFlags(){return[!1,"disabled","no","off"]}get enableFlags(){return[!0,"enabled","yes","on"]}disabledMode(t){const e=this.mode[t];return!!this.disableFlags.find(t=>e===t)}enabledMode(t){const e=this.mode[t];return!!this.enableFlags.find(t=>e===t)}get shouldPreProcessValue(){return!this.disabledMode("notRequired")}preProcessedConstraintValue(t){return this.shouldPreProcessValue?this.isRequired(t)?t:{...t,notRequired:!0}:t}set value(t){this._value=this.preProcessedConstraintValue(t)}get value(){return this._value}initHelpers(){const{config:t}=this;this.errorMessageHandler=(this.config.createErrorMessageHandler||this.createErrorMessageHandler)(this,t),this.constraintBuilder=(this.config.createConstraintBuilder||this.createConstraintBuilder)(this,t),this.rebind("addConstraint","addTrueValueConstraint")}createConstraintBuilder(t,e={}){return new w(t,e)}createErrorMessageHandler(t,e={}){return new E(t,e)}rebind(){[].slice.call(arguments).map(t=>{const e=this[t];this[t]=this.isFunctionType(e)?e.bind(this):e})}validateOnCreate(t,e,s){t||this.error(`create: missing key ${JSON.stringify(s)}`),e||this.error(`create: missing value ${JSON.stringify(s)}`)}get mixedEnabled(){return this.mixedConfig.enabled||["oneOf","notOneOf","when","nullable","isType","label","const","refValueFor"]}get typeEnabled(){return[]}get $typeExtends(){if(Array.isArray(this.typeConfig.extends))return o.default([...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]}convertEnabled(){this.enabled.map(t=>{const e=this.convertFnFor(t);e&&e(this)})}convertFnFor(t){return this.customConvertFnFor(t,this)||this.builtInConvertFnFor(t)}customConvertFnFor(t){return(this.typeConfig.convert||{})[t]}builtInConvertFnFor(t){return this[t].bind(this)}getConstraints(){return this.config.getConstraints(this.value)}createSchemaEntry(){return this.preConvert(),this.convert(),this.postConvert(),this.base}preConvert(){const{preConvert:t}=this.config,e=t&&t.bind(this);e&&e(this)}postConvert(){const{postConvert:t}=this.config,e=t&&t.bind(this);e&&e(this)}convert(){return this.initHelpers(),this.addMappedConstraints(),this.convertEnabled(),this}apply(t){var e=[].slice.call(arguments,1);if("string"!=typeof t)throw new TypeError("[Mixed] apply must take a method name available on the validator instance as first argument");return this.base=e&&e.length&&this.base[t](...e)||this.base,this}applyArr(t,e){if("string"!=typeof t)throw new TypeError("[Mixed] apply must take a method name available on the validator instance as first argument");return this.base=e&&e.length&&this.base[t](e)||this.base,this}addTrueValueConstraint(t,e){const s=this.constraintBuilder.addTrueValueConstraint(t,e);if(s){const{base:t}=s;this.base=t}return this}addConstraint(t,e){if(!this.constraintBuilder)throw new Error(`[YupMixed] addConstraint: Missing constraintBuilder in ${this.constructor.name}`);const s=this.constraintBuilder.addConstraint(t,e);return s&&(this.base=s),this}addMappedConstraints(){const t=Object.keys(this.constraintsMap),e=this.addMappedConstraint.bind(this);return t.map(e),this}addMappedConstraint(t){const{constraintsMap:e}=this,s=this["trueValue"===t?"addTrueValueConstraint":"addConstraint"],r=this.constraints[t];e[t].map(t=>{s(t,{value:r})})}get constraintsMap(){return{simple:["default","required","notRequired","nullable"],trueValue:["strict"]}}refValueFor(){let t=this.constraints.refValueFor;return this.isNothing(t)?this:(this.logInfo("refValueFor",{propRefName:t}),this.apply("when",(e,s)=>e?s.required().oneOf([a.ref(t)]):s))}normalizeValues(t){return Array.isArray(t)?t:[t]}get oneOfValues(){return this.constraints.enum||this.constraints.oneOf||this.constraints.anyOf}get oneOfAliases(){return["oneOf","enum","anyOf"]}get oneOfAlias(){return this.oneOfAliases.find(t=>void 0!==this.constraints[t])}oneOf(){let t=this.oneOfValues;if(this.isNothing(t))return this;t=this.normalizeValues(t);const e=this.resolveValues(t),s=this.oneOfAlias;return this.logDetails("type",{constraintName:s,method:"oneOf",key:this.key,type:this.type},t,e),this.addConstraint(s,{values:e})}oneOfConditional(){let{config:t,parentNode:e,isObject:s,value:r,key:i}=this;const n=r;this.base=this.base.test(i,(r,i)=>{for(let i in n){if(!s(i))return r===i;if(t.buildYup(i,t,e).validate())return!0}return!1})}notOneOfConditional(){let{config:t,parentNode:e,isObject:s,value:r,key:i}=this;const n=r;this.base=this.base.test(i,(r,i)=>{for(let i in n){if(!s(i))return r!==i;if(t.buildYup(i,t,e).validate())return!1}return!0})}logDetailed(t,e){this.logDetails(t,e,...[].slice.call(arguments,2))}get notOneOfValues(){const{not:t,notOneOf:e}=this.constraints;return e||t&&(t.enum||t.oneOf)}notOneOf(){let t=this.oneOfValues;if(this.isNothing(t))return this;t=this.normalizeValues(t);const e=this.resolveValues(t);return this.logDetails("type",{constraintName:"notOneOf",method:"notOneOf",key:this.key,type:this.type},t,e),this.addConstraint("notOneOf",{values:e})}resolveValues(t){return t.map(t=>this.isObjectType(t)?this.resolveValue(t):t)}const(){let t=this.constraints.const;if(this.isNothing(t))return this;if(this.isDataRef(t)){const e=this.normalizeDataRefPath(t);t=a.ref(e)}return this.addConstraint("oneOf",{values:[t]})}normalizeDataRefPath(t){return(t=t.$data||t).split("/").shift().join("/")}isDataRef(t){return this.isPresent(t.$data)}isConst(t){return this.hasKey(t,"const")}resolveValue(t){return this.isConst(t)?t.const:(0,this.config.createYupSchemaEntry)({schema:this.schema,key:this.key,value:t,config:this.config})}validationErrorMessage(t){const e=this.errorMessageHandler.validationErrorMessage.bind(this.errorMessageHandler);return(this.config.validationErrorMessage||e)(t,this)}createWhenConditionFor(t){return(this.config.createWhenCondition||N)({key:this.key,type:this.type,value:this.value,schema:this.schema,properties:this.properties,config:this.config,when:t})}label(){const t=this.value,e=t.title||t.label;return this.base=e&&this.base.label(e)||this.base,this}when(){const t=this.constraints.when;if((e=t)!==Object(e))return this;var e;const{constraint:s}=this.createWhenConditionFor(t);return s?(this.logInfo(`Adding when constraint for ${this.key}`,s),this.addConstraint("when",{values:s,errName:"when"}),this):(this.warn(`Invalid when constraint for: ${t}`),this)}isType(){return this.addConstraint("isType",{value:this.constraints.isType,errName:"notOneOf"}),this}nullable(){const{nullable:t,isNullable:e}=this.constraints;return this.addConstraint("nullable",{value:t||e,errName:"notOneOf"}),this}message(){return config.messages[this.key]||config.messages[this.type]||{}}errMessage(t="default"){return this.message[t]||"error"}toValidJSONSchema(){}normalize(){}deNormalize(){}errorMsg(t){this.throwError(t)}error(t,e){const s=[`[${t}]`,e].join(" ");this.errorMsg(s)}throwError(t){throw t}}const x=["oneOf","enum","required","notRequired","minDate","min","maxDate","max","trim","lowercase","uppercase","email","url","minLength","maxLength","pattern","matches","regex","integer","positive","minimum","maximum"],M={errMessages:(t=x)=>t.reduce((t,e)=>(t[e]=({key:t,value:e})=>`${t}: invalid for ${e.name||e.title}`,t),{})};class V extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.createYupSchemaEntry=this.config.createYupSchemaEntry}get baseType(){return"array"}get validatorInstance(){return this.validator.array()}static create(t){return new V(t)}convert(){return super.convert(),this}get typeEnabled(){return["itemsOf","maxItems","minItems","ensureItems","compact"]}ensureItems(){return this.addConstraint("ensure")}compact(){return this.addConstraint("compact")}itemsOf(){const{items:t,itemsOf:e}=this.constraints,s=t||e||this.constraints.of;if(!this.isNothing(s))if(Array.isArray(s))this.error("itemsOf","does not (yet) support an Array of schemas");else if(this.isObjectType(s)){if(this.createYupSchemaEntry){try{const t=s,e={key:this.key,value:t,config:this.config};this.logTypeInfo("array:of",{schemaConf:e});const r=this.createYupSchemaEntry(e);return this.logTypeInfo("array:of",{schemaEntry:r}),this.addConstraint("of",{constraintValue:r,propValue:t,value:r})}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 s)}maxItems(){const{maxItems:t,max:e}=this.constraints,s=t||e;if(!this.isNumberType(s))return this;if(!this.isValidSize(s))return this.handleInvalidSize("maxItems",s);const r=this.validationErrorMessage("maxItems"),i=s&&this.base.max(s,r);return this.base=i||this.base,this}minItems(){const{minItems:t,min:e}=this.constraints,s=t||e;if(!this.isNumberType(s))return this;if(!this.isValidSize(s))return this.handleInvalidSize("minItems",s);const r=this.validationErrorMessage("minItems"),i=s&&this.base.min(s,r);return this.base=i||this.base,this}$items(){return this}$additionalItems(){return this}$uniqueItems(){return this}$contains(){return this}handleInvalidSize(t,e){const s=`invalid array size constraint for ${t}, was ${e}. Must be a number >= 0`;return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}isValidSize(t){return this.isNumberType(t)&&t>=0}}class k extends m{constructor(t){super(t)}isArray(t){return this.config.isArray||this.error("ArrayHandler: missing isArray in config",this.config),this.config.isArray(t)}handle(t){return this.isArray(t)&&V.create(t).createSchemaEntry()}}function S(t,e={}){return t&&new k(e).handle(t)}class A extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"boolean"}get validatorInstance(){return this.validator.boolean()}static create(t){return new A(t)}}class j{constructor(t){this.config=t}isBoolean(t){return this.config.isBoolean(t)}handle(t){return this.isBoolean(t)&&A.create(t).createSchemaEntry()}}function I(t,e={}){return t&&new j(e).handle(t)}class P extends y{constructor(t,e){super(t.config),this.map=e||this.$map||{},this.typeHandler=t,this.delegates.map(e=>{const s=t[e];s||this.error(`missing delegate: ${e}`,{typeHandler:t}),this[e]=this.isFunctionType(s)?s.bind(t):s})}isStringType(t){return"string"==typeof t}get delegates(){return["constraints","addConstraint","constraintsAdded"]}add(){const t=this.map;Object.keys(t).map(e=>{const s=this.entryNames(t[e]);this.addConstraints(e,s)})}entryNames(t){return Array.isArray(t)?t:[t]}addConstraints(t,e=[]){return e.map(e=>{const s=this.validateAndTransform(e);this.addConstraint(e,{method:t,value:s})}),this}validateAndTransform(t){const e=this.constraints[t];return this.validate(t,e),this.transform(e)}invalidMsg(t,e){return`invalid constraint for ${t}, was ${e}.`}get explainConstraintValidMsg(){return""}invalidConstraintMsg(t,e){return[this.invalidMsg(t,e),this.explainConstraintValidMsg].join("\n")}validate(t,e){return this.isNothing(e)?this:this.isValidConstraint(e)?void 0:this.handleInvalidConstraint(t,e)}isValidConstraint(t){return!0}handleInvalidConstraint(t,e){const s=this.invalidConstraintMsg(t,e);return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}}class D extends P{constructor(t){super(t)}transform(t){return this.typeHandler.toNumber(t)}isValidConstraint(t){return this.typeHandler.isNumberLike(t)||this.typeHandler.isStringType(t)}get explainConstraintValidMsg(){return"Must be a number or convertible to a number"}}class F extends D{constructor(t){super(t)}get $map(){return{moreThan:["exclusiveMinimum","moreThan"],lessThan:["exclusiveMaximum","lessThan"],max:["maximum","max"],min:["minimum","min"]}}}class R extends m{constructor(t,e){super(e),this.obj=t}isValid(){return!1}verify(){return this.isPresent(this.obj)&&this.isValid(this.obj)}}class H extends R{constructor(t,e){super(t,e)}isValid(){return this.config.isNumber(this.obj)}}const $=(t,e={})=>function(t,e){return new H(t,e)}(t,e).verify();function Y(t,e={}){return $(t,e)&&function(t){return q.schemaEntryFor(t)}(t)}class q extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.rangeConstraint=new F(this)}get baseType(){return this.normalizeNumType(this.opts.type)}get validatorInstance(){return this.validator.number()}normalizeNumType(t){return"int"===t?"integer":t}static create(t){return new q(t)}static schemaEntryFor(t){return q.create(t).createSchemaEntry()}get typeEnabled(){return["range","posNeg","integer"]}convert(){return super.convert(),this}range(){this.rangeConstraint.add()}truncate(){return this.addConstraint("truncate")}round(){const{round:t}=this.constraints;if(this.isNothing(t))return this;const e=this.isStringType(t)?t:"round";return t&&this.base.round(e),this}posNeg(){this.positive(),this.negative()}integer(){return this.isInteger&&this.addConstraint("integer"),this}get isInteger(){return this.config.isInteger(this.type)}positive(){return this.addConstraint("positive")}negative(){return this.addConstraint("negative")}get isNegative(){const{exclusiveMaximum:t,negative:e}=this.constraints;return!!e||void 0!==t&&0===t}get isPositive(){const{exclusiveMinimum:t,positive:e}=this.constraints;return!!e||void 0!==t&&0===t}normalize(){this.constraints.maximum=this.constraints.maximum||this.constraints.max,this.constraints.minimum=this.constraints.minimum||this.constraints.min}}class B extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance,this.properties=this.value.properties}get baseType(){return"object"}get validatorInstance(){return this.validator.object()}static create(t){return new B(t)}get typeEnabled(){return["noUnknown","camelCase","constantCase"]}convert(){if(!this.properties)return this;super.convert();const t=this.value,e=this.config;if(t){e.buildYup||this.error("convert","Missing buildYup function from config",e);const s={key:this.key,...this.value,parentNode:this.parentNode},r=this.config.buildYup(t,e,s);this.base=r}return this}camelCase(){return this.addConstraint("camelCase")}constantCase(){return this.addConstraint("constantCase")}noUnknown(){const{noUnknown:t,propertyNames:e}=this.value,s=t||e,r=s&&this.base.noUnknown(s,this.validationErrorMessage("propertyNames")||this.validationErrorMessage("noUnknown"));return this.base=r||this.base,this}}const K=t=>t&&"object"===t.type;class z{constructor(t={}){(t=t||{}).isObject=t.isObject||K,this.config=t,this.schema=t.schema}isObject(t){return this.config.isObject(t.value)}handle(t){return this.isObject(t)&&B.create({...t,config:this.config}).createSchemaEntry()}}function L(t,e={}){return t&&function(t={}){return new z(t)}(e).handle(t)}class U extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"string"}get validatorInstance(){return this.validator.string()}static create(t){return new U(t)}convert(){return super.convert(),this}get typeEnabled(){return["normalize","minLength","maxLength","pattern","lowercase","uppercase","email","url","genericFormat"]}trim(){return this.addConstraint("trim")}lowercase(){return this.addConstraint("lowercase")}uppercase(){return this.addConstraint("uppercase")}genericFormat(){1!=!this.config.format&&this.validator.prototype[this.format]&&this.addConstraint(this.format)}email(){if(!this.isEmail)return this;const t=this.constraintNameFor("email","format"),e="email";return this.addConstraint("email",{constraintValue:!0,constraintName:t,method:e,errName:e}),this}constraintNameFor(){return[].slice.call(arguments).find(t=>this.constraints[t])}get isEmail(){return this.constraints.email||"email"===this.format}url(){if(!this.isUrl)return this;const t=this.constraintNameFor("url","format");return this.addConstraint("url",{constraintValue:!0,constraintName:t,method:"url",errName:"url"}),this}get isUrl(){return this.constraints.url||"url"===this.format}minLength(){const{minLength:t}=this.constraints,e=this.validationErrorMessage("minLength")||this.validationErrorMessage("min"),s=t&&this.base.min(t,e);return this.base=s||this.base,this}maxLength(){const{maxLength:t}=this.constraints,e=this.validationErrorMessage("maxLength")||this.validationErrorMessage("max"),s=t&&this.base.max(t,e);return this.base=s||this.base,this}pattern(){const{pattern:t,flags:e,excludeEmptyString:s}=this.constraints;if(!t)return this;const r=new RegExp(t,e),i=this.validationErrorMessage("pattern")||this.validationErrorMessage("matches")||this.validationErrorMessage("regex"),n=r&&this.base.matches(r,{message:i,excludeEmptyString:s});return this.base=n||this.base,this}normalize(){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}}class W{constructor(t){this.config=t}isString(t){return this.config.isString(t)}handle(t){return this.isString(t)&&U.create({config:this.config,...t}).createSchemaEntry()}}function _(t,e={}){return t&&new W(e).handle(t)}class J extends T{constructor(t){super(t),this.type=this.baseType,this.base=this.validatorInstance}get baseType(){return"date"}get validatorInstance(){return this.validator.date()}static create(t){return new J(t)}get typeEnabled(){return["minDate","maxDate"]}convert(){return super.convert(),this}toDate(t){return this.isStringType(t)&&!this.isValidDateFormat(t)?a.ref(t):new Date(t)}isValidDateType(t){return this.isStringType(t)||this.isDateType(t)}isValidDate(t){return!!this.isValidDateType(t)}isValidDateFormat(t){try{const e=Date.parse(t);return Boolean(e)}catch(t){return!1}}transformToDate(t){return this.isNumberType(t)?new Date(t):t}minDate(){const t=this.constraints.minDate||this.constraints.min;if(this.isNothing(t))return this;const e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("minDate",e);const s=e&&this.base.min(this.toDate(e),this.validationErrorMessage("minDate")||this.validationErrorMessage("min"));return this.base=s||this.base,this}maxDate(){const t=this.constraints.maxDate||this.constraints.max;if(this.isNothing(t))return this;const e=this.transformToDate(t);if(!this.isValidDateType(e))return this.handleInvalidDate("maxDate",e);const s=e&&this.base.max(this.toDate(e),this.validationErrorMessage("maxDate")||this.validationErrorMessage("max"));return this.base=s||this.base,this}handleInvalidDate(t,e){const s=`invalid constraint for ${t}, was ${e}. Must be a number, string (valid date format) or a Date instance`;return this.config.warnOnInvalid?(this.warn(s),this):(this.error(s,e),this)}}class G{constructor(t){this.config=t}isDate(t){return this.config.isDate(t)}isDateCompatible(t){return this.config.isString(t)}handle(t){return J.create(t).createSchemaEntry()}}function Q(t,e={}){return t&&new G(e).handle(t)}var X={__proto__:null,errValKeys:x,defaults:M,YupArray:V,toYupArray:S,YupBoolean:A,toYupBoolean:I,YupNumber:q,toYupNumberSchemaEntry:Y,toYupNumber:function(t,e={}){return $(t,e)&&function(t){return q.create(t)}(t)},YupObject:B,toYupObject:L,YupString:U,toYupString:_,YupDate:J,toYupDate:Q,YupMixed:T,ConvertYupSchemaError:O,Base:m};class Z extends Error{}class tt extends m{constructor(t,e,s){super(e);const{value:r,type:i,kind:n,name:a,key:o,schema:h,types:l,parentNode:c}=t;this.entryHandler=s||t.entryHandler,this.parentNode=c,this.builder=t.builder,this.opts=t,this.kind=n,this.value=r,this.schema=h,this.key=o,this.value=r||{},this.name=a,this.type=i,this.types=l}get validator(){return this.builder.validator}error(t,e){let{opts:s}=this;throw s=s||{},s=e?{data:e,...s}:s,console.error(t,...s),new Z(t)}resolve(){throw"Must be implemented by subclass"}get obj(){const{schema:t,key:e,value:s,type:r,kind:i,config:n,entryHandler:a,parentNode:o}=this;return{schema:t,parentNode:o,key:e,value:s,type:r,kind:i,config:n,entryHandler:a}}}class et extends tt{constructor(t,e,s){super(t,e,s)}resolve(){const{value:t}=this;if(!Array.isArray(t))return;const e=this.config.toMultiType;return e?e(this):this.oneOf()}oneOf(){const t=this.value,e=this.createEntry.bind(this),s=t.map(e);return this.mixed().oneOf(s)}notOneOf(){const t=this.value,e=this.createEntry.bind(this),s=t.map(e);return this.mixed().notOneOf(s)}createEntry(t){const{createYupSchemaEntry:e}=this.config;return t=normalizedValue(t),e({schema:this.schema,key:this.key,value:t,config:this.config})}normalizedValue(t){return"string"==typeof t?{type:t}:t}mixed(){return this.validator.mixed()}}class st extends tt{constructor(t,e,s){super(t,e,s)}resolve(){const{value:t}=this;if(Array.isArray(t))return;const e=this.config.toSingleType;if(e)return e(this);const{obj:s,config:r,entryHandler:i}=this,n=Object.keys(this.types);let a;for(let t of n){const e=this.types[t];if(e&&(a=e(s,r,i)),a)break}return a}}const rt=(t,e,s)=>new it(t,e,s);class it extends tt{constructor(t,e,s){super(t,e,s),this.initResolvers()}initResolvers(){const{opts:t,config:e,entryHandler:s}=this,r=e.createMultiTypeResolver||this.createMultiTypeResolver.bind(this);this.multiTypeResolver=r(t,e,s);const i=e.createSingleTypeResolver||this.createSingleTypeResolver.bind(this);this.singleTypeResolver=i(t,e,s)}createMultiTypeResolver(){const{opts:t,config:e,entryHandler:s}=this;return new et(t,e,s)}createSingleTypeResolver(){const{opts:t,config:e,entryHandler:s}=this;return new st(t,e,s)}resolve(){return this.toMultiType()||this.toSingleType()||this.toDefaultEntry()}toMultiType(){return(this.config.toMultiType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)}toSingleType(){return(this.config.toSingleType||this.singleTypeResolver.resolve.bind(this.singleTypeResolver))(this)}toDefaultEntry(){return this.defaultType()}defaultType(){return this.error("toEntry: unknown type",this.type),!1}}class nt extends Error{}class at extends m{constructor(t){super(t.config);const{schema:e,name:s,key:r,value:i,config:n,builder:a,parentNode:o}=t;this.parentNode=o,this.builder=a,this.opts=t,this.schema=e,this.key=r,this.value=i||{},this.config=n||{},this.name=s,this.init()}get calcType(){const{value:t}=this;return Array.isArray(t)?"array":t.type}get calcKind(){return"array"===this.type?"multi":"single"}createNew(t){return new at(t).toEntry()}init(){this.type=this.calcType,this.kind=this.calcKind,this.setTypeHandlers(),this.setPropertyHandler()}get validator(){return this.builder&&this.builder.validator}setPropertyHandler(){const{config:t}=this;this.propertyValueHandler=(t.createPropertyValueHandler||this.createPropertyValueHandler)(this.propertyHandlerOpts,t)}get propertyHandlerOpts(){const{types:t,value:e,name:s,key:r,type:i,kind:n,schema:a,parentNode:o}=this;return{type:i,parentNode:o,kind:n,types:t,value:e,name:s,key:r,schema:a,entryHandler:this}}createPropertyValueHandler(t,e){return rt(t,e,this)}get defaultTypeHandlerMap(){return{string:_,number:Y,boolean:I,array:S,object:L,date:Q}}setTypeHandlers(){this.types=this.config.types||this.typeHandlers}get typeHandlers(){return{...this.defaultTypeHandlerMap,...this.config.typeHandlers||{}}}isValidSchema(){const{type:t}=this;return this.isStringType(t)}error(t,e){const{opts:s}=this;throw e?console.error(t,e,...s):console.error(t,...s),new nt(t)}toEntry(){if(!this.isValidSchema()){const t=JSON.stringify(this.schema);this.error(`Not a valid schema: type ${this.type} must be a string, was ${typeof this.type} ${t}`)}const{opts:t,config:e}=this;return this.propertyValueHandler.resolve(t,e)}}function ot(t={}){return new at(t).toEntry()}function ht(t,e={},s){return new ct(t,{...e},s).yupSchema}function lt(t){return t===Object(t)}class ct extends m{constructor(t,e={},s){super(e),this.init(t,e,s)}init(t,e,s){e.buildYup=ht,e.createYupSchemaEntry=e.createYupSchemaEntry||ot,this.config=Object.assign(this.config,e),this.schema=t;const r=this.getType(t),i=this.getProps(t);if(this.parentNode=s||{},this.key=this.parentNode.key,this.type=r,this.properties={...i},this.additionalProps=this.getAdditionalProperties(t),this.required=this.getRequired(t),this.dependenciesArray=this.createDependenciesArray()||[],this.setLocale(),("function"==typeof e.init?e.init:()=>{}).bind(this)(t,e),!function(t){return t&&"object"===t}(r))return void this.error(`invalid schema: must be type: "object", was type: ${r}`);if(!lt(i)){const t=JSON.stringify(a);return void this.error(`invalid schema: must have a properties object: ${t}`)}const n=this.getName(t),a=(e.buildProperties||this.buildProperties).bind(this)(t,this),o=this.propsToShape({properties:a,name:n,config:e});this.shapeConfig=o,this.validSchema=!0}createDependenciesArray(){return(this.config.dependenciesMap||{})[this.key||"root"]||[]}get validator(){return a}setLocale(){this.config.locale&&a.setLocale(this.config.locale)}getAdditionalProperties(t){return t.additionalProperties}getRequired(t){const{getRequired:e}=this.config;return e?e(t):t.required||[]}getProps(t){return this.config.getProps(t)}getType(t){return this.config.getType(t)}getName(t){return this.config.getName(t)}get yupSchema(){return a.object().shape(this.shapeConfig,this.dependenciesArray)}buildProperties(){const t=Object.keys(this.properties),e=(this.config.buildProp||this.buildProp).bind(this);return t.reduce(e,{})}getRequiredPropsList(){return Array.isArray(this.required)?[...this.required]:[]}buildProp(t,e){const s=this.properties[e],r=this.getRequiredPropsList();return(this.config.setRequired||this.setRequired).bind(this)(s,e,r),(this.config.setPropEntry||this.setPropEntry).bind(this)(t,e,s),t}setRequired(t,e,s){const r=s.indexOf(e)>=0;return lt(t)||this.warn(`Bad property value: ${t} must be an object`),t.required=this.isRequired(t)||r,t}setPropEntry(t,e,s){t[e]={required:s.required,...s}}isRequired(t){return this.config.isRequired(t)}propsToShape(t={}){const e=this.objPropsToShape(t);return this.objPropsShape=e,this.addPropsShape=this.additionalPropsToShape(e,t),e}additionalPropsToShape(t,e={}){return t}objPropsToShape({name:t}={}){const e={...this.properties},s=Object.keys(e),r=this.reducePropToShape.bind(this);return s.reduce((s,i)=>r(s,i,{name:t,key:i,value:e[i]}),{})}reducePropToShape(t,e,s){const r=this.propToYupSchemaEntry(s);return this.logInfo("propToShape",{...s,yupSchemaEntry:r}),r&&(t[e]=r),t}propToYupSchemaEntry({name:t,key:e,value:s={}}){return this.createYupSchemaEntry({schema:this.schema,parentNode:this.parentNode||this,name:t,key:e,value:s,config:this.config,builder:this})}createYupSchemaEntry(t={}){return this.config.createYupSchemaEntry(t)}onConstraintAdded(t){this.logInfo("Constraint Added",t)}}const ut={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:{}},dt={createValidatorName:(t,e)=>`is${t=(t=(t=l.default(t||e)).replace(/Uri$/,"URI")).replace(/Id$/,"ID")}`,createTestName:(t,e)=>h.default(t||e)},pt={isMagnetURI:(t,e)=>/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i.test(t)};exports.ConstraintBuilder=w,exports.ErrorMessageHandler=E,exports.PropertyValueResolver=it,exports.YupBuilder=ct,exports.YupSchemaEntry=at,exports.YupSchemaEntryError=nt,exports.buildYup=ht,exports.createPropertyValueResolver=rt,exports.createYupSchemaEntry=ot,exports.extendYupApi=function({constraints:e,override:s=!1,validator:r,createValidatorName:i,createTestName:n}={}){if(!r)throw"extendYupApi: missing validator option";Array.isArray(e)&&(e=((t,e={})=>t.reduce((t,s)=>{if("string"!=typeof s&&!(s instanceof Object)){if(!1!==e.throws)throw`toConstraintsMap: invalid entry ${s}`;return t}if("string"==typeof s)t[name]={};else{if(!s.name){if(!1!==e.throws)throw`toConstraintsMap: invalid entry ${s} missing name`;return t}t[s.name]=s}return t},{}))(e)),e=s?e||ut:{...ut,...e||{}},i=i||dt.createValidatorName,n=n||dt.createTestName,Object.keys(e).map(s=>{let{testName:a,optsKey:o,validatorName:h,logging:l}=e[s];const c=i(h,s);a=n(a,s),t.addMethod(t.string,s,(e={})=>{const{message:i}=e,n=e[o];return t.string().test(a,i,t=>{const{path:e,createError:o}=this;let h=r[c];if(h=h||pt[c],"function"!=typeof h)throw Error("No method named ${validatorName} on validator");const u=h(t,n);return!0===l&&console.log("Yup validator bridge",{key:s,fullValidatorName:c,testName:a,value:t,valid:u}),u||o({path:e,message:i})})})})},exports.types=X;
//# sourceMappingURL=index.js.map
{
"name": "schema-to-yup",
"version": "1.12.6",
"version": "1.12.7",
"publishConfig": {

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

@@ -0,1 +1,5 @@

# Schema to Yup schema
Build a Yup schema from a JSON Schema, GraphQL schema (type definition) or any other similar type/class and field/properties model or schema :)
<!-- vscode-markdown-toc -->

@@ -27,34 +31,35 @@

- 9. [Multi-type constraints](#Multi-typeconstraints)
- 10. [Custom builder](#Custombuilder)
- 11. [Custom builder functions](#Custombuilderfunctions)
- 11.1. [Custom init](#Custominit)
- 11.2. [Custom buildProperties](#CustombuildProperties)
- 11.3. [Custom buildProp](#CustombuildProp)
- 11.4. [Custom setRequired](#CustomsetRequired)
- 11.5. [Custom setPropEntry](#CustomsetPropEntry)
- 12. [Custom entry builders](#Customentrybuilders)
- 12.1. [Custom type handlers](#Customtypehandlers)
- 12.1.1. [Custom array type handler](#Customarraytypehandler)
- 12.2. [Additional type handlers](#Additionaltypehandlers)
- 12.3. [Custom constraint handler functions](#Customconstrainthandlerfunctions)
- 12.3.1. [Advanced custom constraint example](#Advancedcustomconstraintexample)
- 12.4. [Custom pipeline steps](#Custompipelinesteps)
- 12.5. [Custom constraint builder](#Customconstraintbuilder)
- 13. [Supporting alternative validators](#Supportingalternativevalidators)
- 14. [Conditional logic](#Conditionallogic)
- 14.1. [Customizing conditional logic](#Customizingconditionallogic)
- 15. [Additional properties](#Additionalproperties)
- 16. [Complex example](#Complexexample)
- 16.1. [Complex/Nested schemas](#ComplexNestedschemas)
- 17. [Custom models](#Custommodels)
- 17.1. [GraphQL schema](#GraphQLschema-1)
- 18. [Other/custom schema format support](#Othercustomschemaformatsupport)
- 18.1. [Custom logs and error handling](#Customlogsanderrorhandling)
- 19. [Localized error messages](#Localizederrormessages)
- 20. [Customization](#Customization)
- 20.1. [Customization example](#Customizationexample)
- 20.2. [Extend Yup API to bridge other validators](#ExtendYupAPItobridgeothervalidators)
- 20.3. [Subclassing](#Subclassing)
- 20.4. [Error messages](#Errormessages)
- 20.5. [Custom error functions](#Customerrorfunctions)
- 10. [Avoiding cyclical dependencies](#Avoidingcyclicaldependencies)
- 11. [Custom builder](#Custombuilder)
- 12. [Custom builder functions](#Custombuilderfunctions)
- 12.1. [Custom init](#Custominit)
- 12.2. [Custom buildProperties](#CustombuildProperties)
- 12.3. [Custom buildProp](#CustombuildProp)
- 12.4. [Custom setRequired](#CustomsetRequired)
- 12.5. [Custom setPropEntry](#CustomsetPropEntry)
- 13. [Custom entry builders](#Customentrybuilders)
- 13.1. [Custom type handlers](#Customtypehandlers)
- 13.1.1. [Custom array type handler](#Customarraytypehandler)
- 13.2. [Additional type handlers](#Additionaltypehandlers)
- 13.3. [Custom constraint handler functions](#Customconstrainthandlerfunctions)
- 13.3.1. [Advanced custom constraint example](#Advancedcustomconstraintexample)
- 13.4. [Custom pipeline steps](#Custompipelinesteps)
- 13.5. [Custom constraint builder](#Customconstraintbuilder)
- 14. [Supporting alternative validators](#Supportingalternativevalidators)
- 15. [Conditional logic](#Conditionallogic)
- 15.1. [Customizing conditional logic](#Customizingconditionallogic)
- 16. [Additional properties](#Additionalproperties)
- 17. [Complex example](#Complexexample)
- 17.1. [Complex/Nested schemas](#ComplexNestedschemas)
- 18. [Custom models](#Custommodels)
- 18.1. [GraphQL schema](#GraphQLschema-1)
- 19. [Other/custom schema format support](#Othercustomschemaformatsupport)
- 19.1. [Custom logs and error handling](#Customlogsanderrorhandling)
- 20. [Localized error messages](#Localizederrormessages)
- 21. [Customization](#Customization)
- 21.1. [Customization example](#Customizationexample)
- 21.2. [Extend Yup API to bridge other validators](#ExtendYupAPItobridgeothervalidators)
- 21.3. [Subclassing](#Subclassing)
- 21.4. [Error messages](#Errormessages)
- 21.5. [Custom error functions](#Customerrorfunctions)

@@ -65,8 +70,4 @@ <!-- vscode-markdown-toc-config

/vscode-markdown-toc-config -->
<!-- /vscode-markdown-toc --><!-- vscode-markdown-toc -->
<!-- /vscode-markdown-toc -->
# Schema to Yup schema
Build a Yup schema from a JSON Schema, GraphQL schema (type definition) or any other similar type/class and field/properties model or schema :)
## 1. <a name='Schemas'></a>Schemas

@@ -439,6 +440,32 @@

To improve support this, pass a custom factory method `createMultiTypeValueResolver` on the `config` object and build on or improve the current implementation.
To improve or customize support for this, you can pass a custom factory method `createMultiTypeValueResolver` on the `config` object and build on or improve the current implementation.
## 10. <a name='Custombuilder'></a>Custom builder
## 10. <a name='Avoidingcyclicaldependencies'></a>Avoiding cyclical dependencies
The Yup validator may cause cyclical dependency error. This can be mitigated by supplying a deendencies array as decribed in this [Yup issue](https://github.com/jquense/yup/issues/176#issuecomment-369925782)
The yup builder lets you supply a `dependenciesMap` on the `config` object where the key for each entry is the key of an object or `root` for the root schema object.
```js
const config = {
dependenciesMap: {
root: ["a", "b", "c"],
b: ["a", "z"],
},
};
```
It is currently implemented as follows in the `YupBuilder`
```js
createDependenciesArray() {
const key = this.key || "root";
const dependenciesMap = this.config.dependenciesMap || {};
const dependencies = dependenciesMap[key] || [];
return dependencies;
}
```
## 11. <a name='Custombuilder'></a>Custom builder
To customize the builder to suit your needs, simply subclass the `YupBuilder` class and create your own factory function which instantiates your subclass.

@@ -462,3 +489,3 @@

## 11. <a name='Custombuilderfunctions'></a>Custom builder functions
## 12. <a name='Custombuilderfunctions'></a>Custom builder functions

@@ -471,3 +498,3 @@ - `init`

### 11.1. <a name='Custominit'></a>Custom init
### 12.1. <a name='Custominit'></a>Custom init

@@ -487,3 +514,3 @@ You can supply a custom `init` function on the `config` object to do custom initialization. The `init` function will be bound to the `YupBuilder` instance so that `this` returns the builder instance.

### 11.2. <a name='CustombuildProperties'></a>Custom buildProperties
### 12.2. <a name='CustombuildProperties'></a>Custom buildProperties

@@ -500,3 +527,3 @@ You can override the built-in `buildProperties` method (see code below) by supplying a custom `buildProperties` function on the `config` object.

### 11.3. <a name='CustombuildProp'></a>Custom buildProp
### 12.3. <a name='CustombuildProp'></a>Custom buildProp

@@ -519,3 +546,3 @@ You can override the built-in `buildProp` method (see code below) by supplying a custom `buildProp` function on the `config` object.

### 11.4. <a name='CustomsetRequired'></a>Custom setRequired
### 12.4. <a name='CustomsetRequired'></a>Custom setRequired

@@ -536,3 +563,3 @@ You can override the built-in `setRequired` method (see code below) by supplying a custom `setRequired` function on the `config` object.

### 11.5. <a name='CustomsetPropEntry'></a>Custom setPropEntry
### 12.5. <a name='CustomsetPropEntry'></a>Custom setPropEntry

@@ -551,3 +578,3 @@ You can override the built-in `setPropEntry` method (see code below) by supplying a custom `setPropEntry` function on the `config` object.

## 12. <a name='Customentrybuilders'></a>Custom entry builders
## 13. <a name='Customentrybuilders'></a>Custom entry builders

@@ -572,3 +599,3 @@ You can pass in custom functions for the following kinds of type entry values

### 12.1. <a name='Customtypehandlers'></a>Custom type handlers
### 13.1. <a name='Customtypehandlers'></a>Custom type handlers

@@ -637,3 +664,3 @@ You can pass any custom type handlers in a `typeHandlers` object as part of the `config` object passes. See `setTypeHandlers()` and `get typeHandlers()` in `entry.js` for how this works internally.

#### 12.1.1. <a name='Customarraytypehandler'></a>Custom array type handler
#### 13.1.1. <a name='Customarraytypehandler'></a>Custom array type handler

@@ -654,3 +681,3 @@ Currently this library has minimal support for the `array` type. To add better `array` type support, create a custom type handler for handling array types and use it as follows.

### 12.2. <a name='Additionaltypehandlers'></a>Additional type handlers
### 13.2. <a name='Additionaltypehandlers'></a>Additional type handlers

@@ -680,3 +707,3 @@ In order to pass a a type handler map that does not rely on any built in type handlers, pass in a `types` object

### 12.3. <a name='Customconstrainthandlerfunctions'></a>Custom constraint handler functions
### 13.3. <a name='Customconstrainthandlerfunctions'></a>Custom constraint handler functions

@@ -768,3 +795,3 @@ You can add custom constraint handler functions directly via the `config` object.

#### 12.3.1. <a name='Advancedcustomconstraintexample'></a>Advanced custom constraint example
#### 13.3.1. <a name='Advancedcustomconstraintexample'></a>Advanced custom constraint example

@@ -822,3 +849,3 @@ ```js

### 12.4. <a name='Custompipelinesteps'></a>Custom pipeline steps
### 13.4. <a name='Custompipelinesteps'></a>Custom pipeline steps

@@ -846,3 +873,3 @@ The conversion pipeline supports pre and post processing to allow for custom functionality, such as preparing or overriding the built-in convert or circumvent bugs.

### 12.5. <a name='Customconstraintbuilder'></a>Custom constraint builder
### 13.5. <a name='Customconstraintbuilder'></a>Custom constraint builder

@@ -895,3 +922,3 @@ This library supports using a custom constraint builder to add and build constraints. All factories are initialized in `initHelpers` and executed as the first step of `convert` (see `mixed.js`)

## 13. <a name='Supportingalternativevalidators'></a>Supporting alternative validators
## 14. <a name='Supportingalternativevalidators'></a>Supporting alternative validators

@@ -985,3 +1012,3 @@ Supply a `validator` instance (or getter function) on the `config` object which returns an instance of the validator you wish to use.

## 14. <a name='Conditionallogic'></a>Conditional logic
## 15. <a name='Conditionallogic'></a>Conditional logic

@@ -1046,3 +1073,3 @@ Basic support for [when conditions](https://github.com/jquense/yup#mixedwhenkeys-string--arraystring-builder-object--value-schema-schema-schema) as requested and outlined in [this issue](https://github.com/kristianmandrup/schema-to-yup/issues/14) is now included.

### 14.1. <a name='Customizingconditionallogic'></a>Customizing conditional logic
### 15.1. <a name='Customizingconditionallogic'></a>Customizing conditional logic

@@ -1067,3 +1094,3 @@ You can now also override, extend or customize the `when` condition logic by passing in your own factory method for the config object entry `createWhenCondition`

## 15. <a name='Additionalproperties'></a>Additional properties
## 16. <a name='Additionalproperties'></a>Additional properties

@@ -1104,3 +1131,3 @@ Currently this library does not have built-in support for the `additionalProperties` feature of JSON schema as described [here](https://json-schema.org/understanding-json-schema/reference/object.html)

## 16. <a name='Complexexample'></a>Complex example
## 17. <a name='Complexexample'></a>Complex example

@@ -1180,3 +1207,3 @@ Here a more complete example of the variations currently possible

### 16.1. <a name='ComplexNestedschemas'></a>Complex/Nested schemas
### 17.1. <a name='ComplexNestedschemas'></a>Complex/Nested schemas

@@ -1187,3 +1214,3 @@ Nested object schema properties are supported.

## 17. <a name='Custommodels'></a>Custom models
## 18. <a name='Custommodels'></a>Custom models

@@ -1214,3 +1241,3 @@ This library now also supports non JSON schema models. See the `types/schema-parser-maps` mappings.

### 17.1. <a name='GraphQLschema-1'></a>GraphQL schema
### 18.1. <a name='GraphQLschema-1'></a>GraphQL schema

@@ -1286,3 +1313,3 @@ To support another model, such as GraphQL schema (type definitions) via [graphSchemaToJson](https://github.com/kristianmandrup/graphSchemaToJson)

## 18. <a name='Othercustomschemaformatsupport'></a>Other/custom schema format support
## 19. <a name='Othercustomschemaformatsupport'></a>Other/custom schema format support

@@ -1322,3 +1349,3 @@ You can supply a `config.schemaParserMap` object with parser entries for any specific schema formats you wish to support.

### 18.1. <a name='Customlogsanderrorhandling'></a>Custom logs and error handling
### 19.1. <a name='Customlogsanderrorhandling'></a>Custom logs and error handling

@@ -1378,3 +1405,3 @@ You can enable logging py passing a `log` option in the `config.enable` object. If set to `true`, it will by default assign the internal log function to `console.log`

## 19. <a name='Localizederrormessages'></a>Localized error messages
## 20. <a name='Localizederrormessages'></a>Localized error messages

@@ -1386,3 +1413,3 @@ You can specify the locale to use in the `config` object.

## 20. <a name='Customization'></a>Customization
## 21. <a name='Customization'></a>Customization

@@ -1394,3 +1421,3 @@ You can supply a `createYupSchemaEntry` function as an entry in the `config` object.

### 20.1. <a name='Customizationexample'></a>Customization example
### 21.1. <a name='Customizationexample'></a>Customization example

@@ -1423,3 +1450,3 @@ ```js

### 20.2. <a name='ExtendYupAPItobridgeothervalidators'></a>Extend Yup API to bridge other validators
### 21.2. <a name='ExtendYupAPItobridgeothervalidators'></a>Extend Yup API to bridge other validators

@@ -1469,3 +1496,3 @@ You can use `extendYupApi` to extend the Yup API with extra validation methods:

### 20.3. <a name='Subclassing'></a>Subclassing
### 21.3. <a name='Subclassing'></a>Subclassing

@@ -1486,3 +1513,3 @@ You can sublass `YupBuilder` or any of the internal classes to create your own custom infrastructure to suit your particular needs, extend with extra features etc.

### 20.4. <a name='Errormessages'></a>Error messages
### 21.4. <a name='Errormessages'></a>Error messages

@@ -1557,3 +1584,3 @@ You can pass an `errMessages` object in the optional `config` object argument with key mappings for your custom validation error messages.

### 20.5. <a name='Customerrorfunctions'></a>Custom error functions
### 21.5. <a name='Customerrorfunctions'></a>Custom error functions

@@ -1560,0 +1587,0 @@ You can also add custom error functions at a granular level with access to `constraints`, `key` , `keyPath`, `title`, `description`, `parentNode` and `typeHandler`

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

const props = this.getProps(schema);
this.parentNode = parentNode;
this.parentNode = parentNode || {};
this.key = this.parentNode.key;
this.type = type;

@@ -39,2 +40,3 @@ this.properties = {

this.required = this.getRequired(schema);
this.dependenciesArray = this.createDependenciesArray() || [];

@@ -70,2 +72,9 @@ this.setLocale();

createDependenciesArray() {
const key = this.key || "root";
const dependenciesMap = this.config.dependenciesMap || {};
const dependencies = dependenciesMap[key] || [];
return dependencies;
}
get validator() {

@@ -101,3 +110,3 @@ return yup;

get yupSchema() {
return yup.object().shape(this.shapeConfig);
return yup.object().shape(this.shapeConfig, this.dependenciesArray);
}

@@ -104,0 +113,0 @@

@@ -25,2 +25,3 @@ export interface TypeHandlerConfig {

format?: boolean;
dependenciesMap?: object;
schemaParserMap?: object;

@@ -27,0 +28,0 @@ messages?: object;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc