@cleverbrush/schema 5.0.0 → 5.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/dist/builders/ObjectSchemaBuilder.js +1 -1
- package/dist/builders/ParseStringSchemaBuilder.js +1 -1
- package/dist/{chunk-X6CT6I2V.js → chunk-W5LLKFM7.js} +2 -2
- package/dist/{chunk-CR2QIV5I.js → chunk-WNAU5MPQ.js} +2 -2
- package/dist/chunk-Z4SFUZSP.js +2 -0
- package/dist/chunk-Z4SFUZSP.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/extension.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-JEBLDVKG.js +0 -2
- package/dist/chunk-JEBLDVKG.js.map +0 -1
- /package/dist/{chunk-X6CT6I2V.js.map → chunk-W5LLKFM7.js.map} +0 -0
- /package/dist/{chunk-CR2QIV5I.js.map → chunk-WNAU5MPQ.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-Z4SFUZSP.js";import"../chunk-2BKBVVZ3.js";export{a as ObjectSchemaBuilder,b as object};
|
|
2
2
|
//# sourceMappingURL=ObjectSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-W5LLKFM7.js";import"../chunk-Z4SFUZSP.js";import"../chunk-2BKBVVZ3.js";export{a as ParseStringSchemaBuilder,b as parseString};
|
|
2
2
|
//# sourceMappingURL=ParseStringSchemaBuilder.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as m}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as m}from"./chunk-Z4SFUZSP.js";import{c as f,f as S}from"./chunk-2BKBVVZ3.js";function x(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function P(o,e){let r=o;for(let a of e.split(".")){if(r==null)return;r=r[a]}return r}function b(o){let e=[];function r(a){return new Proxy(a,{get(t,s){if(s===f)return t[f];if(typeof s!="string")return t[s];let l=t[s];return typeof l!="object"||l===null?l:(e.push(s),r(l))}})}return{proxy:r(o),getPath:()=>e}}var R=class o extends S{#n;#e;#t=null;static create(e){return new o({type:"parseString",...e})}constructor(e){super(e),this.#n=e.objectSchema,this.#e=e.templateDefinition}#s(){if(this.#t)return this.#t;let{literals:e,segments:r}=this.#e,a="^";for(let t=0;t<r.length;t++){a+=x(e[t]);let s=t===r.length-1,l=e[t+1]??"";a+=s&&l===""?"(.*)":"(.*?)"}return a+=x(e[r.length]??""),a+="$",this.#t=new RegExp(a),this.#t}#r(){let{literals:e,segments:r}=this.#e,a="";for(let t=0;t<r.length;t++)a+=e[t]+`{${r[t].path}}`;return a+=e[r.length]??"",a}get template(){return this.#r()}introspect(){return{...super.introspect(),objectSchema:this.#n,templateDefinition:this.#e}}serialize(e){let{literals:r,segments:a}=this.#e,t="";for(let s=0;s<a.length;s++){t+=r[s];let l=a[s].path,d=P(e,l);if(d==null)throw new Error(`Missing required parameter "${l}" for template ${this.#r()}`);t+=String(d)}return t+=r[a.length]??"",t}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){return typeof e>"u"||e===null?typeof e>"u"&&this.hasDefault?(e=this.resolveDefaultValue(),{valid:!0,object:e}):!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]}:this.#a(e,r,(a,t)=>a.validate(t))}async _validateAsync(e,r){return typeof e>"u"||e===null?typeof e>"u"&&this.hasDefault?(e=this.resolveDefaultValue(),{valid:!0,object:e}):!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:await this.getValidationErrorMessage(this.requiredErrorMessage,e)}]}:this.#a(e,r,(a,t)=>a.validateAsync(t))}#a(e,r,a){if(typeof e!="string")return{valid:!1,errors:[{message:`expected a string to parse, but saw ${typeof e}`}]};let{segments:t}=this.#e;if(t.length===0){let n=this.#e.literals[0]??"";return e!==n?{valid:!1,errors:[{message:`expected "${n}" but saw "${e}"`}]}:{valid:!0,object:{}}}let l=this.#s().exec(e);if(!l)return{valid:!1,errors:[{message:`does not match the parse-string pattern ${this.#r()}`}]};let d=r?.doNotStopOnFirstError??!1,p=new Proxy([],{get:(n,u,c)=>{if(u==="length")return t.length;let i=typeof u=="string"?Number(u):Number.NaN;return Number.isInteger(i)&&i>=0&&i<t.length?(i in n||(n[i]=a(t[i].schema,l[i+1])),n[i]):Reflect.get(n,u,c)}});if(d)for(let n=0;n<t.length;n++)p[n];let g=p[0];if(g&&typeof g.then=="function")return(async()=>{let n=[],u={};for(let c=0;c<t.length;c++){let i=await p[c];if(!i.valid){let h=i.errors?.[0]?.message??"validation failed";if(n.push({message:`${t[c].path}: ${h}`}),!d)return{valid:!1,errors:n};continue}t[c].descriptor.setValue(u,i.object,{createMissingStructure:!0})}return n.length>0?{valid:!1,errors:n}:{valid:!0,object:u}})();let y=[],T={};for(let n=0;n<t.length;n++){let u=p[n];if(!u.valid){let c=u.errors?.[0]?.message??"validation failed";if(y.push({message:`${t[n].path}: ${c}`}),!d)return{valid:!1,errors:y};continue}t[n].descriptor.setValue(T,u.object,{createMissingStructure:!0})}return y.length>0?{valid:!1,errors:y}:{valid:!0,object:T}}hasType(e){return this.derive({...this.introspect()},!0)}clearHasType(){return this.derive({...this.introspect()},!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()}createFromProps(e){return o.create(e)}};function v(o,e){if(!(o instanceof m))throw new Error("First argument must be an ObjectSchemaBuilder instance");let r=m.getPropertiesFor(o),t=e(((s,...l)=>{let d=new Set,p=[];for(let g of l){if(typeof g!="function")throw new Error("Template expressions must be property selector functions (e.g. t => t.id)");let{proxy:y,getPath:T}=b(r),n=g(y);if(!n||typeof n!="object"||!(f in n))throw new Error("Template expression must select a property from the schema (e.g. t => t.id)");let u=n[f],c=u.getSchema(),i=T();if(i.length===0)throw new Error("Template expression must select a specific property (e.g. t => t.id), not the root object");let h=i.join(".");if(d.has(h))throw new Error(`Duplicate template parameter: "${h}" is already used in this template`);d.add(h),p.push({schema:c,path:h,descriptor:u})}return{literals:[...s],segments:p}}));return R.create({isRequired:!0,objectSchema:o,templateDefinition:t})}export{R as a,v as b};
|
|
2
|
+
//# sourceMappingURL=chunk-W5LLKFM7.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as j,b as w}from"./chunk-3E5M6GRR.js";import{a as S,b as B}from"./chunk-BMA2X7LI.js";import{a as b,b as R}from"./chunk-BTR3ZGES.js";import{a as M,b as g}from"./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{a as j,b as w}from"./chunk-3E5M6GRR.js";import{a as S,b as B}from"./chunk-BMA2X7LI.js";import{a as b,b as R}from"./chunk-BTR3ZGES.js";import{a as M,b as g}from"./chunk-Z4SFUZSP.js";import{a as N,b as A}from"./chunk-25KL2NBJ.js";import{a as _,b as D}from"./chunk-W5D22D4P.js";import{a as P,b as F}from"./chunk-JH7VLA6C.js";import{a as V,b as v}from"./chunk-VBPZRO7L.js";import{a as c,b as T}from"./chunk-NDESVCWI.js";import{a as x,b as m}from"./chunk-XASMTNON.js";import{a as h,b as p}from"./chunk-D7RXO2FA.js";import{a as f,b as E}from"./chunk-66U6MMJ2.js";import{f as u}from"./chunk-2BKBVVZ3.js";var o=class s extends u{#e;#n;#t;static create(e){return new s({type:"generic",...e})}constructor(e){super(e),this.#e=e.templateFn,this.#n=e.defaults,this.apply=(...n)=>{if(!this.#e)throw new Error("GenericSchemaBuilder: no template function defined");return this.#e(...n)}}introspect(){return{...super.introspect(),templateFn:this.#e,defaults:this.#n}}#a(){if(!(!this.#e||!this.#n))return this.#t||(this.#t=this.#e(...this.#n)),this.#t}#r(e,n){let{valid:a,transaction:r,errors:d}=e;if(!a)return{valid:a,errors:d};let{object:{validatedObject:i}}=r;if(typeof i>"u"&&!this.isRequired||i===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:i};let t=this.#a();return t?t.validate(i,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}async#i(e,n){let{valid:a,transaction:r,errors:d}=e;if(!a)return{valid:a,errors:d};let{object:{validatedObject:i}}=r;if(typeof i>"u"&&!this.isRequired||i===null&&(!this.isRequired||this.isNullable))return{valid:!0,object:i};let t=this.#a();return t?await t.validateAsync(i,n):{valid:!1,errors:[{message:"This is a generic schema template. Call .apply() with concrete schemas to get a validatable schema, or provide default arguments to generic()."}]}}validate(e,n){return super.validate(e,n)}async validateAsync(e,n){return super.validateAsync(e,n)}_validate(e,n){return this.#r(this.preValidateSync(e,n),n)}async _validateAsync(e,n){return this.#i(await super.preValidateAsync(e,n),n)}createFromProps(e){return s.create(e)}hasType(e){return this.derive({...this.introspect()},!0)}clearHasType(){return this.derive({...this.introspect()},!0)}required(e){return super.required(e)}optional(){return super.optional()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}};function C(s,e){let n=e!==void 0?e:s,a=e!==void 0?s:void 0;return o.create({isRequired:!0,templateFn:n,defaults:a})}var K=new WeakSet;function O(s){return K.has(s)}function G(s){let e=n=>{let a=function(...r){return this.withExtension(s,n(...r))};return K.add(a),a};return{argument:()=>e(n=>n),value:n=>e(()=>n),compute:e}}var y={string:P,number:b,boolean:h,date:f,object:M,array:x,tuple:V,record:_,union:j,func:S,any:c,promise:N,generic:o},H={string:F,number:R,boolean:p,date:E,object:g,array:m,tuple:v,record:D,union:w,func:B,any:T,promise:A,generic:C},ie="__cleverbrush_method_literal_brand__";var se="__cleverbrush_extra_type_brand__";var q=new Set(["validate","validateAsync","parse","parseAsync","safeParse","safeParseAsync","introspect","optional","required","addPreprocessor","clearPreprocessors","addValidator","clearValidators","hasType","clearHasType","createFromProps","preValidate","preValidateSync","preValidateAsync","getValidationErrorMessage","getValidationErrorMessageSync","assureValidationErrorMessageProvider","withExtension","getExtension"]);function de(s){let e={};for(let n of Object.keys(s)){if(!(n in y))throw new Error(`Unknown builder type "${n}". Valid types: ${Object.keys(y).join(", ")}`);let a=s[n];if(!a||typeof a!="object")throw new Error(`Extension config for "${n}" must be an object of methods`);e[n]={};for(let r of Object.keys(a)){if(q.has(r))throw new Error(`Cannot override reserved method "${r}" on "${n}"`);let d=a[r];if(typeof d!="function")throw new Error(`Extension method "${n}.${r}" must be a function`);if(O(d)){e[n][r]=d;continue}e[n][r]=function(...i){let t=d.apply(this,i);return t&&typeof t=="object"&&typeof t.withExtension=="function"&&(typeof t.getExtension!="function"||t.getExtension(r)===void 0)?t.withExtension(r,i.length===1?i[0]:i.length===0?!0:i):t}}}return{config:e}}function oe(...s){let e=new Map;for(let a of s)for(let r of Object.keys(a.config)){e.has(r)||e.set(r,new Map);let d=e.get(r),i=a.config[r];for(let t of Object.keys(i)){if(d.has(t))throw new Error(`Extension method collision: "${t}" is defined by multiple extensions for "${r}"`);d.set(t,i[t])}}let n={};for(let a of Object.keys(y)){let r=e.get(a);if(!r||r.size===0){n[a]=H[a];continue}let d=y[a],i=class extends d{constructor(...t){super(...t)}static create(t){return new i({...t})}createFromProps(t){return i.create(t)}};for(let[t,l]of r)Object.defineProperty(i.prototype,t,{value:l,writable:!0,configurable:!0,enumerable:!1});n[a]=(...t)=>{let l=H[a](...t);return Object.setPrototypeOf(l,i.prototype),l}}return n}export{o as a,C as b,G as c,ie as d,se as e,de as f,oe as g};
|
|
2
|
+
//# sourceMappingURL=chunk-WNAU5MPQ.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as P,d as B,f as S}from"./chunk-2BKBVVZ3.js";var O=class{#e;#t;#n=[];#i=[];get seenValue(){let e=this.#e[P].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.#i}get descriptor(){return this.#e[P]}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.#i.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var q="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#i=[];[B]=!0;#a=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.#i=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#i]}}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()}#s(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.#s(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#s(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:i}=e,y=new WeakMap,l=new Set,{doNotStopOnFirstError:a,rootValidationObject:o}=t,s=t.rootPropertyDescriptor,d=t.currentPropertyDescriptor,f=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=y.has(h)?y.get(h):null;if(g||(g=new O(h,o),y.set(h,g)),g.addError(m),l.add(g),R&&p.isValidPropertyDescriptor(R)){let v=y.has(R)?y.get(R):null;v||(v=new O(R,o),y.set(R,v)),v.addChildError(g)}},u=(h=>{let m=typeof h=="function"?h(d):d;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return y.has(m)||y.set(m,new O(m,o)),y.get(m)}),c=()=>[...l].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(d)){let m=h.property(d);if(p.isValidPropertyDescriptor(m)){f(m,h.message,d);return}}p.isValidPropertyDescriptor(d)&&f(d,h.message)};if(!r&&!a&&i){for(let h of i)E(h);return{earlyReturn:!0,result:{valid:r,errors:i,getErrorsFor:u,getInvalidProperties:c}}}if(a&&i)for(let h of i)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:u,getInvalidProperties:c}};if(typeof x!="object"||x===null||Array.isArray(x))return T.length===0&&(T.push({message:q}),f(d,q)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:a?T:[T[0]],getErrorsFor:u,getInvalidProperties:c}};let V=this.#n,j=Object.keys(x);if(V.length===0){if(j.length===0)return a&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:u,getInvalidProperties:c}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:u,getInvalidProperties:c}});if(!this.#t){for(let h=0;h<j.length;h++){let m=`unknown property '${j[h]}'`;if(T.push({message:m}),!a)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:a?T:[T[0]],getErrorsFor:u,getInvalidProperties:c}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:u,getInvalidProperties:c}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:V,objKeys:j,addErrorFor:f,getErrorsFor:u,getInvalidProperties:c,doNotStopOnFirstError:!!a,rootPropertyDescriptor:s,currentPropertyDescriptor:d,validationTransaction:n}}#y(e,r){let{objToValidate:t,objKeys:n,addErrorFor:i,getErrorsFor:y,getInvalidProperties:l,doNotStopOnFirstError:a,currentPropertyDescriptor:o,validationTransaction:s}=e,d=e.errors,f=!1;for(let{result:u}of r)if(!u.valid&&(f=!0,Array.isArray(u.errors)))for(let c of u.errors)d.push(c);for(let u=0;u<n.length;u++){let c=n[u];if(!(c in this.#e)&&!this.#t){let T=`unknown property '${c}'`;if(d.push({message:T}),i(o,T),!a)return s&&s.rollback(),{valid:!1,errors:[d[0]],getErrorsFor:y,getInvalidProperties:l}}}if(!f&&d.length===0){let u={};for(let{key:c,result:T}of r)u[c]=T.object;if(this.#t)for(let c of n)c in this.#e||(u[c]=t[c]);return{valid:!0,object:u,getErrorsFor:y,getInvalidProperties:l}}for(let{key:u,result:c}of r)if(!c.valid){let T=o[u];if(typeof c.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(c,T,i),Array.isArray(c.__externErrorPropertyNames)&&Array.isArray(c.errors))for(let E of c.errors)i(T,E.message,o)}else if(Array.isArray(c.errors)&&p.isValidPropertyDescriptor(T)){for(let E of c.errors)i(T,E.message);Array.isArray(c.getNestedErrors?.())&&p.#l(c,T,i)}}return s.rollback(),{valid:!1,errors:a?d:d[0]?[d[0]]:[],getErrorsFor:y,getInvalidProperties:l}}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"&&!Array.isArray(e)){let t=this.#n;if(!this.#t){let y=Object.keys(e);for(let l=0;l<y.length;l++)if(!(y[l]in this.#e)){let a=this;return{valid:!1,errors:[{message:`unknown property '${y[l]}'`}],getErrorsFor(o){return a.#r(e,r).getErrorsFor(o)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}let n={};for(let y=0;y<t.length;y++){let l=t[y],a=this.#e[l].validate(e[l]);if(!a.valid){let o=this;return{valid:!1,errors:a.errors&&a.errors.length>0?[a.errors[0]]:[],getErrorsFor(s){return o.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}n[l]=a.object}if(this.#t){let y=Object.keys(e);for(let l=0;l<y.length;l++)y[l]in this.#e||(n[y[l]]=e[y[l]])}let i=this;return{valid:!0,object:n,getErrorsFor(y){return i.#r(e,r).getErrorsFor(y)},getInvalidProperties(){return i.#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:i,doNotStopOnFirstError:y,rootPropertyDescriptor:l,currentPropertyDescriptor:a}=t,o=[];for(let s of n){let d=this.#e[s].validate(i[s],{...r,rootPropertyDescriptor:l,currentPropertyDescriptor:a[s]});if(o.push({key:s,result:d}),!d.valid&&!y)break}return this.#y(t,o)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:i,doNotStopOnFirstError:y,rootPropertyDescriptor:l,currentPropertyDescriptor:a}=t,o=[];if(y){let s=await Promise.all(n.map(async d=>{let f=await this.#e[d].validateAsync(i[d],{...r,rootPropertyDescriptor:l,currentPropertyDescriptor:a[d]});return{key:d,result:f}}));o.push(...s)}else for(let s of n){let d=await this.#e[s].validateAsync(i[s],{...r,rootPropertyDescriptor:l,currentPropertyDescriptor:a[s]});if(o.push({key:s,result:d}),!d.valid)break}return this.#y(t,o)}acceptUnknownProps(){return this.derive({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.derive({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.derive({...this.introspect()},!0)}clearHasType(){return this.derive({...this.introspect()},!0)}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.derive({...this.introspect(),constructorSchemas:[...this.#i,e]})}clearConstructors(){return this.derive({...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.derive({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.derive({...this.introspect()},!0)}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.derive({...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.derive({...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(i=>{if(typeof i!="string"||!i)throw new Error("property name must be a string");if(!(i in this.#e))throw new Error(`property ${i.toString()} does not exists in the schema`);t.set(i.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let i of t.keys())delete n.properties[i];return this.derive(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.derive(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((i,y)=>(i[y]=y in r?r[y]:t.properties[y],i),{});return this.derive({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.derive({...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.derive(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.derive({...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.derive({...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.derive({...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.derive(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.derive({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.derive({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#p(e,r,t,n,i){let y=e.introspect();if(!y.properties)return{};let l=Object.keys(y.properties);typeof r!="function"&&(r=o=>o);let a=D((o,s)=>(t||r)(o,s),n,e,i);for(let o of l){let s=y.properties[o];if(s instanceof p){let d=s.introspect().properties;d&&typeof d=="object"&&Object.keys(d).length>0?a[o]=p.#p(s,(f,u)=>{let c=r(f,u);return c?(u&&!c[o]&&(c[o]={}),c[o]):null},r,o,a[P]):a[o]=D(r,o,s,a[P])}else if(s.introspect().type==="array")a[o]=k(s,r,o,a[P]);else if(s[B]===!0){let d=D(r,o,s,a[P]),f=(u,c)=>{let T=r(u,c);return T?(c&&!T[o]&&(T[o]={}),T[o]):null};a[o]=w(d,f)}else a[o]=D(r,o,s,a[P])}return a}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#a.has(e))return e.#a.get(e);let r=p.#p(e);return e.#a.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[P]=="object"}static#c(e,r,t){let i=p.#d(r).introspect().properties,y;if(i)y=Object.keys(i);else if(Array.isArray(e.__externErrorPropertyNames))y=e.__externErrorPropertyNames;else return;for(let l of y){let a=r[l];if(!p.isValidPropertyDescriptor(a))continue;let o=e.getErrorsFor(()=>a);if(!o.isValid)for(let s of o.errors)t(a,s,r);if(a[P].getSchema()?.introspect().type==="array"&&typeof e.getInvalidProperties=="function"){let s=a[P].toJsonPointer()+"/";for(let d of e.getInvalidProperties()){let f=d.descriptor.toJsonPointer();if(!f.startsWith(s))continue;let u=f.slice(s.length).split("/").reduce((c,T)=>c?.[T.replace(/~1/g,"/").replace(/~0/g,"~")],a);if(p.isValidPropertyDescriptor(u))for(let c of d.errors)t(u,c,a)}}if(i){let s=i[l];(s instanceof p||s[B]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(a)&&p.#c(e,a,t)}}}static#l(e,r,t){let n=e.getNestedErrors?.();Array.isArray(n)&&n.forEach((i,y)=>{let l=r[y];if(!(!i||i.valid||!p.isValidPropertyDescriptor(l)))if(typeof i.getInvalidProperties=="function"){let a=l[P].toJsonPointer();for(let o of i.getInvalidProperties()){let s=o.descriptor.toJsonPointer(),d=s===a?"":s.startsWith(a+"/")?s.slice(a.length):s,f=d===""?l:d.slice(1).split("/").reduce((u,c)=>u?.[c.replace(/~1/g,"/").replace(/~0/g,"~")],l);if(p.isValidPropertyDescriptor(f))for(let u of o.errors)t(f,u,r)}}else{for(let a of i.errors??[])t(l,a.message,r);p.#l(i,l,t)}})}static#d(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[P].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},C=(p=>b.create({isRequired:!0,properties:p})),D=(p,e,r,t)=>({[P]:{setValue:(n,i,y)=>{let l=p(n,!!y?.createMissingStructure);return l?(typeof e=="string"&&(l[e]=i),!0):!1},getValue:n=>{let i=p(n,!1);return i?typeof e!="string"?{success:!0,value:i}:Object.hasOwn(i,e)?{success:!0,value:i[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 i=t;for(;i;)typeof i.propertyName=="string"&&n.push(i.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),i=i.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),k=(p,e,r,t)=>{let n=D(e,r,p,t),i=p.introspect(),y=(a,o)=>{let s=e(a,o);return!s||typeof s!="object"?null:(o&&(!Object.hasOwn(s,r)||s[r]==null)&&Object.defineProperty(s,r,{value:i.type==="array"?[]:{},enumerable:!0,writable:!0,configurable:!0}),Object.hasOwn(s,r)?s[r]:null)},l=n[P];if(i.type==="array"){let a=new Map;return new Proxy(n,{get(o,s,d){if(typeof s!="string"||!/^(0|[1-9]\d*)$/.test(s)||Number(s)>=4294967295)return Reflect.get(o,s,d);if(i.elementSchema)return a.has(s)||a.set(s,k(i.elementSchema,(f,u)=>{let c=y(f,u);return Array.isArray(c)?c:null},s,l)),a.get(s)}})}if(i.properties)for(let[a,o]of Object.entries(i.properties))Object.defineProperty(n,a,{value:k(o,y,a,l),enumerable:!0});else if(p[B])return w(n,y);return n},w=(p,e)=>new Proxy(p,{get(r,t,n){if(t===P)return r[P];if(typeof t=="string"&&!(t in r)){let i=D(e,t,void 0,r[P]),y=(l,a)=>{let o=e(l,a);return o!=null&&typeof o=="object"?(a&&!(t in o)&&(o[t]={}),o[t]):null};r[t]=w(i,y)}return Reflect.get(r,t,n)}});C.getPropertiesFor=p=>b.getPropertiesFor(p);C.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,C as b};
|
|
2
|
+
//# sourceMappingURL=chunk-Z4SFUZSP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/builders/PropertyValidationResult.ts","../src/builders/ObjectSchemaBuilder.ts"],"sourcesContent":["import { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';\nimport {\n type InferType,\n type NestedValidationResult,\n type PropertyDescriptorInner,\n type PropertyDescriptorTree,\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n} from './SchemaBuilder.js';\n\n/**\n * Mutable container for nested validation results associated with a specific\n * property descriptor. Implements {@link NestedValidationResult} and tracks\n * the seen value, accumulated error messages, and child results for\n * nested object properties.\n *\n * Used internally by `ObjectSchemaBuilder` during validation to build up\n * a tree of per-property validation results.\n */\nexport class PropertyValidationResult<\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<any, any, any, any, any>,\n TRootSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor = any\n> implements\n NestedValidationResult<TSchema, TRootSchema, TParentPropertyDescriptor>\n{\n #descriptor: PropertyDescriptorTree<\n TSchema,\n TRootSchema,\n any,\n TParentPropertyDescriptor\n >;\n #rootObjectValue: InferType<TRootSchema> | undefined;\n #errors: string[] = [];\n #childErrors: NestedValidationResult<any, any, any>[] = [];\n\n /**\n * The value that was seen at the property location described by the descriptor.\n * Retrieves the value from the root object using the property descriptor's `getValue` method.\n * Returns `undefined` if the property is not found.\n */\n public get seenValue(): InferType<TSchema> | undefined {\n const result = this.#descriptor[\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n ].getValue(this.#rootObjectValue as any);\n\n return (result.success ? result.value : undefined) as any;\n }\n\n /**\n * The list of validation error messages accumulated for this property.\n */\n public get errors(): ReadonlyArray<string> {\n return this.#errors;\n }\n\n /**\n * Whether validation passed for this property and all of its children.\n * Returns `true` only when there are no errors and no child errors.\n */\n public get isValid(): boolean {\n return this.#errors.length === 0 && this.getChildErrors().length === 0;\n }\n\n /**\n * Returns the list of child `NestedValidationResult` instances\n * representing validation results for nested properties.\n */\n public getChildErrors(): ReadonlyArray<\n NestedValidationResult<any, any, any>\n > {\n return this.#childErrors;\n }\n\n /**\n * The inner property descriptor providing `getValue`, `setValue`, and `getSchema`\n * operations for the property this error relates to.\n */\n public get descriptor(): PropertyDescriptorInner<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n > {\n return this.#descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR] as any;\n }\n\n /**\n * Creates a new `PropertyValidationResult`.\n *\n * @param descriptor - the property descriptor tree node this error is associated with;\n * must be a valid descriptor (checked via `ObjectSchemaBuilder.isValidPropertyDescriptor`)\n * @param rootObjectValue - the root object being validated, used to resolve property values\n * @param errors - optional initial list of error message strings\n * @throws if `descriptor` is not a valid property descriptor\n */\n constructor(\n descriptor: PropertyDescriptorTree<\n TSchema,\n TRootSchema,\n any,\n TParentPropertyDescriptor\n >,\n rootObjectValue: InferType<TRootSchema> | undefined,\n errors?: string[]\n ) {\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)) {\n throw new Error('Invalid property descriptor');\n }\n this.#descriptor = descriptor;\n this.#errors = Array.isArray(errors) ? [...errors] : [];\n this.#rootObjectValue = rootObjectValue;\n }\n\n /**\n * Appends a validation error message to this property's error list.\n * @param error - the error message string to add\n */\n addError(error: string): void {\n this.#errors.push(error);\n }\n\n /**\n * Appends a child `NestedValidationResult` for a nested property.\n * @param childError - the child validation result to add\n */\n addChildError(childError: NestedValidationResult<any, any, any>): void {\n this.#childErrors.push(childError);\n }\n\n /**\n * Returns a JSON-serializable representation of this validation result.\n * This ensures `JSON.stringify` includes `isValid` and `errors`,\n * which are otherwise non-enumerable prototype getters.\n */\n toJSON(): { isValid: boolean; errors: ReadonlyArray<string> } {\n return {\n isValid: this.isValid,\n errors: this.errors\n };\n }\n}\n","import { PropertyValidationResult } from './PropertyValidationResult.js';\nimport {\n type BRAND,\n type InferType,\n type NestedValidationResult,\n type PreValidationResult,\n type PropertyDescriptor,\n type PropertyDescriptorInner,\n type PropertyDescriptorTree,\n type PropertySetterOptions,\n SchemaBuilder,\n SYMBOL_HAS_PROPERTIES,\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR,\n type ValidationContext,\n type ValidationError,\n type ValidationErrorMessageProvider,\n type ValidationResult\n} from './SchemaBuilder.js';\n\nconst MUST_BE_AN_OBJECT_ERROR_MESSSAGE = 'must be an object';\n\n/**\n * A callback function to select properties from the schema.\n * Normally it's provided by the user to select property descriptors\n * from the schema for the further usage. e.g. to select source and destination\n * properties for object mappings\n */\nexport type SchemaPropertySelector<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n TPropertySchema extends SchemaBuilder<any, any, any, any, any>,\n TAssignableTo = any,\n TParentPropertyDescriptor = undefined\n> = (\n l: PropertyDescriptorTree<TSchema, TSchema, TAssignableTo>\n) => PropertyDescriptor<TSchema, TPropertySchema, TParentPropertyDescriptor>;\n\ntype ObjectSchemaBuilderProps<\n T extends Record<string, SchemaBuilder> = {},\n TRequired extends boolean = true\n> = ReturnType<ObjectSchemaBuilder<T, TRequired>['introspect']>;\n\ntype ObjectSchemaBuilderCreateProps<\n T extends Record<string, SchemaBuilder> = {},\n TRequired extends boolean = true\n> = Partial<ObjectSchemaBuilderProps<T, TRequired>>;\n\ntype Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\n\n/**\n * Extracts the positional argument types from a schema whose inferred type is a\n * function. When the branded `InferType<T>` resolves to a function type the\n * parameter tuple is extracted; otherwise `any[]` is used as a safe fallback.\n *\n * @example\n * ```ts\n * type Args = ConstructorParams<typeof func().addParameter(string()).addParameter(number())>;\n * // → [string, number]\n * ```\n */\ntype ConstructorParams<T extends SchemaBuilder<any, any, any, any, any>> =\n InferType<T> extends (...args: infer A) => any ? A : any[];\n\n/**\n * Converts a tuple of `FunctionSchemaBuilder`s into an intersection of\n * `new (...args) => TInstance` call signatures, producing overloaded\n * construct signatures in the inferred type.\n *\n * The recursion peels schemas off the front of `TSchemas` one at a time,\n * each contributing one construct overload to the intersection.\n *\n * @example\n * ```ts\n * type Sigs = ConstructorSignatures<\n * [typeof func().addParameter(string()), typeof func().addParameter(number())],\n * { name: string }\n * >;\n * // → { new (p0: string): { name: string } }\n * // & { new (p0: number): { name: string } }\n * ```\n */\ntype ConstructorSignatures<\n TSchemas extends SchemaBuilder<any, any, any, any, any>[],\n TInstance\n> = TSchemas extends [\n infer THead extends SchemaBuilder<any, any, any, any, any>,\n ...infer TTail extends SchemaBuilder<any, any, any, any, any>[]\n]\n ? {\n new (...args: ConstructorParams<THead>): TInstance;\n } & ConstructorSignatures<TTail, TInstance>\n : unknown;\n\n/**\n * Wraps `TInstance` with constructor overload signatures derived from\n * `TSchemas`. When the tuple is empty the type is returned unchanged\n * (no-op); otherwise the result is an intersection of all construct\n * signatures with `TInstance`.\n *\n * This is the type projected onto `InferType<ObjectSchemaBuilder>` when one\n * or more constructors have been registered via `.addConstructor()`.\n *\n * @example\n * ```ts\n * // No constructors — passthrough\n * type A = WithConstructors<[], { name: string }>;\n * // → { name: string }\n *\n * // One constructor\n * type B = WithConstructors<[typeof func().addParameter(string())], { name: string }>;\n * // → { new (p0: string): { name: string } } & { name: string }\n *\n * // Two constructors → overloaded construct signatures\n * type C = WithConstructors<\n * [typeof func().addParameter(string()), typeof func().addParameter(number())],\n * { name: string }\n * >;\n * // → { new (p0: string): { name: string } }\n * // & { new (p0: number): { name: string } }\n * // & { name: string }\n * ```\n */\ntype WithConstructors<\n TSchemas extends SchemaBuilder<any, any, any, any, any>[],\n TInstance\n> = TSchemas extends []\n ? TInstance\n : ConstructorSignatures<TSchemas, TInstance> & TInstance;\n\nexport type RespectPropsOptionality<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in RequiredProps<T>]: InferType<T[K]>;\n} & {\n [K in NotRequiredProps<T>]?: InferType<T[K]>;\n};\n\ntype RespectPropsOptionalityForInput<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in RequiredInputProps<T>]: InferType<T[K]>;\n} & {\n [K in NotRequiredInputProps<T>]?: InferType<T[K]>;\n};\n\ntype MakeChildrenRequired<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: ReturnType<T[K]['required']>;\n};\n\ntype MakeChildrenOptional<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: ReturnType<T[K]['optional']>;\n};\n\n/**\n * Recursively maps each property to its optional form, descending into\n * nested `ObjectSchemaBuilder` schemas. All other schema types (arrays,\n * unions, primitives) are only made optional at the top level.\n */\ntype DeepMakeChildrenOptional<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: T[K] extends ObjectSchemaBuilder<\n // biome-ignore lint/correctness/noUnusedVariables: used in extensions\n infer P extends Record<string, SchemaBuilder<any, any, any, any, any>>,\n any,\n any,\n any,\n any,\n any,\n any\n >\n ? ReturnType<ReturnType<T[K]['deepPartial']>['optional']>\n : ReturnType<T[K]['optional']>;\n};\n\ntype MakeChildOptional<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T\n> = {\n [K in keyof T]: K extends TProp ? ReturnType<T[K]['optional']> : T[K];\n};\n\ntype MakeChildRequired<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T\n> = {\n [K in keyof T]: K extends TProp ? ReturnType<T[K]['required']> : T[K];\n};\n\ntype ModifyPropSchema<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T,\n TSchema extends SchemaBuilder<any, any, any, any, any>\n> = {\n [K in keyof T]: K extends TProp ? TSchema : T[K];\n};\n\nexport type ObjectSchemaValidationResult<\n T,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = TRootSchema\n> = Omit<ValidationResult<T>, 'errors'> & {\n /**\n * A flat list of validation errors.\n *\n * @deprecated Use {@link ObjectSchemaValidationResult.getErrorsFor | getErrorsFor()} instead for\n * per-property error inspection with type-safe property selectors. The `errors` array on\n * `ObjectSchemaBuilder` validation results will be removed in a future major version.\n */\n errors?: ValidationError[];\n /**\n * Returns a nested validation error for the property selected by the `selector` function.\n * This is the **recommended** way to inspect validation errors — it provides type-safe,\n * per-property error details including `isValid`, `errors`, and `seenValue`.\n *\n * Inspect root or property-specific validation errors with a selector.\n *\n * @param selector a callback function to select property from the schema.\n */\n getErrorsFor<TPropertySchema, TParentPropertyDescriptor>(\n selector?: (\n properties: PropertyDescriptorTree<TSchema, TRootSchema>\n ) => PropertyDescriptor<\n TRootSchema,\n TPropertySchema,\n TParentPropertyDescriptor\n >\n ): TPropertySchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n ? PropertyValidationResult<\n TPropertySchema,\n TRootSchema,\n TParentPropertyDescriptor\n >\n : NestedValidationResult<\n TPropertySchema,\n TRootSchema,\n TParentPropertyDescriptor\n >;\n\n /**\n * Returns a list of all property validation results that have direct\n * validation errors. Each entry exposes `.descriptor` (with\n * `.toJsonPointer()` for the property's path) and `.errors`.\n *\n * This is useful for collecting all errors with their full JSON Pointer\n * paths, e.g. for building RFC 9457 Problem Details responses.\n */\n getInvalidProperties(): ReadonlyArray<\n NestedValidationResult<any, TRootSchema, any>\n >;\n};\n\n/**\n * Object schema builder class. Similar to the `object` type\n * in JS. Allows to define a schema for `object` value.\n * Should be used to validate objects with specific properties.\n * Properties should be defined as their own schema builders.\n * You can use any `SchemaBuilder` e.g. `string()`, `number()`,\n * `boolean()`, `array()`, `object()`, etc. to define properties.\n * Which means that you can define nested objects and arrays of\n * any complexity.\n *\n * **NOTE** this class is exported for type annotations and advanced use.\n * Customize via extensions rather than subclassing. Avoid instantiating it\n * directly. Use {@link object | object()} function instead.\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number()\n * });\n *\n * const result = schema.validate({\n * name: 'John',\n * age: 30\n * });\n *\n * // result.valid === true\n * // result.object === { name: 'John', age: 30 }\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number().optional()\n * });\n *\n * const result = schema.validate({\n * name: 'John'\n * });\n * // result.valid === true\n * // result.object === { name: 'John' }\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number();\n * });\n * const result = schema.validate({\n * name: 'John'\n * });\n *\n * // result.valid === false\n * // Inspect property errors using result.getErrorsFor().\n * // result.getErrorsFor((p) => p.age).errors // [\"is expected to have property 'age'\"]\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * })\n * });\n * const result = schema.validate({\n * name: 'John',\n * address: {\n * city: 'New York',\n * country: 'USA'\n * }\n * });\n * // result.valid === true\n * // result.object === {\n * // name: 'John',\n * // address: {\n * // city: 'New York',\n * // country: 'USA'\n * // }\n * // }\n * ```\n * @see {@link object}\n */\nexport class ObjectSchemaBuilder<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n TExplicitType = undefined,\n THasDefault extends boolean = false,\n TExtensions = {},\n TConstructorSchemas extends SchemaBuilder<any, any, any, any, any>[] = []\n> extends SchemaBuilder<\n undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n RespectPropsOptionality<TProperties>\n >\n : TExplicitType,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n /** Native type parameters for extension rebinding; never emitted at runtime. @internal */\n declare readonly __cleverbrush_builder_type__: readonly [\n 'object',\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TConstructorSchemas\n ];\n\n #properties: TProperties = {} as any;\n #acceptUnknownProps = false;\n #propKeys: string[] = [];\n #constructorSchemas: SchemaBuilder<any, any, any, any, any>[] = [];\n\n /** Marks this builder as having sub-properties for descriptor tree recursion. */\n readonly [SYMBOL_HAS_PROPERTIES] = true;\n\n #propertyDescriptorTreeMap: PropertyDescriptorMap = new WeakMap() as any;\n\n /**\n * @hidden\n */\n public static create<\n P extends Record<string, SchemaBuilder>,\n R extends boolean\n >(props: ObjectSchemaBuilderCreateProps<P, R>) {\n return new ObjectSchemaBuilder({\n type: 'object',\n ...props\n } as any);\n }\n\n protected createFromProps<\n T extends Record<string, SchemaBuilder>,\n R extends boolean = true\n >(props: ObjectSchemaBuilderCreateProps<T, R>): this {\n return ObjectSchemaBuilder.create(props as any) as any;\n }\n\n protected constructor(props: ObjectSchemaBuilderCreateProps) {\n super(props as any);\n\n if (typeof props.properties === 'object' && props.properties) {\n this.#properties = props.properties as any;\n this.#propKeys = Object.keys(props.properties);\n }\n\n if (typeof props.acceptUnknownProps === 'boolean') {\n this.#acceptUnknownProps = props.acceptUnknownProps;\n }\n\n if (Array.isArray(props.constructorSchemas)) {\n this.#constructorSchemas = (\n props.constructorSchemas as SchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >[]\n ).filter(s => s instanceof SchemaBuilder);\n }\n }\n\n public introspect() {\n return {\n ...super.introspect(),\n /**\n * Properties defined in schema\n */\n properties: { ...this.#properties },\n /**\n * If set to `true`, schema validation will not\n * return errors if object contains fields which\n * are not defined in the schema `properties`.\n * Set to `false` by default\n */\n acceptUnknownProps: this.#acceptUnknownProps,\n /**\n * The list of constructor schemas registered via `.addConstructor()`.\n * Each element is a `FunctionSchemaBuilder` whose inferred function\n * type provides one overloaded construct signature in `InferType`.\n * Empty array when no constructors have been added.\n */\n constructorSchemas: [\n ...this.#constructorSchemas\n ] as TConstructorSchemas\n };\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): ObjectSchemaBuilder<\n TProperties,\n true,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): ObjectSchemaBuilder<\n TProperties,\n false,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public default(\n value:\n | (undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType)\n | (() => undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType)\n ): ObjectSchemaBuilder<\n TProperties,\n true,\n TNullable,\n TExplicitType,\n true,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.default(value as any) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n false,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.clearDefault() as any;\n }\n\n /**\n * @hidden\n */\n public brand<TBrand extends string | symbol>(\n _name?: TBrand\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n (undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType) & { readonly [K in BRAND]: TBrand },\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * Marks the inferred type as `Readonly<T>` — all top-level properties\n * become `readonly` at the type level. Validation behaviour is unchanged.\n *\n * @see {@link SchemaBuilder.readonly}\n */\n public readonly(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n Readonly<\n undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType\n >,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.readonly();\n }\n\n #applyPropertyDescriptors(\n result: PreValidationResult<any, { validatedObject: any }>\n ): void {\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n result?.context?.rootPropertyDescriptor as any\n )\n ) {\n (result.context.rootPropertyDescriptor as any) =\n ObjectSchemaBuilder.getPropertiesFor(this as any);\n }\n\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n result.context.currentPropertyDescriptor as any\n )\n ) {\n result.context.currentPropertyDescriptor =\n result.context.rootPropertyDescriptor;\n }\n\n if (\n !result.context.rootValidationObject &&\n result.transaction?.object?.validatedObject\n ) {\n result.context.rootValidationObject =\n result.transaction.object.validatedObject;\n }\n }\n\n protected preValidateSync(\n object: any,\n context?: ValidationContext<this>\n ): PreValidationResult<\n InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >,\n { validatedObject: any }\n > {\n const result = super.preValidateSync(object, context);\n this.#applyPropertyDescriptors(result);\n return result;\n }\n\n protected async preValidateAsync(\n object: any,\n context?: ValidationContext<this>\n ): Promise<\n PreValidationResult<\n InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >,\n { validatedObject: any }\n >\n > {\n const result = await super.preValidateAsync(object, context);\n this.#applyPropertyDescriptors(result);\n return result;\n }\n\n /**\n * Shared pre-property-validation setup for both `validate` and\n * `validateAsync`. Handles destructuring the prevalidated result,\n * building the `addErrorFor` / `getErrorsFor` closures, and all early\n * returns that happen before per-property validation.\n */\n #setupValidation(\n prevalidatedResult: PreValidationResult<any, { validatedObject: any }>\n ) {\n const {\n valid,\n context: prevalidationContext,\n transaction: validationTransaction,\n errors: preValidationErrors\n } = prevalidatedResult;\n\n const propertyDescriptorToErrorMap = new WeakMap<\n PropertyDescriptor<any, any, any>,\n PropertyValidationResult<any, any>\n >() as any;\n\n const invalidResults = new Set<PropertyValidationResult<any, any>>();\n\n const { doNotStopOnFirstError, rootValidationObject } =\n prevalidationContext;\n\n const rootPropertyDescriptor: PropertyDescriptor<any, any, undefined> =\n prevalidationContext.rootPropertyDescriptor as any;\n\n const currentPropertyDescriptor: PropertyDescriptor<any, any, unknown> =\n prevalidationContext.currentPropertyDescriptor as any;\n\n const addErrorFor = (\n propertyDescriptor: PropertyDescriptor<any, any, any>,\n message: string,\n parentPropertyDescriptor?: PropertyDescriptor<any, any, any>\n ) => {\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n propertyDescriptor\n )\n ) {\n throw new Error('invalid property descriptor');\n }\n\n let validationError: PropertyValidationResult<any, any> =\n propertyDescriptorToErrorMap.has(propertyDescriptor)\n ? propertyDescriptorToErrorMap.get(propertyDescriptor)\n : (null as any);\n\n if (!validationError) {\n validationError = new PropertyValidationResult(\n propertyDescriptor as any,\n rootValidationObject\n );\n\n propertyDescriptorToErrorMap.set(\n propertyDescriptor,\n validationError\n );\n }\n\n validationError.addError(message);\n invalidResults.add(validationError);\n\n if (\n parentPropertyDescriptor &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n parentPropertyDescriptor\n )\n ) {\n let parentValidationError: PropertyValidationResult<any, any> =\n propertyDescriptorToErrorMap.has(parentPropertyDescriptor)\n ? propertyDescriptorToErrorMap.get(\n parentPropertyDescriptor\n )\n : (null as any);\n\n if (!parentValidationError) {\n parentValidationError = new PropertyValidationResult(\n parentPropertyDescriptor as any,\n rootValidationObject\n );\n propertyDescriptorToErrorMap.set(\n parentPropertyDescriptor,\n parentValidationError\n );\n }\n\n parentValidationError.addChildError(validationError);\n }\n };\n\n const getErrorsFor = (<\n TPropertySchema extends SchemaBuilder<any, any, any, any, any>\n >(\n selector?: (\n properties: PropertyDescriptorTree<any>\n ) => PropertyDescriptor<any, TPropertySchema, any>\n ): PropertyValidationResult<any, any> => {\n const descriptor: PropertyDescriptor<any, any, any> =\n typeof selector === 'function'\n ? selector(currentPropertyDescriptor as any)\n : currentPropertyDescriptor;\n\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n descriptor as any\n )\n ) {\n throw new Error('invalid property descriptor');\n }\n\n if (!propertyDescriptorToErrorMap.has(descriptor)) {\n propertyDescriptorToErrorMap.set(\n descriptor,\n new PropertyValidationResult(\n descriptor as any,\n rootValidationObject\n )\n );\n }\n\n return propertyDescriptorToErrorMap.get(descriptor);\n }) as any;\n\n const getInvalidProperties = () =>\n [...invalidResults].filter(r => r.errors.length > 0);\n\n const errors = prevalidatedResult.errors || [];\n\n /**\n * Routes a pre-validation error through `addErrorFor`, respecting\n * the optional `property` selector on `ValidationError`.\n */\n const routePreValidationError = (error: {\n message: string;\n property?: (tree: any) => any;\n }) => {\n if (\n typeof error.property === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n currentPropertyDescriptor\n )\n ) {\n const targetDescriptor = error.property(\n currentPropertyDescriptor\n );\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n targetDescriptor\n )\n ) {\n addErrorFor(\n targetDescriptor,\n error.message,\n currentPropertyDescriptor\n );\n return;\n }\n }\n // Fallback: attach to root descriptor\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n currentPropertyDescriptor\n )\n ) {\n addErrorFor(currentPropertyDescriptor, error.message);\n }\n };\n\n if (!valid && !doNotStopOnFirstError && preValidationErrors) {\n for (const error of preValidationErrors) {\n routePreValidationError(error);\n }\n\n return {\n earlyReturn: true as const,\n result: {\n valid,\n errors: preValidationErrors,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n // When doNotStopOnFirstError is true and there are pre-validation\n // errors (e.g. from addValidator), route them through addErrorFor\n // so they are visible via getErrorsFor().\n if (doNotStopOnFirstError && preValidationErrors) {\n for (const error of preValidationErrors) {\n routePreValidationError(error);\n }\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = validationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: validationTransaction!.commit().validatedObject,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (\n typeof objToValidate !== 'object' ||\n objToValidate === null ||\n Array.isArray(objToValidate)\n ) {\n // Only add \"must be an object\" when there is no prior error (e.g.\n // a required-violation error already pushed by preValidateAsync).\n if (errors.length === 0) {\n errors.push({\n message: MUST_BE_AN_OBJECT_ERROR_MESSSAGE\n });\n addErrorFor(\n currentPropertyDescriptor,\n MUST_BE_AN_OBJECT_ERROR_MESSSAGE\n );\n }\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors: doNotStopOnFirstError ? errors : [errors[0]],\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n const propKeys = this.#propKeys;\n const objKeys = Object.keys(objToValidate as Object);\n\n if (propKeys.length === 0) {\n if (objKeys.length === 0) {\n if (doNotStopOnFirstError && errors.length > 0) {\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n if (validationTransaction) {\n validationTransaction.commit().validatedObject;\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: {} as any,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (!this.#acceptUnknownProps) {\n for (let i = 0; i < objKeys.length; i++) {\n const message = `unknown property '${objKeys[i]}'`;\n errors.push({\n message\n });\n if (!doNotStopOnFirstError) {\n break;\n }\n }\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors: doNotStopOnFirstError ? errors : [errors[0]],\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (validationTransaction) {\n validationTransaction.commit();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: { ...objToValidate } as any,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n return {\n earlyReturn: false as const,\n errors,\n objToValidate,\n propKeys,\n objKeys,\n addErrorFor,\n getErrorsFor,\n getInvalidProperties,\n doNotStopOnFirstError: !!doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor,\n validationTransaction: validationTransaction!\n };\n }\n\n /**\n * Shared post-property-validation processing for both `validate` and\n * `validateAsync`. Handles unknown-property checks, error aggregation,\n * commit/rollback, and the final result construction.\n */\n #processResults(\n setup: {\n errors: any[];\n objToValidate: any;\n propKeys: string[];\n objKeys: string[];\n addErrorFor: (\n propertyDescriptor: PropertyDescriptor<any, any, any>,\n message: string,\n parentPropertyDescriptor?: PropertyDescriptor<any, any, any>\n ) => void;\n getErrorsFor: any;\n getInvalidProperties: any;\n doNotStopOnFirstError: boolean;\n rootPropertyDescriptor: any;\n currentPropertyDescriptor: any;\n validationTransaction: any;\n },\n validationResults: { key: string; result: ValidationResult<any> }[]\n ): ObjectSchemaValidationResult<any, any> {\n const {\n objToValidate,\n objKeys,\n addErrorFor,\n getErrorsFor,\n getInvalidProperties,\n doNotStopOnFirstError,\n currentPropertyDescriptor,\n validationTransaction\n } = setup;\n\n const errors = setup.errors;\n\n let hasInvalid = false;\n for (const { result } of validationResults) {\n if (!result.valid) {\n hasInvalid = true;\n if (Array.isArray(result.errors)) {\n for (const error of result.errors) {\n errors.push(error);\n }\n }\n }\n }\n\n for (let i = 0; i < objKeys.length; i++) {\n const key = objKeys[i];\n if (!(key in this.#properties) && !this.#acceptUnknownProps) {\n const message = `unknown property '${key}'`;\n errors.push({\n message\n });\n addErrorFor(currentPropertyDescriptor, message);\n if (!doNotStopOnFirstError) {\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n valid: false,\n errors: [errors[0]],\n getErrorsFor,\n getInvalidProperties\n };\n }\n }\n }\n\n if (!hasInvalid && errors.length === 0) {\n const resultObject: Record<string, any> = {};\n for (const { key, result } of validationResults) {\n resultObject[key] = result.object;\n }\n if (this.#acceptUnknownProps) {\n for (const key of objKeys) {\n if (!(key in this.#properties)) {\n resultObject[key] = objToValidate[key];\n }\n }\n }\n return {\n valid: true,\n object: resultObject,\n getErrorsFor,\n getInvalidProperties\n };\n }\n\n for (const { key, result } of validationResults) {\n if (!result.valid) {\n const descriptor = (currentPropertyDescriptor as any)[key];\n if (\n typeof (result as any).getErrorsFor === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)\n ) {\n ObjectSchemaBuilder.#propagateNestedErrors(\n result as any,\n descriptor,\n addErrorFor\n );\n // For extern schemas, also record errors on the extern\n // descriptor itself so getErrorsFor(t => t.extern) works,\n // and pass the parent so getErrorsFor(t => t) is aware.\n if (\n Array.isArray(\n (result as any).__externErrorPropertyNames\n ) &&\n Array.isArray(result.errors)\n ) {\n for (const error of result.errors) {\n addErrorFor(\n descriptor,\n error.message,\n currentPropertyDescriptor\n );\n }\n }\n } else if (Array.isArray(result.errors)) {\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n descriptor\n )\n ) {\n for (const error of result.errors) {\n addErrorFor(descriptor, error.message);\n }\n if (\n Array.isArray((result as any).getNestedErrors?.())\n ) {\n ObjectSchemaBuilder.#propagateIndexedErrors(\n result,\n descriptor,\n addErrorFor\n );\n }\n }\n }\n }\n }\n\n validationTransaction!.rollback();\n\n return {\n valid: false,\n errors: doNotStopOnFirstError\n ? errors\n : errors[0]\n ? [errors[0]]\n : [],\n getErrorsFor,\n getInvalidProperties\n };\n }\n\n /**\n * Adds a `validator` to validators list.\n *\n * Object-level validators can return errors with a `property` selector\n * to route the error to a specific property, making it visible via\n * `getErrorsFor()`.\n *\n * ```ts\n * schema.addValidator((value) => ({\n * valid: false,\n * errors: [{\n * message: 'Passwords do not match',\n * property: (t) => t.confirmPassword\n * }]\n * }));\n * ```\n *\n * The `property` selector uses the same `PropertyDescriptorTree`\n * as `getErrorsFor()` and react-form's `forProperty`.\n */\n public addValidator(\n validator: (\n object: undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n RespectPropsOptionality<TProperties>\n >\n : TExplicitType\n ) =>\n | {\n valid: boolean;\n errors?: Array<{\n message: string;\n property?: (\n properties: PropertyDescriptorTree<\n ObjectSchemaBuilder<TProperties>\n >\n ) => PropertyDescriptor<any, any, any>;\n }>;\n }\n | Promise<{\n valid: boolean;\n errors?: Array<{\n message: string;\n property?: (\n properties: PropertyDescriptorTree<\n ObjectSchemaBuilder<TProperties>\n >\n ) => PropertyDescriptor<any, any, any>;\n }>;\n }>,\n options?: { mutates?: boolean }\n ): this {\n return super.addValidator(validator as any, options);\n }\n\n /**\n * Performs synchronous validation of object schema over the `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n *\n * The returned result includes a `getErrorsFor()` method for type-safe,\n * per-property error inspection.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n public validate(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n > {\n return super.validate(object, context) as any;\n }\n\n /**\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n public async validateAsync(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): Promise<\n ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n >\n > {\n return super.validateAsync(object, context) as any;\n }\n\n /**\n * Performs synchronous validation of object schema over the `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n *\n * The returned result includes a `getErrorsFor()` method for type-safe,\n * per-property error inspection.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n protected _validate(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n > {\n // Fast path: skip preValidateSync + setupValidation when no preprocessors/validators\n if (\n this.canSkipPreValidation &&\n !context?.doNotStopOnFirstError &&\n !context?.rootPropertyDescriptor\n ) {\n // Required / optional check\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue() as typeof object;\n } else if (\n !this.isRequired ||\n (object === null && this.isNullable)\n ) {\n const self = this;\n return {\n valid: true,\n object: object,\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n } else {\n const self = this;\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n this.requiredErrorMessage,\n object as any\n )\n }\n ],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n } else if (typeof object === 'object' && !Array.isArray(object)) {\n const propKeys = this.#propKeys;\n\n // Check for unknown properties\n if (!this.#acceptUnknownProps) {\n const objKeys = Object.keys(object as Record<string, any>);\n for (let i = 0; i < objKeys.length; i++) {\n if (!(objKeys[i] in this.#properties)) {\n const self = this;\n return {\n valid: false,\n errors: [\n {\n message: `unknown property '${objKeys[i]}'`\n }\n ],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n }\n }\n\n // Validate all properties inline — no path passed to children\n const resultObject: Record<string, any> = {};\n for (let i = 0; i < propKeys.length; i++) {\n const key = propKeys[i];\n const result = this.#properties[key].validate(\n (object as any)[key]\n );\n if (!result.valid) {\n const self = this;\n return {\n valid: false,\n errors:\n result.errors && result.errors.length > 0\n ? [result.errors[0]]\n : [],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n resultObject[key] = result.object;\n }\n\n // Copy unknown props if accepted\n if (this.#acceptUnknownProps) {\n const objKeys = Object.keys(object as Record<string, any>);\n for (let i = 0; i < objKeys.length; i++) {\n if (!(objKeys[i] in this.#properties)) {\n resultObject[objKeys[i]] = (object as any)[\n objKeys[i]\n ];\n }\n }\n }\n\n // Lazy getErrorsFor — only builds descriptors if called\n const self = this;\n return {\n valid: true,\n object: resultObject,\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n }\n\n return this.#validateFull(object, context) as any;\n }\n\n /**\n * Full validation path with complete error handling and property descriptors.\n */\n #validateFull(\n object: any,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<any, any> {\n const setup = this.#setupValidation(\n this.preValidateSync(object, context)\n );\n if (setup.earlyReturn) return setup.result as any;\n\n const {\n propKeys,\n objToValidate,\n doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor\n } = setup;\n\n const validationResults: {\n key: string;\n result: ValidationResult<any>;\n }[] = [];\n for (const key of propKeys) {\n const result = this.#properties[key].validate(objToValidate[key], {\n ...context,\n rootPropertyDescriptor: rootPropertyDescriptor as any,\n currentPropertyDescriptor: (currentPropertyDescriptor as any)[\n key\n ]\n });\n validationResults.push({ key, result });\n if (!result.valid && !doNotStopOnFirstError) break;\n }\n\n return this.#processResults(setup, validationResults) as any;\n }\n\n /**\n * Performs async validation of object schema over the `object`.\n * Supports async preprocessors, validators, and error message providers.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n protected async _validateAsync(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): Promise<\n ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n >\n > {\n const setup = this.#setupValidation(\n await this.preValidateAsync(object, context)\n );\n if (setup.earlyReturn) return setup.result as any;\n\n const {\n propKeys,\n objToValidate,\n doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor\n } = setup;\n\n const validationResults: {\n key: string;\n result: ValidationResult<any>;\n }[] = [];\n\n if (doNotStopOnFirstError) {\n const results = await Promise.all(\n propKeys.map(async key => {\n const result = await this.#properties[key].validateAsync(\n objToValidate[key],\n {\n ...context,\n rootPropertyDescriptor:\n rootPropertyDescriptor as any,\n currentPropertyDescriptor: (\n currentPropertyDescriptor as any\n )[key]\n }\n );\n return { key, result };\n })\n );\n validationResults.push(...results);\n } else {\n for (const key of propKeys) {\n const result = await this.#properties[key].validateAsync(\n objToValidate[key],\n {\n ...context,\n rootPropertyDescriptor: rootPropertyDescriptor as any,\n currentPropertyDescriptor: (\n currentPropertyDescriptor as any\n )[key]\n }\n );\n validationResults.push({ key, result });\n if (!result.valid) break;\n }\n }\n\n return this.#processResults(setup, validationResults) as any;\n }\n\n /**\n * Fields not defined in `properties` will not be validated\n * and will be passed through the validation.\n */\n public acceptUnknownProps(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n acceptUnknownProps: true\n } as any) as any;\n }\n\n /**\n * Fields not defined in `properties` will be considered\n * as schema violation. This is the default behavior.\n */\n public notAcceptUnknownProps(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n acceptUnknownProps: false\n } as any) as any;\n }\n\n /**\n * @inheritdoc\n */\n public hasType<T>(\n _notUsed?: T\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n T,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * @inheritdoc\n */\n public clearHasType(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * Appends a constructor overload to the object schema.\n *\n * Each call extends the set of construct signatures on the inferred type by\n * one overload. The accumulated argument lists are taken from the\n * `FunctionSchemaBuilder` passed in — specifically from the positional\n * parameter schemas registered via `.addParameter()`.\n *\n * At **runtime** the schema continues to validate plain objects; the\n * constructor information is purely a TypeScript-level annotation and is\n * stored in `introspect().constructorSchemas` for tooling use.\n *\n * Multiple calls are supported and produce **overloaded** construct\n * signatures in the inferred type, modelling a class that exposes several\n * constructor overloads.\n *\n * @param schema - A `FunctionSchemaBuilder` describing one constructor\n * overload. Use `.addParameter()` on the function schema to declare the\n * parameter types. The return type, if set via `.hasReturnType()`, is\n * ignored — the return type of a constructor is always the instance type\n * derived from the object schema's properties.\n *\n * @returns A new `ObjectSchemaBuilder` whose `TConstructorSchemas` tuple has\n * been extended by `schema`, updating `InferType` to include the new\n * construct signature.\n *\n * @example\n * ```ts\n * import { object, string, number, func, InferType } from '@cleverbrush/schema';\n *\n * // Single constructor\n * const PersonSchema = object({ name: string(), age: number() })\n * .addConstructor(\n * func().addParameter(string()).addParameter(number())\n * );\n *\n * type Person = InferType<typeof PersonSchema>;\n * // → { new (p0: string, p1: number): { name: string; age: number } }\n * // & { name: string; age: number }\n * ```\n *\n * @example\n * ```ts\n * import { object, string, number, func, InferType } from '@cleverbrush/schema';\n *\n * // Multiple constructors via chained calls → overloaded signatures\n * const PointSchema = object({ x: number(), y: number() })\n * .addConstructor(func()) // no-arg ctor\n * .addConstructor(func().addParameter(number()).addParameter(number())); // (x, y) ctor\n *\n * type Point = InferType<typeof PointSchema>;\n * // → { new (): { x: number; y: number } }\n * // & { new (p0: number, p1: number): { x: number; y: number } }\n * // & { x: number; y: number }\n *\n * // Validation still operates on plain objects — the constructor type is\n * // a compile-time annotation only.\n * const result = PointSchema.validate({ x: 1, y: 2 });\n * // result.valid === true\n *\n * // Introspect the registered constructor schemas at runtime:\n * const info = PointSchema.introspect();\n * // info.constructorSchemas.length === 2\n * ```\n */\n public addConstructor<TFunc extends SchemaBuilder<any, any, any, any, any>>(\n schema: TFunc\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n [...TConstructorSchemas, TFunc]\n > &\n TExtensions {\n if (!(schema instanceof SchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the SchemaBuilder class'\n );\n }\n\n return this.derive({\n ...this.introspect(),\n constructorSchemas: [...this.#constructorSchemas, schema]\n } as any) as any;\n }\n\n /**\n * Removes all constructor overloads previously registered via\n * `.addConstructor()`, resetting the `TConstructorSchemas` tuple to `[]`.\n *\n * After calling this method `InferType` reverts to the plain object type\n * derived from the schema's properties — no construct signatures are\n * included.\n *\n * `introspect().constructorSchemas` will return an empty array.\n *\n * @returns A new `ObjectSchemaBuilder` with `TConstructorSchemas = []`.\n *\n * @example\n * ```ts\n * import { object, string, func, InferType } from '@cleverbrush/schema';\n *\n * const WithCtor = object({ name: string() })\n * .addConstructor(func().addParameter(string()));\n *\n * type WithCtorType = InferType<typeof WithCtor>;\n * // → { new (p0: string): { name: string } } & { name: string }\n *\n * const Plain = WithCtor.clearConstructors();\n *\n * type PlainType = InferType<typeof Plain>;\n * // → { name: string }\n *\n * Plain.introspect().constructorSchemas; // []\n * ```\n */\n public clearConstructors(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n []\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n constructorSchemas: []\n } as any) as any;\n }\n\n /**\n * Adds a new property to the object schema. The new property\n * will be validated according to the provided schema.\n * @param propName name of the new property\n * @param schema schema builder of the new property\n */\n public addProp<\n TType extends SchemaBuilder<any, any, any, any, any>,\n TName extends string\n >(\n propName: TName,\n schema: TType\n ): ObjectSchemaBuilder<\n TProperties & {\n [k in TName]: TType;\n },\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n if (typeof propName !== 'string' || !propName) {\n throw new Error('propName must be a non empty string');\n }\n if (propName in this.#properties) {\n throw new Error(`Property ${propName} already exists`);\n }\n if (!(schema instanceof SchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the SchemaBuilder class'\n );\n }\n\n return this.derive({\n ...this.introspect(),\n properties: {\n ...this.introspect().properties,\n [propName]: schema\n }\n } as any) as any;\n }\n\n /**\n * @hidden\n * @deprecated this is for internal use, do not use if you are\n * not sure you need it.\n *\n * TODO: This is used to avoid `&` in resulting types. For example,\n * when you have a schema like `object({prop1: string()})` and then use `addProp({prop2: string()})` method,\n * the resulting type without `optimize` will be something like `{prop1: string} & {prop2: string}`. Which\n * is not we would like to have. Instead we want to have `{prop1: string, prop2: string}`. This is what\n * `optimize` method does. However it is not always possible to do this optimization without losing\n * JSDoc comments, which is sucks. For example, I had to disable optimization for UnionSchemas, because\n * comments were lost. Hopefully it will be fixed in the future by Typescript team or somebody will\n * find a workaround/fix and create a pull request.\n */\n public optimize(): SchemaBuilder<\n undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n Id<RespectPropsOptionality<TProperties>>\n >\n : TExplicitType,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * Adds new properties to the object schema. The same as `.addProp()` but\n * allows to add multiple properties with one call. The new properties\n * will be validated according to the provided schemas.\n * @param props a key/schema object map.\n */\n public addProps<\n TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>\n >(\n props: TProps\n ): ObjectSchemaBuilder<\n TProperties & TProps,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n /**\n * Adds all properties from the `schema` object schema to the current schema.\n * @param schema an instance of `ObjectSchemaBuilder`\n */\n public addProps<\n K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: K\n ): K extends ObjectSchemaBuilder<infer TProp, infer _, any, infer __>\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProp> & TProp,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n public addProps(props: any) {\n if (props instanceof ObjectSchemaBuilder) {\n return this.addProps(props.introspect().properties);\n }\n\n if (typeof props !== 'object') {\n throw new Error('props should be an object');\n }\n if (props === null) {\n throw new Error('props should not be null');\n }\n\n const newProps = { ...this.#properties } as any;\n\n for (const key in props) {\n if (key in this.#properties) {\n throw new Error(`property '${key}' already exists`);\n }\n\n if (!(props[key] instanceof SchemaBuilder)) {\n throw new Error(`${key} is not a SchemaBuilder`);\n }\n\n newProps[key] = props[key] as any;\n }\n\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Omits properties listed in `properties` from the schema.\n * Consider `Omit<Type, 'prop1'|'prop2'...>` as a good illustration\n * from the TS world.\n * @param properties - array of property names (strings) to remove from the schema.\n */\n public omit<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Omit<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Removes `propName` from the list of properties.\n * @param propName property name to remove. Schema should contain\n * this property. An error will be thrown otherwise.\n */\n public omit<TProperty extends keyof TProperties>(\n propName: TProperty\n ): ObjectSchemaBuilder<\n Omit<TProperties, TProperty>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Removes all properties of `schema` from the current schema.\n * `Omit<TSchema, keyof TAnotherSchema>` as a good illustration\n * from the TS world.\n * @param schema schema builder to take properties from.\n */\n public omit<T>(\n schema: T\n ): T extends ObjectSchemaBuilder<\n infer TProps,\n infer TRequired,\n any,\n infer TExplicitType\n >\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProps>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n public omit(propNameOrArrayOrPropsOrBuilder: any): any {\n if (typeof propNameOrArrayOrPropsOrBuilder === 'string') {\n // remove one field\n const propName =\n propNameOrArrayOrPropsOrBuilder as keyof TProperties;\n\n if (!propName || !(propName in this.#properties)) {\n throw new Error(\n `property ${propName.toString()} does not exists in the schema`\n );\n }\n\n return this.derive({\n ...this.introspect(),\n properties: (() => {\n const result = { ...this.#properties };\n delete result[propName];\n return result;\n })()\n } as any);\n } else if (Array.isArray(propNameOrArrayOrPropsOrBuilder)) {\n const propsArray = propNameOrArrayOrPropsOrBuilder as Array<\n keyof TProperties\n >;\n\n const distinctKeys = new Map<keyof TProperties, true>();\n propsArray.forEach(key => {\n if (typeof key !== 'string' || !key) {\n throw new Error('property name must be a string');\n }\n\n if (!(key in this.#properties)) {\n throw new Error(\n `property ${key.toString()} does not exists in the schema`\n );\n }\n\n distinctKeys.set(key.toString(), true);\n });\n\n if (distinctKeys.size === 0) {\n throw new Error('please provide at least one property to omit');\n }\n\n const props = {\n ...this.introspect()\n };\n\n for (const key of distinctKeys.keys()) {\n delete props.properties[key];\n }\n\n return this.derive(props as any);\n } else if (\n propNameOrArrayOrPropsOrBuilder instanceof ObjectSchemaBuilder\n ) {\n const propsToOmit = {\n ...propNameOrArrayOrPropsOrBuilder.introspect().properties\n };\n\n const props = {\n ...this.introspect()\n };\n\n for (const key in propsToOmit) {\n if (key in props.properties) {\n delete props.properties[key];\n }\n }\n\n return this.derive(props as any);\n }\n\n throw new Error('this parameter type is not supported');\n }\n\n /**\n * Adds all properties from `schema` to the current schema.\n * `TSchema & TAnotherSchema` is a good example of the similar concept\n * in the TS type system.\n * @param schema an object schema to take properties from\n */\n public intersect<\n T extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: T\n ): T extends ObjectSchemaBuilder<\n infer TProps,\n infer _,\n any,\n infer TExplType\n >\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProps> & TProps,\n TRequired,\n TNullable,\n TExplType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never {\n if (!(schema instanceof ObjectSchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the ObjectSchemaBuilder class'\n );\n }\n\n const remoteProps = schema.introspect().properties;\n\n const localProps = this.introspect();\n\n const newProps = Object.keys(localProps.properties).reduce(\n (acc, curr) => {\n acc[curr] =\n curr in remoteProps\n ? remoteProps[curr]\n : localProps.properties[curr];\n return acc;\n },\n {} as Record<string, any>\n );\n\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Marks all properties in the current schema as optional.\n * It is the same as call `.optional('propname')` where `propname` is the name\n * of every property in the schema.\n */\n public partial(): ObjectSchemaBuilder<\n MakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Marks all properties from `properties` as optional in the schema.\n * @param properties list of property names (string) to make optional\n */\n public partial<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Omit<TProperties, K> & Pick<MakeChildrenOptional<TProperties>, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Marks property `propName` as optional in the schema.\n * @param propName the name of the property (string).\n */\n public partial<TProperty extends keyof TProperties>(\n propName: TProperty\n ): ObjectSchemaBuilder<\n Omit<TProperties, TProperty> &\n Pick<MakeChildrenOptional<TProperties>, TProperty>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n public partial(propNameOrArray?: any): any {\n if (\n typeof propNameOrArray === 'undefined' ||\n propNameOrArray === null\n ) {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, key) => {\n acc[key] = this.#properties[key].optional();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any);\n }\n\n if (Array.isArray(propNameOrArray)) {\n const propsArray = propNameOrArray as (keyof TProperties)[];\n if (propsArray.length === 0) {\n throw new Error('properties cannot be empty');\n }\n\n const newProps = {\n ...this.introspect()\n } as any;\n\n propsArray.forEach(key => {\n if (typeof key !== 'string') {\n throw new Error(\n 'each propery in property list must be as string value'\n );\n }\n if (!(key in newProps.properties)) {\n throw new Error(\n `property ${key as string} does not exists`\n );\n }\n\n newProps.properties[key as keyof TProperties] =\n newProps.properties[key].optional();\n });\n\n return this.derive(newProps);\n }\n\n if (typeof propNameOrArray === 'string') {\n return this.modifyPropSchema(\n propNameOrArray as keyof TProperties,\n schema => schema.optional()\n );\n }\n\n throw new Error('expecting string or string[] parameter');\n }\n\n /**\n * Recursively marks all properties — and all properties of nested\n * `object()` schemas — as optional. Useful for PATCH API bodies\n * and partial form state where every field at every level is optional.\n *\n * Only nested `ObjectSchemaBuilder` schemas are recursed into.\n * Other schema types (arrays, unions, primitives, lazy) are made\n * optional at the top level but their internals are not modified.\n *\n * @example\n * ```ts\n * const Address = object({\n * street: string(),\n * city: string()\n * });\n *\n * const User = object({\n * name: string(),\n * address: Address\n * });\n *\n * const PatchUser = User.deepPartial();\n * // PatchUser infers as:\n * // { name?: string; address?: { street?: string; city?: string } }\n *\n * PatchUser.validate({ address: { city: 'Paris' } }); // valid\n * PatchUser.validate({}); // valid\n * ```\n *\n * @example\n * ```ts\n * // Three-level nesting\n * const schema = object({\n * a: object({\n * b: object({ c: string() })\n * })\n * }).deepPartial();\n *\n * schema.validate({}); // valid\n * schema.validate({ a: {} }); // valid\n * schema.validate({ a: { b: {} } }); // valid\n * ```\n *\n * @example\n * ```ts\n * // PATCH API body\n * const CreateBody = object({\n * profile: object({ displayName: string(), bio: string() }),\n * settings: object({ theme: string(), language: string() })\n * });\n *\n * const PatchBody = CreateBody.deepPartial();\n * // All fields are optional at every level —\n * // send only what you want to update.\n * ```\n *\n * @see {@link partial} for shallow-only property optionality.\n */\n public deepPartial(): ObjectSchemaBuilder<\n DeepMakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n const newProps: Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {};\n for (const key of Object.keys(this.#properties)) {\n const prop = this.#properties[key];\n if (prop instanceof ObjectSchemaBuilder) {\n newProps[key] = (\n prop as ObjectSchemaBuilder<any, any, any, any, any>\n )\n .deepPartial()\n .optional();\n } else {\n newProps[key] = prop.optional();\n }\n }\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Returns a new schema containing only properties listed in\n * `properties` array.\n * @param properties array of property names (strings)\n */\n public pick<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Pick<TProperties, K>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Returns new schema based on the current schema. This new schema\n * will consists only from properties which names are taken from the\n * `schema` object schema.\n * @param schema schema to take property names list from\n */\n public pick<\n K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: K\n ): K extends ObjectSchemaBuilder<infer TProps, infer _, any, infer __>\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof Omit<TProperties, keyof TProps>>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n /**\n * Returns a new schema consisting of only one property\n * (taken from the `property` property name). If the property\n * does not exists in the current schema, an error will be thrown.\n * @param property the name of the property (string).\n */\n public pick<K extends keyof TProperties>(\n property: K\n ): ObjectSchemaBuilder<\n Pick<TProperties, K>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n public pick(properties: any): any {\n if (typeof properties === 'string') {\n const property = properties as string;\n\n if (!property) {\n throw new Error('property cannot be empty');\n }\n\n if (!(property in this.#properties)) {\n throw new Error(`property ${property} does not exists`);\n }\n\n return this.derive({\n ...this.introspect(),\n properties: {\n [property]: this.#properties[property]\n }\n } as any);\n }\n\n if (Array.isArray(properties)) {\n if (properties.length === 0) {\n throw new Error('properties must be a non empty erray');\n }\n const newProperties = properties.reduce((acc, curr) => {\n if (typeof curr !== 'string' || !curr) {\n throw new Error(\n 'each property name must be a non empty string'\n );\n }\n if (!(curr in this.#properties)) {\n throw new Error(`property ${curr} does not exists`);\n }\n\n acc[curr] = this.#properties[curr];\n return acc;\n }, {});\n\n return this.derive({\n ...this.introspect(),\n properties: newProperties\n } as any);\n }\n\n if (properties instanceof ObjectSchemaBuilder) {\n const externalSchema = properties as ObjectSchemaBuilder;\n\n const props = Object.keys(\n externalSchema.introspect().properties\n ).filter(p => typeof this.#properties[p] !== 'undefined');\n if (props.length === 0) {\n throw new Error(\n 'there are no common properties in provided schemas'\n );\n }\n return this.pick(props as any as keyof TProperties);\n }\n\n throw new Error('string, array or ObjectSchemaBuilder is expected');\n }\n\n /**\n * Modify schema for `propName` and return a new schema.\n * Could be useful if you want to leave all schema intact, but\n * change a type of one property.\n * @param propName name of the property (string)\n * @param callback callback function returning a new schema fo the `propName`. As a first parameter\n * you will receive an old schema for `propName`.\n * @returns\n */\n public modifyPropSchema<\n K extends keyof TProperties,\n R extends SchemaBuilder<any, any, any, any, any>\n >(\n propName: K,\n callback: (builder: TProperties[K]) => R\n ): ObjectSchemaBuilder<\n ModifyPropSchema<TProperties, K, R>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n if (typeof propName !== 'string' || !propName) {\n throw new Error('propName must be a non empty string');\n }\n\n if (!(propName in this.#properties)) {\n throw new Error(\n `property ${propName} does not exists in the schema`\n );\n }\n\n if (typeof callback !== 'function') {\n throw new Error('callback must be a function');\n }\n\n const callbackResult = callback(this.#properties[propName]);\n if (!(callbackResult instanceof SchemaBuilder)) {\n throw new Error('callback must return a SchemaBuilder object');\n }\n\n const props = {\n ...this.introspect()\n } as any;\n\n props.properties = {\n ...props.properties,\n [propName]: callbackResult\n };\n\n return this.derive(props) as any;\n }\n\n /**\n * An alias for `.partial(prop: string)`\n * @param prop name of the property\n */\n public makePropOptional<K extends keyof TProperties>(\n prop: K\n ): ObjectSchemaBuilder<\n MakeChildOptional<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.modifyPropSchema(prop, builder =>\n builder.optional()\n ) as any;\n }\n\n /**\n * Marks `prop` as required property.\n * If `prop` does not exists in the current schema,\n * an error will be thrown.\n * @param prop name of the property\n */\n public makePropRequired<K extends keyof TProperties>(\n prop: K\n ): ObjectSchemaBuilder<\n MakeChildRequired<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.modifyPropSchema(prop, builder =>\n builder.required()\n ) as any;\n }\n\n /**\n * `Partial<T>` would be a good example of the\n * same operation in the TS world.\n */\n public makeAllPropsOptional(): ObjectSchemaBuilder<\n MakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, curr) => {\n acc[curr] = this.#properties[curr].optional();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any) as any;\n }\n\n /**\n * `Required<T>` would be a good example of the\n * same operation in the TS world.\n */\n public makeAllPropsRequired(): ObjectSchemaBuilder<\n MakeChildrenRequired<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, curr) => {\n acc[curr] = this.#properties[curr].required();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any) as any;\n }\n\n static #getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(\n schema: TSchema,\n /* this is to make possibility to traverse the tree and select properties */\n selector?: (arg1: any, arg2: any) => any,\n /* parent object to have a possibility to get link to itself */\n parentSelector?: any,\n /* used to pass the needed property name if `parentSelector` is provided. */\n currentName?: string,\n parentDescriptor?: PropertyDescriptorInner<any, any, any>\n ): PropertyDescriptorTree<TSchema> {\n const introspected = schema.introspect();\n if (!introspected.properties) {\n return {} as any;\n }\n\n const propsNames = Object.keys(introspected.properties);\n\n if (typeof selector !== 'function') {\n selector = o => o;\n }\n const result = createPropertyDescriptorFor(\n (obj, createMissingStructure) =>\n (parentSelector || selector)(obj, createMissingStructure),\n currentName,\n schema,\n parentDescriptor\n );\n\n for (const propName of propsNames) {\n const propSchema = introspected.properties[propName];\n if (propSchema instanceof ObjectSchemaBuilder) {\n const childProperties = propSchema.introspect().properties;\n if (\n childProperties &&\n typeof childProperties === 'object' &&\n Object.keys(childProperties).length > 0\n ) {\n (result as any)[propName] = (\n ObjectSchemaBuilder.#getPropertiesFor as any\n )(\n propSchema,\n (tree: any, createMissingStructure: any) => {\n const selectorResult = selector(\n tree,\n createMissingStructure\n );\n if (selectorResult) {\n if (\n createMissingStructure &&\n !selectorResult[propName]\n ) {\n selectorResult[propName] = {};\n }\n return selectorResult[propName];\n }\n return null;\n },\n selector,\n propName,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n } else {\n (result as any)[propName] = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n }\n } else if (propSchema.introspect().type === 'array') {\n (result as any)[propName] = createIndexedDescriptor(\n propSchema,\n selector,\n propName,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n } else if ((propSchema as any)[SYMBOL_HAS_PROPERTIES] === true) {\n // Extern schema — create a Proxy-based descriptor that\n // lazily creates child descriptors on property access.\n const externBase = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n const externValueSelector = (\n tree: any,\n createMissingStructure: boolean\n ) => {\n const selectorResult = selector(\n tree,\n createMissingStructure\n );\n if (selectorResult) {\n if (\n createMissingStructure &&\n !selectorResult[propName]\n ) {\n selectorResult[propName] = {};\n }\n return selectorResult[propName];\n }\n return null;\n };\n (result as any)[propName] = createExternProxyDescriptor(\n externBase,\n externValueSelector\n );\n } else {\n (result as any)[propName] = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n }\n }\n\n return result as any;\n }\n\n public static getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(schema: TSchema): PropertyDescriptorTree<TSchema, TSchema> {\n if (!(schema instanceof ObjectSchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the ObjectSchemaBuilder class'\n );\n }\n\n if (schema.#propertyDescriptorTreeMap.has(schema)) {\n return schema.#propertyDescriptorTreeMap.get(schema) as any;\n }\n\n const result = ObjectSchemaBuilder.#getPropertiesFor(schema);\n schema.#propertyDescriptorTreeMap.set(schema, result);\n\n return result;\n }\n\n public static isValidPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ) {\n return (\n typeof descriptor === 'object' &&\n descriptor !== null &&\n typeof descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR] === 'object'\n );\n }\n\n static #propagateNestedErrors(\n result: any,\n descriptor: any,\n addErrorFor: (\n descriptor: any,\n message: string,\n parentDescriptor?: any\n ) => void\n ): void {\n const schema =\n ObjectSchemaBuilder.#getSchemaForPropertyDescriptor(descriptor);\n const properties = (schema.introspect() as any).properties;\n\n // Determine which property names to iterate:\n // • For ObjectSchemaBuilder — use introspect().properties keys\n // • For ExternSchemaBuilder — use __externErrorPropertyNames from the result\n let propertyNames: string[];\n if (properties) {\n propertyNames = Object.keys(properties);\n } else if (Array.isArray((result as any).__externErrorPropertyNames)) {\n propertyNames = (result as any).__externErrorPropertyNames;\n } else {\n return;\n }\n\n for (const nestedPropertyName of propertyNames) {\n const nestedPropertyDescriptor = descriptor[nestedPropertyName];\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n nestedPropertyDescriptor\n )\n ) {\n continue;\n }\n const nestedValidationError = result.getErrorsFor(\n () => nestedPropertyDescriptor\n );\n if (!nestedValidationError.isValid) {\n for (const validationError of nestedValidationError.errors) {\n addErrorFor(\n nestedPropertyDescriptor,\n validationError,\n descriptor\n );\n }\n }\n // Indexed descriptors are created lazily, so they are not keys in\n // an object's static property map. Copy precise invalid descriptors\n // below this property as well as the existing aggregate messages.\n if (\n nestedPropertyDescriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n .getSchema()\n ?.introspect().type === 'array' &&\n typeof result.getInvalidProperties === 'function'\n ) {\n const prefix =\n nestedPropertyDescriptor[\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n ].toJsonPointer() + '/';\n for (const invalid of result.getInvalidProperties()) {\n const pointer = invalid.descriptor.toJsonPointer();\n if (!pointer.startsWith(prefix)) continue;\n const target = pointer\n .slice(prefix.length)\n .split('/')\n .reduce(\n (node: any, part: string) =>\n node?.[\n part.replace(/~1/g, '/').replace(/~0/g, '~')\n ],\n nestedPropertyDescriptor\n );\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(target))\n continue;\n for (const message of invalid.errors)\n addErrorFor(target, message, nestedPropertyDescriptor);\n }\n }\n // Recurse into nested object schemas (only when we have a property map)\n if (properties) {\n const nestedSchema = properties[nestedPropertyName];\n if (\n (nestedSchema instanceof ObjectSchemaBuilder ||\n (nestedSchema as any)[SYMBOL_HAS_PROPERTIES] ===\n true) &&\n typeof result.getErrorsFor === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n nestedPropertyDescriptor\n )\n ) {\n ObjectSchemaBuilder.#propagateNestedErrors(\n result,\n nestedPropertyDescriptor,\n addErrorFor\n );\n }\n }\n }\n }\n\n /** Propagate structured array results without interpreting message strings. */\n static #propagateIndexedErrors(\n result: any,\n descriptor: any,\n addErrorFor: (descriptor: any, message: string, parent?: any) => void\n ): void {\n const children = result.getNestedErrors?.();\n if (!Array.isArray(children)) return;\n children.forEach((child, index) => {\n const indexed = descriptor[index];\n if (\n !child ||\n child.valid ||\n !ObjectSchemaBuilder.isValidPropertyDescriptor(indexed)\n )\n return;\n if (typeof child.getInvalidProperties === 'function') {\n const prefix =\n indexed[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR].toJsonPointer();\n for (const invalid of child.getInvalidProperties()) {\n const pointer = invalid.descriptor.toJsonPointer();\n const relative =\n pointer === prefix\n ? ''\n : pointer.startsWith(prefix + '/')\n ? pointer.slice(prefix.length)\n : pointer;\n const target =\n relative === ''\n ? indexed\n : relative\n .slice(1)\n .split('/')\n .reduce(\n (node: any, part: string) =>\n node?.[\n part\n .replace(/~1/g, '/')\n .replace(/~0/g, '~')\n ],\n indexed\n );\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(target))\n continue;\n for (const message of invalid.errors)\n addErrorFor(target, message, descriptor);\n }\n } else {\n for (const error of child.errors ?? [])\n addErrorFor(indexed, error.message, descriptor);\n ObjectSchemaBuilder.#propagateIndexedErrors(\n child,\n indexed,\n addErrorFor\n );\n }\n });\n }\n\n static #getSchemaForPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ): SchemaBuilder<any, any, any, any, any> {\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)) {\n throw new Error('descriptor is not a valid property descriptor');\n }\n\n return descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR].getSchema();\n }\n\n public nullable(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n true,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > {\n return super.nullable() as any;\n }\n\n public notNullable(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n false,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > {\n return super.notNullable() as any;\n }\n}\n\nexport interface Object {\n /**\n * Defines a schema for empty object `{}`\n */\n (): ObjectSchemaBuilder<{}, true>;\n /**\n * Defines an object schema, properties definitions are takens from `props`.\n * @param props key/schema object map for schema's properties.\n */\n <TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(\n props: TProps\n ): ObjectSchemaBuilder<TProps, true>;\n /**\n * Defines an object schema, properties definitions are takens from `props`.\n * @param props key/schema object map for schema's properties.\n */\n <TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(\n props?: TProps\n ): ObjectSchemaBuilder<TProps, true>;\n /**\n * Returns a tree of property descriptors for the given `schema`.\n * The structure of the tree is the same as the structure of the `schema`.\n * Which gives you an opportunity to access property descriptors for each\n * property in the schema in a useful and type-safe way.\n * @param schema\n */\n getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(schema: TSchema): PropertyDescriptorTree<TSchema, TSchema>;\n\n /**\n * Verifies if the given `descriptor` is a valid property descriptor.\n * @param descriptor a property descriptor to check\n */\n isValidPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ): boolean;\n}\n\nconst object = (props => {\n return ObjectSchemaBuilder.create({\n isRequired: true,\n properties: props\n }) as any;\n}) as Object;\n\ntype PropertyDescriptorMap = Map<\n ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n PropertyDescriptorMap | PropertyDescriptorTree<any, any>\n>;\n\nconst createPropertyDescriptorFor = (\n selector: (arg0: any, arg1: boolean) => any,\n propertyName?: string,\n schema?: SchemaBuilder<any, any, any, any, any>,\n parent?: PropertyDescriptorInner<any, any, any>\n) => ({\n [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: {\n setValue: (\n obj: any,\n newValue: any,\n options?: PropertySetterOptions\n ) => {\n const selectorResult = selector(\n obj,\n !!options?.createMissingStructure\n );\n if (!selectorResult) return false;\n\n if (typeof propertyName === 'string') {\n selectorResult[propertyName] = newValue;\n }\n\n return true;\n },\n getValue: (obj: any) => {\n const selectorResult = selector(obj, false);\n if (!selectorResult)\n return {\n success: false\n };\n\n if (typeof propertyName !== 'string') {\n return {\n success: true,\n value: selectorResult\n };\n }\n\n if (Object.hasOwn(selectorResult, propertyName)) {\n return {\n success: true,\n value: selectorResult[propertyName]\n };\n }\n\n return {\n success: false\n };\n },\n\n getSchema: () => schema,\n parent,\n propertyName,\n toJsonPointer: () => {\n const segments: string[] = [];\n if (typeof propertyName === 'string') {\n segments.push(\n propertyName.replace(/~/g, '~0').replace(/\\//g, '~1')\n );\n }\n let ancestor = parent;\n while (ancestor) {\n if (typeof ancestor.propertyName === 'string') {\n segments.push(\n ancestor.propertyName\n .replace(/~/g, '~0')\n .replace(/\\//g, '~1')\n );\n }\n ancestor = ancestor.parent as any;\n }\n segments.reverse();\n return segments.length > 0 ? '/' + segments.join('/') : '';\n }\n }\n});\n\n/** Build only requested array indices, preserving descriptor identity. */\nconst createIndexedDescriptor = (\n schema: SchemaBuilder<any, any, any, any, any>,\n parentSelector: (value: any, create: boolean) => any,\n name: string,\n parent: PropertyDescriptorInner<any, any, any>\n): any => {\n const base = createPropertyDescriptorFor(\n parentSelector,\n name,\n schema,\n parent\n );\n const intro = schema.introspect() as any;\n const valueSelector = (root: any, create: boolean) => {\n const container = parentSelector(root, create);\n if (!container || typeof container !== 'object') return null;\n if (\n create &&\n (!Object.hasOwn(container, name) || container[name] == null)\n ) {\n Object.defineProperty(container, name, {\n value: intro.type === 'array' ? [] : {},\n enumerable: true,\n writable: true,\n configurable: true\n });\n }\n return Object.hasOwn(container, name) ? container[name] : null;\n };\n const inner = base[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n if (intro.type === 'array') {\n const indices = new Map<string, any>();\n return new Proxy(base, {\n get(target, key, receiver) {\n if (\n typeof key !== 'string' ||\n !/^(0|[1-9]\\d*)$/.test(key) ||\n Number(key) >= 4294967295\n ) {\n return Reflect.get(target, key, receiver);\n }\n if (!intro.elementSchema) return undefined;\n if (!indices.has(key)) {\n indices.set(\n key,\n createIndexedDescriptor(\n intro.elementSchema,\n (root, create) => {\n const array = valueSelector(root, create);\n return Array.isArray(array) ? array : null;\n },\n key,\n inner as any\n )\n );\n }\n return indices.get(key);\n }\n });\n }\n if (intro.properties) {\n for (const [key, child] of Object.entries(intro.properties)) {\n Object.defineProperty(base, key, {\n value: createIndexedDescriptor(\n child as any,\n valueSelector,\n key,\n inner as any\n ),\n enumerable: true\n });\n }\n } else if ((schema as any)[SYMBOL_HAS_PROPERTIES]) {\n return createExternProxyDescriptor(base, valueSelector);\n }\n return base;\n};\n\n/**\n * Creates a Proxy-wrapped property descriptor for an extern schema.\n * Child descriptors are lazily created when accessed by name, enabling\n * `getErrorsFor(t => t.order.id)` navigation without an explicit\n * property map.\n *\n * Each child is also Proxy-wrapped for arbitrary-depth navigation.\n *\n * @param baseDescriptor - The base descriptor (with SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR)\n * @param valueSelector - Selector that navigates to the extern's VALUE in the root object\n */\nconst createExternProxyDescriptor = (\n baseDescriptor: ReturnType<typeof createPropertyDescriptorFor>,\n valueSelector: (obj: any, createMissingStructure: boolean) => any\n): any =>\n new Proxy(baseDescriptor, {\n get(target: any, prop: PropertyKey, receiver: any): any {\n // Fast path for the descriptor symbol — no interception\n if (prop === SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR) {\n return target[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n }\n\n // For string keys, lazily create and cache child descriptors\n if (typeof prop === 'string' && !(prop in target)) {\n const child = createPropertyDescriptorFor(\n valueSelector,\n prop,\n undefined,\n target[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n\n // Build a value selector for the child's own children\n const childValueSelector = (\n obj: any,\n createMissingStructure: boolean\n ) => {\n const parentValue = valueSelector(\n obj,\n createMissingStructure\n );\n if (\n parentValue != null &&\n typeof parentValue === 'object'\n ) {\n if (createMissingStructure && !(prop in parentValue)) {\n parentValue[prop as string] = {};\n }\n return parentValue[prop as string];\n }\n return null;\n };\n\n // Recursively wrap so deeper paths like t.order.address.city work\n target[prop] = createExternProxyDescriptor(\n child,\n childValueSelector\n );\n }\n\n return Reflect.get(target, prop, receiver);\n }\n });\n\n(object as any).getPropertiesFor = <\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<\n TProperties,\n TRequired,\n false,\n TExplicitType,\n false,\n {},\n []\n >\n>(\n schema: ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n): PropertyDescriptorTree<TSchema, TSchema> =>\n ObjectSchemaBuilder.getPropertiesFor(schema) as any;\n\n(object as any).isValidPropertyDescriptor =\n ObjectSchemaBuilder.isValidPropertyDescriptor;\n\nexport { object };\n\ntype RequiredProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<any, infer TReq, any, any>\n ? TReq extends true\n ? k\n : never\n : never]: T[k];\n};\n\ntype NotRequiredProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<any, infer TReq, any, any>\n ? TReq extends true\n ? never\n : k\n : never]: T[k];\n};\n\ntype RequiredInputProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<\n any,\n infer TReq,\n any,\n infer THasDef\n >\n ? TReq extends true\n ? THasDef extends true\n ? never\n : k\n : never\n : never]: T[k];\n};\n\ntype NotRequiredInputProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<\n any,\n infer TReq,\n any,\n infer THasDef\n >\n ? TReq extends true\n ? THasDef extends true\n ? k\n : never\n : k\n : never]: T[k];\n};\n"],"mappings":"sDAkBO,IAAMA,EAAN,KAkBP,CACIC,GAMAC,GACAC,GAAoB,CAAC,EACrBC,GAAwD,CAAC,EAOzD,IAAW,WAA4C,CACnD,IAAMC,EAAS,KAAKJ,GAChBK,CACJ,EAAE,SAAS,KAAKJ,EAAuB,EAEvC,OAAQG,EAAO,QAAUA,EAAO,MAAQ,MAC5C,CAKA,IAAW,QAAgC,CACvC,OAAO,KAAKF,EAChB,CAMA,IAAW,SAAmB,CAC1B,OAAO,KAA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0BACZhB,EAAoB","names":["PropertyValidationResult","#descriptor","#rootObjectValue","#errors","#childErrors","result","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","descriptor","rootObjectValue","errors","ObjectSchemaBuilder","error","childError","MUST_BE_AN_OBJECT_ERROR_MESSSAGE","ObjectSchemaBuilder","_ObjectSchemaBuilder","SchemaBuilder","#properties","#acceptUnknownProps","#propKeys","#constructorSchemas","SYMBOL_HAS_PROPERTIES","#propertyDescriptorTreeMap","props","s","errorMessage","value","_name","#applyPropertyDescriptors","result","object","context","#setupValidation","prevalidatedResult","valid","prevalidationContext","validationTransaction","preValidationErrors","propertyDescriptorToErrorMap","invalidResults","doNotStopOnFirstError","rootValidationObject","rootPropertyDescriptor","currentPropertyDescriptor","addErrorFor","propertyDescriptor","message","parentPropertyDescriptor","validationError","PropertyValidationResult","parentValidationError","getErrorsFor","selector","descriptor","getInvalidProperties","r","errors","routePreValidationError","error","targetDescriptor","objToValidate","propKeys","objKeys","i","#processResults","setup","validationResults","hasInvalid","key","resultObject","#propagateNestedErrors","#propagateIndexedErrors","validator","options","self","#validateFull","results","_notUsed","schema","propName","newProps","propNameOrArrayOrPropsOrBuilder","propsArray","distinctKeys","propsToOmit","remoteProps","localProps","acc","curr","propNameOrArray","prop","properties","property","newProperties","p","callback","callbackResult","builder","#getPropertiesFor","parentSelector","currentName","parentDescriptor","introspected","propsNames","createPropertyDescriptorFor","obj","createMissingStructure","propSchema","childProperties","tree","selectorResult","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","createIndexedDescriptor","externBase","externValueSelector","createExternProxyDescriptor","#getSchemaForPropertyDescriptor","propertyNames","nestedPropertyName","nestedPropertyDescriptor","nestedValidationError","prefix","invalid","pointer","target","node","part","nestedSchema","children","child","index","indexed","relative","propertyName","parent","newValue","segments","ancestor","name","base","intro","valueSelector","root","create","container","inner","indices","receiver","array","baseDescriptor","childValueSelector","parentValue"]}
|
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as s,b as t,c as u,d as v,e as w,f as x}from"./chunk-ZYWDTLNL.js";import{a as C,b as D}from"./chunk-
|
|
1
|
+
import{a as s,b as t,c as u,d as v,e as w,f as x}from"./chunk-ZYWDTLNL.js";import{a as C,b as D}from"./chunk-W5LLKFM7.js";import{a as q,b as r,c as O,d as P,e as Q,f as R,g as S}from"./chunk-WNAU5MPQ.js";import{a as M,b as N}from"./chunk-3E5M6GRR.js";import{a as o,b as p}from"./chunk-BMA2X7LI.js";import{a as y,b as z}from"./chunk-BTR3ZGES.js";import{a as A,b as B}from"./chunk-Z4SFUZSP.js";import{a as E,b as F}from"./chunk-25KL2NBJ.js";import{a as G,b as H}from"./chunk-W5D22D4P.js";import{a as I,b as J}from"./chunk-JH7VLA6C.js";import{a as K,b as L}from"./chunk-VBPZRO7L.js";import{a as e,b as f}from"./chunk-NDESVCWI.js";import{a as g,b as h}from"./chunk-XASMTNON.js";import{a as i,b as j}from"./chunk-D7RXO2FA.js";import{a as k,b as l}from"./chunk-66U6MMJ2.js";import{a as m,b as n}from"./chunk-K7TDPKGQ.js";import{b as a,c as b,d as c,f as d}from"./chunk-2BKBVVZ3.js";export{e as AnySchemaBuilder,g as ArraySchemaBuilder,i as BooleanSchemaBuilder,k as DateSchemaBuilder,Q as EXTRA_TYPE_BRAND,m as ExternSchemaBuilder,o as FunctionSchemaBuilder,q as GenericSchemaBuilder,s as IntersectionSchemaBuilder,u as LazySchemaBuilder,P as METHOD_LITERAL_BRAND,w as NullSchemaBuilder,y as NumberSchemaBuilder,A as ObjectSchemaBuilder,C as ParseStringSchemaBuilder,E as PromiseSchemaBuilder,G as RecordSchemaBuilder,c as SYMBOL_HAS_PROPERTIES,b as SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR,d as SchemaBuilder,a as SchemaValidationError,I as StringSchemaBuilder,K as TupleSchemaBuilder,M as UnionSchemaBuilder,f as any,h as array,j as boolean,l as date,R as defineExtension,O as defineMetadataMethod,n as extern,p as func,r as generic,t as intersection,v as lazy,x as nul,z as number,B as object,D as parseString,F as promise,H as record,J as string,L as tuple,N as union,S as withExtensions};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|
package/dist/extension.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{c as a,d as b,e as c,f as d,g as e}from"./chunk-
|
|
1
|
+
import{c as a,d as b,e as c,f as d,g as e}from"./chunk-WNAU5MPQ.js";import"./chunk-3E5M6GRR.js";import"./chunk-BMA2X7LI.js";import"./chunk-BTR3ZGES.js";import"./chunk-Z4SFUZSP.js";import"./chunk-25KL2NBJ.js";import"./chunk-W5D22D4P.js";import"./chunk-JH7VLA6C.js";import"./chunk-VBPZRO7L.js";import"./chunk-NDESVCWI.js";import"./chunk-XASMTNON.js";import"./chunk-D7RXO2FA.js";import"./chunk-66U6MMJ2.js";import"./chunk-2BKBVVZ3.js";export{c as EXTRA_TYPE_BRAND,b as METHOD_LITERAL_BRAND,d as defineExtension,a as defineMetadataMethod,e as withExtensions};
|
|
2
2
|
//# sourceMappingURL=extension.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as ee,b as re,c as E,d as g,e as ne,f as te}from"./chunk-ZYWDTLNL.js";import{a as B,b}from"./chunk-
|
|
1
|
+
import{a as ee,b as re,c as E,d as g,e as ne,f as te}from"./chunk-ZYWDTLNL.js";import{a as B,b}from"./chunk-W5LLKFM7.js";import{a as Y,b as Z,c as de,d as ue,e as le,f as u,g as p}from"./chunk-WNAU5MPQ.js";import{a as oe}from"./chunk-3E5M6GRR.js";import{a as X}from"./chunk-BMA2X7LI.js";import{a as ie}from"./chunk-BTR3ZGES.js";import{a as ae}from"./chunk-Z4SFUZSP.js";import{a as T}from"./chunk-25KL2NBJ.js";import{a as V}from"./chunk-W5D22D4P.js";import{a as se}from"./chunk-JH7VLA6C.js";import{a as v}from"./chunk-VBPZRO7L.js";import{a as C}from"./chunk-NDESVCWI.js";import{a as W}from"./chunk-XASMTNON.js";import{a as _}from"./chunk-D7RXO2FA.js";import{a as G}from"./chunk-66U6MMJ2.js";import{a as J,b as Q}from"./chunk-K7TDPKGQ.js";import{b as I,c as L,d as K,f as z}from"./chunk-2BKBVVZ3.js";function i(e,r,n,a){return{valid:!1,errors:[{message:M(e,r,n,a)}]}}function M(e,r,n,a){if(e===void 0)return r;if(typeof e=="string")return e;let t=e(n,a);if(t instanceof Promise)throw new Error("Async error message providers require validateAsync(). Use a string or sync function instead.");return t}var l=u({array:{nonempty(e){return this.withExtension("nonempty",!0).addValidator(r=>Array.isArray(r)?r.length>0?{valid:!0,errors:[]}:i(e,"must not be empty",r,this):i(e,"must not be empty",r,this))},unique(e,r){let n=e??!0;return this.withExtension("unique",n).addValidator(a=>{if(!Array.isArray(a))return i(r,"must contain unique elements",a,this);let t=new Set;for(let s of a){let d=e?e(s):s;if(t.has(d))return i(r,"must contain unique elements",a,this);t.add(d)}return{valid:!0,errors:[]}})}}});var m=u({number:{positive(e){return this.withExtension("positive",!0).addValidator(r=>typeof r!="number"?i(e,"must be a positive number",r,this):r>0?{valid:!0,errors:[]}:i(e,"must be a positive number",r,this))},negative(e){return this.withExtension("negative",!0).addValidator(r=>typeof r!="number"?i(e,"must be a negative number",r,this):r<0?{valid:!0,errors:[]}:i(e,"must be a negative number",r,this))},finite(e){return this.withExtension("finite",!0).addValidator(r=>typeof r!="number"?i(e,"must be a finite number",r,this):Number.isFinite(r)?{valid:!0,errors:[]}:i(e,"must be a finite number",r,this))},multipleOf(e,r){if(e===0||!Number.isFinite(e))throw new Error("multipleOf: n must be a finite, non-zero number");return this.withExtension("multipleOf",e).addValidator(n=>{if(typeof n!="number")return i(r,`must be a multiple of ${e}`,n,this);let a=Math.abs(n%e),t=Math.abs(e)*1e-10;return a<t||Math.abs(a-Math.abs(e))<t?{valid:!0,errors:[]}:i(r,`must be a multiple of ${e}`,n,this)})},oneOf(...e){let r,n;if(e.length===0)throw new Error("oneOf requires at least one value");if(Array.isArray(e[0]))r=e[0],n=e[1];else{let t=e[e.length-1];typeof t=="string"||typeof t=="function"?(r=e.slice(0,-1),n=t):(r=e,n=void 0)}if(r.length===0)throw new Error("oneOf requires at least one value");let a=new Set(r);return this.withExtension("oneOf",r).addValidator(t=>typeof t=="number"&&a.has(t)?{valid:!0,errors:[]}:i(n,`must be one of: ${r.join(", ")}`,t,this))}}});var P=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,f=/^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,S=/^(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$|^::(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4}$|^(?:[0-9a-f]{1,4}:){1,6}:[0-9a-f]{1,4}$|^(?:[0-9a-f]{1,4}:){1,5}(?::[0-9a-f]{1,4}){1,2}$|^(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,3}$|^(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}$|^(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}$|^[0-9a-f]{1,4}:(?::[0-9a-f]{1,4}){1,6}$|^::$/i,y=u({string:{email(e){return this.withExtension("email",!0).addValidator(r=>typeof r!="string"?i(e,"must be a valid email",r,this):/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?{valid:!0,errors:[]}:i(e,"must be a valid email",r,this))},url(e,r){let n;if(typeof e=="string"||typeof e=="function"?(r=e,n=void 0):n=e,n?.protocols!==void 0&&(n.protocols.length===0||n.protocols.some(s=>!s||s.trim()==="")))throw new Error("url: opts.protocols must be a non-empty array of non-empty strings");let a=n?.protocols??["http","https"],t=n?.protocols?{protocols:n.protocols}:!0;return this.withExtension("url",t).addValidator(s=>{if(typeof s!="string")return i(r,"must be a valid URL",s,this);let d=!1,h="must be a valid URL";try{let x=new URL(s).protocol.replace(":","");d=a.includes(x),d||(h=`protocol must be one of: ${a.join(", ")}`)}catch{}return d?{valid:!0,errors:[]}:i(r,h,s,this)})},uuid(e){return this.withExtension("uuid",!0).addValidator(r=>typeof r!="string"?i(e,"must be a valid UUID",r,this):P.test(r)?{valid:!0,errors:[]}:i(e,"must be a valid UUID",r,this))},ip(e,r){let n=e?.version,a=n?{version:n}:!0;return this.withExtension("ip",a).addValidator(t=>{let s=n?`must be a valid ${n} IP address`:"must be a valid IP address";if(typeof t!="string")return i(r,s,t,this);let d;return n==="v4"?d=f.test(t):n==="v6"?d=S.test(t):d=f.test(t)||S.test(t),d?{valid:!0,errors:[]}:i(r,s,t,this)})},trim(){return this.addPreprocessor(e=>typeof e=="string"?e.trim():e)},toLowerCase(){return this.addPreprocessor(e=>typeof e=="string"?e.toLowerCase():e)},nonempty(e){return this.withExtension("nonempty",!0).addValidator(r=>typeof r!="string"?i(e,"must not be empty",r,this):r.length>0?{valid:!0,errors:[]}:i(e,"must not be empty",r,this))},oneOf(...e){let r,n;if(e.length===0)throw new Error("oneOf requires at least one value");if(Array.isArray(e[0]))r=e[0],n=e[1];else{let t=e[e.length-1];typeof t=="function"?(r=e.slice(0,-1),n=t):(r=e,n=void 0)}if(r.length===0)throw new Error("oneOf requires at least one value");let a=new Set(r);return this.withExtension("oneOf",r).addValidator(t=>typeof t=="string"&&a.has(t)?{valid:!0,errors:[]}:i(n,`must be one of: ${r.join(", ")}`,t,this))}}});var o=p(y,m,l),c=o.string,w=o.number,N=o.array,O=o.boolean,A=o.date,R=o.object,j=o.union,H=o.func,$=o.any,U=o.tuple,k=o.record,F=o.promise;function q(...e){return Array.isArray(e[0])?c().oneOf(e[0],e[1]):c().oneOf(...e)}export{C as AnySchemaBuilder,W as ArraySchemaBuilder,_ as BooleanSchemaBuilder,G as DateSchemaBuilder,le as EXTRA_TYPE_BRAND,J as ExternSchemaBuilder,X as FunctionSchemaBuilder,Y as GenericSchemaBuilder,ee as IntersectionSchemaBuilder,E as LazySchemaBuilder,ue as METHOD_LITERAL_BRAND,ne as NullSchemaBuilder,ie as NumberSchemaBuilder,ae as ObjectSchemaBuilder,B as ParseStringSchemaBuilder,T as PromiseSchemaBuilder,V as RecordSchemaBuilder,K as SYMBOL_HAS_PROPERTIES,L as SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR,z as SchemaBuilder,I as SchemaValidationError,se as StringSchemaBuilder,v as TupleSchemaBuilder,oe as UnionSchemaBuilder,$ as any,N as array,l as arrayExtensions,O as boolean,A as date,u as defineExtension,de as defineMetadataMethod,q as enumOf,Q as extern,H as func,Z as generic,re as intersection,g as lazy,te as nul,w as number,m as numberExtensions,R as object,b as parseString,F as promise,k as record,c as string,y as stringExtensions,U as tuple,j as union,p as withExtensions};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -109,9 +109,9 @@
|
|
|
109
109
|
},
|
|
110
110
|
"type": "module",
|
|
111
111
|
"types": "./dist/index.d.ts",
|
|
112
|
-
"version": "5.
|
|
112
|
+
"version": "5.1.0",
|
|
113
113
|
"devDependencies": {
|
|
114
|
-
"@cleverbrush/deep": "^5.
|
|
114
|
+
"@cleverbrush/deep": "^5.1.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"@standard-schema/spec": "^1.1.0"
|
package/dist/chunk-JEBLDVKG.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{c as P,d as B,f as S}from"./chunk-2BKBVVZ3.js";var O=class{#e;#t;#n=[];#i=[];get seenValue(){let e=this.#e[P].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.#i}get descriptor(){return this.#e[P]}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.#i.push(e)}toJSON(){return{isValid:this.isValid,errors:this.errors}}};var q="must be an object",b=class p extends S{#e={};#t=!1;#n=[];#i=[];[B]=!0;#a=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.#i=e.constructorSchemas.filter(r=>r instanceof S))}introspect(){return{...super.introspect(),properties:{...this.#e},acceptUnknownProps:this.#t,constructorSchemas:[...this.#i]}}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()}#s(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.#s(t),t}async preValidateAsync(e,r){let t=await super.preValidateAsync(e,r);return this.#s(t),t}#o(e){let{valid:r,context:t,transaction:n,errors:i}=e,y=new WeakMap,c=new Set,{doNotStopOnFirstError:a,rootValidationObject:o}=t,s=t.rootPropertyDescriptor,d=t.currentPropertyDescriptor,f=(h,m,R)=>{if(!p.isValidPropertyDescriptor(h))throw new Error("invalid property descriptor");let g=y.has(h)?y.get(h):null;if(g||(g=new O(h,o),y.set(h,g)),g.addError(m),c.add(g),R&&p.isValidPropertyDescriptor(R)){let v=y.has(R)?y.get(R):null;v||(v=new O(R,o),y.set(R,v)),v.addChildError(g)}},u=(h=>{let m=typeof h=="function"?h(d):d;if(!p.isValidPropertyDescriptor(m))throw new Error("invalid property descriptor");return y.has(m)||y.set(m,new O(m,o)),y.get(m)}),l=()=>[...c].filter(h=>h.errors.length>0),T=e.errors||[],E=h=>{if(typeof h.property=="function"&&p.isValidPropertyDescriptor(d)){let m=h.property(d);if(p.isValidPropertyDescriptor(m)){f(m,h.message,d);return}}p.isValidPropertyDescriptor(d)&&f(d,h.message)};if(!r&&!a&&i){for(let h of i)E(h);return{earlyReturn:!0,result:{valid:r,errors:i,getErrorsFor:u,getInvalidProperties:l}}}if(a&&i)for(let h of i)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:u,getInvalidProperties:l}};if(typeof x!="object"||x===null)return T.length===0&&(T.push({message:q}),f(d,q)),n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:a?T:[T[0]],getErrorsFor:u,getInvalidProperties:l}};let V=this.#n,j=Object.keys(x);if(V.length===0){if(j.length===0)return a&&T.length>0?{earlyReturn:!0,result:{valid:!1,errors:T,getErrorsFor:u,getInvalidProperties:l}}:(n&&n.commit().validatedObject,{earlyReturn:!0,result:{valid:!0,object:{},getErrorsFor:u,getInvalidProperties:l}});if(!this.#t){for(let h=0;h<j.length;h++){let m=`unknown property '${j[h]}'`;if(T.push({message:m}),!a)break}return n&&n.rollback(),{earlyReturn:!0,result:{valid:!1,errors:a?T:[T[0]],getErrorsFor:u,getInvalidProperties:l}}}return n&&n.commit(),{earlyReturn:!0,result:{valid:!0,object:{...x},getErrorsFor:u,getInvalidProperties:l}}}return{earlyReturn:!1,errors:T,objToValidate:x,propKeys:V,objKeys:j,addErrorFor:f,getErrorsFor:u,getInvalidProperties:l,doNotStopOnFirstError:!!a,rootPropertyDescriptor:s,currentPropertyDescriptor:d,validationTransaction:n}}#y(e,r){let{objToValidate:t,objKeys:n,addErrorFor:i,getErrorsFor:y,getInvalidProperties:c,doNotStopOnFirstError:a,currentPropertyDescriptor:o,validationTransaction:s}=e,d=e.errors,f=!1;for(let{result:u}of r)if(!u.valid&&(f=!0,Array.isArray(u.errors)))for(let l of u.errors)d.push(l);for(let u=0;u<n.length;u++){let l=n[u];if(!(l in this.#e)&&!this.#t){let T=`unknown property '${l}'`;if(d.push({message:T}),i(o,T),!a)return s&&s.rollback(),{valid:!1,errors:[d[0]],getErrorsFor:y,getInvalidProperties:c}}}if(!f&&d.length===0){let u={};for(let{key:l,result:T}of r)u[l]=T.object;if(this.#t)for(let l of n)l in this.#e||(u[l]=t[l]);return{valid:!0,object:u,getErrorsFor:y,getInvalidProperties:c}}for(let{key:u,result:l}of r)if(!l.valid){let T=o[u];if(typeof l.getErrorsFor=="function"&&p.isValidPropertyDescriptor(T)){if(p.#c(l,T,i),Array.isArray(l.__externErrorPropertyNames)&&Array.isArray(l.errors))for(let E of l.errors)i(T,E.message,o)}else if(Array.isArray(l.errors)&&p.isValidPropertyDescriptor(T)){for(let E of l.errors)i(T,E.message);Array.isArray(l.getNestedErrors?.())&&p.#l(l,T,i)}}return s.rollback(),{valid:!1,errors:a?d:d[0]?[d[0]]:[],getErrorsFor:y,getInvalidProperties:c}}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 y=Object.keys(e);for(let c=0;c<y.length;c++)if(!(y[c]in this.#e)){let a=this;return{valid:!1,errors:[{message:`unknown property '${y[c]}'`}],getErrorsFor(o){return a.#r(e,r).getErrorsFor(o)},getInvalidProperties(){return a.#r(e,r).getInvalidProperties()}}}}let n={};for(let y=0;y<t.length;y++){let c=t[y],a=this.#e[c].validate(e[c]);if(!a.valid){let o=this;return{valid:!1,errors:a.errors&&a.errors.length>0?[a.errors[0]]:[],getErrorsFor(s){return o.#r(e,r).getErrorsFor(s)},getInvalidProperties(){return o.#r(e,r).getInvalidProperties()}}}n[c]=a.object}if(this.#t){let y=Object.keys(e);for(let c=0;c<y.length;c++)y[c]in this.#e||(n[y[c]]=e[y[c]])}let i=this;return{valid:!0,object:n,getErrorsFor(y){return i.#r(e,r).getErrorsFor(y)},getInvalidProperties(){return i.#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:i,doNotStopOnFirstError:y,rootPropertyDescriptor:c,currentPropertyDescriptor:a}=t,o=[];for(let s of n){let d=this.#e[s].validate(i[s],{...r,rootPropertyDescriptor:c,currentPropertyDescriptor:a[s]});if(o.push({key:s,result:d}),!d.valid&&!y)break}return this.#y(t,o)}async _validateAsync(e,r){let t=this.#o(await this.preValidateAsync(e,r));if(t.earlyReturn)return t.result;let{propKeys:n,objToValidate:i,doNotStopOnFirstError:y,rootPropertyDescriptor:c,currentPropertyDescriptor:a}=t,o=[];if(y){let s=await Promise.all(n.map(async d=>{let f=await this.#e[d].validateAsync(i[d],{...r,rootPropertyDescriptor:c,currentPropertyDescriptor:a[d]});return{key:d,result:f}}));o.push(...s)}else for(let s of n){let d=await this.#e[s].validateAsync(i[s],{...r,rootPropertyDescriptor:c,currentPropertyDescriptor:a[s]});if(o.push({key:s,result:d}),!d.valid)break}return this.#y(t,o)}acceptUnknownProps(){return this.derive({...this.introspect(),acceptUnknownProps:!0})}notAcceptUnknownProps(){return this.derive({...this.introspect(),acceptUnknownProps:!1})}hasType(e){return this.derive({...this.introspect()},!0)}clearHasType(){return this.derive({...this.introspect()},!0)}addConstructor(e){if(!(e instanceof S))throw new Error("schema must be an instance of the SchemaBuilder class");return this.derive({...this.introspect(),constructorSchemas:[...this.#i,e]})}clearConstructors(){return this.derive({...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.derive({...this.introspect(),properties:{...this.introspect().properties,[e]:r}})}optimize(){return this.derive({...this.introspect()},!0)}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.derive({...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.derive({...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(i=>{if(typeof i!="string"||!i)throw new Error("property name must be a string");if(!(i in this.#e))throw new Error(`property ${i.toString()} does not exists in the schema`);t.set(i.toString(),!0)}),t.size===0)throw new Error("please provide at least one property to omit");let n={...this.introspect()};for(let i of t.keys())delete n.properties[i];return this.derive(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.derive(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((i,y)=>(i[y]=y in r?r[y]:t.properties[y],i),{});return this.derive({...this.introspect(),properties:n})}partial(e){if(typeof e>"u"||e===null)return this.derive({...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.derive(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.derive({...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.derive({...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.derive({...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.derive(n)}makePropOptional(e){return this.modifyPropSchema(e,r=>r.optional())}makePropRequired(e){return this.modifyPropSchema(e,r=>r.required())}makeAllPropsOptional(){return this.derive({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].optional(),e),{})})}makeAllPropsRequired(){return this.derive({...this.introspect(),properties:Object.keys(this.#e).reduce((e,r)=>(e[r]=this.#e[r].required(),e),{})})}static#p(e,r,t,n,i){let y=e.introspect();if(!y.properties)return{};let c=Object.keys(y.properties);if(c.length===0)return{};typeof r!="function"&&(r=o=>o);let a=D((o,s)=>(t||r)(o,s),n,e,i);for(let o of c){let s=y.properties[o];if(s instanceof p){let d=s.introspect().properties;d&&typeof d=="object"&&Object.keys(d).length>0?a[o]=p.#p(s,(f,u)=>{let l=r(f,u);return l?(u&&!l[o]&&(l[o]={}),l[o]):null},r,o,a[P]):a[o]=D(r,o,s,a[P])}else if(s.introspect().type==="array")a[o]=k(s,r,o,a[P]);else if(s[B]===!0){let d=D(r,o,s,a[P]),f=(u,l)=>{let T=r(u,l);return T?(l&&!T[o]&&(T[o]={}),T[o]):null};a[o]=w(d,f)}else a[o]=D(r,o,s,a[P])}return a}static getPropertiesFor(e){if(!(e instanceof p))throw new Error("schema must be an instance of the ObjectSchemaBuilder class");if(e.#a.has(e))return e.#a.get(e);let r=p.#p(e);return e.#a.set(e,r),r}static isValidPropertyDescriptor(e){return typeof e=="object"&&e!==null&&typeof e[P]=="object"}static#c(e,r,t){let i=p.#d(r).introspect().properties,y;if(i)y=Object.keys(i);else if(Array.isArray(e.__externErrorPropertyNames))y=e.__externErrorPropertyNames;else return;for(let c of y){let a=r[c];if(!p.isValidPropertyDescriptor(a))continue;let o=e.getErrorsFor(()=>a);if(!o.isValid)for(let s of o.errors)t(a,s,r);if(a[P].getSchema()?.introspect().type==="array"&&typeof e.getInvalidProperties=="function"){let s=a[P].toJsonPointer()+"/";for(let d of e.getInvalidProperties()){let f=d.descriptor.toJsonPointer();if(!f.startsWith(s))continue;let u=f.slice(s.length).split("/").reduce((l,T)=>l?.[T.replace(/~1/g,"/").replace(/~0/g,"~")],a);if(p.isValidPropertyDescriptor(u))for(let l of d.errors)t(u,l,a)}}if(i){let s=i[c];(s instanceof p||s[B]===!0)&&typeof e.getErrorsFor=="function"&&p.isValidPropertyDescriptor(a)&&p.#c(e,a,t)}}}static#l(e,r,t){let n=e.getNestedErrors?.();Array.isArray(n)&&n.forEach((i,y)=>{let c=r[y];if(!(!i||i.valid||!p.isValidPropertyDescriptor(c)))if(typeof i.getInvalidProperties=="function"){let a=c[P].toJsonPointer();for(let o of i.getInvalidProperties()){let s=o.descriptor.toJsonPointer(),d=s===a?"":s.startsWith(a+"/")?s.slice(a.length):s,f=d===""?c:d.slice(1).split("/").reduce((u,l)=>u?.[l.replace(/~1/g,"/").replace(/~0/g,"~")],c);if(p.isValidPropertyDescriptor(f))for(let u of o.errors)t(f,u,r)}}else{for(let a of i.errors??[])t(c,a.message,r);p.#l(i,c,t)}})}static#d(e){if(!p.isValidPropertyDescriptor(e))throw new Error("descriptor is not a valid property descriptor");return e[P].getSchema()}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},C=(p=>b.create({isRequired:!0,properties:p})),D=(p,e,r,t)=>({[P]:{setValue:(n,i,y)=>{let c=p(n,!!y?.createMissingStructure);return c?(typeof e=="string"&&(c[e]=i),!0):!1},getValue:n=>{let i=p(n,!1);return i?typeof e!="string"?{success:!0,value:i}:Object.hasOwn(i,e)?{success:!0,value:i[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 i=t;for(;i;)typeof i.propertyName=="string"&&n.push(i.propertyName.replace(/~/g,"~0").replace(/\//g,"~1")),i=i.parent;return n.reverse(),n.length>0?"/"+n.join("/"):""}}}),k=(p,e,r,t)=>{let n=D(e,r,p,t),i=p.introspect(),y=(a,o)=>{let s=e(a,o);return!s||typeof s!="object"?null:(o&&(!Object.hasOwn(s,r)||s[r]==null)&&Object.defineProperty(s,r,{value:i.type==="array"?[]:{},enumerable:!0,writable:!0,configurable:!0}),Object.hasOwn(s,r)?s[r]:null)},c=n[P];if(i.type==="array"){let a=new Map;return new Proxy(n,{get(o,s,d){if(typeof s!="string"||!/^(0|[1-9]\d*)$/.test(s)||Number(s)>=4294967295)return Reflect.get(o,s,d);if(i.elementSchema)return a.has(s)||a.set(s,k(i.elementSchema,(f,u)=>{let l=y(f,u);return Array.isArray(l)?l:null},s,c)),a.get(s)}})}if(i.properties)for(let[a,o]of Object.entries(i.properties))Object.defineProperty(n,a,{value:k(o,y,a,c),enumerable:!0});else if(p[B])return w(n,y);return n},w=(p,e)=>new Proxy(p,{get(r,t,n){if(t===P)return r[P];if(typeof t=="string"&&!(t in r)){let i=D(e,t,void 0,r[P]),y=(c,a)=>{let o=e(c,a);return o!=null&&typeof o=="object"?(a&&!(t in o)&&(o[t]={}),o[t]):null};r[t]=w(i,y)}return Reflect.get(r,t,n)}});C.getPropertiesFor=p=>b.getPropertiesFor(p);C.isValidPropertyDescriptor=b.isValidPropertyDescriptor;export{b as a,C as b};
|
|
2
|
-
//# sourceMappingURL=chunk-JEBLDVKG.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/builders/PropertyValidationResult.ts","../src/builders/ObjectSchemaBuilder.ts"],"sourcesContent":["import { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';\nimport {\n type InferType,\n type NestedValidationResult,\n type PropertyDescriptorInner,\n type PropertyDescriptorTree,\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n} from './SchemaBuilder.js';\n\n/**\n * Mutable container for nested validation results associated with a specific\n * property descriptor. Implements {@link NestedValidationResult} and tracks\n * the seen value, accumulated error messages, and child results for\n * nested object properties.\n *\n * Used internally by `ObjectSchemaBuilder` during validation to build up\n * a tree of per-property validation results.\n */\nexport class PropertyValidationResult<\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<any, any, any, any, any>,\n TRootSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor = any\n> implements\n NestedValidationResult<TSchema, TRootSchema, TParentPropertyDescriptor>\n{\n #descriptor: PropertyDescriptorTree<\n TSchema,\n TRootSchema,\n any,\n TParentPropertyDescriptor\n >;\n #rootObjectValue: InferType<TRootSchema> | undefined;\n #errors: string[] = [];\n #childErrors: NestedValidationResult<any, any, any>[] = [];\n\n /**\n * The value that was seen at the property location described by the descriptor.\n * Retrieves the value from the root object using the property descriptor's `getValue` method.\n * Returns `undefined` if the property is not found.\n */\n public get seenValue(): InferType<TSchema> | undefined {\n const result = this.#descriptor[\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n ].getValue(this.#rootObjectValue as any);\n\n return (result.success ? result.value : undefined) as any;\n }\n\n /**\n * The list of validation error messages accumulated for this property.\n */\n public get errors(): ReadonlyArray<string> {\n return this.#errors;\n }\n\n /**\n * Whether validation passed for this property and all of its children.\n * Returns `true` only when there are no errors and no child errors.\n */\n public get isValid(): boolean {\n return this.#errors.length === 0 && this.getChildErrors().length === 0;\n }\n\n /**\n * Returns the list of child `NestedValidationResult` instances\n * representing validation results for nested properties.\n */\n public getChildErrors(): ReadonlyArray<\n NestedValidationResult<any, any, any>\n > {\n return this.#childErrors;\n }\n\n /**\n * The inner property descriptor providing `getValue`, `setValue`, and `getSchema`\n * operations for the property this error relates to.\n */\n public get descriptor(): PropertyDescriptorInner<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n > {\n return this.#descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR] as any;\n }\n\n /**\n * Creates a new `PropertyValidationResult`.\n *\n * @param descriptor - the property descriptor tree node this error is associated with;\n * must be a valid descriptor (checked via `ObjectSchemaBuilder.isValidPropertyDescriptor`)\n * @param rootObjectValue - the root object being validated, used to resolve property values\n * @param errors - optional initial list of error message strings\n * @throws if `descriptor` is not a valid property descriptor\n */\n constructor(\n descriptor: PropertyDescriptorTree<\n TSchema,\n TRootSchema,\n any,\n TParentPropertyDescriptor\n >,\n rootObjectValue: InferType<TRootSchema> | undefined,\n errors?: string[]\n ) {\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)) {\n throw new Error('Invalid property descriptor');\n }\n this.#descriptor = descriptor;\n this.#errors = Array.isArray(errors) ? [...errors] : [];\n this.#rootObjectValue = rootObjectValue;\n }\n\n /**\n * Appends a validation error message to this property's error list.\n * @param error - the error message string to add\n */\n addError(error: string): void {\n this.#errors.push(error);\n }\n\n /**\n * Appends a child `NestedValidationResult` for a nested property.\n * @param childError - the child validation result to add\n */\n addChildError(childError: NestedValidationResult<any, any, any>): void {\n this.#childErrors.push(childError);\n }\n\n /**\n * Returns a JSON-serializable representation of this validation result.\n * This ensures `JSON.stringify` includes `isValid` and `errors`,\n * which are otherwise non-enumerable prototype getters.\n */\n toJSON(): { isValid: boolean; errors: ReadonlyArray<string> } {\n return {\n isValid: this.isValid,\n errors: this.errors\n };\n }\n}\n","import { PropertyValidationResult } from './PropertyValidationResult.js';\nimport {\n type BRAND,\n type InferType,\n type NestedValidationResult,\n type PreValidationResult,\n type PropertyDescriptor,\n type PropertyDescriptorInner,\n type PropertyDescriptorTree,\n type PropertySetterOptions,\n SchemaBuilder,\n SYMBOL_HAS_PROPERTIES,\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR,\n type ValidationContext,\n type ValidationError,\n type ValidationErrorMessageProvider,\n type ValidationResult\n} from './SchemaBuilder.js';\n\nconst MUST_BE_AN_OBJECT_ERROR_MESSSAGE = 'must be an object';\n\n/**\n * A callback function to select properties from the schema.\n * Normally it's provided by the user to select property descriptors\n * from the schema for the further usage. e.g. to select source and destination\n * properties for object mappings\n */\nexport type SchemaPropertySelector<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n TPropertySchema extends SchemaBuilder<any, any, any, any, any>,\n TAssignableTo = any,\n TParentPropertyDescriptor = undefined\n> = (\n l: PropertyDescriptorTree<TSchema, TSchema, TAssignableTo>\n) => PropertyDescriptor<TSchema, TPropertySchema, TParentPropertyDescriptor>;\n\ntype ObjectSchemaBuilderProps<\n T extends Record<string, SchemaBuilder> = {},\n TRequired extends boolean = true\n> = ReturnType<ObjectSchemaBuilder<T, TRequired>['introspect']>;\n\ntype ObjectSchemaBuilderCreateProps<\n T extends Record<string, SchemaBuilder> = {},\n TRequired extends boolean = true\n> = Partial<ObjectSchemaBuilderProps<T, TRequired>>;\n\ntype Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\n\n/**\n * Extracts the positional argument types from a schema whose inferred type is a\n * function. When the branded `InferType<T>` resolves to a function type the\n * parameter tuple is extracted; otherwise `any[]` is used as a safe fallback.\n *\n * @example\n * ```ts\n * type Args = ConstructorParams<typeof func().addParameter(string()).addParameter(number())>;\n * // → [string, number]\n * ```\n */\ntype ConstructorParams<T extends SchemaBuilder<any, any, any, any, any>> =\n InferType<T> extends (...args: infer A) => any ? A : any[];\n\n/**\n * Converts a tuple of `FunctionSchemaBuilder`s into an intersection of\n * `new (...args) => TInstance` call signatures, producing overloaded\n * construct signatures in the inferred type.\n *\n * The recursion peels schemas off the front of `TSchemas` one at a time,\n * each contributing one construct overload to the intersection.\n *\n * @example\n * ```ts\n * type Sigs = ConstructorSignatures<\n * [typeof func().addParameter(string()), typeof func().addParameter(number())],\n * { name: string }\n * >;\n * // → { new (p0: string): { name: string } }\n * // & { new (p0: number): { name: string } }\n * ```\n */\ntype ConstructorSignatures<\n TSchemas extends SchemaBuilder<any, any, any, any, any>[],\n TInstance\n> = TSchemas extends [\n infer THead extends SchemaBuilder<any, any, any, any, any>,\n ...infer TTail extends SchemaBuilder<any, any, any, any, any>[]\n]\n ? {\n new (...args: ConstructorParams<THead>): TInstance;\n } & ConstructorSignatures<TTail, TInstance>\n : unknown;\n\n/**\n * Wraps `TInstance` with constructor overload signatures derived from\n * `TSchemas`. When the tuple is empty the type is returned unchanged\n * (no-op); otherwise the result is an intersection of all construct\n * signatures with `TInstance`.\n *\n * This is the type projected onto `InferType<ObjectSchemaBuilder>` when one\n * or more constructors have been registered via `.addConstructor()`.\n *\n * @example\n * ```ts\n * // No constructors — passthrough\n * type A = WithConstructors<[], { name: string }>;\n * // → { name: string }\n *\n * // One constructor\n * type B = WithConstructors<[typeof func().addParameter(string())], { name: string }>;\n * // → { new (p0: string): { name: string } } & { name: string }\n *\n * // Two constructors → overloaded construct signatures\n * type C = WithConstructors<\n * [typeof func().addParameter(string()), typeof func().addParameter(number())],\n * { name: string }\n * >;\n * // → { new (p0: string): { name: string } }\n * // & { new (p0: number): { name: string } }\n * // & { name: string }\n * ```\n */\ntype WithConstructors<\n TSchemas extends SchemaBuilder<any, any, any, any, any>[],\n TInstance\n> = TSchemas extends []\n ? TInstance\n : ConstructorSignatures<TSchemas, TInstance> & TInstance;\n\nexport type RespectPropsOptionality<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in RequiredProps<T>]: InferType<T[K]>;\n} & {\n [K in NotRequiredProps<T>]?: InferType<T[K]>;\n};\n\ntype RespectPropsOptionalityForInput<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in RequiredInputProps<T>]: InferType<T[K]>;\n} & {\n [K in NotRequiredInputProps<T>]?: InferType<T[K]>;\n};\n\ntype MakeChildrenRequired<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: ReturnType<T[K]['required']>;\n};\n\ntype MakeChildrenOptional<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: ReturnType<T[K]['optional']>;\n};\n\n/**\n * Recursively maps each property to its optional form, descending into\n * nested `ObjectSchemaBuilder` schemas. All other schema types (arrays,\n * unions, primitives) are only made optional at the top level.\n */\ntype DeepMakeChildrenOptional<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = {\n [K in keyof T]: T[K] extends ObjectSchemaBuilder<\n // biome-ignore lint/correctness/noUnusedVariables: used in extensions\n infer P extends Record<string, SchemaBuilder<any, any, any, any, any>>,\n any,\n any,\n any,\n any,\n any,\n any\n >\n ? ReturnType<ReturnType<T[K]['deepPartial']>['optional']>\n : ReturnType<T[K]['optional']>;\n};\n\ntype MakeChildOptional<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T\n> = {\n [K in keyof T]: K extends TProp ? ReturnType<T[K]['optional']> : T[K];\n};\n\ntype MakeChildRequired<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T\n> = {\n [K in keyof T]: K extends TProp ? ReturnType<T[K]['required']> : T[K];\n};\n\ntype ModifyPropSchema<\n T extends Record<any, SchemaBuilder<any, any, any, any, any>>,\n TProp extends keyof T,\n TSchema extends SchemaBuilder<any, any, any, any, any>\n> = {\n [K in keyof T]: K extends TProp ? TSchema : T[K];\n};\n\nexport type ObjectSchemaValidationResult<\n T,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = TRootSchema\n> = Omit<ValidationResult<T>, 'errors'> & {\n /**\n * A flat list of validation errors.\n *\n * @deprecated Use {@link ObjectSchemaValidationResult.getErrorsFor | getErrorsFor()} instead for\n * per-property error inspection with type-safe property selectors. The `errors` array on\n * `ObjectSchemaBuilder` validation results will be removed in a future major version.\n */\n errors?: ValidationError[];\n /**\n * Returns a nested validation error for the property selected by the `selector` function.\n * This is the **recommended** way to inspect validation errors — it provides type-safe,\n * per-property error details including `isValid`, `errors`, and `seenValue`.\n *\n * Inspect root or property-specific validation errors with a selector.\n *\n * @param selector a callback function to select property from the schema.\n */\n getErrorsFor<TPropertySchema, TParentPropertyDescriptor>(\n selector?: (\n properties: PropertyDescriptorTree<TSchema, TRootSchema>\n ) => PropertyDescriptor<\n TRootSchema,\n TPropertySchema,\n TParentPropertyDescriptor\n >\n ): TPropertySchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n ? PropertyValidationResult<\n TPropertySchema,\n TRootSchema,\n TParentPropertyDescriptor\n >\n : NestedValidationResult<\n TPropertySchema,\n TRootSchema,\n TParentPropertyDescriptor\n >;\n\n /**\n * Returns a list of all property validation results that have direct\n * validation errors. Each entry exposes `.descriptor` (with\n * `.toJsonPointer()` for the property's path) and `.errors`.\n *\n * This is useful for collecting all errors with their full JSON Pointer\n * paths, e.g. for building RFC 9457 Problem Details responses.\n */\n getInvalidProperties(): ReadonlyArray<\n NestedValidationResult<any, TRootSchema, any>\n >;\n};\n\n/**\n * Object schema builder class. Similar to the `object` type\n * in JS. Allows to define a schema for `object` value.\n * Should be used to validate objects with specific properties.\n * Properties should be defined as their own schema builders.\n * You can use any `SchemaBuilder` e.g. `string()`, `number()`,\n * `boolean()`, `array()`, `object()`, etc. to define properties.\n * Which means that you can define nested objects and arrays of\n * any complexity.\n *\n * **NOTE** this class is exported for type annotations and advanced use.\n * Customize via extensions rather than subclassing. Avoid instantiating it\n * directly. Use {@link object | object()} function instead.\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number()\n * });\n *\n * const result = schema.validate({\n * name: 'John',\n * age: 30\n * });\n *\n * // result.valid === true\n * // result.object === { name: 'John', age: 30 }\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number().optional()\n * });\n *\n * const result = schema.validate({\n * name: 'John'\n * });\n * // result.valid === true\n * // result.object === { name: 'John' }\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * age: number();\n * });\n * const result = schema.validate({\n * name: 'John'\n * });\n *\n * // result.valid === false\n * // Inspect property errors using result.getErrorsFor().\n * // result.getErrorsFor((p) => p.age).errors // [\"is expected to have property 'age'\"]\n * ```\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * })\n * });\n * const result = schema.validate({\n * name: 'John',\n * address: {\n * city: 'New York',\n * country: 'USA'\n * }\n * });\n * // result.valid === true\n * // result.object === {\n * // name: 'John',\n * // address: {\n * // city: 'New York',\n * // country: 'USA'\n * // }\n * // }\n * ```\n * @see {@link object}\n */\nexport class ObjectSchemaBuilder<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n TExplicitType = undefined,\n THasDefault extends boolean = false,\n TExtensions = {},\n TConstructorSchemas extends SchemaBuilder<any, any, any, any, any>[] = []\n> extends SchemaBuilder<\n undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n RespectPropsOptionality<TProperties>\n >\n : TExplicitType,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n /** Native type parameters for extension rebinding; never emitted at runtime. @internal */\n declare readonly __cleverbrush_builder_type__: readonly [\n 'object',\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TConstructorSchemas\n ];\n\n #properties: TProperties = {} as any;\n #acceptUnknownProps = false;\n #propKeys: string[] = [];\n #constructorSchemas: SchemaBuilder<any, any, any, any, any>[] = [];\n\n /** Marks this builder as having sub-properties for descriptor tree recursion. */\n readonly [SYMBOL_HAS_PROPERTIES] = true;\n\n #propertyDescriptorTreeMap: PropertyDescriptorMap = new WeakMap() as any;\n\n /**\n * @hidden\n */\n public static create<\n P extends Record<string, SchemaBuilder>,\n R extends boolean\n >(props: ObjectSchemaBuilderCreateProps<P, R>) {\n return new ObjectSchemaBuilder({\n type: 'object',\n ...props\n } as any);\n }\n\n protected createFromProps<\n T extends Record<string, SchemaBuilder>,\n R extends boolean = true\n >(props: ObjectSchemaBuilderCreateProps<T, R>): this {\n return ObjectSchemaBuilder.create(props as any) as any;\n }\n\n protected constructor(props: ObjectSchemaBuilderCreateProps) {\n super(props as any);\n\n if (typeof props.properties === 'object' && props.properties) {\n this.#properties = props.properties as any;\n this.#propKeys = Object.keys(props.properties);\n }\n\n if (typeof props.acceptUnknownProps === 'boolean') {\n this.#acceptUnknownProps = props.acceptUnknownProps;\n }\n\n if (Array.isArray(props.constructorSchemas)) {\n this.#constructorSchemas = (\n props.constructorSchemas as SchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >[]\n ).filter(s => s instanceof SchemaBuilder);\n }\n }\n\n public introspect() {\n return {\n ...super.introspect(),\n /**\n * Properties defined in schema\n */\n properties: { ...this.#properties },\n /**\n * If set to `true`, schema validation will not\n * return errors if object contains fields which\n * are not defined in the schema `properties`.\n * Set to `false` by default\n */\n acceptUnknownProps: this.#acceptUnknownProps,\n /**\n * The list of constructor schemas registered via `.addConstructor()`.\n * Each element is a `FunctionSchemaBuilder` whose inferred function\n * type provides one overloaded construct signature in `InferType`.\n * Empty array when no constructors have been added.\n */\n constructorSchemas: [\n ...this.#constructorSchemas\n ] as TConstructorSchemas\n };\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): ObjectSchemaBuilder<\n TProperties,\n true,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): ObjectSchemaBuilder<\n TProperties,\n false,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public default(\n value:\n | (undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType)\n | (() => undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType)\n ): ObjectSchemaBuilder<\n TProperties,\n true,\n TNullable,\n TExplicitType,\n true,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.default(value as any) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n false,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.clearDefault() as any;\n }\n\n /**\n * @hidden\n */\n public brand<TBrand extends string | symbol>(\n _name?: TBrand\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n (undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType) & { readonly [K in BRAND]: TBrand },\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * Marks the inferred type as `Readonly<T>` — all top-level properties\n * become `readonly` at the type level. Validation behaviour is unchanged.\n *\n * @see {@link SchemaBuilder.readonly}\n */\n public readonly(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n Readonly<\n undefined extends TExplicitType\n ? RespectPropsOptionality<TProperties>\n : TExplicitType\n >,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return super.readonly();\n }\n\n #applyPropertyDescriptors(\n result: PreValidationResult<any, { validatedObject: any }>\n ): void {\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n result?.context?.rootPropertyDescriptor as any\n )\n ) {\n (result.context.rootPropertyDescriptor as any) =\n ObjectSchemaBuilder.getPropertiesFor(this as any);\n }\n\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n result.context.currentPropertyDescriptor as any\n )\n ) {\n result.context.currentPropertyDescriptor =\n result.context.rootPropertyDescriptor;\n }\n\n if (\n !result.context.rootValidationObject &&\n result.transaction?.object?.validatedObject\n ) {\n result.context.rootValidationObject =\n result.transaction.object.validatedObject;\n }\n }\n\n protected preValidateSync(\n object: any,\n context?: ValidationContext<this>\n ): PreValidationResult<\n InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >,\n { validatedObject: any }\n > {\n const result = super.preValidateSync(object, context);\n this.#applyPropertyDescriptors(result);\n return result;\n }\n\n protected async preValidateAsync(\n object: any,\n context?: ValidationContext<this>\n ): Promise<\n PreValidationResult<\n InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >,\n { validatedObject: any }\n >\n > {\n const result = await super.preValidateAsync(object, context);\n this.#applyPropertyDescriptors(result);\n return result;\n }\n\n /**\n * Shared pre-property-validation setup for both `validate` and\n * `validateAsync`. Handles destructuring the prevalidated result,\n * building the `addErrorFor` / `getErrorsFor` closures, and all early\n * returns that happen before per-property validation.\n */\n #setupValidation(\n prevalidatedResult: PreValidationResult<any, { validatedObject: any }>\n ) {\n const {\n valid,\n context: prevalidationContext,\n transaction: validationTransaction,\n errors: preValidationErrors\n } = prevalidatedResult;\n\n const propertyDescriptorToErrorMap = new WeakMap<\n PropertyDescriptor<any, any, any>,\n PropertyValidationResult<any, any>\n >() as any;\n\n const invalidResults = new Set<PropertyValidationResult<any, any>>();\n\n const { doNotStopOnFirstError, rootValidationObject } =\n prevalidationContext;\n\n const rootPropertyDescriptor: PropertyDescriptor<any, any, undefined> =\n prevalidationContext.rootPropertyDescriptor as any;\n\n const currentPropertyDescriptor: PropertyDescriptor<any, any, unknown> =\n prevalidationContext.currentPropertyDescriptor as any;\n\n const addErrorFor = (\n propertyDescriptor: PropertyDescriptor<any, any, any>,\n message: string,\n parentPropertyDescriptor?: PropertyDescriptor<any, any, any>\n ) => {\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n propertyDescriptor\n )\n ) {\n throw new Error('invalid property descriptor');\n }\n\n let validationError: PropertyValidationResult<any, any> =\n propertyDescriptorToErrorMap.has(propertyDescriptor)\n ? propertyDescriptorToErrorMap.get(propertyDescriptor)\n : (null as any);\n\n if (!validationError) {\n validationError = new PropertyValidationResult(\n propertyDescriptor as any,\n rootValidationObject\n );\n\n propertyDescriptorToErrorMap.set(\n propertyDescriptor,\n validationError\n );\n }\n\n validationError.addError(message);\n invalidResults.add(validationError);\n\n if (\n parentPropertyDescriptor &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n parentPropertyDescriptor\n )\n ) {\n let parentValidationError: PropertyValidationResult<any, any> =\n propertyDescriptorToErrorMap.has(parentPropertyDescriptor)\n ? propertyDescriptorToErrorMap.get(\n parentPropertyDescriptor\n )\n : (null as any);\n\n if (!parentValidationError) {\n parentValidationError = new PropertyValidationResult(\n parentPropertyDescriptor as any,\n rootValidationObject\n );\n propertyDescriptorToErrorMap.set(\n parentPropertyDescriptor,\n parentValidationError\n );\n }\n\n parentValidationError.addChildError(validationError);\n }\n };\n\n const getErrorsFor = (<\n TPropertySchema extends SchemaBuilder<any, any, any, any, any>\n >(\n selector?: (\n properties: PropertyDescriptorTree<any>\n ) => PropertyDescriptor<any, TPropertySchema, any>\n ): PropertyValidationResult<any, any> => {\n const descriptor: PropertyDescriptor<any, any, any> =\n typeof selector === 'function'\n ? selector(currentPropertyDescriptor as any)\n : currentPropertyDescriptor;\n\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n descriptor as any\n )\n ) {\n throw new Error('invalid property descriptor');\n }\n\n if (!propertyDescriptorToErrorMap.has(descriptor)) {\n propertyDescriptorToErrorMap.set(\n descriptor,\n new PropertyValidationResult(\n descriptor as any,\n rootValidationObject\n )\n );\n }\n\n return propertyDescriptorToErrorMap.get(descriptor);\n }) as any;\n\n const getInvalidProperties = () =>\n [...invalidResults].filter(r => r.errors.length > 0);\n\n const errors = prevalidatedResult.errors || [];\n\n /**\n * Routes a pre-validation error through `addErrorFor`, respecting\n * the optional `property` selector on `ValidationError`.\n */\n const routePreValidationError = (error: {\n message: string;\n property?: (tree: any) => any;\n }) => {\n if (\n typeof error.property === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n currentPropertyDescriptor\n )\n ) {\n const targetDescriptor = error.property(\n currentPropertyDescriptor\n );\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n targetDescriptor\n )\n ) {\n addErrorFor(\n targetDescriptor,\n error.message,\n currentPropertyDescriptor\n );\n return;\n }\n }\n // Fallback: attach to root descriptor\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n currentPropertyDescriptor\n )\n ) {\n addErrorFor(currentPropertyDescriptor, error.message);\n }\n };\n\n if (!valid && !doNotStopOnFirstError && preValidationErrors) {\n for (const error of preValidationErrors) {\n routePreValidationError(error);\n }\n\n return {\n earlyReturn: true as const,\n result: {\n valid,\n errors: preValidationErrors,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n // When doNotStopOnFirstError is true and there are pre-validation\n // errors (e.g. from addValidator), route them through addErrorFor\n // so they are visible via getErrorsFor().\n if (doNotStopOnFirstError && preValidationErrors) {\n for (const error of preValidationErrors) {\n routePreValidationError(error);\n }\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = validationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: validationTransaction!.commit().validatedObject,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (typeof objToValidate !== 'object' || objToValidate === null) {\n // Only add \"must be an object\" when there is no prior error (e.g.\n // a required-violation error already pushed by preValidateAsync).\n if (errors.length === 0) {\n errors.push({\n message: MUST_BE_AN_OBJECT_ERROR_MESSSAGE\n });\n addErrorFor(\n currentPropertyDescriptor,\n MUST_BE_AN_OBJECT_ERROR_MESSSAGE\n );\n }\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors: doNotStopOnFirstError ? errors : [errors[0]],\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n const propKeys = this.#propKeys;\n const objKeys = Object.keys(objToValidate as Object);\n\n if (propKeys.length === 0) {\n if (objKeys.length === 0) {\n if (doNotStopOnFirstError && errors.length > 0) {\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n if (validationTransaction) {\n validationTransaction.commit().validatedObject;\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: {} as any,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (!this.#acceptUnknownProps) {\n for (let i = 0; i < objKeys.length; i++) {\n const message = `unknown property '${objKeys[i]}'`;\n errors.push({\n message\n });\n if (!doNotStopOnFirstError) {\n break;\n }\n }\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: false,\n errors: doNotStopOnFirstError ? errors : [errors[0]],\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n if (validationTransaction) {\n validationTransaction.commit();\n }\n return {\n earlyReturn: true as const,\n result: {\n valid: true,\n object: { ...objToValidate } as any,\n getErrorsFor,\n getInvalidProperties\n }\n };\n }\n\n return {\n earlyReturn: false as const,\n errors,\n objToValidate,\n propKeys,\n objKeys,\n addErrorFor,\n getErrorsFor,\n getInvalidProperties,\n doNotStopOnFirstError: !!doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor,\n validationTransaction: validationTransaction!\n };\n }\n\n /**\n * Shared post-property-validation processing for both `validate` and\n * `validateAsync`. Handles unknown-property checks, error aggregation,\n * commit/rollback, and the final result construction.\n */\n #processResults(\n setup: {\n errors: any[];\n objToValidate: any;\n propKeys: string[];\n objKeys: string[];\n addErrorFor: (\n propertyDescriptor: PropertyDescriptor<any, any, any>,\n message: string,\n parentPropertyDescriptor?: PropertyDescriptor<any, any, any>\n ) => void;\n getErrorsFor: any;\n getInvalidProperties: any;\n doNotStopOnFirstError: boolean;\n rootPropertyDescriptor: any;\n currentPropertyDescriptor: any;\n validationTransaction: any;\n },\n validationResults: { key: string; result: ValidationResult<any> }[]\n ): ObjectSchemaValidationResult<any, any> {\n const {\n objToValidate,\n objKeys,\n addErrorFor,\n getErrorsFor,\n getInvalidProperties,\n doNotStopOnFirstError,\n currentPropertyDescriptor,\n validationTransaction\n } = setup;\n\n const errors = setup.errors;\n\n let hasInvalid = false;\n for (const { result } of validationResults) {\n if (!result.valid) {\n hasInvalid = true;\n if (Array.isArray(result.errors)) {\n for (const error of result.errors) {\n errors.push(error);\n }\n }\n }\n }\n\n for (let i = 0; i < objKeys.length; i++) {\n const key = objKeys[i];\n if (!(key in this.#properties) && !this.#acceptUnknownProps) {\n const message = `unknown property '${key}'`;\n errors.push({\n message\n });\n addErrorFor(currentPropertyDescriptor, message);\n if (!doNotStopOnFirstError) {\n if (validationTransaction) {\n validationTransaction.rollback();\n }\n return {\n valid: false,\n errors: [errors[0]],\n getErrorsFor,\n getInvalidProperties\n };\n }\n }\n }\n\n if (!hasInvalid && errors.length === 0) {\n const resultObject: Record<string, any> = {};\n for (const { key, result } of validationResults) {\n resultObject[key] = result.object;\n }\n if (this.#acceptUnknownProps) {\n for (const key of objKeys) {\n if (!(key in this.#properties)) {\n resultObject[key] = objToValidate[key];\n }\n }\n }\n return {\n valid: true,\n object: resultObject,\n getErrorsFor,\n getInvalidProperties\n };\n }\n\n for (const { key, result } of validationResults) {\n if (!result.valid) {\n const descriptor = (currentPropertyDescriptor as any)[key];\n if (\n typeof (result as any).getErrorsFor === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)\n ) {\n ObjectSchemaBuilder.#propagateNestedErrors(\n result as any,\n descriptor,\n addErrorFor\n );\n // For extern schemas, also record errors on the extern\n // descriptor itself so getErrorsFor(t => t.extern) works,\n // and pass the parent so getErrorsFor(t => t) is aware.\n if (\n Array.isArray(\n (result as any).__externErrorPropertyNames\n ) &&\n Array.isArray(result.errors)\n ) {\n for (const error of result.errors) {\n addErrorFor(\n descriptor,\n error.message,\n currentPropertyDescriptor\n );\n }\n }\n } else if (Array.isArray(result.errors)) {\n if (\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n descriptor\n )\n ) {\n for (const error of result.errors) {\n addErrorFor(descriptor, error.message);\n }\n if (\n Array.isArray((result as any).getNestedErrors?.())\n ) {\n ObjectSchemaBuilder.#propagateIndexedErrors(\n result,\n descriptor,\n addErrorFor\n );\n }\n }\n }\n }\n }\n\n validationTransaction!.rollback();\n\n return {\n valid: false,\n errors: doNotStopOnFirstError\n ? errors\n : errors[0]\n ? [errors[0]]\n : [],\n getErrorsFor,\n getInvalidProperties\n };\n }\n\n /**\n * Adds a `validator` to validators list.\n *\n * Object-level validators can return errors with a `property` selector\n * to route the error to a specific property, making it visible via\n * `getErrorsFor()`.\n *\n * ```ts\n * schema.addValidator((value) => ({\n * valid: false,\n * errors: [{\n * message: 'Passwords do not match',\n * property: (t) => t.confirmPassword\n * }]\n * }));\n * ```\n *\n * The `property` selector uses the same `PropertyDescriptorTree`\n * as `getErrorsFor()` and react-form's `forProperty`.\n */\n public addValidator(\n validator: (\n object: undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n RespectPropsOptionality<TProperties>\n >\n : TExplicitType\n ) =>\n | {\n valid: boolean;\n errors?: Array<{\n message: string;\n property?: (\n properties: PropertyDescriptorTree<\n ObjectSchemaBuilder<TProperties>\n >\n ) => PropertyDescriptor<any, any, any>;\n }>;\n }\n | Promise<{\n valid: boolean;\n errors?: Array<{\n message: string;\n property?: (\n properties: PropertyDescriptorTree<\n ObjectSchemaBuilder<TProperties>\n >\n ) => PropertyDescriptor<any, any, any>;\n }>;\n }>,\n options?: { mutates?: boolean }\n ): this {\n return super.addValidator(validator as any, options);\n }\n\n /**\n * Performs synchronous validation of object schema over the `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n *\n * The returned result includes a `getErrorsFor()` method for type-safe,\n * per-property error inspection.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n public validate(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n > {\n return super.validate(object, context) as any;\n }\n\n /**\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n public async validateAsync(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): Promise<\n ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n >\n > {\n return super.validateAsync(object, context) as any;\n }\n\n /**\n * Performs synchronous validation of object schema over the `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n *\n * The returned result includes a `getErrorsFor()` method for type-safe,\n * per-property error inspection.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n protected _validate(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n > {\n // Fast path: skip preValidateSync + setupValidation when no preprocessors/validators\n if (\n this.canSkipPreValidation &&\n !context?.doNotStopOnFirstError &&\n !context?.rootPropertyDescriptor\n ) {\n // Required / optional check\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue() as typeof object;\n } else if (\n !this.isRequired ||\n (object === null && this.isNullable)\n ) {\n const self = this;\n return {\n valid: true,\n object: object,\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n } else {\n const self = this;\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n this.requiredErrorMessage,\n object as any\n )\n }\n ],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n } else if (typeof object === 'object') {\n const propKeys = this.#propKeys;\n\n // Check for unknown properties\n if (!this.#acceptUnknownProps) {\n const objKeys = Object.keys(object as Record<string, any>);\n for (let i = 0; i < objKeys.length; i++) {\n if (!(objKeys[i] in this.#properties)) {\n const self = this;\n return {\n valid: false,\n errors: [\n {\n message: `unknown property '${objKeys[i]}'`\n }\n ],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n }\n }\n\n // Validate all properties inline — no path passed to children\n const resultObject: Record<string, any> = {};\n for (let i = 0; i < propKeys.length; i++) {\n const key = propKeys[i];\n const result = this.#properties[key].validate(\n (object as any)[key]\n );\n if (!result.valid) {\n const self = this;\n return {\n valid: false,\n errors:\n result.errors && result.errors.length > 0\n ? [result.errors[0]]\n : [],\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n resultObject[key] = result.object;\n }\n\n // Copy unknown props if accepted\n if (this.#acceptUnknownProps) {\n const objKeys = Object.keys(object as Record<string, any>);\n for (let i = 0; i < objKeys.length; i++) {\n if (!(objKeys[i] in this.#properties)) {\n resultObject[objKeys[i]] = (object as any)[\n objKeys[i]\n ];\n }\n }\n }\n\n // Lazy getErrorsFor — only builds descriptors if called\n const self = this;\n return {\n valid: true,\n object: resultObject,\n getErrorsFor(selector?: any) {\n return self\n .#validateFull(object, context)\n .getErrorsFor(selector);\n },\n getInvalidProperties() {\n return self\n .#validateFull(object, context)\n .getInvalidProperties();\n }\n } as any;\n }\n }\n\n return this.#validateFull(object, context) as any;\n }\n\n /**\n * Full validation path with complete error handling and property descriptors.\n */\n #validateFull(\n object: any,\n context?: ValidationContext<this>\n ): ObjectSchemaValidationResult<any, any> {\n const setup = this.#setupValidation(\n this.preValidateSync(object, context)\n );\n if (setup.earlyReturn) return setup.result as any;\n\n const {\n propKeys,\n objToValidate,\n doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor\n } = setup;\n\n const validationResults: {\n key: string;\n result: ValidationResult<any>;\n }[] = [];\n for (const key of propKeys) {\n const result = this.#properties[key].validate(objToValidate[key], {\n ...context,\n rootPropertyDescriptor: rootPropertyDescriptor as any,\n currentPropertyDescriptor: (currentPropertyDescriptor as any)[\n key\n ]\n });\n validationResults.push({ key, result });\n if (!result.valid && !doNotStopOnFirstError) break;\n }\n\n return this.#processResults(setup, validationResults) as any;\n }\n\n /**\n * Performs async validation of object schema over the `object`.\n * Supports async preprocessors, validators, and error message providers.\n *\n * @param object The object to validate against this schema.\n * @param context Optional `ValidationContext` settings.\n */\n protected async _validateAsync(\n object: undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionalityForInput<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n context?: ValidationContext<this>\n ): Promise<\n ObjectSchemaValidationResult<\n undefined extends TExplicitType\n ? InferType<\n SchemaBuilder<\n undefined extends TExplicitType\n ? Id<RespectPropsOptionality<TProperties>>\n : TExplicitType,\n TRequired\n >\n >\n : TExplicitType,\n this\n >\n > {\n const setup = this.#setupValidation(\n await this.preValidateAsync(object, context)\n );\n if (setup.earlyReturn) return setup.result as any;\n\n const {\n propKeys,\n objToValidate,\n doNotStopOnFirstError,\n rootPropertyDescriptor,\n currentPropertyDescriptor\n } = setup;\n\n const validationResults: {\n key: string;\n result: ValidationResult<any>;\n }[] = [];\n\n if (doNotStopOnFirstError) {\n const results = await Promise.all(\n propKeys.map(async key => {\n const result = await this.#properties[key].validateAsync(\n objToValidate[key],\n {\n ...context,\n rootPropertyDescriptor:\n rootPropertyDescriptor as any,\n currentPropertyDescriptor: (\n currentPropertyDescriptor as any\n )[key]\n }\n );\n return { key, result };\n })\n );\n validationResults.push(...results);\n } else {\n for (const key of propKeys) {\n const result = await this.#properties[key].validateAsync(\n objToValidate[key],\n {\n ...context,\n rootPropertyDescriptor: rootPropertyDescriptor as any,\n currentPropertyDescriptor: (\n currentPropertyDescriptor as any\n )[key]\n }\n );\n validationResults.push({ key, result });\n if (!result.valid) break;\n }\n }\n\n return this.#processResults(setup, validationResults) as any;\n }\n\n /**\n * Fields not defined in `properties` will not be validated\n * and will be passed through the validation.\n */\n public acceptUnknownProps(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n acceptUnknownProps: true\n } as any) as any;\n }\n\n /**\n * Fields not defined in `properties` will be considered\n * as schema violation. This is the default behavior.\n */\n public notAcceptUnknownProps(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n acceptUnknownProps: false\n } as any) as any;\n }\n\n /**\n * @inheritdoc\n */\n public hasType<T>(\n _notUsed?: T\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n T,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * @inheritdoc\n */\n public clearHasType(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * Appends a constructor overload to the object schema.\n *\n * Each call extends the set of construct signatures on the inferred type by\n * one overload. The accumulated argument lists are taken from the\n * `FunctionSchemaBuilder` passed in — specifically from the positional\n * parameter schemas registered via `.addParameter()`.\n *\n * At **runtime** the schema continues to validate plain objects; the\n * constructor information is purely a TypeScript-level annotation and is\n * stored in `introspect().constructorSchemas` for tooling use.\n *\n * Multiple calls are supported and produce **overloaded** construct\n * signatures in the inferred type, modelling a class that exposes several\n * constructor overloads.\n *\n * @param schema - A `FunctionSchemaBuilder` describing one constructor\n * overload. Use `.addParameter()` on the function schema to declare the\n * parameter types. The return type, if set via `.hasReturnType()`, is\n * ignored — the return type of a constructor is always the instance type\n * derived from the object schema's properties.\n *\n * @returns A new `ObjectSchemaBuilder` whose `TConstructorSchemas` tuple has\n * been extended by `schema`, updating `InferType` to include the new\n * construct signature.\n *\n * @example\n * ```ts\n * import { object, string, number, func, InferType } from '@cleverbrush/schema';\n *\n * // Single constructor\n * const PersonSchema = object({ name: string(), age: number() })\n * .addConstructor(\n * func().addParameter(string()).addParameter(number())\n * );\n *\n * type Person = InferType<typeof PersonSchema>;\n * // → { new (p0: string, p1: number): { name: string; age: number } }\n * // & { name: string; age: number }\n * ```\n *\n * @example\n * ```ts\n * import { object, string, number, func, InferType } from '@cleverbrush/schema';\n *\n * // Multiple constructors via chained calls → overloaded signatures\n * const PointSchema = object({ x: number(), y: number() })\n * .addConstructor(func()) // no-arg ctor\n * .addConstructor(func().addParameter(number()).addParameter(number())); // (x, y) ctor\n *\n * type Point = InferType<typeof PointSchema>;\n * // → { new (): { x: number; y: number } }\n * // & { new (p0: number, p1: number): { x: number; y: number } }\n * // & { x: number; y: number }\n *\n * // Validation still operates on plain objects — the constructor type is\n * // a compile-time annotation only.\n * const result = PointSchema.validate({ x: 1, y: 2 });\n * // result.valid === true\n *\n * // Introspect the registered constructor schemas at runtime:\n * const info = PointSchema.introspect();\n * // info.constructorSchemas.length === 2\n * ```\n */\n public addConstructor<TFunc extends SchemaBuilder<any, any, any, any, any>>(\n schema: TFunc\n ): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n [...TConstructorSchemas, TFunc]\n > &\n TExtensions {\n if (!(schema instanceof SchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the SchemaBuilder class'\n );\n }\n\n return this.derive({\n ...this.introspect(),\n constructorSchemas: [...this.#constructorSchemas, schema]\n } as any) as any;\n }\n\n /**\n * Removes all constructor overloads previously registered via\n * `.addConstructor()`, resetting the `TConstructorSchemas` tuple to `[]`.\n *\n * After calling this method `InferType` reverts to the plain object type\n * derived from the schema's properties — no construct signatures are\n * included.\n *\n * `introspect().constructorSchemas` will return an empty array.\n *\n * @returns A new `ObjectSchemaBuilder` with `TConstructorSchemas = []`.\n *\n * @example\n * ```ts\n * import { object, string, func, InferType } from '@cleverbrush/schema';\n *\n * const WithCtor = object({ name: string() })\n * .addConstructor(func().addParameter(string()));\n *\n * type WithCtorType = InferType<typeof WithCtor>;\n * // → { new (p0: string): { name: string } } & { name: string }\n *\n * const Plain = WithCtor.clearConstructors();\n *\n * type PlainType = InferType<typeof Plain>;\n * // → { name: string }\n *\n * Plain.introspect().constructorSchemas; // []\n * ```\n */\n public clearConstructors(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n []\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n constructorSchemas: []\n } as any) as any;\n }\n\n /**\n * Adds a new property to the object schema. The new property\n * will be validated according to the provided schema.\n * @param propName name of the new property\n * @param schema schema builder of the new property\n */\n public addProp<\n TType extends SchemaBuilder<any, any, any, any, any>,\n TName extends string\n >(\n propName: TName,\n schema: TType\n ): ObjectSchemaBuilder<\n TProperties & {\n [k in TName]: TType;\n },\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n if (typeof propName !== 'string' || !propName) {\n throw new Error('propName must be a non empty string');\n }\n if (propName in this.#properties) {\n throw new Error(`Property ${propName} already exists`);\n }\n if (!(schema instanceof SchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the SchemaBuilder class'\n );\n }\n\n return this.derive({\n ...this.introspect(),\n properties: {\n ...this.introspect().properties,\n [propName]: schema\n }\n } as any) as any;\n }\n\n /**\n * @hidden\n * @deprecated this is for internal use, do not use if you are\n * not sure you need it.\n *\n * TODO: This is used to avoid `&` in resulting types. For example,\n * when you have a schema like `object({prop1: string()})` and then use `addProp({prop2: string()})` method,\n * the resulting type without `optimize` will be something like `{prop1: string} & {prop2: string}`. Which\n * is not we would like to have. Instead we want to have `{prop1: string, prop2: string}`. This is what\n * `optimize` method does. However it is not always possible to do this optimization without losing\n * JSDoc comments, which is sucks. For example, I had to disable optimization for UnionSchemas, because\n * comments were lost. Hopefully it will be fixed in the future by Typescript team or somebody will\n * find a workaround/fix and create a pull request.\n */\n public optimize(): SchemaBuilder<\n undefined extends TExplicitType\n ? WithConstructors<\n TConstructorSchemas,\n Id<RespectPropsOptionality<TProperties>>\n >\n : TExplicitType,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > {\n return this.derive(\n {\n ...this.introspect()\n } as any,\n true\n ) as any;\n }\n\n /**\n * Adds new properties to the object schema. The same as `.addProp()` but\n * allows to add multiple properties with one call. The new properties\n * will be validated according to the provided schemas.\n * @param props a key/schema object map.\n */\n public addProps<\n TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>\n >(\n props: TProps\n ): ObjectSchemaBuilder<\n TProperties & TProps,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n /**\n * Adds all properties from the `schema` object schema to the current schema.\n * @param schema an instance of `ObjectSchemaBuilder`\n */\n public addProps<\n K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: K\n ): K extends ObjectSchemaBuilder<infer TProp, infer _, any, infer __>\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProp> & TProp,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n public addProps(props: any) {\n if (props instanceof ObjectSchemaBuilder) {\n return this.addProps(props.introspect().properties);\n }\n\n if (typeof props !== 'object') {\n throw new Error('props should be an object');\n }\n if (props === null) {\n throw new Error('props should not be null');\n }\n\n const newProps = { ...this.#properties } as any;\n\n for (const key in props) {\n if (key in this.#properties) {\n throw new Error(`property '${key}' already exists`);\n }\n\n if (!(props[key] instanceof SchemaBuilder)) {\n throw new Error(`${key} is not a SchemaBuilder`);\n }\n\n newProps[key] = props[key] as any;\n }\n\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Omits properties listed in `properties` from the schema.\n * Consider `Omit<Type, 'prop1'|'prop2'...>` as a good illustration\n * from the TS world.\n * @param properties - array of property names (strings) to remove from the schema.\n */\n public omit<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Omit<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Removes `propName` from the list of properties.\n * @param propName property name to remove. Schema should contain\n * this property. An error will be thrown otherwise.\n */\n public omit<TProperty extends keyof TProperties>(\n propName: TProperty\n ): ObjectSchemaBuilder<\n Omit<TProperties, TProperty>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Removes all properties of `schema` from the current schema.\n * `Omit<TSchema, keyof TAnotherSchema>` as a good illustration\n * from the TS world.\n * @param schema schema builder to take properties from.\n */\n public omit<T>(\n schema: T\n ): T extends ObjectSchemaBuilder<\n infer TProps,\n infer TRequired,\n any,\n infer TExplicitType\n >\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProps>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n public omit(propNameOrArrayOrPropsOrBuilder: any): any {\n if (typeof propNameOrArrayOrPropsOrBuilder === 'string') {\n // remove one field\n const propName =\n propNameOrArrayOrPropsOrBuilder as keyof TProperties;\n\n if (!propName || !(propName in this.#properties)) {\n throw new Error(\n `property ${propName.toString()} does not exists in the schema`\n );\n }\n\n return this.derive({\n ...this.introspect(),\n properties: (() => {\n const result = { ...this.#properties };\n delete result[propName];\n return result;\n })()\n } as any);\n } else if (Array.isArray(propNameOrArrayOrPropsOrBuilder)) {\n const propsArray = propNameOrArrayOrPropsOrBuilder as Array<\n keyof TProperties\n >;\n\n const distinctKeys = new Map<keyof TProperties, true>();\n propsArray.forEach(key => {\n if (typeof key !== 'string' || !key) {\n throw new Error('property name must be a string');\n }\n\n if (!(key in this.#properties)) {\n throw new Error(\n `property ${key.toString()} does not exists in the schema`\n );\n }\n\n distinctKeys.set(key.toString(), true);\n });\n\n if (distinctKeys.size === 0) {\n throw new Error('please provide at least one property to omit');\n }\n\n const props = {\n ...this.introspect()\n };\n\n for (const key of distinctKeys.keys()) {\n delete props.properties[key];\n }\n\n return this.derive(props as any);\n } else if (\n propNameOrArrayOrPropsOrBuilder instanceof ObjectSchemaBuilder\n ) {\n const propsToOmit = {\n ...propNameOrArrayOrPropsOrBuilder.introspect().properties\n };\n\n const props = {\n ...this.introspect()\n };\n\n for (const key in propsToOmit) {\n if (key in props.properties) {\n delete props.properties[key];\n }\n }\n\n return this.derive(props as any);\n }\n\n throw new Error('this parameter type is not supported');\n }\n\n /**\n * Adds all properties from `schema` to the current schema.\n * `TSchema & TAnotherSchema` is a good example of the similar concept\n * in the TS type system.\n * @param schema an object schema to take properties from\n */\n public intersect<\n T extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: T\n ): T extends ObjectSchemaBuilder<\n infer TProps,\n infer _,\n any,\n infer TExplType\n >\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof TProps> & TProps,\n TRequired,\n TNullable,\n TExplType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never {\n if (!(schema instanceof ObjectSchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the ObjectSchemaBuilder class'\n );\n }\n\n const remoteProps = schema.introspect().properties;\n\n const localProps = this.introspect();\n\n const newProps = Object.keys(localProps.properties).reduce(\n (acc, curr) => {\n acc[curr] =\n curr in remoteProps\n ? remoteProps[curr]\n : localProps.properties[curr];\n return acc;\n },\n {} as Record<string, any>\n );\n\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Marks all properties in the current schema as optional.\n * It is the same as call `.optional('propname')` where `propname` is the name\n * of every property in the schema.\n */\n public partial(): ObjectSchemaBuilder<\n MakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Marks all properties from `properties` as optional in the schema.\n * @param properties list of property names (string) to make optional\n */\n public partial<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Omit<TProperties, K> & Pick<MakeChildrenOptional<TProperties>, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Marks property `propName` as optional in the schema.\n * @param propName the name of the property (string).\n */\n public partial<TProperty extends keyof TProperties>(\n propName: TProperty\n ): ObjectSchemaBuilder<\n Omit<TProperties, TProperty> &\n Pick<MakeChildrenOptional<TProperties>, TProperty>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n public partial(propNameOrArray?: any): any {\n if (\n typeof propNameOrArray === 'undefined' ||\n propNameOrArray === null\n ) {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, key) => {\n acc[key] = this.#properties[key].optional();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any);\n }\n\n if (Array.isArray(propNameOrArray)) {\n const propsArray = propNameOrArray as (keyof TProperties)[];\n if (propsArray.length === 0) {\n throw new Error('properties cannot be empty');\n }\n\n const newProps = {\n ...this.introspect()\n } as any;\n\n propsArray.forEach(key => {\n if (typeof key !== 'string') {\n throw new Error(\n 'each propery in property list must be as string value'\n );\n }\n if (!(key in newProps.properties)) {\n throw new Error(\n `property ${key as string} does not exists`\n );\n }\n\n newProps.properties[key as keyof TProperties] =\n newProps.properties[key].optional();\n });\n\n return this.derive(newProps);\n }\n\n if (typeof propNameOrArray === 'string') {\n return this.modifyPropSchema(\n propNameOrArray as keyof TProperties,\n schema => schema.optional()\n );\n }\n\n throw new Error('expecting string or string[] parameter');\n }\n\n /**\n * Recursively marks all properties — and all properties of nested\n * `object()` schemas — as optional. Useful for PATCH API bodies\n * and partial form state where every field at every level is optional.\n *\n * Only nested `ObjectSchemaBuilder` schemas are recursed into.\n * Other schema types (arrays, unions, primitives, lazy) are made\n * optional at the top level but their internals are not modified.\n *\n * @example\n * ```ts\n * const Address = object({\n * street: string(),\n * city: string()\n * });\n *\n * const User = object({\n * name: string(),\n * address: Address\n * });\n *\n * const PatchUser = User.deepPartial();\n * // PatchUser infers as:\n * // { name?: string; address?: { street?: string; city?: string } }\n *\n * PatchUser.validate({ address: { city: 'Paris' } }); // valid\n * PatchUser.validate({}); // valid\n * ```\n *\n * @example\n * ```ts\n * // Three-level nesting\n * const schema = object({\n * a: object({\n * b: object({ c: string() })\n * })\n * }).deepPartial();\n *\n * schema.validate({}); // valid\n * schema.validate({ a: {} }); // valid\n * schema.validate({ a: { b: {} } }); // valid\n * ```\n *\n * @example\n * ```ts\n * // PATCH API body\n * const CreateBody = object({\n * profile: object({ displayName: string(), bio: string() }),\n * settings: object({ theme: string(), language: string() })\n * });\n *\n * const PatchBody = CreateBody.deepPartial();\n * // All fields are optional at every level —\n * // send only what you want to update.\n * ```\n *\n * @see {@link partial} for shallow-only property optionality.\n */\n public deepPartial(): ObjectSchemaBuilder<\n DeepMakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n const newProps: Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {};\n for (const key of Object.keys(this.#properties)) {\n const prop = this.#properties[key];\n if (prop instanceof ObjectSchemaBuilder) {\n newProps[key] = (\n prop as ObjectSchemaBuilder<any, any, any, any, any>\n )\n .deepPartial()\n .optional();\n } else {\n newProps[key] = prop.optional();\n }\n }\n return this.derive({\n ...this.introspect(),\n properties: newProps\n } as any) as any;\n }\n\n /**\n * Returns a new schema containing only properties listed in\n * `properties` array.\n * @param properties array of property names (strings)\n */\n public pick<K extends keyof TProperties>(\n properties: K[]\n ): ObjectSchemaBuilder<\n Pick<TProperties, K>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n /**\n * Returns new schema based on the current schema. This new schema\n * will consists only from properties which names are taken from the\n * `schema` object schema.\n * @param schema schema to take property names list from\n */\n public pick<\n K extends ObjectSchemaBuilder<any, any, any, any, any, any, any>\n >(\n schema: K\n ): K extends ObjectSchemaBuilder<infer TProps, infer _, any, infer __>\n ? ObjectSchemaBuilder<\n Omit<TProperties, keyof Omit<TProperties, keyof TProps>>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions\n : never;\n\n /**\n * Returns a new schema consisting of only one property\n * (taken from the `property` property name). If the property\n * does not exists in the current schema, an error will be thrown.\n * @param property the name of the property (string).\n */\n public pick<K extends keyof TProperties>(\n property: K\n ): ObjectSchemaBuilder<\n Pick<TProperties, K>,\n TRequired,\n TNullable,\n undefined,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions;\n\n public pick(properties: any): any {\n if (typeof properties === 'string') {\n const property = properties as string;\n\n if (!property) {\n throw new Error('property cannot be empty');\n }\n\n if (!(property in this.#properties)) {\n throw new Error(`property ${property} does not exists`);\n }\n\n return this.derive({\n ...this.introspect(),\n properties: {\n [property]: this.#properties[property]\n }\n } as any);\n }\n\n if (Array.isArray(properties)) {\n if (properties.length === 0) {\n throw new Error('properties must be a non empty erray');\n }\n const newProperties = properties.reduce((acc, curr) => {\n if (typeof curr !== 'string' || !curr) {\n throw new Error(\n 'each property name must be a non empty string'\n );\n }\n if (!(curr in this.#properties)) {\n throw new Error(`property ${curr} does not exists`);\n }\n\n acc[curr] = this.#properties[curr];\n return acc;\n }, {});\n\n return this.derive({\n ...this.introspect(),\n properties: newProperties\n } as any);\n }\n\n if (properties instanceof ObjectSchemaBuilder) {\n const externalSchema = properties as ObjectSchemaBuilder;\n\n const props = Object.keys(\n externalSchema.introspect().properties\n ).filter(p => typeof this.#properties[p] !== 'undefined');\n if (props.length === 0) {\n throw new Error(\n 'there are no common properties in provided schemas'\n );\n }\n return this.pick(props as any as keyof TProperties);\n }\n\n throw new Error('string, array or ObjectSchemaBuilder is expected');\n }\n\n /**\n * Modify schema for `propName` and return a new schema.\n * Could be useful if you want to leave all schema intact, but\n * change a type of one property.\n * @param propName name of the property (string)\n * @param callback callback function returning a new schema fo the `propName`. As a first parameter\n * you will receive an old schema for `propName`.\n * @returns\n */\n public modifyPropSchema<\n K extends keyof TProperties,\n R extends SchemaBuilder<any, any, any, any, any>\n >(\n propName: K,\n callback: (builder: TProperties[K]) => R\n ): ObjectSchemaBuilder<\n ModifyPropSchema<TProperties, K, R>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n if (typeof propName !== 'string' || !propName) {\n throw new Error('propName must be a non empty string');\n }\n\n if (!(propName in this.#properties)) {\n throw new Error(\n `property ${propName} does not exists in the schema`\n );\n }\n\n if (typeof callback !== 'function') {\n throw new Error('callback must be a function');\n }\n\n const callbackResult = callback(this.#properties[propName]);\n if (!(callbackResult instanceof SchemaBuilder)) {\n throw new Error('callback must return a SchemaBuilder object');\n }\n\n const props = {\n ...this.introspect()\n } as any;\n\n props.properties = {\n ...props.properties,\n [propName]: callbackResult\n };\n\n return this.derive(props) as any;\n }\n\n /**\n * An alias for `.partial(prop: string)`\n * @param prop name of the property\n */\n public makePropOptional<K extends keyof TProperties>(\n prop: K\n ): ObjectSchemaBuilder<\n MakeChildOptional<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.modifyPropSchema(prop, builder =>\n builder.optional()\n ) as any;\n }\n\n /**\n * Marks `prop` as required property.\n * If `prop` does not exists in the current schema,\n * an error will be thrown.\n * @param prop name of the property\n */\n public makePropRequired<K extends keyof TProperties>(\n prop: K\n ): ObjectSchemaBuilder<\n MakeChildRequired<TProperties, K>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.modifyPropSchema(prop, builder =>\n builder.required()\n ) as any;\n }\n\n /**\n * `Partial<T>` would be a good example of the\n * same operation in the TS world.\n */\n public makeAllPropsOptional(): ObjectSchemaBuilder<\n MakeChildrenOptional<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, curr) => {\n acc[curr] = this.#properties[curr].optional();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any) as any;\n }\n\n /**\n * `Required<T>` would be a good example of the\n * same operation in the TS world.\n */\n public makeAllPropsRequired(): ObjectSchemaBuilder<\n MakeChildrenRequired<TProperties>,\n TRequired,\n TNullable,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > &\n TExtensions {\n return this.derive({\n ...this.introspect(),\n properties: Object.keys(this.#properties).reduce(\n (acc, curr) => {\n acc[curr] = this.#properties[curr].required();\n return acc;\n },\n {} as Record<string, any>\n )\n } as any) as any;\n }\n\n static #getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(\n schema: TSchema,\n /* this is to make possibility to traverse the tree and select properties */\n selector?: (arg1: any, arg2: any) => any,\n /* parent object to have a possibility to get link to itself */\n parentSelector?: any,\n /* used to pass the needed property name if `parentSelector` is provided. */\n currentName?: string,\n parentDescriptor?: PropertyDescriptorInner<any, any, any>\n ): PropertyDescriptorTree<TSchema> {\n const introspected = schema.introspect();\n if (!introspected.properties) {\n return {} as any;\n }\n\n const propsNames = Object.keys(introspected.properties);\n\n if (propsNames.length === 0) {\n return {} as any;\n }\n\n if (typeof selector !== 'function') {\n selector = o => o;\n }\n const result = createPropertyDescriptorFor(\n (obj, createMissingStructure) =>\n (parentSelector || selector)(obj, createMissingStructure),\n currentName,\n schema,\n parentDescriptor\n );\n\n for (const propName of propsNames) {\n const propSchema = introspected.properties[propName];\n if (propSchema instanceof ObjectSchemaBuilder) {\n const childProperties = propSchema.introspect().properties;\n if (\n childProperties &&\n typeof childProperties === 'object' &&\n Object.keys(childProperties).length > 0\n ) {\n (result as any)[propName] = (\n ObjectSchemaBuilder.#getPropertiesFor as any\n )(\n propSchema,\n (tree: any, createMissingStructure: any) => {\n const selectorResult = selector(\n tree,\n createMissingStructure\n );\n if (selectorResult) {\n if (\n createMissingStructure &&\n !selectorResult[propName]\n ) {\n selectorResult[propName] = {};\n }\n return selectorResult[propName];\n }\n return null;\n },\n selector,\n propName,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n } else {\n (result as any)[propName] = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n }\n } else if (propSchema.introspect().type === 'array') {\n (result as any)[propName] = createIndexedDescriptor(\n propSchema,\n selector,\n propName,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n } else if ((propSchema as any)[SYMBOL_HAS_PROPERTIES] === true) {\n // Extern schema — create a Proxy-based descriptor that\n // lazily creates child descriptors on property access.\n const externBase = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n const externValueSelector = (\n tree: any,\n createMissingStructure: boolean\n ) => {\n const selectorResult = selector(\n tree,\n createMissingStructure\n );\n if (selectorResult) {\n if (\n createMissingStructure &&\n !selectorResult[propName]\n ) {\n selectorResult[propName] = {};\n }\n return selectorResult[propName];\n }\n return null;\n };\n (result as any)[propName] = createExternProxyDescriptor(\n externBase,\n externValueSelector\n );\n } else {\n (result as any)[propName] = createPropertyDescriptorFor(\n selector,\n propName,\n propSchema,\n result[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n }\n }\n\n return result as any;\n }\n\n public static getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(schema: TSchema): PropertyDescriptorTree<TSchema, TSchema> {\n if (!(schema instanceof ObjectSchemaBuilder)) {\n throw new Error(\n 'schema must be an instance of the ObjectSchemaBuilder class'\n );\n }\n\n if (schema.#propertyDescriptorTreeMap.has(schema)) {\n return schema.#propertyDescriptorTreeMap.get(schema) as any;\n }\n\n const result = ObjectSchemaBuilder.#getPropertiesFor(schema);\n schema.#propertyDescriptorTreeMap.set(schema, result);\n\n return result;\n }\n\n public static isValidPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ) {\n return (\n typeof descriptor === 'object' &&\n descriptor !== null &&\n typeof descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR] === 'object'\n );\n }\n\n static #propagateNestedErrors(\n result: any,\n descriptor: any,\n addErrorFor: (\n descriptor: any,\n message: string,\n parentDescriptor?: any\n ) => void\n ): void {\n const schema =\n ObjectSchemaBuilder.#getSchemaForPropertyDescriptor(descriptor);\n const properties = (schema.introspect() as any).properties;\n\n // Determine which property names to iterate:\n // • For ObjectSchemaBuilder — use introspect().properties keys\n // • For ExternSchemaBuilder — use __externErrorPropertyNames from the result\n let propertyNames: string[];\n if (properties) {\n propertyNames = Object.keys(properties);\n } else if (Array.isArray((result as any).__externErrorPropertyNames)) {\n propertyNames = (result as any).__externErrorPropertyNames;\n } else {\n return;\n }\n\n for (const nestedPropertyName of propertyNames) {\n const nestedPropertyDescriptor = descriptor[nestedPropertyName];\n if (\n !ObjectSchemaBuilder.isValidPropertyDescriptor(\n nestedPropertyDescriptor\n )\n ) {\n continue;\n }\n const nestedValidationError = result.getErrorsFor(\n () => nestedPropertyDescriptor\n );\n if (!nestedValidationError.isValid) {\n for (const validationError of nestedValidationError.errors) {\n addErrorFor(\n nestedPropertyDescriptor,\n validationError,\n descriptor\n );\n }\n }\n // Indexed descriptors are created lazily, so they are not keys in\n // an object's static property map. Copy precise invalid descriptors\n // below this property as well as the existing aggregate messages.\n if (\n nestedPropertyDescriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n .getSchema()\n ?.introspect().type === 'array' &&\n typeof result.getInvalidProperties === 'function'\n ) {\n const prefix =\n nestedPropertyDescriptor[\n SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR\n ].toJsonPointer() + '/';\n for (const invalid of result.getInvalidProperties()) {\n const pointer = invalid.descriptor.toJsonPointer();\n if (!pointer.startsWith(prefix)) continue;\n const target = pointer\n .slice(prefix.length)\n .split('/')\n .reduce(\n (node: any, part: string) =>\n node?.[\n part.replace(/~1/g, '/').replace(/~0/g, '~')\n ],\n nestedPropertyDescriptor\n );\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(target))\n continue;\n for (const message of invalid.errors)\n addErrorFor(target, message, nestedPropertyDescriptor);\n }\n }\n // Recurse into nested object schemas (only when we have a property map)\n if (properties) {\n const nestedSchema = properties[nestedPropertyName];\n if (\n (nestedSchema instanceof ObjectSchemaBuilder ||\n (nestedSchema as any)[SYMBOL_HAS_PROPERTIES] ===\n true) &&\n typeof result.getErrorsFor === 'function' &&\n ObjectSchemaBuilder.isValidPropertyDescriptor(\n nestedPropertyDescriptor\n )\n ) {\n ObjectSchemaBuilder.#propagateNestedErrors(\n result,\n nestedPropertyDescriptor,\n addErrorFor\n );\n }\n }\n }\n }\n\n /** Propagate structured array results without interpreting message strings. */\n static #propagateIndexedErrors(\n result: any,\n descriptor: any,\n addErrorFor: (descriptor: any, message: string, parent?: any) => void\n ): void {\n const children = result.getNestedErrors?.();\n if (!Array.isArray(children)) return;\n children.forEach((child, index) => {\n const indexed = descriptor[index];\n if (\n !child ||\n child.valid ||\n !ObjectSchemaBuilder.isValidPropertyDescriptor(indexed)\n )\n return;\n if (typeof child.getInvalidProperties === 'function') {\n const prefix =\n indexed[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR].toJsonPointer();\n for (const invalid of child.getInvalidProperties()) {\n const pointer = invalid.descriptor.toJsonPointer();\n const relative =\n pointer === prefix\n ? ''\n : pointer.startsWith(prefix + '/')\n ? pointer.slice(prefix.length)\n : pointer;\n const target =\n relative === ''\n ? indexed\n : relative\n .slice(1)\n .split('/')\n .reduce(\n (node: any, part: string) =>\n node?.[\n part\n .replace(/~1/g, '/')\n .replace(/~0/g, '~')\n ],\n indexed\n );\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(target))\n continue;\n for (const message of invalid.errors)\n addErrorFor(target, message, descriptor);\n }\n } else {\n for (const error of child.errors ?? [])\n addErrorFor(indexed, error.message, descriptor);\n ObjectSchemaBuilder.#propagateIndexedErrors(\n child,\n indexed,\n addErrorFor\n );\n }\n });\n }\n\n static #getSchemaForPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ): SchemaBuilder<any, any, any, any, any> {\n if (!ObjectSchemaBuilder.isValidPropertyDescriptor(descriptor)) {\n throw new Error('descriptor is not a valid property descriptor');\n }\n\n return descriptor[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR].getSchema();\n }\n\n public nullable(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n true,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > {\n return super.nullable() as any;\n }\n\n public notNullable(): ObjectSchemaBuilder<\n TProperties,\n TRequired,\n false,\n TExplicitType,\n THasDefault,\n TExtensions,\n TConstructorSchemas\n > {\n return super.notNullable() as any;\n }\n}\n\nexport interface Object {\n /**\n * Defines a schema for empty object `{}`\n */\n (): ObjectSchemaBuilder<{}, true>;\n /**\n * Defines an object schema, properties definitions are takens from `props`.\n * @param props key/schema object map for schema's properties.\n */\n <TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(\n props: TProps\n ): ObjectSchemaBuilder<TProps, true>;\n /**\n * Defines an object schema, properties definitions are takens from `props`.\n * @param props key/schema object map for schema's properties.\n */\n <TProps extends Record<string, SchemaBuilder<any, any, any, any, any>>>(\n props?: TProps\n ): ObjectSchemaBuilder<TProps, true>;\n /**\n * Returns a tree of property descriptors for the given `schema`.\n * The structure of the tree is the same as the structure of the `schema`.\n * Which gives you an opportunity to access property descriptors for each\n * property in the schema in a useful and type-safe way.\n * @param schema\n */\n getPropertiesFor<\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n >(schema: TSchema): PropertyDescriptorTree<TSchema, TSchema>;\n\n /**\n * Verifies if the given `descriptor` is a valid property descriptor.\n * @param descriptor a property descriptor to check\n */\n isValidPropertyDescriptor(\n descriptor: PropertyDescriptor<any, any, any>\n ): boolean;\n}\n\nconst object = (props => {\n return ObjectSchemaBuilder.create({\n isRequired: true,\n properties: props\n }) as any;\n}) as Object;\n\ntype PropertyDescriptorMap = Map<\n ObjectSchemaBuilder<any, any, any, any, any, any, any>,\n PropertyDescriptorMap | PropertyDescriptorTree<any, any>\n>;\n\nconst createPropertyDescriptorFor = (\n selector: (arg0: any, arg1: boolean) => any,\n propertyName?: string,\n schema?: SchemaBuilder<any, any, any, any, any>,\n parent?: PropertyDescriptorInner<any, any, any>\n) => ({\n [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: {\n setValue: (\n obj: any,\n newValue: any,\n options?: PropertySetterOptions\n ) => {\n const selectorResult = selector(\n obj,\n !!options?.createMissingStructure\n );\n if (!selectorResult) return false;\n\n if (typeof propertyName === 'string') {\n selectorResult[propertyName] = newValue;\n }\n\n return true;\n },\n getValue: (obj: any) => {\n const selectorResult = selector(obj, false);\n if (!selectorResult)\n return {\n success: false\n };\n\n if (typeof propertyName !== 'string') {\n return {\n success: true,\n value: selectorResult\n };\n }\n\n if (Object.hasOwn(selectorResult, propertyName)) {\n return {\n success: true,\n value: selectorResult[propertyName]\n };\n }\n\n return {\n success: false\n };\n },\n\n getSchema: () => schema,\n parent,\n propertyName,\n toJsonPointer: () => {\n const segments: string[] = [];\n if (typeof propertyName === 'string') {\n segments.push(\n propertyName.replace(/~/g, '~0').replace(/\\//g, '~1')\n );\n }\n let ancestor = parent;\n while (ancestor) {\n if (typeof ancestor.propertyName === 'string') {\n segments.push(\n ancestor.propertyName\n .replace(/~/g, '~0')\n .replace(/\\//g, '~1')\n );\n }\n ancestor = ancestor.parent as any;\n }\n segments.reverse();\n return segments.length > 0 ? '/' + segments.join('/') : '';\n }\n }\n});\n\n/** Build only requested array indices, preserving descriptor identity. */\nconst createIndexedDescriptor = (\n schema: SchemaBuilder<any, any, any, any, any>,\n parentSelector: (value: any, create: boolean) => any,\n name: string,\n parent: PropertyDescriptorInner<any, any, any>\n): any => {\n const base = createPropertyDescriptorFor(\n parentSelector,\n name,\n schema,\n parent\n );\n const intro = schema.introspect() as any;\n const valueSelector = (root: any, create: boolean) => {\n const container = parentSelector(root, create);\n if (!container || typeof container !== 'object') return null;\n if (\n create &&\n (!Object.hasOwn(container, name) || container[name] == null)\n ) {\n Object.defineProperty(container, name, {\n value: intro.type === 'array' ? [] : {},\n enumerable: true,\n writable: true,\n configurable: true\n });\n }\n return Object.hasOwn(container, name) ? container[name] : null;\n };\n const inner = base[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n if (intro.type === 'array') {\n const indices = new Map<string, any>();\n return new Proxy(base, {\n get(target, key, receiver) {\n if (\n typeof key !== 'string' ||\n !/^(0|[1-9]\\d*)$/.test(key) ||\n Number(key) >= 4294967295\n ) {\n return Reflect.get(target, key, receiver);\n }\n if (!intro.elementSchema) return undefined;\n if (!indices.has(key)) {\n indices.set(\n key,\n createIndexedDescriptor(\n intro.elementSchema,\n (root, create) => {\n const array = valueSelector(root, create);\n return Array.isArray(array) ? array : null;\n },\n key,\n inner as any\n )\n );\n }\n return indices.get(key);\n }\n });\n }\n if (intro.properties) {\n for (const [key, child] of Object.entries(intro.properties)) {\n Object.defineProperty(base, key, {\n value: createIndexedDescriptor(\n child as any,\n valueSelector,\n key,\n inner as any\n ),\n enumerable: true\n });\n }\n } else if ((schema as any)[SYMBOL_HAS_PROPERTIES]) {\n return createExternProxyDescriptor(base, valueSelector);\n }\n return base;\n};\n\n/**\n * Creates a Proxy-wrapped property descriptor for an extern schema.\n * Child descriptors are lazily created when accessed by name, enabling\n * `getErrorsFor(t => t.order.id)` navigation without an explicit\n * property map.\n *\n * Each child is also Proxy-wrapped for arbitrary-depth navigation.\n *\n * @param baseDescriptor - The base descriptor (with SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR)\n * @param valueSelector - Selector that navigates to the extern's VALUE in the root object\n */\nconst createExternProxyDescriptor = (\n baseDescriptor: ReturnType<typeof createPropertyDescriptorFor>,\n valueSelector: (obj: any, createMissingStructure: boolean) => any\n): any =>\n new Proxy(baseDescriptor, {\n get(target: any, prop: PropertyKey, receiver: any): any {\n // Fast path for the descriptor symbol — no interception\n if (prop === SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR) {\n return target[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR];\n }\n\n // For string keys, lazily create and cache child descriptors\n if (typeof prop === 'string' && !(prop in target)) {\n const child = createPropertyDescriptorFor(\n valueSelector,\n prop,\n undefined,\n target[SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]\n );\n\n // Build a value selector for the child's own children\n const childValueSelector = (\n obj: any,\n createMissingStructure: boolean\n ) => {\n const parentValue = valueSelector(\n obj,\n createMissingStructure\n );\n if (\n parentValue != null &&\n typeof parentValue === 'object'\n ) {\n if (createMissingStructure && !(prop in parentValue)) {\n parentValue[prop as string] = {};\n }\n return parentValue[prop as string];\n }\n return null;\n };\n\n // Recursively wrap so deeper paths like t.order.address.city work\n target[prop] = createExternProxyDescriptor(\n child,\n childValueSelector\n );\n }\n\n return Reflect.get(target, prop, receiver);\n }\n });\n\n(object as any).getPropertiesFor = <\n TProperties extends Record<\n string,\n SchemaBuilder<any, any, any, any, any>\n > = {},\n TRequired extends boolean = true,\n TExplicitType = undefined,\n TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n > = ObjectSchemaBuilder<\n TProperties,\n TRequired,\n false,\n TExplicitType,\n false,\n {},\n []\n >\n>(\n schema: ObjectSchemaBuilder<TProperties, TRequired, false, TExplicitType>\n): PropertyDescriptorTree<TSchema, TSchema> =>\n ObjectSchemaBuilder.getPropertiesFor(schema) as any;\n\n(object as any).isValidPropertyDescriptor =\n ObjectSchemaBuilder.isValidPropertyDescriptor;\n\nexport { object };\n\ntype RequiredProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<any, infer TReq, any, any>\n ? TReq extends true\n ? k\n : never\n : never]: T[k];\n};\n\ntype NotRequiredProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<any, infer TReq, any, any>\n ? TReq extends true\n ? never\n : k\n : never]: T[k];\n};\n\ntype RequiredInputProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<\n any,\n infer TReq,\n any,\n infer THasDef\n >\n ? TReq extends true\n ? THasDef extends true\n ? never\n : k\n : never\n : never]: T[k];\n};\n\ntype NotRequiredInputProps<\n T extends Record<string, SchemaBuilder<any, any, any, any, any>>\n> = keyof {\n [k in keyof T as T[k] extends SchemaBuilder<\n any,\n infer TReq,\n any,\n infer THasDef\n >\n ? TReq extends true\n ? THasDef extends true\n ? k\n : never\n : k\n : never]: T[k];\n};\n"],"mappings":"sDAkBO,IAAMA,EAAN,KAkBP,CACIC,GAMAC,GACAC,GAAoB,CAAC,EACrBC,GAAwD,CAAC,EAOzD,IAAW,WAA4C,CACnD,IAAMC,EAAS,KAAKJ,GAChBK,CACJ,EAAE,SAAS,KAAKJ,EAAuB,EAEvC,OAAQG,EAAO,QAAUA,EAAO,MAAQ,MAC5C,CAKA,IAAW,QAAgC,CACvC,OAAO,KAAKF,EAChB,CAMA,IAAW,SAAmB,CAC1B,OAAO,KAAKA,GAAQ,SAAW,GAAK,KAAK,eAAe,EAAE,SAAW,CACzE,CAMO,gBAEL,CACE,OAAO,KAAKC,EAChB,CAMA,IAAW,YAIT,CACE,OAAO,KAAKH,GAAYK,CAAiC,CAC7D,CAWA,YACIC,EAMAC,EACAC,EACF,CACE,GAAI,CAACC,EAAoB,0BAA0BH,CAAU,EACzD,MAAM,IAAI,MAAM,6BAA6B,EAEjD,KAAKN,GAAcM,EACnB,KAAKJ,GAAU,MAAM,QAAQM,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6D,CAAK,IAAK,OAAO,QAAQW,EAAM,UAAU,EACtD,OAAO,eAAeD,EAAMvE,EAAK,CAC7B,MAAO4C,EACHiB,EACAY,EACAzE,EACA6E,CACJ,EACA,WAAY,EAChB,CAAC,UAEGnE,EAAezD,CAAqB,EAC5C,OAAO8F,EAA4BwB,EAAME,CAAa,EAE1D,OAAOF,CACX,EAaMxB,EAA8B,CAChCkC,EACAR,IAEA,IAAI,MAAMQ,EAAgB,CACtB,IAAIzB,EAAalC,EAAmByD,EAAoB,CAEpD,GAAIzD,IAASqB,EACT,OAAOa,EAAOb,CAAiC,EAInD,GAAI,OAAOrB,GAAS,UAAY,EAAEA,KAAQkC,GAAS,CAC/C,IAAMK,EAAQzB,EACVqC,EACAnD,EACA,OACAkC,EAAOb,CAAiC,CAC5C,EAGMuC,EAAqB,CACvB7C,EACAC,IACC,CACD,IAAM6C,EAAcV,EAChBpC,EACAC,CACJ,EACA,OACI6C,GAAe,MACf,OAAOA,GAAgB,UAEnB7C,GAA0B,EAAEhB,KAAQ6D,KACpCA,EAAY7D,CAAc,EAAI,CAAC,GAE5B6D,EAAY7D,CAAc,GAE9B,IACX,EAGAkC,EAAOlC,CAAI,EAAIyB,EACXc,EACAqB,CACJ,CACJ,CAEA,OAAO,QAAQ,IAAI1B,EAAQlC,EAAMyD,CAAQ,CAC7C,CACJ,CAAC,EAEJrH,EAAe,iBAyBZgD,GAEAhE,EAAoB,iBAAiBgE,CAAM,EAE9ChD,EAAe,0BACZhB,EAAoB","names":["PropertyValidationResult","#descriptor","#rootObjectValue","#errors","#childErrors","result","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","descriptor","rootObjectValue","errors","ObjectSchemaBuilder","error","childError","MUST_BE_AN_OBJECT_ERROR_MESSSAGE","ObjectSchemaBuilder","_ObjectSchemaBuilder","SchemaBuilder","#properties","#acceptUnknownProps","#propKeys","#constructorSchemas","SYMBOL_HAS_PROPERTIES","#propertyDescriptorTreeMap","props","s","errorMessage","value","_name","#applyPropertyDescriptors","result","object","context","#setupValidation","prevalidatedResult","valid","prevalidationContext","validationTransaction","preValidationErrors","propertyDescriptorToErrorMap","invalidResults","doNotStopOnFirstError","rootValidationObject","rootPropertyDescriptor","currentPropertyDescriptor","addErrorFor","propertyDescriptor","message","parentPropertyDescriptor","validationError","PropertyValidationResult","parentValidationError","getErrorsFor","selector","descriptor","getInvalidProperties","r","errors","routePreValidationError","error","targetDescriptor","objToValidate","propKeys","objKeys","i","#processResults","setup","validationResults","hasInvalid","key","resultObject","#propagateNestedErrors","#propagateIndexedErrors","validator","options","self","#validateFull","results","_notUsed","schema","propName","newProps","propNameOrArrayOrPropsOrBuilder","propsArray","distinctKeys","propsToOmit","remoteProps","localProps","acc","curr","propNameOrArray","prop","properties","property","newProperties","p","callback","callbackResult","builder","#getPropertiesFor","parentSelector","currentName","parentDescriptor","introspected","propsNames","createPropertyDescriptorFor","obj","createMissingStructure","propSchema","childProperties","tree","selectorResult","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","createIndexedDescriptor","externBase","externValueSelector","createExternProxyDescriptor","#getSchemaForPropertyDescriptor","propertyNames","nestedPropertyName","nestedPropertyDescriptor","nestedValidationError","prefix","invalid","pointer","target","node","part","nestedSchema","children","child","index","indexed","relative","propertyName","parent","newValue","segments","ancestor","name","base","intro","valueSelector","root","create","container","inner","indices","receiver","array","baseDescriptor","childValueSelector","parentValue"]}
|
|
File without changes
|
|
File without changes
|