@cleverbrush/schema 3.1.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -2
- package/dist/builders/AnySchemaBuilder.js +1 -1
- package/dist/builders/ArraySchemaBuilder.js +1 -1
- package/dist/builders/BooleanSchemaBuilder.js +1 -1
- package/dist/builders/DateSchemaBuilder.js +1 -1
- package/dist/builders/ExternSchemaBuilder.js +1 -1
- package/dist/builders/FunctionSchemaBuilder.js +1 -1
- package/dist/builders/IntersectionSchemaBuilder.d.ts +124 -0
- package/dist/builders/NumberSchemaBuilder.js +1 -1
- package/dist/builders/ObjectSchemaBuilder.js +1 -1
- package/dist/builders/ParseStringSchemaBuilder.d.ts +9 -0
- package/dist/builders/ParseStringSchemaBuilder.js +1 -1
- package/dist/builders/PromiseSchemaBuilder.js +1 -1
- package/dist/builders/RecordSchemaBuilder.js +1 -1
- package/dist/builders/SchemaBuilder.d.ts +13 -7
- package/dist/builders/StringSchemaBuilder.js +1 -1
- package/dist/builders/TupleSchemaBuilder.js +1 -1
- package/dist/builders/UnionSchemaBuilder.js +1 -1
- package/dist/chunk-54RHS4F4.js +2 -0
- package/dist/chunk-54RHS4F4.js.map +1 -0
- package/dist/{chunk-K6Z47OQY.js → chunk-6LSN7NXQ.js} +2 -2
- package/dist/{chunk-WQDYWDOE.js → chunk-C6YQOKWB.js} +2 -2
- package/dist/{chunk-BUEVZ3KA.js → chunk-ELPPAHNO.js} +2 -2
- package/dist/{chunk-QARCEYGO.js → chunk-G424M7GI.js} +2 -2
- package/dist/{chunk-WDMJBGBD.js → chunk-JUFZ7PLO.js} +2 -2
- package/dist/{chunk-ZC6YBKCP.js → chunk-K4ZLXLE2.js} +2 -2
- package/dist/{chunk-NUW3VXZV.js → chunk-KC45JEFL.js} +2 -2
- package/dist/{chunk-EIVZX4ZO.js → chunk-NF4CRFMN.js} +2 -2
- package/dist/{chunk-YQZHDMRF.js → chunk-ORV2G6ZL.js} +2 -2
- package/dist/{chunk-CFIJQ4GP.js → chunk-PQINUGZW.js} +2 -2
- package/dist/chunk-REYZ7G7J.js +2 -0
- package/dist/chunk-REYZ7G7J.js.map +1 -0
- package/dist/chunk-VSU5GILY.js +2 -0
- package/dist/chunk-VSU5GILY.js.map +1 -0
- package/dist/chunk-XHSBY2QK.js +2 -0
- package/dist/chunk-XHSBY2QK.js.map +1 -0
- package/dist/{chunk-ZFI27R3L.js → chunk-XL723XFL.js} +2 -2
- package/dist/{chunk-HN774HD7.js → chunk-XPLTW5DI.js} +2 -2
- package/dist/{chunk-PHE4LIAN.js → chunk-YAOZEA2R.js} +2 -2
- package/dist/core.d.ts +4 -2
- package/dist/core.js +1 -1
- package/dist/extension.d.ts +76 -4
- package/dist/extension.js +2 -0
- package/dist/extension.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
- package/dist/chunk-3JMDGYDT.js +0 -2
- package/dist/chunk-3JMDGYDT.js.map +0 -1
- package/dist/chunk-DY7J6RNN.js +0 -2
- package/dist/chunk-DY7J6RNN.js.map +0 -1
- package/dist/chunk-GXPV6UQK.js +0 -2
- package/dist/chunk-GXPV6UQK.js.map +0 -1
- /package/dist/{chunk-K6Z47OQY.js.map → chunk-6LSN7NXQ.js.map} +0 -0
- /package/dist/{chunk-WQDYWDOE.js.map → chunk-C6YQOKWB.js.map} +0 -0
- /package/dist/{chunk-BUEVZ3KA.js.map → chunk-ELPPAHNO.js.map} +0 -0
- /package/dist/{chunk-QARCEYGO.js.map → chunk-G424M7GI.js.map} +0 -0
- /package/dist/{chunk-WDMJBGBD.js.map → chunk-JUFZ7PLO.js.map} +0 -0
- /package/dist/{chunk-ZC6YBKCP.js.map → chunk-K4ZLXLE2.js.map} +0 -0
- /package/dist/{chunk-NUW3VXZV.js.map → chunk-KC45JEFL.js.map} +0 -0
- /package/dist/{chunk-EIVZX4ZO.js.map → chunk-NF4CRFMN.js.map} +0 -0
- /package/dist/{chunk-YQZHDMRF.js.map → chunk-ORV2G6ZL.js.map} +0 -0
- /package/dist/{chunk-CFIJQ4GP.js.map → chunk-PQINUGZW.js.map} +0 -0
- /package/dist/{chunk-ZFI27R3L.js.map → chunk-XL723XFL.js.map} +0 -0
- /package/dist/{chunk-HN774HD7.js.map → chunk-XPLTW5DI.js.map} +0 -0
- /package/dist/{chunk-PHE4LIAN.js.map → chunk-YAOZEA2R.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as f,d as k,f as S}from"./chunk-3JMDGYDT.js";var O=class{#e;#t;#n=[];#a=[];get seenValue(){let e=this.#e[f].getValue(this.#t);return e.success?e.value:void 0}get errors(){return this.#n}get isValid(){return this.#n.length===0&&this.getChildErrors().length===0}getChildErrors(){return this.#a}get descriptor(){return this.#e[f]}constructor(e,r,t){if(!b.isValidPropertyDescriptor(e))throw new Error("Invalid property descriptor");this.#e=e,this.#n=Array.isArray(t)?[...t]:[],this.#t=r}addError(e){this.#n.push(e)}addChildError(e){this.#a.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var V="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#a=[];[k]=!0;#s=new WeakMap;static create(e){return new p({type:"object",...e})}createFromProps(e){return p.create(e)}constructor(e){super(e),typeof e.properties=="object"&&e.properties&&(this.#e=e.properties,this.#n=Object.keys(e.properties)),typeof e.acceptUnknownProps=="boolean"&&(this.#t=e.acceptUnknownProps),Array.isArray(e.constructorSchemas)&&(this.#a=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#a]}}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}#i(e){p.isValidPropertyDescriptor(e?.context?.rootPropertyDescriptor)||(e.context.rootPropertyDescriptor=p.getPropertiesFor(this)),p.isValidPropertyDescriptor(e.context.currentPropertyDescriptor)||(e.context.currentPropertyDescriptor=e.context.rootPropertyDescriptor),!e.context.rootValidationObject&&e.transaction?.object?.validatedObject&&(e.context.rootValidationObject=e.transaction.object.validatedObject)}preValidateSync(e,r){let t=super.preValidateSync(e,r);return this.#i(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#i(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:a}=e,s=new WeakMap,y=new Set,{doNotStopOnFirstError:o,rootValidationObject:i}=t,l=t.rootPropertyDescriptor,u=t.currentPropertyDescriptor,P=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=s.has(h)?s.get(h):null;if(g||(g=new O(h,i),s.set(h,g)),g.addError(m),y.add(g),R&&p.isValidPropertyDescriptor(R)){let j=s.has(R)?s.get(R):null;j||(j=new O(R,i),s.set(R,j)),j.addChildError(g)}},d=(h=>{let m=typeof h=="function"?h(u):u;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return s.has(m)||s.set(m,new O(m,i)),s.get(m)}),c=()=>[...y].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(u)){let m=h.property(u);if(p.isValidPropertyDescriptor(m)){P(m,h.message,u);return}}p.isValidPropertyDescriptor(u)&&P(u,h.message)};if(!r&&!o&&a){for(let h of a)E(h);return{earlyReturn:!0,result:{valid:r,errors:a,getErrorsFor:d,getInvalidProperties:c}}}if(o&&a)for(let h of a)E(h);let{object:{validatedObject:x}}=n;if(typeof x>"u"&&!this.isRequired||x===null&&(!this.isRequired||this.isNullable))return{earlyReturn:!0,result:{valid:!0,object:n.commit().validatedObject,getErrorsFor:d,getInvalidProperties:c}};if(typeof x!="object"||x===null)return T.length===0&&(T.push({message:V}),P(u,V)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}};let w=this.#n,D=Object.keys(x);if(w.length===0){if(D.length===0)return o&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:d,getInvalidProperties:c}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:d,getInvalidProperties:c}});if(!this.#t){for(let h=0;h<D.length;h++){let m=`unknown property '${D[h]}'`;if(T.push({message:m}),!o)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:d,getInvalidProperties:c}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:w,objKeys:D,addErrorFor:P,getErrorsFor:d,getInvalidProperties:c,doNotStopOnFirstError:!!o,rootPropertyDescriptor:l,currentPropertyDescriptor:u,validationTransaction:n}}#p(e,r){let{objToValidate:t,objKeys:n,addErrorFor:a,getErrorsFor:s,getInvalidProperties:y,doNotStopOnFirstError:o,currentPropertyDescriptor:i,validationTransaction:l}=e,u=e.errors,P=!1;for(let{result:d}of r)if(!d.valid&&(P=!0,Array.isArray(d.errors)))for(let c of d.errors)u.push(c);for(let d=0;d<n.length;d++){let c=n[d];if(!(c in this.#e)&&!this.#t){let T=`unknown property '${c}'`;if(u.push({message:T}),a(i,T),!o)return l&&l.rollback(),{valid:!1,errors:[u[0]],getErrorsFor:s,getInvalidProperties:y}}}if(!P&&u.length===0){let d={};for(let{key:c,result:T}of r)d[c]=T.object;if(this.#t)for(let c of n)c in this.#e||(d[c]=t[c]);return{valid:!0,object:d,getErrorsFor:s,getInvalidProperties:y}}for(let{key:d,result:c}of r)if(!c.valid){let T=i[d];if(typeof c.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(c,T,a),Array.isArray(c.__externErrorPropertyNames)&&Array.isArray(c.errors))for(let E of c.errors)a(T,E.message,i)}else if(Array.isArray(c.errors)&&p.isValidPropertyDescriptor(T))for(let E of c.errors)a(T,E.message)}return l.rollback(),{valid:!1,errors:o?u:u[0]?[u[0]]:[],getErrorsFor:s,getInvalidProperties:y}}addValidator(e,r){return super.addValidator(e,r)}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation&&!r?.doNotStopOnFirstError&&!r?.rootPropertyDescriptor){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let t=this;return{valid:!0,object:e,getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else{let t=this;return{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else if(typeof e=="object"){let t=this.#n;if(!this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)if(!(s[y]in this.#e)){let o=this;return{valid:!1,errors:[{message:`unknown property '${s[y]}'`}],getErrorsFor(i){return o.#r(e,r).getErrorsFor(i)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}}let n={};for(let s=0;s<t.length;s++){let y=t[s],o=this.#e[y].validate(e[y]);if(!o.valid){let i=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getErrorsFor(l){return i.#r(e,r).getErrorsFor(l)},getInvalidProperties(){return i.#r(e,r).getInvalidProperties()}}}n[y]=o.object}if(this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)s[y]in this.#e||(n[s[y]]=e[s[y]])}let a=this;return{valid:!0,object:n,getErrorsFor(s){return a.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}return this.#r(e,r)}#r(e,r){let t=this.#o(this.preValidateSync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];for(let l of n){let u=this.#e[l].validate(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid&&!s)break}return this.#p(t,i)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];if(s){let l=await Promise.all(n.map(async u=>{let P=await this.#e[u].validateAsync(a[u],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[u]});return{key:u,result:P}}));i.push(...l)}else for(let l of n){let u=await this.#e[l].validateAsync(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid)break}return this.#p(t,i)}acceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),constructorSchemas:[...this.#a,e]})}clearConstructors(){return this.createFromProps({...this.introspect(),constructorSchemas:[]})}addProp(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(e in this.#e)throw new Error(`Property ${e} already exists`);if(!(r instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.createFromProps({...this.introspect()})}addProps(e){if(e instanceof p)return this.addProps(e.introspect().properties);if(typeof e!="object")throw new Error("props should be an object");if(e===null)throw new Error("props should not be null");let r={...this.#e};for(let t in e){if(t in this.#e)throw new Error(`property '${t}' already exists`);if(!(e[t]instanceof S))throw new Error(`${t} is not a SchemaBuilder`);r[t]=e[t]}return this.createFromProps({...this.introspect(),properties:r})}omit(e){if(typeof e=="string"){let r=e;if(!r||!(r in this.#e))throw new Error(`property ${r.toString()} does not exists in the schema`);return this.createFromProps({...this.introspect(),properties:(()=>{let t={...this.#e};return delete t[r],t})()})}else if(Array.isArray(e)){let r=e,t=new Map;if(r.forEach(a=>{if(typeof a!="string"||!a)throw new Error("property name must be a string");if(!(a in this.#e))throw new Error(`property ${a.toString()} does not exists in the schema`);t.set(a.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let a of t.keys())delete n.properties[a];return this.createFromProps(n)}else if(e instanceof p){let r={...e.introspect().properties},t={...this.introspect()};for(let n in r)n in t.properties&&delete t.properties[n];return this.createFromProps(t)}throw new Error("this parameter type is not supported")}intersect(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");let r=e.introspect().properties,t=this.introspect(),n=Object.keys(t.properties).reduce((a,s)=>(a[s]=s in r?r[s]:t.properties[s],a),{});return this.createFromProps({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((r,t)=>(r[t]=this.#e[t].optional(),r),{})});if(Array.isArray(e)){let r=e;if(r.length===0)throw new Error("properties cannot be empty");let t={...this.introspect()};return r.forEach(n=>{if(typeof n!="string")throw new Error("each propery in property list must be as string value");if(!(n in t.properties))throw new Error(`property ${n} does not exists`);t.properties[n]=t.properties[n].optional()}),this.createFromProps(t)}if(typeof e=="string")return this.modifyPropSchema(e,r=>r.optional());throw new Error("expecting string or string[] parameter")}deepPartial(){let e={};for(let r of Object.keys(this.#e)){let t=this.#e[r];t instanceof p?e[r]=t.deepPartial().optional():e[r]=t.optional()}return this.createFromProps({...this.introspect(),properties:e})}pick(e){if(typeof e=="string"){let r=e;if(!r)throw new Error("property cannot be empty");if(!(r in this.#e))throw new Error(`property ${r} does not exists`);return this.createFromProps({...this.introspect(),properties:{[r]:this.#e[r]}})}if(Array.isArray(e)){if(e.length===0)throw new Error("properties must be a non empty erray");let r=e.reduce((t,n)=>{if(typeof n!="string"||!n)throw new Error("each property name must be a non empty string");if(!(n in this.#e))throw new Error(`property ${n} does not exists`);return t[n]=this.#e[n],t},{});return this.createFromProps({...this.introspect(),properties:r})}if(e instanceof p){let t=Object.keys(e.introspect().properties).filter(n=>typeof this.#e[n]<"u");if(t.length===0)throw new Error("there are no common properties in provided schemas");return this.pick(t)}throw new Error("string, array or ObjectSchemaBuilder is expected")}modifyPropSchema(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(!(e in this.#e))throw new Error(`property ${e} does not exists in the schema`);if(typeof r!="function")throw new Error("callback must be a function");let t=r(this.#e[e]);if(!(t instanceof S))throw new Error("callback must return a SchemaBuilder object");let n={...this.introspect()};return n.properties={...n.properties,[e]:t},this.createFromProps(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#y(e,r,t,n,a){let s=e.introspect();if(!s.properties)return{};let y=Object.keys(s.properties);if(y.length===0)return{};typeof r!="function"&&(r=i=>i);let o=B((i,l)=>(t||r)(i,l),n,e,a);for(let i of y){let l=s.properties[i];if(l instanceof p){let u=l.introspect().properties;u&&typeof u=="object"&&Object.keys(u).length>0?o[i]=p.#y(l,(P,d)=>{let c=r(P,d);return c?(d&&!c[i]&&(c[i]={}),c[i]):null},r,i,o[f]):o[i]=B(r,i,l,o[f])}else if(l[k]===!0){let u=B(r,i,l,o[f]),P=(d,c)=>{let T=r(d,c);return T?(c&&!T[i]&&(T[i]={}),T[i]):null};o[i]=q(u,P)}else o[i]=B(r,i,l,o[f])}return o}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#s.has(e))return e.#s.get(e);let r=p.#y(e);return e.#s.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[f]=="object"}static#c(e,r,t){let a=p.#l(r).introspect().properties,s;if(a)s=Object.keys(a);else if(Array.isArray(e.__externErrorPropertyNames))s=e.__externErrorPropertyNames;else return;for(let y of s){let o=r[y];if(!p.isValidPropertyDescriptor(o))continue;let i=e.getErrorsFor(()=>o);if(!i.isValid)for(let l of i.errors)t(o,l,r);if(a){let l=a[y];(l instanceof p||l[k]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(o)&&p.#c(e,o,t)}}}static#l(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[f].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},v=(p=>b.create({isRequired:!0,properties:p})),B=(p,e,r,t)=>({[f]:{setValue:(n,a,s)=>{let y=p(n,!!s?.createMissingStructure);return y?(typeof e=="string"&&(y[e]=a),!0):!1},getValue:n=>{let a=p(n,!1);return a?typeof e!="string"?{success:!0,value:a}:Object.hasOwn(a,e)?{success:!0,value:a[e]}:{success:!1}:{success:!1}},getSchema:()=>r,parent:t,propertyName:e,toJsonPointer:()=>{let n=[];typeof e=="string"&&n.push(e.replace(/~/g,"~0").replace(/\//g,"~1"));let a=t;for(;a;)typeof a.propertyName=="string"&&n.push(a.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),a=a.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),q=(p,e)=>new Proxy(p,{get(r,t,n){if(t===f)return r[f];if(typeof t=="string"&&!(t in r)){let a=B(e,t,void 0,r[f]),s=(y,o)=>{let i=e(y,o);return i!=null&&typeof i=="object"?(o&&!(t in i)&&(i[t]={}),i[t]):null};r[t]=q(a,s)}return Reflect.get(r,t,n)}});v.getPropertiesFor=p=>b.getPropertiesFor(p);v.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,v as b};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as f,d as k,f as S}from"./chunk-REYZ7G7J.js";var O=class{#e;#t;#n=[];#a=[];get seenValue(){let e=this.#e[f].getValue(this.#t);return e.success?e.value:void 0}get errors(){return this.#n}get isValid(){return this.#n.length===0&&this.getChildErrors().length===0}getChildErrors(){return this.#a}get descriptor(){return this.#e[f]}constructor(e,r,t){if(!b.isValidPropertyDescriptor(e))throw new Error("Invalid property descriptor");this.#e=e,this.#n=Array.isArray(t)?[...t]:[],this.#t=r}addError(e){this.#n.push(e)}addChildError(e){this.#a.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var V="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#a=[];[k]=!0;#s=new WeakMap;static create(e){return new p({type:"object",...e})}createFromProps(e){return p.create(e)}constructor(e){super(e),typeof e.properties=="object"&&e.properties&&(this.#e=e.properties,this.#n=Object.keys(e.properties)),typeof e.acceptUnknownProps=="boolean"&&(this.#t=e.acceptUnknownProps),Array.isArray(e.constructorSchemas)&&(this.#a=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#a]}}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}#i(e){p.isValidPropertyDescriptor(e?.context?.rootPropertyDescriptor)||(e.context.rootPropertyDescriptor=p.getPropertiesFor(this)),p.isValidPropertyDescriptor(e.context.currentPropertyDescriptor)||(e.context.currentPropertyDescriptor=e.context.rootPropertyDescriptor),!e.context.rootValidationObject&&e.transaction?.object?.validatedObject&&(e.context.rootValidationObject=e.transaction.object.validatedObject)}preValidateSync(e,r){let t=super.preValidateSync(e,r);return this.#i(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#i(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:a}=e,s=new WeakMap,y=new Set,{doNotStopOnFirstError:o,rootValidationObject:i}=t,l=t.rootPropertyDescriptor,u=t.currentPropertyDescriptor,P=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=s.has(h)?s.get(h):null;if(g||(g=new O(h,i),s.set(h,g)),g.addError(m),y.add(g),R&&p.isValidPropertyDescriptor(R)){let j=s.has(R)?s.get(R):null;j||(j=new O(R,i),s.set(R,j)),j.addChildError(g)}},d=(h=>{let m=typeof h=="function"?h(u):u;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return s.has(m)||s.set(m,new O(m,i)),s.get(m)}),c=()=>[...y].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(u)){let m=h.property(u);if(p.isValidPropertyDescriptor(m)){P(m,h.message,u);return}}p.isValidPropertyDescriptor(u)&&P(u,h.message)};if(!r&&!o&&a){for(let h of a)E(h);return{earlyReturn:!0,result:{valid:r,errors:a,getErrorsFor:d,getInvalidProperties:c}}}if(o&&a)for(let h of a)E(h);let{object:{validatedObject:x}}=n;if(typeof x>"u"&&!this.isRequired||x===null&&(!this.isRequired||this.isNullable))return{earlyReturn:!0,result:{valid:!0,object:n.commit().validatedObject,getErrorsFor:d,getInvalidProperties:c}};if(typeof x!="object"||x===null)return T.length===0&&(T.push({message:V}),P(u,V)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}};let w=this.#n,D=Object.keys(x);if(w.length===0){if(D.length===0)return o&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:d,getInvalidProperties:c}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:d,getInvalidProperties:c}});if(!this.#t){for(let h=0;h<D.length;h++){let m=`unknown property '${D[h]}'`;if(T.push({message:m}),!o)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:o?T:[T[0]],getErrorsFor:d,getInvalidProperties:c}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:d,getInvalidProperties:c}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:w,objKeys:D,addErrorFor:P,getErrorsFor:d,getInvalidProperties:c,doNotStopOnFirstError:!!o,rootPropertyDescriptor:l,currentPropertyDescriptor:u,validationTransaction:n}}#p(e,r){let{objToValidate:t,objKeys:n,addErrorFor:a,getErrorsFor:s,getInvalidProperties:y,doNotStopOnFirstError:o,currentPropertyDescriptor:i,validationTransaction:l}=e,u=e.errors,P=!1;for(let{result:d}of r)if(!d.valid&&(P=!0,Array.isArray(d.errors)))for(let c of d.errors)u.push(c);for(let d=0;d<n.length;d++){let c=n[d];if(!(c in this.#e)&&!this.#t){let T=`unknown property '${c}'`;if(u.push({message:T}),a(i,T),!o)return l&&l.rollback(),{valid:!1,errors:[u[0]],getErrorsFor:s,getInvalidProperties:y}}}if(!P&&u.length===0){let d={};for(let{key:c,result:T}of r)d[c]=T.object;if(this.#t)for(let c of n)c in this.#e||(d[c]=t[c]);return{valid:!0,object:d,getErrorsFor:s,getInvalidProperties:y}}for(let{key:d,result:c}of r)if(!c.valid){let T=i[d];if(typeof c.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(c,T,a),Array.isArray(c.__externErrorPropertyNames)&&Array.isArray(c.errors))for(let E of c.errors)a(T,E.message,i)}else if(Array.isArray(c.errors)&&p.isValidPropertyDescriptor(T))for(let E of c.errors)a(T,E.message)}return l.rollback(),{valid:!1,errors:o?u:u[0]?[u[0]]:[],getErrorsFor:s,getInvalidProperties:y}}addValidator(e,r){return super.addValidator(e,r)}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation&&!r?.doNotStopOnFirstError&&!r?.rootPropertyDescriptor){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let t=this;return{valid:!0,object:e,getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else{let t=this;return{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],getErrorsFor(n){return t.#r(e,r).getErrorsFor(n)},getInvalidProperties(){return t.#r(e,r).getInvalidProperties()}}}else if(typeof e=="object"){let t=this.#n;if(!this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)if(!(s[y]in this.#e)){let o=this;return{valid:!1,errors:[{message:`unknown property '${s[y]}'`}],getErrorsFor(i){return o.#r(e,r).getErrorsFor(i)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}}let n={};for(let s=0;s<t.length;s++){let y=t[s],o=this.#e[y].validate(e[y]);if(!o.valid){let i=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getErrorsFor(l){return i.#r(e,r).getErrorsFor(l)},getInvalidProperties(){return i.#r(e,r).getInvalidProperties()}}}n[y]=o.object}if(this.#t){let s=Object.keys(e);for(let y=0;y<s.length;y++)s[y]in this.#e||(n[s[y]]=e[s[y]])}let a=this;return{valid:!0,object:n,getErrorsFor(s){return a.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}return this.#r(e,r)}#r(e,r){let t=this.#o(this.preValidateSync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];for(let l of n){let u=this.#e[l].validate(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid&&!s)break}return this.#p(t,i)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:a,doNotStopOnFirstError:s,rootPropertyDescriptor:y,currentPropertyDescriptor:o}=t,i=[];if(s){let l=await Promise.all(n.map(async u=>{let P=await this.#e[u].validateAsync(a[u],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[u]});return{key:u,result:P}}));i.push(...l)}else for(let l of n){let u=await this.#e[l].validateAsync(a[l],{...r,rootPropertyDescriptor:y,currentPropertyDescriptor:o[l]});if(i.push({key:l,result:u}),!u.valid)break}return this.#p(t,i)}acceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.createFromProps({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),constructorSchemas:[...this.#a,e]})}clearConstructors(){return this.createFromProps({...this.introspect(),constructorSchemas:[]})}addProp(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(e in this.#e)throw new Error(`Property ${e} already exists`);if(!(r instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.createFromProps({...this.introspect()})}addProps(e){if(e instanceof p)return this.addProps(e.introspect().properties);if(typeof e!="object")throw new Error("props should be an object");if(e===null)throw new Error("props should not be null");let r={...this.#e};for(let t in e){if(t in this.#e)throw new Error(`property '${t}' already exists`);if(!(e[t]instanceof S))throw new Error(`${t} is not a SchemaBuilder`);r[t]=e[t]}return this.createFromProps({...this.introspect(),properties:r})}omit(e){if(typeof e=="string"){let r=e;if(!r||!(r in this.#e))throw new Error(`property ${r.toString()} does not exists in the schema`);return this.createFromProps({...this.introspect(),properties:(()=>{let t={...this.#e};return delete t[r],t})()})}else if(Array.isArray(e)){let r=e,t=new Map;if(r.forEach(a=>{if(typeof a!="string"||!a)throw new Error("property name must be a string");if(!(a in this.#e))throw new Error(`property ${a.toString()} does not exists in the schema`);t.set(a.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let a of t.keys())delete n.properties[a];return this.createFromProps(n)}else if(e instanceof p){let r={...e.introspect().properties},t={...this.introspect()};for(let n in r)n in t.properties&&delete t.properties[n];return this.createFromProps(t)}throw new Error("this parameter type is not supported")}intersect(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");let r=e.introspect().properties,t=this.introspect(),n=Object.keys(t.properties).reduce((a,s)=>(a[s]=s in r?r[s]:t.properties[s],a),{});return this.createFromProps({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((r,t)=>(r[t]=this.#e[t].optional(),r),{})});if(Array.isArray(e)){let r=e;if(r.length===0)throw new Error("properties cannot be empty");let t={...this.introspect()};return r.forEach(n=>{if(typeof n!="string")throw new Error("each propery in property list must be as string value");if(!(n in t.properties))throw new Error(`property ${n} does not exists`);t.properties[n]=t.properties[n].optional()}),this.createFromProps(t)}if(typeof e=="string")return this.modifyPropSchema(e,r=>r.optional());throw new Error("expecting string or string[] parameter")}deepPartial(){let e={};for(let r of Object.keys(this.#e)){let t=this.#e[r];t instanceof p?e[r]=t.deepPartial().optional():e[r]=t.optional()}return this.createFromProps({...this.introspect(),properties:e})}pick(e){if(typeof e=="string"){let r=e;if(!r)throw new Error("property cannot be empty");if(!(r in this.#e))throw new Error(`property ${r} does not exists`);return this.createFromProps({...this.introspect(),properties:{[r]:this.#e[r]}})}if(Array.isArray(e)){if(e.length===0)throw new Error("properties must be a non empty erray");let r=e.reduce((t,n)=>{if(typeof n!="string"||!n)throw new Error("each property name must be a non empty string");if(!(n in this.#e))throw new Error(`property ${n} does not exists`);return t[n]=this.#e[n],t},{});return this.createFromProps({...this.introspect(),properties:r})}if(e instanceof p){let t=Object.keys(e.introspect().properties).filter(n=>typeof this.#e[n]<"u");if(t.length===0)throw new Error("there are no common properties in provided schemas");return this.pick(t)}throw new Error("string, array or ObjectSchemaBuilder is expected")}modifyPropSchema(e,r){if(typeof e!="string"||!e)throw new Error("propName must be a non empty string");if(!(e in this.#e))throw new Error(`property ${e} does not exists in the schema`);if(typeof r!="function")throw new Error("callback must be a function");let t=r(this.#e[e]);if(!(t instanceof S))throw new Error("callback must return a SchemaBuilder object");let n={...this.introspect()};return n.properties={...n.properties,[e]:t},this.createFromProps(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.createFromProps({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#y(e,r,t,n,a){let s=e.introspect();if(!s.properties)return{};let y=Object.keys(s.properties);if(y.length===0)return{};typeof r!="function"&&(r=i=>i);let o=B((i,l)=>(t||r)(i,l),n,e,a);for(let i of y){let l=s.properties[i];if(l instanceof p){let u=l.introspect().properties;u&&typeof u=="object"&&Object.keys(u).length>0?o[i]=p.#y(l,(P,d)=>{let c=r(P,d);return c?(d&&!c[i]&&(c[i]={}),c[i]):null},r,i,o[f]):o[i]=B(r,i,l,o[f])}else if(l[k]===!0){let u=B(r,i,l,o[f]),P=(d,c)=>{let T=r(d,c);return T?(c&&!T[i]&&(T[i]={}),T[i]):null};o[i]=q(u,P)}else o[i]=B(r,i,l,o[f])}return o}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#s.has(e))return e.#s.get(e);let r=p.#y(e);return e.#s.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[f]=="object"}static#c(e,r,t){let a=p.#l(r).introspect().properties,s;if(a)s=Object.keys(a);else if(Array.isArray(e.__externErrorPropertyNames))s=e.__externErrorPropertyNames;else return;for(let y of s){let o=r[y];if(!p.isValidPropertyDescriptor(o))continue;let i=e.getErrorsFor(()=>o);if(!i.isValid)for(let l of i.errors)t(o,l,r);if(a){let l=a[y];(l instanceof p||l[k]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(o)&&p.#c(e,o,t)}}}static#l(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[f].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},v=(p=>b.create({isRequired:!0,properties:p})),B=(p,e,r,t)=>({[f]:{setValue:(n,a,s)=>{let y=p(n,!!s?.createMissingStructure);return y?(typeof e=="string"&&(y[e]=a),!0):!1},getValue:n=>{let a=p(n,!1);return a?typeof e!="string"?{success:!0,value:a}:Object.hasOwn(a,e)?{success:!0,value:a[e]}:{success:!1}:{success:!1}},getSchema:()=>r,parent:t,propertyName:e,toJsonPointer:()=>{let n=[];typeof e=="string"&&n.push(e.replace(/~/g,"~0").replace(/\//g,"~1"));let a=t;for(;a;)typeof a.propertyName=="string"&&n.push(a.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),a=a.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),q=(p,e)=>new Proxy(p,{get(r,t,n){if(t===f)return r[f];if(typeof t=="string"&&!(t in r)){let a=B(e,t,void 0,r[f]),s=(y,o)=>{let i=e(y,o);return i!=null&&typeof i=="object"?(o&&!(t in i)&&(i[t]={}),i[t]):null};r[t]=q(a,s)}return Reflect.get(r,t,n)}});v.getPropertiesFor=p=>b.getPropertiesFor(p);v.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,v as b};
|
|
2
|
+
//# sourceMappingURL=chunk-6LSN7NXQ.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as h,e as m,f as c}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as h,e as m,f as c}from"./chunk-REYZ7G7J.js";var f=class T extends c{#e;#n=null;#t=null;static create(e){return new T({type:"union",...e})}constructor(e){super(e),Array.isArray(e.options)&&(this.#e=e.options,this.#o())}#o(){let e=this.#e;if(!e||e.length<2)return;let n=[];for(let s of e){let t=s.introspect();if(t.type!=="object")return;n.push(t)}let i=n[0].properties;if(i)for(let s of Object.keys(i)){let t=new Map,a=!0;for(let o=0;o<n.length;o++){let d=n[o].properties;if(!d||!(s in d)){a=!1;break}let r=d[s].introspect();if(r.isRequired!==!0){a=!1;break}let l=r.equalsTo;if(l==null){a=!1;break}if(typeof l!="string"&&typeof l!="number"){a=!1;break}if(t.has(l)){a=!1;break}t.set(l,e[o])}if(a&&t.size===e.length){this.#n=s,this.#t=t;return}}}introspect(){return{...super.introspect(),options:this.#e,discriminatorPropertyName:this.#n??void 0}}get isNullRequiredViolation(){return!1}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#r(e,n){let{valid:i,transaction:s,context:t,errors:a}=n,o={[h]:{setValue:()=>!1,getValue:u=>({success:!0,value:u}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},d=[],y=m([],()=>e,()=>d,()=>o[h]),r=(()=>y);if(!i)return d.push(...(a||[]).map(u=>u.message||String(u))),{needsOptionValidation:!1,result:{valid:i,errors:a,getNestedErrors:r}};let{object:{validatedObject:l}}=s;return typeof l>"u"&&!this.isRequired||l===null&&(!this.isRequired||this.isNullable)?{needsOptionValidation:!1,result:{valid:!0,object:l,getNestedErrors:r}}:{needsOptionValidation:!0,objToValidate:l,prevalidationContext:t,preValidationTransaction:s,getNestedErrors:r,optionResults:y,rootErrors:d}}#s(e,n,i,s,t,a){if(i[n]=e,e.valid)return{valid:!0,object:e.object,getNestedErrors:a};let o=e.errors;return Array.isArray(o)&&o.length>0&&o.length<t.minErrorsCount&&(t.resultingErrors=o,t.minErrorsCount=o.length),t.objToValidate=s.rollback().validatedObject,null}validate(e,n){return super.validate(e,n)}async validateAsync(e,n){return super.validateAsync(e,n)}_validate(e,n){if(this.canSkipPreValidation&&!n?.doNotStopOnFirstError&&!n?.rootPropertyDescriptor){if(typeof e>"u")if(this.hasDefault)e=this.resolveDefaultValue();else return this.isRequired?this.#i(!1,void 0,[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}],e,n):this.#i(!0,e,void 0,e,n);else if(e===null&&(!this.isRequired||this.isNullable))return this.#i(!0,e,void 0,e,n);if(this.#n&&this.#t&&typeof e=="object"&&e!==null){let i=e[this.#n],s=this.#t.get(i);if(s){let t=s.validate(e);return this.#i(t.valid,t.valid?t.object:void 0,t.valid?void 0:t.errors,e,n)}return this.#i(!1,void 0,[{message:"value doesn't match any option in union schema"}],e,n)}if(!this.#n){let i=this.#e,s=Number.MAX_SAFE_INTEGER,t=[];for(let a=0;a<i.length;a++){let o=i[a].validate(e);if(o.valid)return this.#i(!0,o.object,void 0,e,n);let d=o.errors;Array.isArray(d)&&d.length>0&&d.length<s&&(t=d,s=d.length)}return this.#i(!1,void 0,t,e,n)}}return this.#a(e,n)}#i(e,n,i,s,t){let a=this;return e?{valid:!0,object:n,getNestedErrors(){return a.#a(s,t).getNestedErrors()}}:{valid:!1,errors:i,getNestedErrors(){return a.#a(s,t).getNestedErrors()}}}#a(e,n){let i=this.#r(e,this.preValidateSync(e,n));if(!i.needsOptionValidation)return i.result;let{prevalidationContext:s,preValidationTransaction:t,getNestedErrors:a,optionResults:o,rootErrors:d}=i;if(this.#n&&this.#t){let r=i.objToValidate;if(typeof r=="object"&&r!==null){let l=r[this.#n],u=this.#t.get(l);if(u){let p=u.validate(r,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0});if(p.valid)return{valid:!0,object:p.object,getNestedErrors:a}}}}let y={objToValidate:i.objToValidate,minErrorsCount:Number.MAX_SAFE_INTEGER,resultingErrors:[]};for(let r=0;r<this.#e.length;r++){let l=this.#e[r].validate(y.objToValidate,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0}),u=this.#s(l,r,o,t,y,a);if(u)return u}return d.push("value doesn't match any option in union schema"),{valid:!1,errors:y.resultingErrors,getNestedErrors:a}}async _validateAsync(e,n){let i=this.#r(e,await super.preValidateAsync(e,n));if(!i.needsOptionValidation)return i.result;let{prevalidationContext:s,preValidationTransaction:t,getNestedErrors:a,optionResults:o,rootErrors:d}=i;if(this.#n&&this.#t){let r=i.objToValidate;if(typeof r=="object"&&r!==null){let l=r[this.#n],u=this.#t.get(l);if(u){let p=await u.validateAsync(r,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0});if(p.valid)return{valid:!0,object:p.object,getNestedErrors:a}}}}let y={objToValidate:i.objToValidate,minErrorsCount:Number.MAX_SAFE_INTEGER,resultingErrors:[]};for(let r=0;r<this.#e.length;r++){let l=await this.#e[r].validateAsync(y.objToValidate,{...s,currentPropertyDescriptor:void 0,rootPropertyDescriptor:void 0}),u=this.#s(l,r,o,t,y,a);if(u)return u}return d.push("value doesn't match any option in union schema"),{valid:!1,errors:y.resultingErrors,getNestedErrors:a}}createFromProps(e){return T.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}or(e){if(!(e instanceof c))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),options:[...this.#e,e]})}removeOption(e){if(typeof e!="number"||e<0||e>this.#e.length)throw new Error("index must be >= 0 and <= count of the options");return this.createFromProps({...this.introspect(),options:this.#e.filter((n,i)=>i!==e)})}removeFirstOption(){return this.removeOption(0)}reset(e){if(!(e instanceof c))throw new Error("schema must be an instance of the SchemaBuilder class");return this.createFromProps({...this.introspect(),options:[e]})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},E=T=>f.create({isRequired:!0,options:[T]});export{f as a,E as b};
|
|
2
|
+
//# sourceMappingURL=chunk-C6YQOKWB.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as l}from"./chunk-REYZ7G7J.js";var n=class i extends l{#e;#b=function(){return`expected to be at least ${this.#e}`};#a=this.#b;#r;#N=function(){return`expected to be no more than or equal to ${this.#r}`};#u=this.#N;#s;#E=function(){return`expected to be equal to ${this.#s}`};#n=this.#E;#t=!0;#l=function(){return"is not expected to be NaN"};#o=this.#l;#d=!0;#T=function(){return"is expected to be a finite number"};#m=this.#T;#h=!0;#i=function(){return"is expected to be an integer"};#c=this.#i;static create(e){return new i({type:"number",...e})}constructor(e){super(e),typeof e.min=="number"&&(this.#e=e.min),this.#a=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#b),typeof e.max=="number"&&(this.#r=e.max),this.#u=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#N),typeof e.ensureNotNaN=="boolean"&&(this.#t=e.ensureNotNaN),this.#o=this.assureValidationErrorMessageProvider(e.ensureNotNaNErrorMessageProvider,this.#l),typeof e.ensureIsFinite=="boolean"&&(this.#d=e.ensureIsFinite),this.#m=this.assureValidationErrorMessageProvider(e.ensureIsFiniteErrorMessageProvider,this.#T),typeof e.isInteger=="boolean"&&(this.#h=e.isInteger),this.#c=this.assureValidationErrorMessageProvider(e.ensureIsIntegerErrorMessageProvider,this.#i),(typeof e.equalsTo=="number"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#n=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#E)}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#a,max:this.#r,maxValidationErrorMessageProvider:this.#u,ensureNotNaN:this.#t,ensureNotNaNErrorMessageProvider:this.#o,ensureIsFinite:this.#d,ensureIsFiniteErrorMessageProvider:this.#m,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#n,isInteger:this.#h,ensureIsIntegerErrorMessageProvider:this.#c,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#f(e){return typeof e!="number"?{message:`expected type number, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#n}:this.#t&&Number.isNaN(e)?{provider:this.#o}:this.#d&&!Number.isFinite(e)&&this.#t&&!Number.isNaN(e)?{provider:this.#m}:this.#h&&!Number.isNaN(e)&&Number.isFinite(e)&&!Number.isInteger(e)?{provider:this.#c}:typeof this.#e<"u"&&e<this.#e?{provider:this.#a}:typeof this.#r<"u"&&e>this.#r?{provider:this.#u}:null}#R(e){let{valid:r,transaction:s,errors:t}=e;if(!r)return{done:!0,result:{valid:r,errors:t}};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:a}};let u=this.#f(a);return u?"message"in u?{done:!0,result:{valid:!1,errors:[{message:u.message}]}}:{done:!1,provider:u.provider,objToValidate:a}:{done:!0,result:{valid:!0,object:s.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let t=this.#f(e);return t?"message"in t?{valid:!1,errors:[{message:t.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,e)}]}:{valid:!0,object:e}}let s=this.#R(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#R(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return i.create(e)}equals(e,r){if(typeof e!="number")throw new Error("number expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}isFloat(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}clearIsInteger(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}isInteger(e){return this.createFromProps({...this.introspect(),isInteger:!0,ensureIsIntegerErrorMessageProvider:e})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}notNaN(e){return this.createFromProps({...this.introspect(),ensureNotNaN:!0,ensureNotNaNErrorMessageProvider:e})}canBeNaN(){return this.createFromProps({...this.introspect(),ensureNotNaN:!1,ensureNotNaNErrorMessageProvider:this.#l})}isFinite(e){return this.createFromProps({...this.introspect(),ensureIsFinite:!0,ensureIsFiniteErrorMessageProvider:e})}canBeInfinite(){return this.createFromProps({...this.introspect(),ensureIsFinite:!1,ensureIsFiniteErrorMessageProvider:this.#T})}coerce(){return this.addPreprocessor((e=>typeof e=="string"?Number(e):e),{mutates:!0})}min(e,r){if(typeof e!="number")throw new Error("minValue must be a number");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(typeof e!="number")throw new Error("maxValue must be a number");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}};function d(i){return typeof i=="number"?n.create({isRequired:!0,equalsTo:i}):n.create({isRequired:!0})}export{n as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-ELPPAHNO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as p,e as f,f as T}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as p,e as f,f as T}from"./chunk-REYZ7G7J.js";var m=class h extends T{#e;#t;static create(e){return new h({type:"tuple",...e})}constructor(e){super(e),Array.isArray(e.elements)?this.#e=e.elements:this.#e=[],e.restSchema instanceof T&&(this.#t=e.restSchema)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#a(e){if(e.length<this.#e.length){let l=this.#e.length;return`expected a tuple with at least ${l} element${l===1?"":"s"}, got ${e.length}`}if(!(this.#t instanceof T)&&e.length!==this.#e.length){let l=this.#e.length;return`expected a tuple of exactly ${l} element${l===1?"":"s"}, got ${e.length}`}return null}#n(e,l){let{valid:o,context:r,errors:a,transaction:n}=l,i={[p]:{setValue:()=>!1,getValue:t=>({success:!0,value:t}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},d=[],y=f([],()=>e,()=>d,()=>i[p]),c=(()=>y);if(!o)return d.push(...(a||[]).map(t=>t.message||String(t))),{needsElementValidation:!1,result:{valid:o,errors:a,getNestedErrors:c}};let{object:{validatedObject:u}}=n;return typeof u>"u"&&!this.isRequired||u===null&&(!this.isRequired||this.isNullable)?{needsElementValidation:!1,result:{valid:!0,object:u,getNestedErrors:c}}:Array.isArray(u)?{needsElementValidation:!0,objToValidate:u,prevalidationContext:r,getNestedErrors:c,elementResults:y,rootErrors:d}:(d.push("array expected"),{needsElementValidation:!1,result:{valid:!1,errors:[{message:"array expected"}],getNestedErrors:c}})}#r(e,l,o){let r=!0;for(let a=0;a<e.length;a++)e[a]?.valid||(r=!1),l[a]=e[a];return Object.assign({valid:r,getNestedErrors:o},r?{}:{errors:e.map(a=>a?.errors).filter(a=>a).flatMap(a=>a?.map(n=>({...n})))},r?{object:e.map(a=>a?.object)}:{})}validate(e,l){return super.validate(e,l)}async validateAsync(e,l){return super.validateAsync(e,l)}_validate(e,l){if(this.canSkipPreValidation&&!l?.doNotStopOnFirstError){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let n=this;return{valid:!0,object:e,getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}else return this.#s(e,l);if(!Array.isArray(e))return this.#s(e,l);let o=this.#a(e);if(o){let n=this;return{valid:!1,errors:[{message:o}],getNestedErrors(){return n.#s(e,l).getNestedErrors()}}}let r=new Array(e.length);for(let n=0;n<this.#e.length;n++){let i=this.#e[n].validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}if(this.#t instanceof T)for(let n=this.#e.length;n<e.length;n++){let i=this.#t.validate(e[n]);if(!i.valid){let d=this;return{valid:!1,errors:i.errors&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors(){return d.#s(e,l).getNestedErrors()}}}r[n]=i.object}let a=this;return{valid:!0,object:r,getNestedErrors(){return a.#s(e,l).getNestedErrors()}}}return this.#s(e,l)}#s(e,l){let o=this.#n(e,this.preValidateSync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let t=0;t<this.#e.length;t++)u[t]=this.#e[t].validate(r[t],{...a});if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++)u[t]=this.#t.validate(r[t],{...a});return this.#r(u,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=this.#e[t].validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=this.#t.validate(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}async _validateAsync(e,l){let o=this.#n(e,await super.preValidateAsync(e,l));if(!o.needsElementValidation)return o.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:n,elementResults:i,rootErrors:d}=o,y=this.#a(r);if(y)return d.push(y),{valid:!1,errors:[{message:y}],getNestedErrors:n};let c=this.#t instanceof T?r.length:this.#e.length;if(a.doNotStopOnFirstError){let u=new Array(c);for(let s=0;s<this.#e.length;s++)u[s]=this.#e[s].validateAsync(r[s],{...a});if(this.#t instanceof T)for(let s=this.#e.length;s<r.length;s++)u[s]=this.#t.validateAsync(r[s],{...a});let t=await Promise.all(u);return this.#r(t,i,n)}else{let u=new Array(c);for(let t=0;t<this.#e.length;t++){let s=await this.#e[t].validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}if(this.#t instanceof T)for(let t=this.#e.length;t<r.length;t++){let s=await this.#t.validateAsync(r[t],{...a});if(i[t]=s,s.valid)u[t]=s.object;else return{valid:!1,errors:Array.isArray(s.errors)&&s.errors.length>0?[s.errors[0]]:[],getNestedErrors:n}}return{valid:!0,object:u,getNestedErrors:n}}}createFromProps(e){return h.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}introspect(){return{...super.introspect(),elements:this.#e,restSchema:this.#t}}rest(e){return h.create({...this.introspect(),restSchema:e})}clearRest(){return h.create({...this.introspect(),restSchema:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},R=h=>m.create({isRequired:!0,elements:h});export{m as a,R as b};
|
|
2
|
+
//# sourceMappingURL=chunk-G424M7GI.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as i}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as i}from"./chunk-REYZ7G7J.js";var r=class s extends i{#e;static create(e){return new s({type:"promise",...e})}constructor(e){super(e),e.resolvedType instanceof i&&(this.#e=e.resolvedType)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}introspect(){return{...super.introspect(),resolvedType:this.#e}}#a(e){let{valid:a,transaction:n,errors:l}=e;if(!a)return{valid:a,errors:l};let{object:{validatedObject:t}}=n;return typeof t>"u"&&!this.isRequired||t===null&&(!this.isRequired||this.isNullable)?{valid:!0,object:t}:t==null||typeof t.then!="function"?{valid:!1,errors:[{message:`expected a Promise, but saw ${t===null?"null":typeof t}`}]}:{valid:!0,object:t}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){return this.#a(this.preValidateSync(e,a))}async _validateAsync(e,a){return this.#a(await super.preValidateAsync(e,a))}createFromProps(e){return s.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}hasResolvedType(e){return this.createFromProps({...this.introspect(),resolvedType:e})}};function o(s){return r.create({isRequired:!0,resolvedType:s})}export{r as a,o as b};
|
|
2
|
+
//# sourceMappingURL=chunk-JUFZ7PLO.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as n}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as n}from"./chunk-REYZ7G7J.js";var r=class s extends n{#e=[];#a;static create(e){return new s({type:"function",...e})}constructor(e){super(e),Array.isArray(e.parameters)&&(this.#e=e.parameters.filter(a=>a instanceof n)),e.returnType instanceof n&&(this.#a=e.returnType)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}introspect(){return{...super.introspect(),parameters:[...this.#e],returnType:this.#a}}#t(e){let{valid:a,transaction:i,errors:u}=e;if(!a)return{valid:a,errors:u};let{object:{validatedObject:t}}=i;return typeof t>"u"&&!this.isRequired||t===null&&(!this.isRequired||this.isNullable)?{valid:!0,object:t}:typeof t!="function"?{valid:!1,errors:[{message:`expected type function, but saw ${typeof t}`}]}:{valid:!0,object:t}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){return this.#t(this.preValidateSync(e,a))}async _validateAsync(e,a){return this.#t(await super.preValidateAsync(e,a))}createFromProps(e){return s.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}nullable(){return super.nullable()}addParameter(e){return this.createFromProps({...this.introspect(),parameters:[...this.#e,e]})}hasReturnType(e){return this.createFromProps({...this.introspect(),returnType:e})}notNullable(){return super.notNullable()}},T=()=>r.create({isRequired:!0});export{r as a,T as b};
|
|
2
|
+
//# sourceMappingURL=chunk-K4ZLXLE2.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as T,e as p,f as h}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{c as T,e as p,f as h}from"./chunk-REYZ7G7J.js";var y=class m extends h{#r;#l=function(){return`is expected to have no less than ${this.#r} elements`};#n=this.#l;#t;#u=function(){return`is expected to have no more than ${this.#t} elements`};#s=this.#u;#e;static create(e){return new m({type:"array",...e})}constructor(e){super(e),typeof e.minLength=="number"&&(this.#r=e.minLength),this.#n=this.assureValidationErrorMessageProvider(e.minLengthValidationErrorMessageProvider,this.#l),typeof e.maxLength=="number"&&(this.#t=e.maxLength),this.#s=this.assureValidationErrorMessageProvider(e.maxLengthValidationErrorMessageProvider,this.#u),e.elementSchema instanceof h&&(this.#e=e.elementSchema)}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#o(e,t){let{valid:u,context:r,errors:a,transaction:l}=t,d={[T]:{setValue:()=>!1,getValue:i=>({success:!0,value:i}),getSchema:()=>this,parent:void 0,propertyName:void 0,toJsonPointer:()=>""}},o=[],c=p([],()=>e,()=>o,()=>d[T]),s=(()=>c);if(!u)return o.push(...(a||[]).map(i=>i.message||String(i))),{needsElementValidation:!1,result:{valid:u,errors:a,getNestedErrors:s}};let{object:{validatedObject:n}}=l;return typeof n>"u"&&!this.isRequired||n===null&&(!this.isRequired||this.isNullable)?{needsElementValidation:!1,result:{valid:!0,object:n,getNestedErrors:s}}:Array.isArray(n)?{needsElementValidation:!0,objToValidate:n,prevalidationContext:r,getNestedErrors:s,elementResults:c,rootErrors:o}:(o.push("array expected"),{needsElementValidation:!1,result:{valid:!1,errors:[{message:"array expected"}],getNestedErrors:s}})}#i(e){return typeof this.#t=="number"&&e.length>this.#t?{provider:this.#s}:typeof this.#r=="number"&&e.length<this.#r?{provider:this.#n}:null}#d(e,t,u){let r=!0;for(let a=0;a<e.length;a++)e[a]?.valid||(r=!1),t[a]=e[a];return Object.assign({valid:r,getNestedErrors:u},r?{}:{errors:e.map(a=>a?.errors).filter(a=>a).flatMap(a=>a?.map(l=>({...l})))},r?{object:e.map(a=>a?.object)}:{})}validate(e,t){return super.validate(e,t)}async validateAsync(e,t){return super.validateAsync(e,t)}_validate(e,t){if(this.canSkipPreValidation&&!t?.doNotStopOnFirstError&&this.#e instanceof h){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else if(!this.isRequired||e===null&&this.isNullable){let a=this;return{valid:!0,object:e,getNestedErrors(){return a.#a(e,t).getNestedErrors()}}}else return this.#a(e,t);if(!Array.isArray(e))return this.#a(e,t);if(this.#i(e))return this.#a(e,t);let u=e.length;if(u>0){let a=new Array(u);for(let d=0;d<u;d++){let o=this.#e.validate(e[d]);if(!o.valid){let c=this;return{valid:!1,errors:o.errors&&o.errors.length>0?[o.errors[0]]:[],getNestedErrors(){return c.#a(e,t).getNestedErrors()}}}a[d]=o.object}let l=this;return{valid:!0,object:a,getNestedErrors(){return l.#a(e,t).getNestedErrors()}}}let r=this;return{valid:!0,object:e,getNestedErrors(){return r.#a(e,t).getNestedErrors()}}}return this.#a(e,t)}#a(e,t){let u=this.#o(e,this.preValidateSync(e,t));if(!u.needsElementValidation)return u.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:l,elementResults:d,rootErrors:o}=u,c=this.#i(r);if(c){let s=this.getValidationErrorMessageSync(c.provider,r);return o.push(s),{valid:!1,errors:[{message:s}],getNestedErrors:l}}if(r.length>0&&this.#e instanceof h)if(a.doNotStopOnFirstError){let s=[];for(let n=0;n<r.length;n++)s.push(this.#e.validate(r[n],{...a}));return this.#d(s,d,l)}else{let s=new Array(r.length);for(let n=0;n<r.length;n++){let i=this.#e.validate(r[n],{...a});if(d[n]=i,i.valid)s[n]=i.object;else return{valid:!1,errors:Array.isArray(i.errors)&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors:l}}return{valid:!0,object:s,getNestedErrors:l}}return{valid:!0,object:r,getNestedErrors:l}}async _validateAsync(e,t){let u=this.#o(e,await super.preValidateAsync(e,t));if(!u.needsElementValidation)return u.result;let{objToValidate:r,prevalidationContext:a,getNestedErrors:l,elementResults:d,rootErrors:o}=u,c=this.#i(r);if(c){let s=await this.getValidationErrorMessage(c.provider,r);return o.push(s),{valid:!1,errors:[{message:s}],getNestedErrors:l}}if(r.length>0&&this.#e instanceof h)if(a.doNotStopOnFirstError){let s=await Promise.all(r.map(n=>this.#e?.validateAsync(n,a)));return this.#d(s,d,l)}else{let s=new Array(r.length);for(let n=0;n<r.length;n++){let i=await this.#e.validateAsync(r[n],{...a});if(d[n]=i,i.valid)s[n]=i.object;else return{valid:!1,errors:Array.isArray(i.errors)&&i.errors.length>0?[i.errors[0]]:[],getNestedErrors:l}}return{valid:!0,object:s,getNestedErrors:l}}return{valid:!0,object:r,getNestedErrors:l}}createFromProps(e){return m.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}introspect(){return{...super.introspect(),elementSchema:this.#e,minLength:this.#r,minLengthValidationErrorMessageProvider:this.#n,maxLength:this.#t,maxLengthValidationErrorMessageProvider:this.#s}}of(e){return m.create({...this.introspect(),elementSchema:e})}clearOf(){return m.create({...this.introspect(),elementSchema:void 0})}minLength(e,t){if(typeof e!="number"||e<0)throw new Error("length is expected to be a number which is >= 0");return m.create({...this.introspect(),minLength:e,minLengthValidationErrorMessageProvider:t})}clearMinLength(){let e=this.introspect();return delete e.minLength,this.createFromProps({...e})}maxLength(e,t){if(typeof e!="number"||e<0)throw new Error("length is expected to be a number which is >= 0");return m.create({...this.introspect(),maxLength:e,maxLengthValidationErrorMessageProvider:t})}clearMaxLength(){let e=this.introspect();return delete e.maxLength,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},S=m=>y.create({isRequired:!0,elementSchema:m});export{y as a,S as b};
|
|
2
|
+
//# sourceMappingURL=chunk-KC45JEFL.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as u,f as l}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as u,f as l}from"./chunk-REYZ7G7J.js";var d=t=>{if(typeof t>"u")return t;if(typeof t=="string"){let e=Date.parse(t);return Number.isNaN(e)?t:new Date(e)}return t},T=t=>{if(typeof t>"u")return t;if(typeof t=="number"){let e=new Date(t);return Number.isNaN(e.getTime())?t:e}return t},o=class t extends l{#e;#c=function(){return`is expected to be after ${this.#e} (${this.#e?.getTime()})`};#i=this.#c;#r;#h=function(){return`is expected to be before ${this.#r} (${this.#r?.getTime()})`};#n=this.#h;#t;#m=function(){return`is expected to be equal ${this.#t} (${this.#t?.getTime()})`};#u=this.#m;#o=!1;#f=function(){return"is expected to be in future"};#l=this.#f;#d=!1;#p=function(){return"is expected to be in past"};#T=this.#p;#s=!1;#a=!1;#E=!0;static create(e){return new t({type:"date",...e})}constructor(e){super(e),e.min instanceof Date&&(this.#e=e.min),this.#i=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#c),e.max instanceof Date&&(this.#r=e.max),this.#n=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#h),typeof e.ensureIsInFuture=="boolean"&&(this.#o=e.ensureIsInFuture),this.#l=this.assureValidationErrorMessageProvider(e.ensureIsInFutureValidationErrorMessageProvider,this.#f),typeof e.ensureIsInPast=="boolean"&&(this.#d=e.ensureIsInPast),this.#T=this.assureValidationErrorMessageProvider(e.ensureIsInPastValidationErrorMessageProvider,this.#p),typeof e.parseFromJson=="boolean"&&(this.#s=e.parseFromJson),typeof e.parseFromEpoch=="boolean"&&(this.#a=e.parseFromEpoch),(e.equalsTo instanceof Date||typeof e.equalsTo>"u")&&(this.#t=e.equalsTo),this.#u=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#m),this.#E=this.canSkipPreValidation&&!this.#s&&!this.#a}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#i,max:this.#r,maxValidationErrorMessageProvider:this.#n,ensureIsInFuture:this.#o,ensureIsInFutureValidationErrorMessageProvider:this.#l,ensureIsInPast:this.#d,ensureIsInPastValidationErrorMessageProvider:this.#T,equalsTo:this.#t,equalsToValidationErrorMessageProvider:this.#u,parseFromEpoch:this.#a,parseFromJson:this.#s,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return e instanceof Date?typeof this.#t<"u"&&e.getTime()!==this.#t.getTime()?{provider:this.#u}:this.#o&&e<=new Date?{provider:this.#l}:this.#d&&e>=new Date?{provider:this.#T}:typeof this.#e<"u"&&e<this.#e?{provider:this.#i}:typeof this.#r<"u"&&e>this.#r?{provider:this.#n}:null:{message:`expected instance of Date, but saw ${typeof e}`}}#D(e){let{valid:r,errors:s}=e;if(!r)return{done:!0,result:{valid:r,errors:s}};let{transaction:a}=e,{object:{validatedObject:i}}=a;if(typeof i>"u"&&!this.isRequired||i===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:i}};this.#s&&(a=u({validatedObject:d(i)}),i=a.object.validatedObject),this.#a&&(a=u({validatedObject:T(i)}),i=a.object.validatedObject);let n=this.#R(i);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:i}:{done:!0,result:{valid:!0,object:a.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.#E){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let a=this.#R(e);return a?"message"in a?{valid:!1,errors:[{message:a.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(a.provider,e)}]}:{valid:!0,object:e}}let s=this.#D(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#D(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return t.create(e)}equals(e,r){if(!(e instanceof Date))throw new Error("Date expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}isInFuture(e){return this.createFromProps({...this.introspect(),ensureIsInFuture:!0,ensureIsInFutureValidationErrorMessageProvider:e})}clearIsInFuture(){return this.createFromProps({...this.introspect(),ensureIsInFuture:!1})}isInPast(e){return this.createFromProps({...this.introspect(),ensureIsInPast:!0,ensureIsInPastValidationErrorMessageProvider:e})}clearIsInPast(){return this.createFromProps({...this.introspect(),ensureIsInPast:!1})}min(e,r){if(!(e instanceof Date))throw new Error("minValue must be a Date");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(!(e instanceof Date))throw new Error("maxValue must be a Date");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}coerce(){return this.addPreprocessor((e=>{if(typeof e=="string"){let r=new Date(e);return Number.isNaN(r.getTime())?e:r}return e}),{mutates:!0})}acceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!0})}doNotAcceptJsonString(){return this.createFromProps({...this.introspect(),parseFromJson:!1})}acceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!0})}doNotAcceptEpoch(){return this.createFromProps({...this.introspect(),parseFromEpoch:!1})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},m=()=>o.create({isRequired:!0});export{o as a,m as b};
|
|
2
|
+
//# sourceMappingURL=chunk-NF4CRFMN.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as o}from"./chunk-REYZ7G7J.js";var l=class a extends o{#t;#T=function(){return`is expected to have a length of at least ${this.#t} characters`};#n=this.#T;#i;#g=function(){return`is expected to have a length of no more than ${this.#i} characters`};#l=this.#g;#s;#c=function(e){return`is expected to be equal to "${this.#s}" but saw "${e}"`};#o=this.#c;#e;#m=function(){return`is expected to start with "${this.#e}"`};#u=this.#m;#r;#E=function(){return`is expected to end with "${this.#r}"`};#d=this.#E;#a;#f=function(){return`is expected to match the pattern ${this.#a}`};#h=this.#f;static create(e){return new a({type:"string",...e})}constructor(e){super(e),typeof e.minLength=="number"&&(this.#t=e.minLength),this.#n=this.assureValidationErrorMessageProvider(e.minLengthValidationErrorMessageProvider,this.#T),typeof e.maxLength=="number"&&(this.#i=e.maxLength),this.#l=this.assureValidationErrorMessageProvider(e.maxLengthValidationErrorMessageProvider,this.#g),(typeof e.equalsTo=="string"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#o=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#c),typeof e.startsWith=="string"&&e.startsWith.length>0&&(this.#e=e.startsWith),this.#u=this.assureValidationErrorMessageProvider(e.startsWithValidationErrorMessageProvider,this.#m),typeof e.endsWith=="string"&&e.endsWith.length>0&&(this.#r=e.endsWith),this.#d=this.assureValidationErrorMessageProvider(e.endsWithValidationErrorMessageProvider,this.#E),e.matches instanceof RegExp&&(this.#a=e.matches),this.#h=this.assureValidationErrorMessageProvider(e.matchesValidationErrorMessageProvider,this.#f)}introspect(){return{...super.introspect(),minLength:this.#t,minLengthValidationErrorMessageProvider:this.#n,maxLength:this.#i,maxLengthValidationErrorMessageProvider:this.#l,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#o,startsWith:this.#e,startsWithValidationErrorMessageProvider:this.#u,endsWith:this.#r,endsWithValidationErrorMessageProvider:this.#d,matches:this.#a,matchesValidationErrorMessageProvider:this.#h,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#R(e){return typeof e!="string"?{message:`expected type string, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#o}:typeof this.#e=="string"&&this.#e.length>0&&!e.startsWith(this.#e)?{provider:this.#u}:typeof this.#r=="string"&&this.#r.length>0&&!e.endsWith(this.#r)?{provider:this.#d}:typeof this.#t<"u"&&e.length<this.#t?{provider:this.#n}:typeof this.#i<"u"&&e.length>this.#i?{provider:this.#l}:this.#a instanceof RegExp&&!this.#a.test(e)?{provider:this.#h}:null}#p(e){let{valid:r,transaction:t,errors:i}=e;if(!r)return{done:!0,result:{valid:r,errors:i}};let{object:{validatedObject:s}}=t;if(typeof s>"u"&&!this.isRequired||s===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:s}};let n=this.#R(s);return n?"message"in n?{done:!0,result:{valid:!1,errors:[{message:n.message}]}}:{done:!1,provider:n.provider,objToValidate:s}:{done:!0,result:{valid:!0,object:s}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let i=this.#R(e);return i?"message"in i?{valid:!1,errors:[{message:i.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(i.provider,e)}]}:{valid:!0,object:e}}let t=this.#p(this.preValidateSync(e,r));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,r){let t=this.#p(await super.preValidateAsync(e,r));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return a.create(e)}equals(e,r){if(typeof e!="string")throw new Error("string expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}minLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),minLength:e,minLengthValidationErrorMessageProvider:r})}clearMinLength(){let e=this.introspect();return delete e.minLength,this.createFromProps({...e})}maxLength(e,r){if(typeof e!="number")throw new Error("length must be a number");return this.createFromProps({...this.introspect(),maxLength:e,maxLengthValidationErrorMessageProvider:r})}clearMaxLength(){let e=this.introspect();return delete e.maxLength,this.createFromProps({...e})}startsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),startsWith:e,startsWithValidationErrorMessageProvider:r})}clearStartsWith(){let e=this.introspect();return delete e.startsWith,this.createFromProps({...e})}endsWith(e,r){if(typeof e!="string"||!e)throw new Error("non empty string expected");return this.createFromProps({...this.introspect(),endsWith:e,endsWithValidationErrorMessageProvider:r})}clearEndsWith(){let e=this.introspect();return delete e.endsWith,this.createFromProps({...e})}matches(e,r){if(!(e instanceof RegExp))throw new Error("regexp expected");return this.createFromProps({...this.introspect(),matches:e,matchesValidationErrorMessageProvider:r})}clearMatches(){let e=this.introspect();return delete e.matches,this.createFromProps({...e})}};function d(a,e){return typeof a=="string"?l.create({isRequired:!0,equalsTo:a,equalsToValidationErrorMessageProvider:e}):l.create({isRequired:!0})}export{l as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-ORV2G6ZL.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{f as o}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{f as o}from"./chunk-REYZ7G7J.js";var i=class n extends o{#e;#t=function(){return`is expected to be equal ${this.#e}`};#a=this.#t;static create(e){return new n({type:"boolean",...e})}constructor(e){super(e),(typeof e.equalsTo=="boolean"||typeof e.equalsTo>"u")&&(this.#e=e.equalsTo),this.#a=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#t)}introspect(){return{...super.introspect(),equalsTo:this.#e,equalsToValidationErrorMessageProvider:this.#a}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#s(e){return typeof e!="boolean"?{message:"expected to be boolean"}:typeof this.#e<"u"&&e!==this.#e?{provider:this.#a}:null}#r(e){let{valid:a,transaction:t,errors:s}=e;if(!a)return{done:!0,result:{valid:a,errors:s}};let{object:{validatedObject:r}}=t;if(typeof r>"u"&&!this.isRequired||r===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:r}};let l=this.#s(r);return l?"message"in l?{done:!0,result:{valid:!1,errors:[{message:l.message}]}}:{done:!1,provider:l.provider,objToValidate:r}:{done:!0,result:{valid:!0,object:r}}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let s=this.#s(e);return s?"message"in s?{valid:!1,errors:[{message:s.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,e)}]}:{valid:!0,object:e}}let t=this.#r(this.preValidateSync(e,a));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,a){let t=this.#r(await super.preValidateAsync(e,a));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return n.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}equals(e,a){if(typeof e!="boolean")throw new Error("boolean expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:a})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}coerce(){return this.addPreprocessor((e=>e==="true"?!0:e==="false"?!1:e),{mutates:!0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},d=()=>i.create({isRequired:!0});export{i as a,d as b};
|
|
2
|
+
//# sourceMappingURL=chunk-PQINUGZW.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var y=Symbol("transaction"),P=[Error,RegExp,Date],R={shouldNotWrapWithTransaction:u=>!!P.find(e=>u instanceof e)},h=(u,e)=>{let r={},a=new Map;e=Object.assign({},R,e||{});let{shouldNotWrapWithTransaction:i}=e,l=()=>!!Object.keys(r).find(s=>r[s]?.[y]?r[s][y].isDirty():!0)||a.size>0,c=()=>{let s={};Object.keys(u).forEach(t=>{s[t]=u[t]}),Object.keys(r).forEach(t=>{let o=r[t];if(o[y]){let{commit:d}=o[y];s[t]=d()}else s[t]=r[t]});for(let t of a.keys())delete s[t];return r={},a=new Map,s},p=()=>{for(let s in r){let t=r[s];t&&typeof t=="object"&&t[y]&&t[y].rollback()}return r={},a=new Map,u};if(Array.isArray(u)){let s=u.map(d=>typeof d=="object"&&d&&!i(d)?h(d).object:d),t=()=>s.map(d=>d&&typeof d[y]=="object"?d[y].commit():d),o=()=>!!s.find((d,f)=>d&&typeof d[y]=="object"?d[y].isDirty():s[f]!==u[f]);return Object.defineProperty(s,y,{writable:!1,configurable:!1,value:{initial:u,object:s,commit:t,rollback:()=>u,isDirty:o}}),{object:s,commit:t,rollback:()=>u,isDirty:o}}let n=new Proxy(u,{set:(s,t,o)=>s&&s[t]===o?(delete r[t],!0):(r[t]=o,a.delete(t),!0),ownKeys:s=>[...Object.keys(s).filter(t=>!a.has(t)),...Object.keys(r).filter(t=>!(t in s))],getOwnPropertyDescriptor:(s,t)=>{if(!a.has(t))return t in r?Object.getOwnPropertyDescriptor(r,t):Object.getOwnPropertyDescriptor(s,t)},has:(s,t)=>a.has(t)?!1:t in r?!0:t in s,get:(s,t)=>{if(typeof t=="symbol")return t===y?{initial:u,object:n,commit:c,rollback:p,isDirty:l}:s[t];if(t in r)return r[t];if(!a.has(t)){if(!g(s[t])&&typeof s[t]=="object"&&s[t]&&!i(s[t])){let{object:o}=h(s[t],e);return r[t]=o,o}return s[t]}},deleteProperty:(s,t)=>(t in r&&(r[t]&&typeof r[t][y]=="object"&&r[t][y].rollback(),delete r[t]),t in s&&a.set(t,!0),!0)});return{object:n,commit:c,rollback:p,isDirty:l}},T=u=>({object:u,commit:()=>u,rollback:()=>u,isDirty:()=>!1}),g=u=>u&&typeof u=="object"&&Object.hasOwn(u,y);var m=class extends Error{errors;constructor(e){let r=e.length>0?e.map(a=>a.message).join("; "):"Validation failed";super(r),this.name="SchemaValidationError",this.errors=e}},x=Symbol(),v=Symbol();function E(u,e,r,a){return Object.defineProperties(u,{seenValue:{get:e,enumerable:!1},errors:{get:r,enumerable:!1},isValid:{get:()=>r().length===0,enumerable:!1},descriptor:{get:a,enumerable:!1}}),u}var b=class{#d=!0;#a=!1;#y=!1;#p;#h;#e=[];#t=[];#n=!1;#T=!0;#c={};#f="base";#m="is required";#o="is required";#s=void 0;#i=void 0;#l=!1;#b=void 0;#u;get"~standard"(){if(this.#u)return this.#u;let e=this;return this.#u={version:1,vendor:"@cleverbrush/schema",async validate(r){let a=await e.validateAsync(r);return a.valid?{value:a.object}:{issues:(a.errors??[]).map(i=>({message:i.message}))}}},this.#u}get type(){return this.#f}set type(e){if(typeof e!="string"||!e)throw new Error("value should be non empty string");this.#f=e}get preprocessors(){return this.#e}get validators(){return this.#t}get isRequired(){return this.#d}get isNullable(){return this.#a}set isRequired(e){if(typeof e!="boolean")throw new Error("should be a boolean value");this.#d=e}get requiredErrorMessage(){return this.#o}get hasDefault(){return this.#s!==void 0}get hasCatch(){return this.#l}resolveCatchValue(){return typeof this.#i=="function"?this.#i():this.#i}get isReadonly(){return this.#y}resolveDefaultValue(){return typeof this.#s=="function"?this.#s():this.#s}get canSkipPreValidation(){return this.#T}get isNullRequiredViolation(){return!0}#P(e,r){let a=r?.doNotStopOnFirstError??!1,i={doNotStopOnFirstError:a,rootPropertyDescriptor:r?.rootPropertyDescriptor,currentPropertyDescriptor:r?.currentPropertyDescriptor},l=this.#n;return{doNotStopOnFirstError:a,resultingContext:i,transaction:l?h({validatedObject:e}):T({validatedObject:e}),errors:[]}}#r(e,r){return{valid:!1,errors:[e[0]].filter(a=>a),context:r}}#R(e,r,a){return Array.isArray(a)&&a.length?a:[{message:`Validator #${e}${r?` (${r})`:""} didn't pass.`}]}#g(e,r,a,i){return e.length>0?{valid:!1,errors:e.filter(l=>l).filter((l,c)=>r?!0:c===0),context:a,transaction:i}:{valid:!0,context:a,transaction:i}}preValidateSync(e,r){let a=this.#P(e,r),{doNotStopOnFirstError:i,resultingContext:l,errors:c}=a,p=a.transaction,n=p.object.validatedObject;if(this.#e.length>0){let s=0;for(let t of this.#e)try{let o=t.fn(n);if(o instanceof Promise)throw new Error(`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} returned a Promise. Use validateAsync() for schemas with async preprocessors.`);n=o}catch(o){if(o.message?.includes("Use validateAsync()"))throw o;if(c.push({message:`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}p=this.#n?h({validatedObject:n}):T({validatedObject:n})}if(typeof n>"u"&&this.hasDefault&&(n=this.resolveDefaultValue(),p=this.#n?h({validatedObject:n}):T({validatedObject:n})),this.#t.length>0&&!(n==null&&!this.isRequired)&&!(n===null&&this.#a)){let s=0;for(let t of this.#t)try{let o=t.fn(n);if(o instanceof Promise)throw new Error(`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} returned a Promise. Use validateAsync() for schemas with async validators.`);let{valid:d,errors:f}=o;if(!d&&(c.push(...this.#R(s,t.fn.name,f)),!i))return this.#r(c,l)}catch(o){if(o.message?.includes("Use validateAsync()"))throw o;if(c.push({message:`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}}return this.isRequired&&(typeof n>"u"||n===null&&this.isNullRequiredViolation&&!this.#a)&&(c.push({message:this.getValidationErrorMessageSync(this.#o,n)}),!i)?(p.rollback(),this.#r(c,l)):this.#g(c,i,l,p)}async preValidateAsync(e,r){let a=this.#P(e,r),{doNotStopOnFirstError:i,resultingContext:l,errors:c}=a,p=a.transaction,n=p.object.validatedObject;if(this.#e.length>0){let s=0;for(let t of this.#e)try{n=await Promise.resolve(t.fn(n))}catch(o){if(c.push({message:`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}p=this.#n?h({validatedObject:n}):T({validatedObject:n})}if(typeof n>"u"&&this.hasDefault&&(n=this.resolveDefaultValue(),p=this.#n?h({validatedObject:n}):T({validatedObject:n})),this.#t.length>0&&!(n==null&&!this.isRequired)&&!(n===null&&this.#a)){let s=0;for(let t of this.#t)try{let{valid:o,errors:d}=await Promise.resolve(t.fn(n));if(!o&&(c.push(...this.#R(s,t.fn.name,d)),!i))return this.#r(c,l)}catch(o){if(c.push({message:`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}}return this.isRequired&&(typeof n>"u"||n===null&&this.isNullRequiredViolation&&!this.#a)&&(c.push({message:await this.getValidationErrorMessage(this.#o,n)}),!i)?(p.rollback(),this.#r(c,l)):this.#g(c,i,l,p)}preValidate(e,r){return this.preValidateAsync(e,r)}introspect(){return{type:this.type,isRequired:this.#d,isNullable:this.#a,isReadonly:this.#y,preprocessors:[...this.preprocessors],validators:[...this.validators],requiredValidationErrorMessageProvider:this.#o,extensions:{...this.#c},hasDefault:this.#s!==void 0,defaultValue:this.#s,description:this.#p,schemaName:this.#h,hasCatch:this.#l,catchValue:this.#i,example:this.#b}}optional(){return this.createFromProps({...this.introspect(),isRequired:!1})}nullable(){return this.createFromProps({...this.introspect(),isNullable:!0})}notNullable(){return this.createFromProps({...this.introspect(),isNullable:!1})}default(e){return this.createFromProps({...this.introspect(),defaultValue:e})}catch(e){return this.createFromProps({...this.introspect(),catchValue:e,hasCatch:!0})}clearDefault(){return this.createFromProps({...this.introspect(),defaultValue:void 0})}describe(e){return this.createFromProps({...this.introspect(),description:e})}example(e){return this.createFromProps({...this.introspect(),example:e})}schemaName(e){return this.createFromProps({...this.introspect(),schemaName:e})}brand(e){return this.createFromProps({...this.introspect()})}readonly(){return this.createFromProps({...this.introspect(),isReadonly:!0})}required(e){return this.createFromProps({...this.introspect(),isRequired:!0,...e!==void 0?{requiredValidationErrorMessageProvider:this.assureValidationErrorMessageProvider(e,this.#m)}:{}})}addPreprocessor(e,r){if(typeof e!="function")throw new Error("preprocessor must be a function");return this.createFromProps({...this.introspect(),preprocessors:[...this.preprocessors,{fn:e,mutates:r?.mutates??!0}]})}clearPreprocessors(){return this.createFromProps({...this.introspect(),preprocessors:[]})}addValidator(e,r){if(typeof e!="function")throw new Error("validator must be a function");return this.createFromProps({...this.introspect(),validators:[...this.validators,{fn:e,mutates:r?.mutates??!1}]})}clearValidators(){return this.createFromProps({...this.introspect(),validators:[]})}validate(e,r){let a=this._validate(e,r);if(!a.valid&&this.#l){let i=this.resolveCatchValue(),l=this._validate(i,r);return l.valid?l:{valid:!0,object:i}}return a}async validateAsync(e,r){let a=await this._validateAsync(e,r);if(!a.valid&&this.#l){let i=this.resolveCatchValue(),l=await this._validateAsync(i,r);return l.valid?l:{valid:!0,object:i}}return a}getValidationErrorMessageSync(e,r){if(typeof e=="string")return e;if(typeof e=="function"){let a=e(r,this);if(a instanceof Promise)throw new Error("Async error message providers require validateAsync(). Use a string or sync function instead.");return a}throw new Error("Invalid error message provider must be a string or a function returning a string")}async getValidationErrorMessage(e,r){if(typeof e=="string")return e;if(typeof e=="function")return e(r,this);throw new Error("Invalid error message provider must be a string or a function returning a string or a promise of a string")}assureValidationErrorMessageProvider(e,r){return typeof e=="string"?e:typeof e=="function"?e.bind(this):typeof r=="function"?r.bind(this):r}withExtension(e,r){return this.createFromProps({...this.introspect(),extensions:{...this.#c,[e]:r}})}getExtension(e){return this.#c[e]}parse(e,r){let a=this.validate(e,r);if(!a.valid)throw new m(a.errors||[]);return a.object}async parseAsync(e,r){let a=await this.validateAsync(e,r);if(!a.valid)throw new m(a.errors||[]);return a.object}safeParse(e,r){return this.validate(e,r)}safeParseAsync(e,r){return this.validateAsync(e,r)}constructor(e){if(!(typeof e=="object"&&e))throw new Error("SchemaBuilder props must be an object");let{type:r,preprocessors:a,validators:i,isRequired:l}=e;this.type=r,typeof l=="boolean"&&(this.isRequired=l),typeof e.isNullable=="boolean"&&(this.#a=e.isNullable),typeof e.isReadonly=="boolean"&&(this.#y=e.isReadonly),Array.isArray(a)&&(this.#e=[...a]),Array.isArray(i)&&(this.#t=[...i]),this.#n=this.#e.some(c=>c.mutates)||this.#t.some(c=>c.mutates),this.#T=this.#e.length===0&&this.#t.length===0,typeof e.extensions=="object"&&e.extensions&&(this.#c={...e.extensions}),e.defaultValue!==void 0&&(this.#s=e.defaultValue),e.hasCatch&&(this.#l=!0,this.#i=e.catchValue),typeof e.description=="string"&&(this.#p=e.description),typeof e.schemaName=="string"&&(this.#h=e.schemaName),e.example!==void 0&&(this.#b=e.example),this.#o=this.assureValidationErrorMessageProvider(e.requiredValidationErrorMessageProvider,this.#m)}};export{h as a,m as b,x as c,v as d,E as e,b as f};
|
|
2
|
+
//# sourceMappingURL=chunk-REYZ7G7J.js.map
|