@cleverbrush/schema 2.0.0 → 3.0.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.
Files changed (87) hide show
  1. package/README.md +412 -8
  2. package/dist/builders/AnySchemaBuilder.js +1 -1
  3. package/dist/builders/ArraySchemaBuilder.d.ts +2 -0
  4. package/dist/builders/ArraySchemaBuilder.js +1 -1
  5. package/dist/builders/BooleanSchemaBuilder.d.ts +15 -0
  6. package/dist/builders/BooleanSchemaBuilder.js +1 -1
  7. package/dist/builders/DateSchemaBuilder.d.ts +20 -0
  8. package/dist/builders/DateSchemaBuilder.js +1 -1
  9. package/dist/builders/ExternSchemaBuilder.d.ts +2 -0
  10. package/dist/builders/ExternSchemaBuilder.js +1 -1
  11. package/dist/builders/FunctionSchemaBuilder.d.ts +162 -18
  12. package/dist/builders/FunctionSchemaBuilder.js +1 -1
  13. package/dist/builders/GenericSchemaBuilder.d.ts +294 -0
  14. package/dist/builders/LazySchemaBuilder.d.ts +2 -0
  15. package/dist/builders/NumberSchemaBuilder.d.ts +16 -0
  16. package/dist/builders/NumberSchemaBuilder.js +1 -1
  17. package/dist/builders/ObjectSchemaBuilder.d.ts +262 -42
  18. package/dist/builders/ObjectSchemaBuilder.js +1 -1
  19. package/dist/builders/ParseStringSchemaBuilder.d.ts +204 -0
  20. package/dist/builders/ParseStringSchemaBuilder.js +2 -0
  21. package/dist/builders/ParseStringSchemaBuilder.js.map +1 -0
  22. package/dist/builders/PromiseSchemaBuilder.d.ts +213 -0
  23. package/dist/builders/PromiseSchemaBuilder.js +2 -0
  24. package/dist/builders/PromiseSchemaBuilder.js.map +1 -0
  25. package/dist/builders/RecordSchemaBuilder.d.ts +2 -0
  26. package/dist/builders/RecordSchemaBuilder.js +1 -1
  27. package/dist/builders/SchemaBuilder.d.ts +89 -0
  28. package/dist/builders/StringSchemaBuilder.d.ts +2 -0
  29. package/dist/builders/StringSchemaBuilder.js +1 -1
  30. package/dist/builders/TupleSchemaBuilder.d.ts +2 -0
  31. package/dist/builders/TupleSchemaBuilder.js +1 -1
  32. package/dist/builders/UnionSchemaBuilder.d.ts +8 -0
  33. package/dist/builders/UnionSchemaBuilder.js +1 -1
  34. package/dist/chunk-3JMDGYDT.js +2 -0
  35. package/dist/chunk-3JMDGYDT.js.map +1 -0
  36. package/dist/{chunk-KESLT5EE.js → chunk-BUEVZ3KA.js} +2 -2
  37. package/dist/{chunk-KESLT5EE.js.map → chunk-BUEVZ3KA.js.map} +1 -1
  38. package/dist/{chunk-KFTO7TMB.js → chunk-CFIJQ4GP.js} +2 -2
  39. package/dist/{chunk-KFTO7TMB.js.map → chunk-CFIJQ4GP.js.map} +1 -1
  40. package/dist/chunk-DY7J6RNN.js +2 -0
  41. package/dist/chunk-DY7J6RNN.js.map +1 -0
  42. package/dist/{chunk-YWBNVHR6.js → chunk-EIVZX4ZO.js} +2 -2
  43. package/dist/{chunk-YWBNVHR6.js.map → chunk-EIVZX4ZO.js.map} +1 -1
  44. package/dist/chunk-GXPV6UQK.js +2 -0
  45. package/dist/chunk-GXPV6UQK.js.map +1 -0
  46. package/dist/{chunk-ZAN4ZHCJ.js → chunk-HN774HD7.js} +2 -2
  47. package/dist/chunk-K6Z47OQY.js +2 -0
  48. package/dist/chunk-K6Z47OQY.js.map +1 -0
  49. package/dist/chunk-NUW3VXZV.js +2 -0
  50. package/dist/chunk-NUW3VXZV.js.map +1 -0
  51. package/dist/{chunk-MKAYFPAR.js → chunk-PHE4LIAN.js} +2 -2
  52. package/dist/chunk-QARCEYGO.js +2 -0
  53. package/dist/chunk-QARCEYGO.js.map +1 -0
  54. package/dist/chunk-WDMJBGBD.js +2 -0
  55. package/dist/chunk-WDMJBGBD.js.map +1 -0
  56. package/dist/chunk-WQDYWDOE.js +2 -0
  57. package/dist/chunk-WQDYWDOE.js.map +1 -0
  58. package/dist/{chunk-FWUEUW2N.js → chunk-YQZHDMRF.js} +2 -2
  59. package/dist/chunk-ZC6YBKCP.js +2 -0
  60. package/dist/chunk-ZC6YBKCP.js.map +1 -0
  61. package/dist/{chunk-IJ6FO37G.js → chunk-ZFI27R3L.js} +2 -2
  62. package/dist/core.d.ts +7 -2
  63. package/dist/core.js +1 -1
  64. package/dist/extension.d.ts +10 -2
  65. package/dist/extensions/index.d.ts +5 -1
  66. package/dist/index.d.ts +4 -1
  67. package/dist/index.js +1 -1
  68. package/dist/index.js.map +1 -1
  69. package/package.json +12 -4
  70. package/dist/chunk-BFCMDDTX.js +0 -2
  71. package/dist/chunk-BFCMDDTX.js.map +0 -1
  72. package/dist/chunk-CTP4RHDG.js +0 -2
  73. package/dist/chunk-CTP4RHDG.js.map +0 -1
  74. package/dist/chunk-EUQ5AE3H.js +0 -2
  75. package/dist/chunk-EUQ5AE3H.js.map +0 -1
  76. package/dist/chunk-NXPH3ZUW.js +0 -2
  77. package/dist/chunk-NXPH3ZUW.js.map +0 -1
  78. package/dist/chunk-S5TC6NSU.js +0 -2
  79. package/dist/chunk-S5TC6NSU.js.map +0 -1
  80. package/dist/chunk-Z7QZ7IXT.js +0 -2
  81. package/dist/chunk-Z7QZ7IXT.js.map +0 -1
  82. package/dist/chunk-ZUPYV5TI.js +0 -2
  83. package/dist/chunk-ZUPYV5TI.js.map +0 -1
  84. /package/dist/{chunk-ZAN4ZHCJ.js.map → chunk-HN774HD7.js.map} +0 -0
  85. /package/dist/{chunk-MKAYFPAR.js.map → chunk-PHE4LIAN.js.map} +0 -0
  86. /package/dist/{chunk-FWUEUW2N.js.map → chunk-YQZHDMRF.js.map} +0 -0
  87. /package/dist/{chunk-IJ6FO37G.js.map → chunk-ZFI27R3L.js.map} +0 -0
@@ -0,0 +1,2 @@
1
+ var y=Symbol("transaction"),P=[Error,RegExp,Date],R={shouldNotWrapWithTransaction:u=>!!P.find(e=>u instanceof e)},h=(u,e)=>{let r={},a=new Map;e=Object.assign({},R,e||{});let{shouldNotWrapWithTransaction:i}=e,l=()=>!!Object.keys(r).find(s=>r[s]?.[y]?r[s][y].isDirty():!0)||a.size>0,c=()=>{let s={};Object.keys(u).forEach(t=>{s[t]=u[t]}),Object.keys(r).forEach(t=>{let o=r[t];if(o[y]){let{commit:d}=o[y];s[t]=d()}else s[t]=r[t]});for(let t of a.keys())delete s[t];return r={},a=new Map,s},p=()=>{for(let s in r){let t=r[s];t&&typeof t=="object"&&t[y]&&t[y].rollback()}return r={},a=new Map,u};if(Array.isArray(u)){let s=u.map(d=>typeof d=="object"&&d&&!i(d)?h(d).object:d),t=()=>s.map(d=>d&&typeof d[y]=="object"?d[y].commit():d),o=()=>!!s.find((d,f)=>d&&typeof d[y]=="object"?d[y].isDirty():s[f]!==u[f]);return Object.defineProperty(s,y,{writable:!1,configurable:!1,value:{initial:u,object:s,commit:t,rollback:()=>u,isDirty:o}}),{object:s,commit:t,rollback:()=>u,isDirty:o}}let n=new Proxy(u,{set:(s,t,o)=>s&&s[t]===o?(delete r[t],!0):(r[t]=o,a.delete(t),!0),ownKeys:s=>[...Object.keys(s).filter(t=>!a.has(t)),...Object.keys(r).filter(t=>!(t in s))],getOwnPropertyDescriptor:(s,t)=>{if(!a.has(t))return t in r?Object.getOwnPropertyDescriptor(r,t):Object.getOwnPropertyDescriptor(s,t)},has:(s,t)=>a.has(t)?!1:t in r?!0:t in s,get:(s,t)=>{if(typeof t=="symbol")return t===y?{initial:u,object:n,commit:c,rollback:p,isDirty:l}:s[t];if(t in r)return r[t];if(!a.has(t)){if(!g(s[t])&&typeof s[t]=="object"&&s[t]&&!i(s[t])){let{object:o}=h(s[t],e);return r[t]=o,o}return s[t]}},deleteProperty:(s,t)=>(t in r&&(r[t]&&typeof r[t][y]=="object"&&r[t][y].rollback(),delete r[t]),t in s&&a.set(t,!0),!0)});return{object:n,commit:c,rollback:p,isDirty:l}},T=u=>({object:u,commit:()=>u,rollback:()=>u,isDirty:()=>!1}),g=u=>u&&typeof u=="object"&&Object.hasOwn(u,y);var m=class extends Error{errors;constructor(e){let r=e.length>0?e.map(a=>a.message).join("; "):"Validation failed";super(r),this.name="SchemaValidationError",this.errors=e}},x=Symbol(),v=Symbol();function E(u,e,r,a){return Object.defineProperties(u,{seenValue:{get:e,enumerable:!1},errors:{get:r,enumerable:!1},isValid:{get:()=>r().length===0,enumerable:!1},descriptor:{get:a,enumerable:!1}}),u}var b=class{#d=!0;#a=!1;#y=!1;#p;#h;#e=[];#t=[];#n=!1;#T=!0;#c={};#f="base";#m="is required";#o="is required";#s=void 0;#i=void 0;#l=!1;#b=void 0;#u;get"~standard"(){if(this.#u)return this.#u;let e=this;return this.#u={version:1,vendor:"@cleverbrush/schema",validate(r){let a=e.validate(r);return a.valid?{value:a.object}:{issues:(a.errors??[]).map(i=>({message:i.message}))}}},this.#u}get type(){return this.#f}set type(e){if(typeof e!="string"||!e)throw new Error("value should be non empty string");this.#f=e}get preprocessors(){return this.#e}get validators(){return this.#t}get isRequired(){return this.#d}get isNullable(){return this.#a}set isRequired(e){if(typeof e!="boolean")throw new Error("should be a boolean value");this.#d=e}get requiredErrorMessage(){return this.#o}get hasDefault(){return this.#s!==void 0}get hasCatch(){return this.#l}resolveCatchValue(){return typeof this.#i=="function"?this.#i():this.#i}get isReadonly(){return this.#y}resolveDefaultValue(){return typeof this.#s=="function"?this.#s():this.#s}get canSkipPreValidation(){return this.#T}get isNullRequiredViolation(){return!0}#P(e,r){let a=r?.doNotStopOnFirstError??!1,i={doNotStopOnFirstError:a,rootPropertyDescriptor:r?.rootPropertyDescriptor,currentPropertyDescriptor:r?.currentPropertyDescriptor},l=this.#n;return{doNotStopOnFirstError:a,resultingContext:i,transaction:l?h({validatedObject:e}):T({validatedObject:e}),errors:[]}}#r(e,r){return{valid:!1,errors:[e[0]].filter(a=>a),context:r}}#R(e,r,a){return Array.isArray(a)&&a.length?a:[{message:`Validator #${e}${r?` (${r})`:""} didn't pass.`}]}#g(e,r,a,i){return e.length>0?{valid:!1,errors:e.filter(l=>l).filter((l,c)=>r?!0:c===0),context:a,transaction:i}:{valid:!0,context:a,transaction:i}}preValidateSync(e,r){let a=this.#P(e,r),{doNotStopOnFirstError:i,resultingContext:l,errors:c}=a,p=a.transaction,n=p.object.validatedObject;if(this.#e.length>0){let s=0;for(let t of this.#e)try{let o=t.fn(n);if(o instanceof Promise)throw new Error(`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} returned a Promise. Use validateAsync() for schemas with async preprocessors.`);n=o}catch(o){if(o.message?.includes("Use validateAsync()"))throw o;if(c.push({message:`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}p=this.#n?h({validatedObject:n}):T({validatedObject:n})}if(typeof n>"u"&&this.hasDefault&&(n=this.resolveDefaultValue(),p=this.#n?h({validatedObject:n}):T({validatedObject:n})),this.#t.length>0&&!(n==null&&!this.isRequired)&&!(n===null&&this.#a)){let s=0;for(let t of this.#t)try{let o=t.fn(n);if(o instanceof Promise)throw new Error(`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} returned a Promise. Use validateAsync() for schemas with async validators.`);let{valid:d,errors:f}=o;if(!d&&(c.push(...this.#R(s,t.fn.name,f)),!i))return this.#r(c,l)}catch(o){if(o.message?.includes("Use validateAsync()"))throw o;if(c.push({message:`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}}return this.isRequired&&(typeof n>"u"||n===null&&this.isNullRequiredViolation&&!this.#a)&&(c.push({message:this.getValidationErrorMessageSync(this.#o,n)}),!i)?(p.rollback(),this.#r(c,l)):this.#g(c,i,l,p)}async preValidateAsync(e,r){let a=this.#P(e,r),{doNotStopOnFirstError:i,resultingContext:l,errors:c}=a,p=a.transaction,n=p.object.validatedObject;if(this.#e.length>0){let s=0;for(let t of this.#e)try{n=await Promise.resolve(t.fn(n))}catch(o){if(c.push({message:`Preprocessor #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}p=this.#n?h({validatedObject:n}):T({validatedObject:n})}if(typeof n>"u"&&this.hasDefault&&(n=this.resolveDefaultValue(),p=this.#n?h({validatedObject:n}):T({validatedObject:n})),this.#t.length>0&&!(n==null&&!this.isRequired)&&!(n===null&&this.#a)){let s=0;for(let t of this.#t)try{let{valid:o,errors:d}=await Promise.resolve(t.fn(n));if(!o&&(c.push(...this.#R(s,t.fn.name,d)),!i))return this.#r(c,l)}catch(o){if(c.push({message:`Validator #${s}${t.fn.name?` (${t.fn.name})`:""} thrown an error: ${o.message}`}),!i)return this.#r(c,l)}finally{s++}}return this.isRequired&&(typeof n>"u"||n===null&&this.isNullRequiredViolation&&!this.#a)&&(c.push({message:await this.getValidationErrorMessage(this.#o,n)}),!i)?(p.rollback(),this.#r(c,l)):this.#g(c,i,l,p)}preValidate(e,r){return this.preValidateAsync(e,r)}introspect(){return{type:this.type,isRequired:this.#d,isNullable:this.#a,isReadonly:this.#y,preprocessors:[...this.preprocessors],validators:[...this.validators],requiredValidationErrorMessageProvider:this.#o,extensions:{...this.#c},hasDefault:this.#s!==void 0,defaultValue:this.#s,description:this.#p,schemaName:this.#h,hasCatch:this.#l,catchValue:this.#i,example:this.#b}}optional(){return this.createFromProps({...this.introspect(),isRequired:!1})}nullable(){return this.createFromProps({...this.introspect(),isNullable:!0})}notNullable(){return this.createFromProps({...this.introspect(),isNullable:!1})}default(e){return this.createFromProps({...this.introspect(),defaultValue:e})}catch(e){return this.createFromProps({...this.introspect(),catchValue:e,hasCatch:!0})}clearDefault(){return this.createFromProps({...this.introspect(),defaultValue:void 0})}describe(e){return this.createFromProps({...this.introspect(),description:e})}example(e){return this.createFromProps({...this.introspect(),example:e})}schemaName(e){return this.createFromProps({...this.introspect(),schemaName:e})}brand(e){return this.createFromProps({...this.introspect()})}readonly(){return this.createFromProps({...this.introspect(),isReadonly:!0})}required(e){return this.createFromProps({...this.introspect(),isRequired:!0,...e!==void 0?{requiredValidationErrorMessageProvider:this.assureValidationErrorMessageProvider(e,this.#m)}:{}})}addPreprocessor(e,r){if(typeof e!="function")throw new Error("preprocessor must be a function");return this.createFromProps({...this.introspect(),preprocessors:[...this.preprocessors,{fn:e,mutates:r?.mutates??!0}]})}clearPreprocessors(){return this.createFromProps({...this.introspect(),preprocessors:[]})}addValidator(e,r){if(typeof e!="function")throw new Error("validator must be a function");return this.createFromProps({...this.introspect(),validators:[...this.validators,{fn:e,mutates:r?.mutates??!1}]})}clearValidators(){return this.createFromProps({...this.introspect(),validators:[]})}validate(e,r){let a=this._validate(e,r);if(!a.valid&&this.#l){let i=this.resolveCatchValue(),l=this._validate(i,r);return l.valid?l:{valid:!0,object:i}}return a}async validateAsync(e,r){let a=await this._validateAsync(e,r);if(!a.valid&&this.#l){let i=this.resolveCatchValue(),l=await this._validateAsync(i,r);return l.valid?l:{valid:!0,object:i}}return a}getValidationErrorMessageSync(e,r){if(typeof e=="string")return e;if(typeof e=="function"){let a=e(r,this);if(a instanceof Promise)throw new Error("Async error message providers require validateAsync(). Use a string or sync function instead.");return a}throw new Error("Invalid error message provider must be a string or a function returning a string")}async getValidationErrorMessage(e,r){if(typeof e=="string")return e;if(typeof e=="function")return e(r,this);throw new Error("Invalid error message provider must be a string or a function returning a string or a promise of a string")}assureValidationErrorMessageProvider(e,r){return typeof e=="string"?e:typeof e=="function"?e.bind(this):typeof r=="function"?r.bind(this):r}withExtension(e,r){return this.createFromProps({...this.introspect(),extensions:{...this.#c,[e]:r}})}getExtension(e){return this.#c[e]}parse(e,r){let a=this.validate(e,r);if(!a.valid)throw new m(a.errors||[]);return a.object}async parseAsync(e,r){let a=await this.validateAsync(e,r);if(!a.valid)throw new m(a.errors||[]);return a.object}safeParse(e,r){return this.validate(e,r)}safeParseAsync(e,r){return this.validateAsync(e,r)}constructor(e){if(!(typeof e=="object"&&e))throw new Error("SchemaBuilder props must be an object");let{type:r,preprocessors:a,validators:i,isRequired:l}=e;this.type=r,typeof l=="boolean"&&(this.isRequired=l),typeof e.isNullable=="boolean"&&(this.#a=e.isNullable),typeof e.isReadonly=="boolean"&&(this.#y=e.isReadonly),Array.isArray(a)&&(this.#e=[...a]),Array.isArray(i)&&(this.#t=[...i]),this.#n=this.#e.some(c=>c.mutates)||this.#t.some(c=>c.mutates),this.#T=this.#e.length===0&&this.#t.length===0,typeof e.extensions=="object"&&e.extensions&&(this.#c={...e.extensions}),e.defaultValue!==void 0&&(this.#s=e.defaultValue),e.hasCatch&&(this.#l=!0,this.#i=e.catchValue),typeof e.description=="string"&&(this.#p=e.description),typeof e.schemaName=="string"&&(this.#h=e.schemaName),e.example!==void 0&&(this.#b=e.example),this.#o=this.assureValidationErrorMessageProvider(e.requiredValidationErrorMessageProvider,this.#m)}};export{h as a,m as b,x as c,v as d,E as e,b as f};
2
+ //# sourceMappingURL=chunk-3JMDGYDT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/transaction.ts","../src/builders/SchemaBuilder.ts"],"sourcesContent":["const TRANSACTION_SYMBOL = Symbol('transaction');\n\nconst defaultNonTransactionalTypes = [Error, RegExp, Date];\n\n/**\n * Options for customizing transaction behavior.\n */\nexport type TransactionOptions = {\n /**\n * An optional callback returning boolean. Called for every\n * nested object's property (recursively) which is not\n * null `Object`. Using this function you can define if `child`\n * should be wrapped with transaction. It is useful for\n * some cases like Error, Map, etc. when you want to preserve a link,\n * instead of creation of the new transaction.\n * By default it's filtering all instances inheriting from Error and RegExp\n * If `true` is returned from this function `child` will not be wrapped with\n * nested transaction object.\n */\n shouldNotWrapWithTransaction?: (child: any) => boolean;\n};\n\nconst defaultTransactionOptions: TransactionOptions = {\n shouldNotWrapWithTransaction: child =>\n !!defaultNonTransactionalTypes.find(t => child instanceof t)\n};\n\n/**\n * A transaction wrapper around an object. Provides copy-on-write semantics:\n * modifications to `object` are isolated from the original until `commit()` is called.\n * Use `rollback()` to discard changes, and `isDirty()` to check for pending modifications.\n */\nexport type Transaction<T> = {\n /**\n * Transaction object you can modify (equals to `initial` right after the call).\n * All changes to `object` will not be reflected to `initial` until `commit`\n * is called.\n */\n object: T;\n /**\n * Commits transaction, all changes to `object` will be reflected to `initial`\n * after the call of this function.\n */\n commit: () => T;\n /**\n * Rollbacks transaction moving it to the initial state (`object` will be equal to `initial`\n * after the call of this function).\n */\n rollback: () => T;\n /**\n * Returns `true` if there are any changes to `object` which make it different from `initial`.\n */\n isDirty: () => boolean;\n};\n\n/**\n * Starts a transaction over the `initial` object. The returned `object` is a\n * proxy (for plain objects) or a shallow copy (for arrays) that tracks mutations\n * without modifying `initial`. Call `commit()` to apply or `rollback()` to discard changes.\n *\n * @param initial - the object or array to wrap in a transaction\n * @param options - optional configuration to control which nested values are wrapped\n * @returns a {@link Transaction} with `object`, `commit`, `rollback`, and `isDirty` members\n */\nexport const transaction = <T extends {}>(\n initial: T,\n options?: TransactionOptions\n): Transaction<T> => {\n let newProperties: Record<string | symbol, any> = {};\n let deletedProperties = new Map<keyof T, true>();\n\n options = Object.assign({}, defaultTransactionOptions, options || {});\n\n const { shouldNotWrapWithTransaction } =\n options as Required<TransactionOptions>;\n\n const isDirty = () =>\n !!Object.keys(newProperties).find(key => {\n if (newProperties[key]?.[TRANSACTION_SYMBOL]) {\n return newProperties[key][TRANSACTION_SYMBOL].isDirty();\n }\n return true;\n }) || ((deletedProperties.size > 0) as any);\n\n const commit = () => {\n const result = {} as Record<string, any>;\n Object.keys(initial).forEach(key => {\n result[key] = (initial as any)[key];\n });\n\n Object.keys(newProperties).forEach(key => {\n const value = newProperties[key];\n if (value[TRANSACTION_SYMBOL]) {\n const { commit: childCommit } = value[TRANSACTION_SYMBOL];\n result[key] = childCommit();\n } else {\n result[key] = newProperties[key];\n }\n });\n\n for (const key of deletedProperties.keys()) {\n delete result[key as string];\n }\n\n newProperties = {};\n deletedProperties = new Map<keyof T, true>();\n\n return result as T;\n };\n\n const rollback = () => {\n for (const key in newProperties) {\n const value = newProperties[key];\n if (\n value &&\n typeof value === 'object' &&\n value[TRANSACTION_SYMBOL]\n ) {\n // this is nested transaction, let's rollback it as well\n value[TRANSACTION_SYMBOL].rollback();\n }\n }\n newProperties = {};\n deletedProperties = new Map<keyof T, true>();\n return initial;\n };\n\n if (Array.isArray(initial)) {\n const result = initial.map(el =>\n typeof el === 'object' && el && !shouldNotWrapWithTransaction(el)\n ? transaction(el).object\n : el\n );\n const commitArray = () =>\n result.map(el =>\n el && typeof el[TRANSACTION_SYMBOL] === 'object'\n ? el[TRANSACTION_SYMBOL].commit()\n : el\n );\n\n const isDirtyArray = () => {\n return !!result.find((val, index) => {\n if (val && typeof val[TRANSACTION_SYMBOL] === 'object') {\n return val[TRANSACTION_SYMBOL].isDirty();\n }\n return result[index] !== initial[index];\n });\n };\n Object.defineProperty(result, TRANSACTION_SYMBOL, {\n writable: false,\n configurable: false,\n value: {\n initial,\n object: result,\n commit: commitArray as any,\n rollback: () => initial,\n isDirty: isDirtyArray\n }\n });\n return {\n object: result as any,\n commit: commitArray as any,\n rollback: () => initial,\n isDirty: isDirtyArray\n };\n }\n\n const proxy = new Proxy<T>(initial, {\n set: (target, property, value) => {\n if (target && (target as any)[property] === value) {\n delete newProperties[property];\n return true;\n }\n newProperties[property] = value;\n deletedProperties.delete(property as any);\n return true;\n },\n ownKeys: target => {\n return [\n ...Object.keys(target).filter(\n (k: any) => !deletedProperties.has(k)\n ),\n ...Object.keys(newProperties).filter((k: any) => !(k in target))\n ];\n },\n getOwnPropertyDescriptor: (target, prop: any) => {\n if (deletedProperties.has(prop)) {\n return undefined;\n }\n\n if (prop in newProperties) {\n return Object.getOwnPropertyDescriptor(newProperties, prop);\n }\n\n return Object.getOwnPropertyDescriptor(target, prop);\n },\n has: (target, prop: any) => {\n if (deletedProperties.has(prop)) {\n return false;\n }\n\n if (prop in newProperties) {\n return true;\n }\n\n return prop in target;\n },\n get: (target, prop) => {\n if (typeof prop === 'symbol') {\n if (prop === TRANSACTION_SYMBOL) {\n return {\n initial,\n object: proxy,\n commit,\n rollback,\n isDirty\n };\n }\n return (target as any)[prop];\n }\n\n if (prop in newProperties) {\n return newProperties[prop];\n }\n\n if (deletedProperties.has(prop as any)) {\n return undefined;\n }\n\n if (\n !isTransaction((target as any)[prop]) &&\n typeof (target as any)[prop] === 'object' &&\n (target as any)[prop] &&\n !shouldNotWrapWithTransaction((target as any)[prop])\n ) {\n const { object } = transaction((target as any)[prop], options);\n newProperties[prop] = object;\n return object;\n }\n\n return (target as any)[prop];\n },\n deleteProperty: (target, p) => {\n if (p in newProperties) {\n if (\n newProperties[p] &&\n typeof newProperties[p][TRANSACTION_SYMBOL] === 'object'\n ) {\n newProperties[p][TRANSACTION_SYMBOL].rollback();\n }\n delete newProperties[p];\n }\n if (p in target) {\n deletedProperties.set(p as any, true);\n }\n return true;\n }\n });\n\n return {\n object: proxy,\n commit,\n rollback,\n isDirty\n };\n};\n\n/**\n * Creates a lightweight no-op transaction that wraps the `initial` value\n * without any Proxy or copy-on-write overhead. `commit()` and `rollback()`\n * simply return the original object, and `isDirty()` is always `false`.\n *\n * Use this when no preprocessors or validators are defined — there is no\n * risk of mutation, so the full transaction machinery can be skipped.\n */\nexport const noopTransaction = <T extends {}>(initial: T): Transaction<T> => ({\n object: initial,\n commit: () => initial,\n rollback: () => initial,\n isDirty: () => false\n});\n\n/**\n * Checks if `obj` is an instance of a transaction.\n * @param obj object to check if it's a transaction\n * @returns `true` if `obj` is a transaction, `false` otherwise\n */\nexport const isTransaction = (obj: any) =>\n obj && typeof obj === 'object' && Object.hasOwn(obj, TRANSACTION_SYMBOL);\n","import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n noopTransaction,\n type Transaction,\n transaction\n} from '../utils/transaction.js';\nimport type { ArraySchemaBuilder } from './ArraySchemaBuilder.js';\nimport type { ExternSchemaBuilder } from './ExternSchemaBuilder.js';\nimport type { ObjectSchemaBuilder } from './ObjectSchemaBuilder.js';\n\n/** @internal Symbol used as the key for the type brand on schema builders. */\ndeclare const __type: unique symbol;\n/** @internal */\nexport type SchemaTypeBrand = typeof __type;\n\n/** @internal Symbol used as the key for the default-value brand on schema builders. */\ndeclare const __hasDefault: unique symbol;\n/** @internal */\nexport type HasDefaultBrand = typeof __hasDefault;\n\n/** Symbol used as the key for branded/opaque types. */\ndeclare const __brand: unique symbol;\n/** Symbol used as the key for branded/opaque types. */\nexport type BRAND = typeof __brand;\n\n/**\n * Intersects a base type with a phantom brand tag.\n * The brand exists only at the type level — zero runtime cost.\n *\n * @example\n * ```ts\n * type Email = Brand<string, 'Email'>;\n * type UserId = Brand<number, 'UserId'>;\n * ```\n */\nexport type Brand<T, TBrand extends string | symbol> = T & {\n readonly [K in BRAND]: TBrand;\n};\n\n/**\n * Infers the TypeScript type that a `SchemaBuilder` instance validates.\n * Takes into account type optimizations (via `optimize()`) and whether the schema is optional.\n *\n * @example\n * ```ts\n * const userSchema = object({ name: string(), age: number().optional() });\n * type User = InferType<typeof userSchema>;\n * // { name: string; age?: number }\n * ```\n */\nexport type InferType<T> = T extends {\n optimize: (...args: any[]) => {\n readonly [K in SchemaTypeBrand]: infer TOptimized;\n };\n}\n ? TOptimized\n : T extends { readonly [K in SchemaTypeBrand]: infer TType }\n ? TType\n : T;\n\n/**\n * Represents a single validation error with a human-readable error message.\n *\n * When returned from an object-level validator (via {@link SchemaBuilder.addValidator | addValidator}),\n * the optional `property` selector can route the error to a specific property\n * so that {@link ObjectSchemaValidationResult.getErrorsFor | getErrorsFor()} reports it\n * on that property rather than only on the root object.\n *\n * ```ts\n * .addValidator((v) => ({\n * valid: false,\n * errors: [{\n * message: 'Passwords do not match',\n * property: (t) => t.confirmPassword\n * }]\n * }))\n * ```\n */\nexport type ValidationError = {\n message: string;\n /**\n * Optional property selector that targets this error to a specific\n * property of the validated object. Uses the same selector signature\n * as `getErrorsFor()` and react-form's `forProperty`.\n */\n property?: (tree: any) => any;\n};\n\n/**\n * Used to represent a validation result for nested\n * objects/properties. Contains a list of errors and\n * the value that caused them.\n */\nexport type NestedValidationResult<\n TSchema,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor\n> = {\n /**\n * Value that property had and which caused error or errors\n */\n seenValue?: InferType<TSchema>;\n /**\n * A list of errors, empty if object satisfies a schema\n */\n errors: ReadonlyArray<string>;\n\n /**\n * Whether validation passed for this property and all of its children.\n */\n isValid: boolean;\n\n get descriptor(): PropertyDescriptorInner<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >;\n};\n\n/**\n * Utility type that makes a value `T` optional (i.e. `T | undefined`).\n * Used internally by {@link InferType} to represent optional schema fields.\n */\nexport type MakeOptional<T> = { prop?: T }['prop'];\n\n/**\n * Type of the function that provides a validation error message for\n * the given `seenValue` and `schema`. Can be a string or a function\n * returning a string or a promise of a string.\n * Should be used to provide a custom validation error message.\n */\nexport type ValidationErrorMessageProvider<\n TSchema extends SchemaBuilder<any, any, any, any, any> = SchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >\n> =\n | string\n | ((\n seenValue: InferType<TSchema>,\n schema: TSchema\n ) => string | Promise<string>);\n\nexport type ValidationResult<T> = {\n /**\n * If `true` - object satisfies schema\n */\n valid: boolean;\n /**\n * Contains validated object. Can be different (if there are any preprocessors in the schema) from object\n * passed to the `validate` method of the `SchemaBuilder` class.\n */\n object?: T;\n errors?: ValidationError[];\n};\n\n/**\n * Error thrown by {@link SchemaBuilder.parse | parse()} and\n * {@link SchemaBuilder.parseAsync | parseAsync()} when validation fails.\n * Carries the full array of {@link ValidationError | validation errors}.\n */\nexport class SchemaValidationError extends Error {\n public readonly errors: ValidationError[];\n\n constructor(errors: ValidationError[]) {\n const message =\n errors.length > 0\n ? errors.map(e => e.message).join('; ')\n : 'Validation failed';\n super(message);\n this.name = 'SchemaValidationError';\n this.errors = errors;\n }\n}\n\n/**\n * Internal result returned by the `preValidate` step of `SchemaBuilder`.\n * Contains the validation context, any early errors, and the transaction\n * wrapping the (possibly preprocessed) value.\n */\nexport type PreValidationResult<T, TTransactionType> = Omit<\n ValidationResult<T>,\n 'object'\n> & {\n context: ValidationContext;\n transaction?: Transaction<TTransactionType>;\n rootPropertyDescriptor?: PropertyDescriptor<any, any, undefined>;\n};\n\ntype ValidatorResult<T> = Omit<ValidationResult<T>, 'object' | 'errors'> & {\n errors?: ValidationError[];\n};\n\n/**\n * A function that transforms the value before validation.\n * Preprocessors run in order before validators and can modify or replace the value.\n *\n * @param object - the current value to preprocess\n * @returns the transformed value, or a Promise resolving to it\n */\nexport type Preprocessor<T> = (object: T) => Promise<T> | T;\n\n/**\n * A custom validation function that checks a value and returns a result\n * indicating whether the value is valid, along with optional error messages.\n *\n * @param object - the value to validate\n * @returns a result with `valid` boolean and optional `errors` array, or a Promise resolving to it\n */\nexport type Validator<T> = (\n object: T\n) => Promise<ValidatorResult<T>> | ValidatorResult<T>;\n\n/**\n * Internal wrapper that pairs a preprocessor function with metadata\n * indicating whether it may mutate the value.\n */\nexport type PreprocessorEntry<T> = { fn: Preprocessor<T>; mutates: boolean };\n\n/**\n * Internal wrapper that pairs a validator function with metadata\n * indicating whether it may mutate the value.\n */\nexport type ValidatorEntry<T> = { fn: Validator<T>; mutates: boolean };\n\n/**\n * Configuration properties used to construct a `SchemaBuilder` instance.\n * Contains the schema type identifier, requirement flag, and lists of\n * preprocessors and validators.\n */\nexport type SchemaBuilderProps<T> = {\n type: string;\n isRequired?: boolean;\n isNullable?: boolean;\n isReadonly?: boolean;\n preprocessors: PreprocessorEntry<T>[];\n validators: ValidatorEntry<T>[];\n requiredValidationErrorMessageProvider?: ValidationErrorMessageProvider;\n extensions?: Record<string, unknown>;\n defaultValue?: T | (() => T);\n catchValue?: T | (() => T);\n hasCatch?: boolean;\n description?: string;\n schemaName?: string;\n example?: unknown;\n};\n\nexport type ValidationContext<\n TSchema extends SchemaBuilder<any, any, any, any> = SchemaBuilder<\n any,\n any,\n any,\n any\n >\n> = {\n /**\n * Optional. By default validation will stop after the first validation error, in case if\n * you want to receive all validation erors, please set this flag to `true`.\n * You might need it to display validation errors.\n */\n doNotStopOnFirstError?: boolean;\n\n /**\n * Optional. If you define a `rootPropertyDescriptor` while validating an object,\n * it will report all validation errors with the path starting from the root property.\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n rootPropertyDescriptor?: TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any\n >\n ? PropertyDescriptor<TSchema, TSchema, undefined>\n : never;\n\n /**\n * Optional. This is a property descriptor for the current object being validated.\n * This descriptor is descendant of the `rootPropertyDescriptor` and is used to provide\n * a path to the current object being validated in the root object.\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n currentPropertyDescriptor?: TSchema extends ObjectSchemaBuilder<\n any,\n any,\n any\n >\n ? PropertyDescriptor<TSchema, TSchema, unknown>\n : never;\n\n /**\n * Optional. Used along with `rootPropertyDescriptor` and `currentPropertyDescriptor` to provide\n * a root validation object, this object will be used to retrieve the value of properties\n * using the `rootPropertyDescriptor` because the `rootPropertyDescriptor` is a property descriptor\n * for the root object, and it needs the root object along with the whole structure to get the\n * value of the property.\n *\n * Normally it's used internally by the library for validation of nested objects and\n * should not be used directly (but who knows, maybe you will find a use case for it).\n */\n rootValidationObject?: InferType<TSchema>;\n};\n\n/**\n * A symbol to mark property descriptors in the schema.\n * Normally, you should not use it directly unless you want\n * to develop some advanced features or extend the library.\n * In normal conditions it's used internally by the library.\n */\nexport const SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR = Symbol();\n\n/**\n * A symbol that marks a schema as having sub-properties that can\n * participate in property descriptor trees. When a schema exposes\n * `[SYMBOL_HAS_PROPERTIES] = true` **and** its `introspect()` returns\n * a `properties` record, it will be recursed into by\n * `ObjectSchemaBuilder.getPropertiesFor()` — the same way nested\n * `ObjectSchemaBuilder` instances are.\n *\n * Currently implemented by `ObjectSchemaBuilder` (always) and\n * `ExternSchemaBuilder` (when created with an explicit property map).\n */\nexport const SYMBOL_HAS_PROPERTIES = Symbol();\n\n/**\n * Describes a property in a schema. And gives you\n * a possibility to access property value and set it.\n * suppose you have a schema like this:\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * id: number()\n * });\n * ```\n * then you can get a property descriptor for the `address.city` property\n * like this:\n * ```ts\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n *\n * And then you can use it to get and set the value of this property having the object:\n * ```ts\n * const obj = {\n * name: 'Leo',\n * address: {\n * city: 'Kozelsk',\n * country: 'Russia'\n * },\n * id: 123\n * };\n *\n * const success = addressCityDescriptor.setValue(obj, 'Venyov');\n * // this returns you a boolean value indicating if the value was set successfully\n * ```\n */\n\nexport type PropertySetterOptions = {\n /**\n * If set to `true`, the method will create missing structure\n * in the object to set the value. For example, if you have a schema\n * and property descriptor like this:\n * ```ts\n * const schema = object({\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * });\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n * And then you try to set a new value to the `address.city` property on the object\n * which does not have `address` property:\n * ```ts\n * const obj = {\n * name: 'Leo'\n * };\n * const success = addressCityDescriptor.setValue(obj, 'Venyov', { createMissingStructure: true });\n * // success === true\n * // obj === {\n * // name: 'Leo',\n * // address: {\n * // city: 'Venyov'\n * // }\n * // }\n */\n createMissingStructure?: boolean;\n};\n\n/**\n * Extracts the inner property descriptor type from a `PropertyDescriptor`.\n * Returns `undefined` if `T` is not a valid `PropertyDescriptor`.\n */\nexport type PropertyDescriptorInnerFromPropertyDescriptor<T> =\n T extends PropertyDescriptor<\n infer TSchema,\n infer TPropertySchema,\n infer TParentPropertyDescriptor\n >\n ? PropertyDescriptorInner<\n TSchema,\n TPropertySchema,\n TParentPropertyDescriptor\n >\n : undefined;\n\nexport type PropertyDescriptorInner<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TPropertySchema,\n TParentPropertyDescriptor\n> = {\n /**\n * Sets a new value to the property. If the process was successful,\n * the method returns `true`, otherwise `false`.\n * It can return `false` if the property could not be set to the object\n * which can happen if the `setValue` method is called with an object\n * which does not comply with the schema.\n * for example, if you have a schema and property descriptopr like this:\n * ```ts\n * const schema = object({\n * name: string(),\n * address: object({\n * city: string(),\n * country: string()\n * }),\n * id: number()\n * });\n *\n * const addressCityDescriptor = object.getPropertiesFor(schema).address.city;\n * ```\n * And then you try to set a new value to the `address.city` property on the object\n * which does not have `address` property:\n * ```ts\n * const obj = {\n * name: 'Leo'\n * };\n *\n * const success = addressCityDescriptor.setValue(obj, 'Venyov');\n * // success === false\n * ```\n *\n * @param obj Object to set the value to\n * @param value a new value to set to the property\n * @param options additional optional parameters to control the process\n * @returns\n */\n setValue: (\n obj: InferType<TSchema>,\n value: InferType<TPropertySchema>,\n options?: PropertySetterOptions\n ) => boolean;\n /**\n * Gets the value of the property from the object.\n * @param obj object to get the value from\n * @returns an object containing a `value` and `success` properties. `value` is the value of the property\n * if it was found in the object, `success` is a boolean value indicating if the property was found in the object.\n */\n getValue: (obj: InferType<TSchema>) => {\n value?: InferType<TPropertySchema>;\n success: boolean;\n };\n\n /**\n * Gets the schema for the property described by the property descriptor.\n * @returns a schema for the property\n */\n getSchema: () => TPropertySchema;\n\n parent: PropertyDescriptorInnerFromPropertyDescriptor<TParentPropertyDescriptor>;\n // extends PropertyDescriptor<\n // any,\n // any,\n // any\n // >\n // ? TParentPropertyDescriptor\n // : never;\n\n /**\n * The name of this property within its parent object, or `undefined`\n * for the root descriptor.\n */\n propertyName: string | undefined;\n\n /**\n * Returns a JSON Pointer (RFC 6901) string representing this\n * property's path from the root descriptor.\n *\n * Property names are escaped per RFC 6901 (`~` → `~0`, `/` → `~1`).\n * The root descriptor returns an empty string (`''`).\n */\n toJsonPointer: () => string;\n};\n\n/**\n * A wrapper object keyed by {@link SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR} that\n * holds a {@link PropertyDescriptorInner} for a particular property within\n * an object schema. Used to get/set property values on validated objects.\n */\nexport type PropertyDescriptor<\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TPropertySchema,\n TParentPropertyDescriptor\n> = {\n [SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR]: PropertyDescriptorInner<\n TRootSchema,\n TPropertySchema,\n TParentPropertyDescriptor\n >;\n};\n\n/**\n * A tree of property descriptors for the schema.\n * Has a possibility to filter properties by the type (`TAssignableTo` type parameter).\n */\nexport type PropertyDescriptorTree<\n TSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any> = TSchema,\n TAssignableTo = any,\n TParentPropertyDescriptor = undefined\n> = PropertyDescriptor<TRootSchema, TSchema, TParentPropertyDescriptor> &\n (TSchema extends ObjectSchemaBuilder<infer TProperties, any, any>\n ? {\n [K in keyof TProperties]: TProperties[K] extends ObjectSchemaBuilder<\n any,\n any,\n any\n >\n ? PropertyDescriptorTree<\n TProperties[K],\n TRootSchema,\n any,\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n : TProperties[K] extends ExternSchemaBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n infer TExternResult\n >\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n > &\n ExternOutputPropertyDescriptors<\n TExternResult,\n TRootSchema,\n PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n >\n : TProperties[K] extends ArraySchemaBuilder<\n infer TArrayElement,\n any,\n any\n >\n ? TArrayElement extends ObjectSchemaBuilder<\n any,\n any,\n any,\n any,\n any\n >\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n : InferType<TProperties[K]> extends TAssignableTo\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n : never\n : InferType<TProperties[K]> extends TAssignableTo\n ? PropertyDescriptor<\n TRootSchema,\n TProperties[K],\n PropertyDescriptor<\n TRootSchema,\n TSchema,\n TParentPropertyDescriptor\n >\n >\n : never;\n }\n : never);\n\n/**\n * Recursively maps the keys of an extern schema's output type into\n * property descriptors. When a value is a plain-object type its keys\n * are expanded recursively; primitives, arrays, Dates, and functions\n * are treated as leaves.\n *\n * @internal\n */\ntype ExternOutputPropertyDescriptors<\n TOutput,\n TRootSchema extends ObjectSchemaBuilder<any, any, any, any, any>,\n TParentPropertyDescriptor\n> = TOutput extends\n | Date\n | Function\n | readonly any[]\n | string\n | number\n | boolean\n | symbol\n | bigint\n | null\n | undefined\n ? {}\n : TOutput extends Record<string, any>\n ? {\n [K in keyof TOutput]: PropertyDescriptor<\n TRootSchema,\n SchemaBuilder<TOutput[K], true, false, false, {}>,\n TParentPropertyDescriptor\n > &\n ExternOutputPropertyDescriptors<\n TOutput[K],\n TRootSchema,\n PropertyDescriptor<\n TRootSchema,\n SchemaBuilder<TOutput[K], true, false, false, {}>,\n TParentPropertyDescriptor\n >\n >;\n }\n : {};\n\n/**\n * Creates an array augmented with non-enumerable NestedValidationResult\n * properties (`seenValue`, `errors`, `isValid`, `descriptor`).\n * Used by UnionSchemaBuilder and ArraySchemaBuilder to return hybrid\n * arrays from `getErrorsFor()`.\n */\nexport function createHybridErrorArray<T extends any[]>(\n items: T,\n seenValue: () => any,\n errors: () => ReadonlyArray<string>,\n descriptor: () => any\n): T {\n Object.defineProperties(items, {\n seenValue: {\n get: seenValue,\n enumerable: false\n },\n errors: {\n get: errors,\n enumerable: false\n },\n isValid: {\n get: () => errors().length === 0,\n enumerable: false\n },\n descriptor: {\n get: descriptor,\n enumerable: false\n }\n });\n return items;\n}\n\n/**\n * Resolves the full output type of a schema, accounting for `TRequired` and\n * `TNullable` modifiers. Mirrors the branded `[__type]` computation so that\n * the `~standard` Standard Schema property carries the correct inferred type.\n *\n * - When `TRequired = true` and `TNullable = false` the result is `TResult`.\n * - When `TRequired = true` and `TNullable = true` the result is `TResult | null`.\n * - When `TRequired = false` the result is wrapped by {@link MakeOptional},\n * adding `| undefined` (and `| null` when also nullable).\n *\n * @internal\n */\ntype ResolvedSchemaType<\n TResult,\n TRequired extends boolean,\n TNullable extends boolean\n> = TRequired extends true\n ? TNullable extends true\n ? TResult | null\n : TResult\n : MakeOptional<TNullable extends true ? TResult | null : TResult>;\n\n/**\n * Base class for all schema builders. Provides basic functionality for schema building.\n *\n * **Note:** this class is not intended to be used directly, use one of the subclasses instead.\n * @typeparam TResult Type of the object that will be returned by `validate()` method.\n * @typeparam TRequired If `true`, object will be required. If `false`, object will be optional.\n */\nexport abstract class SchemaBuilder<\n TResult = any,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n THasDefault extends boolean = false,\n // biome-ignore lint/correctness/noUnusedVariables: used in extensions\n TExtensions = {}\n> {\n #isRequired = true;\n #isNullable = false;\n #isReadonly = false;\n #description: string | undefined;\n #schemaName: string | undefined;\n #preprocessors: PreprocessorEntry<TResult>[] = [];\n #validators: ValidatorEntry<TResult>[] = [];\n #hasMutating = false;\n #canSkipPreValidation = true;\n #extensions: Record<string, unknown> = {};\n #type = 'base';\n #defaultRequiredErrorMessageProvider: ValidationErrorMessageProvider =\n 'is required';\n #requiredErrorMessageProvider: ValidationErrorMessageProvider =\n 'is required';\n #defaultValue: TResult | (() => TResult) | undefined = undefined;\n #catchValue: TResult | (() => TResult) | undefined = undefined;\n #hasCatch = false;\n #example: unknown | undefined = undefined;\n /**\n * Cached result of the first `['~standard']` access. Stored so that\n * repeated property reads return the exact same object reference, which\n * is required by the Standard Schema spec.\n */\n #standardProps:\n | StandardSchemaV1.Props<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n >\n | undefined;\n\n /**\n * Type-level brand encoding the inferred type of this schema.\n * Not emitted at runtime — used only by {@link InferType}.\n * @internal\n */\n declare readonly [__type]: TRequired extends true\n ? TNullable extends true\n ? TResult | null\n : TResult\n : MakeOptional<TNullable extends true ? TResult | null : TResult>;\n\n /**\n * Type-level brand encoding whether this schema has a default value.\n * Not emitted at runtime — used by input type inference.\n * @internal\n */\n declare readonly [__hasDefault]: THasDefault;\n\n /**\n * Standard Schema v1 interface.\n *\n * Exposes this schema as a [Standard Schema v1](https://standardschema.dev/)\n * validator, enabling out-of-the-box interoperability with any library that\n * consumes the spec — including tRPC, TanStack Form, React Hook Form, T3 Env,\n * Hono, Elysia, next-safe-action, and 50+ other tools.\n *\n * Every `SchemaBuilder` subclass (all 13 builders) inherits this property\n * automatically — no additional setup required.\n *\n * **Shape of the returned object:**\n * - `version` — always `1` (Standard Schema spec version)\n * - `vendor` — `'@cleverbrush/schema'`\n * - `validate(value)` — synchronous; wraps this builder's own `.validate()`\n * and converts its result to the Standard Schema `Result<Output>` format:\n * - Success: `{ value: <validated output> }`\n * - Failure: `{ issues: [{ message: string }, …] }`\n *\n * The returned object is **cached** after the first access so repeated reads\n * return the same reference (required by the spec).\n *\n * @example\n * ```ts\n * import { object, string, number } from '@cleverbrush/schema';\n *\n * const UserSchema = object({\n * name: string().minLength(2),\n * email: string().email(),\n * age: number().min(18).optional(),\n * });\n *\n * // Grab the Standard Schema interface\n * const std = UserSchema['~standard'];\n * // std.version === 1\n * // std.vendor === '@cleverbrush/schema'\n *\n * const ok = std.validate({ name: 'Alice', email: 'alice@example.com' });\n * // { value: { name: 'Alice', email: 'alice@example.com', age: undefined } }\n *\n * const fail = std.validate({ name: 'A', email: 'not-an-email' });\n * // { issues: [{ message: 'minLength' }, { message: 'email' }] }\n *\n * // Pass directly to TanStack Form, T3 Env, tRPC, etc.:\n * // validators: { onChange: UserSchema, onBlur: UserSchema }\n * ```\n *\n * @see https://standardschema.dev/\n */\n get ['~standard'](): StandardSchemaV1.Props<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n > {\n if (this.#standardProps) return this.#standardProps;\n // Capture `this` for the closure so the validate callback can call\n // the schema's own validate method.\n const self = this;\n this.#standardProps = {\n version: 1 as const,\n vendor: '@cleverbrush/schema',\n validate(\n value: unknown\n ): StandardSchemaV1.Result<\n ResolvedSchemaType<TResult, TRequired, TNullable>\n > {\n // Standard Schema validate accepts `unknown`, while the\n // schema's own validate() has a typed parameter. The cast\n // is safe because validate() performs full runtime\n // validation regardless of the compile-time input type.\n const result = self.validate(value as any);\n if (result.valid) {\n return {\n value: result.object as ResolvedSchemaType<\n TResult,\n TRequired,\n TNullable\n >\n };\n }\n return {\n issues: (result.errors ?? []).map(e => ({\n message: e.message\n }))\n };\n }\n };\n return this.#standardProps;\n }\n\n /**\n * Set type of schema explicitly. `notUsed` param is needed only for case when JS is used. E.g. when you\n * can't call method like `schema.hasType<Date>()`, so instead you can call `schema.hasType(new Date())`\n * with the same result.\n */\n public abstract hasType<T>(notUsed?: T): any;\n\n /**\n * Clears type set by call to `.hasType<T>()`, default schema type inference will be used\n * for schema returned by this call.\n */\n public abstract clearHasType(): any;\n\n /**\n * Protected method used to create a new instance of the Builder\n * defined by the `props` object. Should be used to instantiate new\n * builders to keep builder's immutability.\n * @param props arbitrary props object\n */\n protected abstract createFromProps(props: any): this;\n\n /**\n * The string identifier of the schema type (e.g. `'string'`, `'number'`, `'object'`).\n */\n protected get type() {\n return this.#type;\n }\n\n /**\n * Sets the schema type identifier. Must be a non-empty string.\n */\n protected set type(value: string) {\n if (typeof value !== 'string' || !value)\n throw new Error('value should be non empty string');\n this.#type = value;\n }\n\n /**\n * A list of preprocessors associated with\n * the Builder\n */\n protected get preprocessors() {\n return this.#preprocessors;\n }\n\n /**\n * A list of validators associated with\n * the Builder\n */\n protected get validators() {\n return this.#validators;\n }\n\n /**\n * Whether the schema requires a non-null/non-undefined value.\n */\n protected get isRequired(): TRequired {\n return this.#isRequired as TRequired;\n }\n\n /**\n * Whether `null` is an accepted value for this schema.\n */\n protected get isNullable(): boolean {\n return this.#isNullable;\n }\n\n /**\n * Sets the requirement flag. Must be a boolean.\n */\n protected set isRequired(value: boolean) {\n if (typeof value !== 'boolean')\n throw new Error('should be a boolean value');\n this.#isRequired = value as any;\n }\n\n /**\n * The error message provider used for the \"is required\" error.\n * Exposed for fast-path validation in subclasses.\n */\n protected get requiredErrorMessage(): ValidationErrorMessageProvider {\n return this.#requiredErrorMessageProvider;\n }\n\n /**\n * Whether this schema has a default value configured via `.default()`.\n * Exposed for fast-path validation in subclasses.\n */\n protected get hasDefault(): boolean {\n return this.#defaultValue !== undefined;\n }\n\n /**\n * Whether this schema has a catch/fallback value configured via `.catch()`.\n */\n protected get hasCatch(): boolean {\n return this.#hasCatch;\n }\n\n /**\n * Resolves the catch/fallback value. If the stored value is a factory function,\n * it is called to produce the value (useful for mutable fallbacks like `() => []`).\n */\n protected resolveCatchValue(): TResult {\n return typeof this.#catchValue === 'function'\n ? (this.#catchValue as () => TResult)()\n : (this.#catchValue as TResult);\n }\n\n /**\n * Whether this schema is marked as readonly.\n * Type-level only — no runtime enforcement.\n */\n protected get isReadonly(): boolean {\n return this.#isReadonly;\n }\n\n /**\n * Resolves the default value. If the stored default is a function,\n * it is called to produce the value (useful for mutable defaults).\n */\n protected resolveDefaultValue(): TResult {\n return typeof this.#defaultValue === 'function'\n ? (this.#defaultValue as () => TResult)()\n : (this.#defaultValue as TResult);\n }\n\n /**\n * Whether `preValidateSync` can be skipped entirely.\n * True when there are no preprocessors and no validators,\n * so the only work would be the required check and wrapping\n * in a noop transaction — which subclasses can do inline.\n */\n protected get canSkipPreValidation(): boolean {\n return this.#canSkipPreValidation;\n }\n\n /**\n * Whether `null` should count as a required-constraint violation.\n *\n * By default `null` is treated the same as `undefined` for the purposes\n * of the required check — i.e. a required schema rejects both.\n * Subclasses that may legally receive `null` as a value (e.g.\n * `UnionSchemaBuilder` when a `NullSchemaBuilder` option is present)\n * can override this to `false` so that `null` bypasses the required\n * check and is passed directly to their option-validation logic.\n *\n * @protected\n */\n protected get isNullRequiredViolation(): boolean {\n return true;\n }\n\n /**\n * Shared setup for both {@link preValidateSync} and {@link preValidateAsync}.\n * Builds the validation context, creates the initial transaction, and\n * returns mutable state for the caller to drive.\n */\n #initPreValidation(object: any, context?: ValidationContext) {\n const doNotStopOnFirstError = context?.doNotStopOnFirstError ?? false;\n\n const resultingContext: ValidationContext = {\n doNotStopOnFirstError,\n rootPropertyDescriptor: context?.rootPropertyDescriptor,\n currentPropertyDescriptor: context?.currentPropertyDescriptor\n };\n\n const needsTransaction = this.#hasMutating;\n\n return {\n doNotStopOnFirstError,\n resultingContext,\n transaction: needsTransaction\n ? transaction({ validatedObject: object })\n : noopTransaction({ validatedObject: object }),\n errors: [] as ValidationError[]\n };\n }\n\n /**\n * Builds the failed early-return result used when\n * `doNotStopOnFirstError` is false.\n */\n #earlyFailResult(\n errors: ValidationError[],\n resultingContext: ValidationContext\n ): PreValidationResult<any, { validatedObject: any }> {\n return {\n valid: false,\n errors: [errors[0]].filter(e => e),\n context: resultingContext\n };\n }\n\n /**\n * Builds the error entries for a validator that reported `valid: false`.\n */\n #validatorFailureErrors(\n index: number,\n name: string | undefined,\n validatorErrors: ValidationError[] | undefined\n ): ValidationError[] {\n if (Array.isArray(validatorErrors) && validatorErrors.length) {\n return validatorErrors;\n }\n return [\n {\n message: `Validator #${index}${\n name ? ` (${name})` : ''\n } didn't pass.`\n }\n ];\n }\n\n /**\n * Assembles the final {@link PreValidationResult} after all preprocessors,\n * validators, and the required check have run.\n */\n #buildPreValidationResult(\n errors: ValidationError[],\n doNotStopOnFirstError: boolean,\n resultingContext: ValidationContext,\n trans: Transaction<{ validatedObject: any }>\n ): PreValidationResult<any, { validatedObject: any }> {\n if (errors.length > 0) {\n return {\n valid: false,\n errors: errors\n .filter(e => e)\n .filter((_e, i) =>\n doNotStopOnFirstError ? true : i === 0\n ),\n context: resultingContext,\n transaction: trans\n };\n }\n\n return {\n valid: true,\n context: resultingContext,\n transaction: trans\n };\n }\n\n /**\n * Synchronous version of {@link preValidateAsync}.\n * Throws at runtime if any preprocessor or validator returns a Promise.\n *\n * @param object - the value to pre-validate\n * @param context - optional validation context settings\n * @returns a `PreValidationResult` containing the preprocessed transaction, context, and any errors\n * @throws Error if a preprocessor or validator returns a Promise (use {@link preValidateAsync} instead)\n */\n protected preValidateSync(\n object: any,\n context?: ValidationContext\n ): PreValidationResult<any, { validatedObject: any }> {\n const state = this.#initPreValidation(object, context);\n const { doNotStopOnFirstError, resultingContext, errors } = state;\n let preprocessingTransaction = state.transaction;\n let preprocessedObject =\n preprocessingTransaction.object.validatedObject;\n\n if (this.#preprocessors.length > 0) {\n let currentPrepropIndex = 0;\n for (const entry of this.#preprocessors) {\n try {\n const result = entry.fn(preprocessedObject);\n if (result instanceof Promise) {\n throw new Error(\n `Preprocessor #${currentPrepropIndex}${entry.fn.name ? ` (${entry.fn.name})` : ''} returned a Promise. Use validateAsync() for schemas with async preprocessors.`\n );\n }\n preprocessedObject = result;\n } catch (err) {\n if (\n (err as Error).message?.includes('Use validateAsync()')\n ) {\n throw err;\n }\n errors.push({\n message: `Preprocessor #${currentPrepropIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentPrepropIndex++;\n }\n }\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (typeof preprocessedObject === 'undefined' && this.hasDefault) {\n preprocessedObject = this.resolveDefaultValue();\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (\n this.#validators.length > 0 &&\n !(preprocessedObject == null && !this.isRequired) &&\n !(preprocessedObject === null && this.#isNullable)\n ) {\n let currentValidatorIndex = 0;\n for (const entry of this.#validators) {\n try {\n const validatorResult = entry.fn(preprocessedObject);\n if (validatorResult instanceof Promise) {\n throw new Error(\n `Validator #${currentValidatorIndex}${entry.fn.name ? ` (${entry.fn.name})` : ''} returned a Promise. Use validateAsync() for schemas with async validators.`\n );\n }\n const { valid, errors: validatorErrors } = validatorResult;\n if (!valid) {\n errors.push(\n ...this.#validatorFailureErrors(\n currentValidatorIndex,\n entry.fn.name,\n validatorErrors\n )\n );\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(\n errors,\n resultingContext\n );\n }\n }\n } catch (err) {\n if (\n (err as Error).message?.includes('Use validateAsync()')\n ) {\n throw err;\n }\n errors.push({\n message: `Validator #${currentValidatorIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentValidatorIndex++;\n }\n }\n }\n\n if (\n this.isRequired &&\n (typeof preprocessedObject === 'undefined' ||\n (preprocessedObject === null &&\n this.isNullRequiredViolation &&\n !this.#isNullable))\n ) {\n errors.push({\n message: this.getValidationErrorMessageSync(\n this.#requiredErrorMessageProvider,\n preprocessedObject\n )\n });\n if (!doNotStopOnFirstError) {\n preprocessingTransaction.rollback();\n return this.#earlyFailResult(errors, resultingContext);\n }\n }\n\n return this.#buildPreValidationResult(\n errors,\n doNotStopOnFirstError,\n resultingContext,\n preprocessingTransaction\n );\n }\n\n /**\n * Async version of pre-validation. Runs preprocessors, validators, and the\n * required/optional check on `object`. Supports async preprocessors,\n * validators, and error message providers.\n *\n * @param object - the value to pre-validate\n * @param context - optional validation context settings\n * @returns a `PreValidationResult` containing the preprocessed transaction, context, and any errors\n */\n protected async preValidateAsync(\n object: any,\n context?: ValidationContext\n ): Promise<PreValidationResult<any, { validatedObject: any }>> {\n const state = this.#initPreValidation(object, context);\n const { doNotStopOnFirstError, resultingContext, errors } = state;\n let preprocessingTransaction = state.transaction;\n let preprocessedObject =\n preprocessingTransaction.object.validatedObject;\n\n if (this.#preprocessors.length > 0) {\n let currentPrepropIndex = 0;\n for (const entry of this.#preprocessors) {\n try {\n preprocessedObject = await Promise.resolve(\n entry.fn(preprocessedObject)\n );\n } catch (err) {\n errors.push({\n message: `Preprocessor #${currentPrepropIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentPrepropIndex++;\n }\n }\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (typeof preprocessedObject === 'undefined' && this.hasDefault) {\n preprocessedObject = this.resolveDefaultValue();\n preprocessingTransaction = this.#hasMutating\n ? transaction({ validatedObject: preprocessedObject })\n : noopTransaction({ validatedObject: preprocessedObject });\n }\n\n if (\n this.#validators.length > 0 &&\n !(preprocessedObject == null && !this.isRequired) &&\n !(preprocessedObject === null && this.#isNullable)\n ) {\n let currentValidatorIndex = 0;\n for (const entry of this.#validators) {\n try {\n const { valid, errors: validatorErrors } =\n await Promise.resolve(entry.fn(preprocessedObject));\n if (!valid) {\n errors.push(\n ...this.#validatorFailureErrors(\n currentValidatorIndex,\n entry.fn.name,\n validatorErrors\n )\n );\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(\n errors,\n resultingContext\n );\n }\n }\n } catch (err) {\n errors.push({\n message: `Validator #${currentValidatorIndex}${\n entry.fn.name ? ` (${entry.fn.name})` : ''\n } thrown an error: ${(err as Error).message}`\n });\n if (!doNotStopOnFirstError) {\n return this.#earlyFailResult(errors, resultingContext);\n }\n } finally {\n currentValidatorIndex++;\n }\n }\n }\n\n if (\n this.isRequired &&\n (typeof preprocessedObject === 'undefined' ||\n (preprocessedObject === null &&\n this.isNullRequiredViolation &&\n !this.#isNullable))\n ) {\n errors.push({\n message: await this.getValidationErrorMessage(\n this.#requiredErrorMessageProvider,\n preprocessedObject\n )\n });\n if (!doNotStopOnFirstError) {\n preprocessingTransaction.rollback();\n return this.#earlyFailResult(errors, resultingContext);\n }\n }\n\n return this.#buildPreValidationResult(\n errors,\n doNotStopOnFirstError,\n resultingContext,\n preprocessingTransaction\n );\n }\n\n /**\n * @deprecated Use {@link preValidateAsync} instead. This alias will be removed in a future version.\n */\n protected preValidate(\n object: any,\n context?: ValidationContext\n ): Promise<PreValidationResult<any, { validatedObject: any }>> {\n return this.preValidateAsync(object, context);\n }\n\n /**\n * Generates a serializable object describing the defined schema\n */\n public introspect() {\n return {\n /**\n * String `id` of schema type, e.g. `string', `number` or `object`.\n */\n type: this.type,\n /**\n * If set to `false`, schema will be optional (`null` or `undefined` values\n * will be considered as valid).\n */\n isRequired: this.#isRequired,\n /**\n * If set to `true`, schema values of `null` are considered valid.\n */\n isNullable: this.#isNullable,\n /**\n * If set to `true`, the inferred type is marked as readonly.\n * Type-level only — no runtime enforcement.\n */\n isReadonly: this.#isReadonly,\n /**\n * Array of preprocessor functions\n */\n preprocessors: [\n ...this.preprocessors\n ] as readonly PreprocessorEntry<TResult>[],\n /**\n * Array of validator functions\n */\n validators: [\n ...this.validators\n ] as readonly ValidatorEntry<TResult>[],\n /**\n * Custom error message provider for the 'is required' validation error.\n */\n requiredValidationErrorMessageProvider:\n this.#requiredErrorMessageProvider,\n /**\n * Extension metadata. Stores custom state set by schema extensions.\n */\n extensions: { ...this.#extensions },\n /**\n * Whether a default value (or factory) has been set on this schema.\n */\n hasDefault: this.#defaultValue !== undefined,\n /**\n * The default value or factory function.\n */\n defaultValue: this.#defaultValue,\n /**\n * The human-readable description attached to this schema via `.describe()`,\n * or `undefined` if none was set.\n */\n description: this.#description,\n /**\n * The logical name attached to this schema via `.schemaName()`,\n * or `undefined` if none was set.\n */\n schemaName: this.#schemaName,\n /**\n * Whether a catch/fallback value has been set on this schema via `.catch()`.\n */\n\n hasCatch: this.#hasCatch,\n /**\n * The catch/fallback value or factory function set via `.catch()`.\n */\n catchValue: this.#catchValue,\n /**\n * An example value attached to this schema via `.example()`,\n * or `undefined` if none was set.\n */\n example: this.#example\n };\n }\n\n /**\n * Makes schema optional (consider `null` and `undefined` as valid objects for this schema)\n */\n public optional() {\n return this.createFromProps({\n ...this.introspect(),\n isRequired: false\n }) as any;\n }\n\n /**\n * Makes schema nullable — `null` is accepted as a valid value.\n *\n * Unlike `.optional()` which accepts `undefined`, `.nullable()` accepts\n * `null`. The inferred type changes from `T` to `T | null`. Combine with\n * `.optional()` to accept both `null` and `undefined`.\n */\n public nullable() {\n return this.createFromProps({\n ...this.introspect(),\n isNullable: true\n }) as any;\n }\n\n /**\n * Removes the nullable mark — `null` is no longer accepted as a valid\n * value. This is the counterpart of `.nullable()`.\n */\n public notNullable() {\n return this.createFromProps({\n ...this.introspect(),\n isNullable: false\n }) as any;\n }\n\n /**\n * Sets a default value for this schema. When the input is `undefined`,\n * the default value is used instead. The default is still validated\n * against the schema's constraints.\n *\n * Accepts either a static value or a factory function (useful for\n * mutable defaults like `() => new Date()` or `() => []`).\n *\n * @example\n * ```ts\n * const schema = string().default('hello');\n * schema.validate(undefined); // { valid: true, object: 'hello' }\n * schema.validate('world'); // { valid: true, object: 'world' }\n * ```\n *\n * @example\n * ```ts\n * // Factory function for mutable defaults\n * const schema = array(string()).default(() => []);\n * ```\n */\n public default(value: TResult | (() => TResult)) {\n return this.createFromProps({\n ...this.introspect(),\n defaultValue: value\n }) as any;\n }\n\n /**\n * Sets a fallback value for this schema. When validation **fails** for any reason,\n * the fallback value is returned as a successful result instead of validation errors.\n *\n * This is useful for graceful degradation — for example, providing a safe default\n * when parsing untrusted input that might not conform to the schema.\n *\n * Accepts either a static value or a factory function. Factory functions are called\n * each time the fallback is needed (useful for mutable values like `() => []`).\n *\n * Unlike {@link default}, which only fires when the input is `undefined`, `.catch()`\n * fires on **any** validation failure — type mismatch, constraint violation, etc.\n *\n * When `.catch()` is set, {@link parse} and {@link parseAsync} will **never throw**.\n *\n * @param value - the fallback value, or a factory function producing the fallback\n *\n * @example\n * ```ts\n * const schema = string().catch('unknown');\n * schema.validate(42); // { valid: true, object: 'unknown' }\n * schema.validate('hello'); // { valid: true, object: 'hello' }\n * schema.parse(42); // 'unknown' (no throw)\n * ```\n *\n * @example\n * ```ts\n * // Factory function for mutable fallbacks\n * const schema = array(string()).catch(() => []);\n * schema.validate(null); // { valid: true, object: [] }\n * ```\n *\n * @example\n * ```ts\n * // Contrast with .default() — default fires only on undefined\n * const d = string().default('anon');\n * d.validate(undefined); // { valid: true, object: 'anon' } ← fires\n * d.validate(42); // { valid: false, errors: [...] } ← does NOT fire\n *\n * const c = string().catch('anon');\n * c.validate(undefined); // { valid: true, object: 'anon' } ← fires\n * c.validate(42); // { valid: true, object: 'anon' } ← also fires\n * ```\n */\n public catch(value: TResult | (() => TResult)): this {\n return this.createFromProps({\n ...this.introspect(),\n catchValue: value,\n hasCatch: true\n }) as unknown as this;\n }\n\n /**\n * Removes the default value set by a previous call to `.default()`.\n */\n public clearDefault() {\n return this.createFromProps({\n ...this.introspect(),\n defaultValue: undefined\n }) as any;\n }\n\n /**\n * Attaches a human-readable description to this schema as runtime metadata.\n *\n * The description has no effect on validation — it is purely informational.\n * It is accessible via `.introspect().description` and is emitted as the\n * `description` field by `toJsonSchema()` from `@cleverbrush/schema-json`.\n *\n * Useful for documentation generation, form labels, and AI tool descriptions.\n *\n * @example\n * ```ts\n * const schema = object({\n * name: string().describe('The user\\'s full name'),\n * age: number().optional().describe('Age in years'),\n * }).describe('A user object');\n *\n * schema.introspect().description; // 'A user object'\n * ```\n */\n public describe(text: string): this {\n return this.createFromProps({\n ...this.introspect(),\n description: text\n }) as unknown as this;\n }\n\n /**\n * Attaches an example value to this schema instance.\n *\n * The example is purely metadata — it has no effect on validation.\n * It is accessible via `.introspect().example` and is emitted as the\n * `example` keyword in JSON Schema output and OpenAPI spec generation.\n *\n * @example\n * ```ts\n * import { string } from '@cleverbrush/schema';\n *\n * const Email = string().example('user@example.com');\n *\n * Email.introspect().example; // 'user@example.com'\n * ```\n */\n public example(value: TResult): this {\n return this.createFromProps({\n ...this.introspect(),\n example: value\n }) as unknown as this;\n }\n\n /**\n * Attaches a logical name to this schema instance.\n *\n * The name is purely metadata — it has no effect on validation. It is\n * accessible via `.introspect().schemaName` and can be consumed by any\n * tool that introspects schemas at runtime, such as OpenAPI spec\n * generators, documentation tools, form libraries, or code generators.\n *\n * **Uniqueness** is the responsibility of the consuming tool. Passing the\n * same constant (same object reference) to multiple consumers is always\n * safe; how conflicts between different instances with the same name are\n * handled depends on the tool.\n *\n * @example\n * ```ts\n * import { object, string, number } from '@cleverbrush/schema';\n *\n * export const UserSchema = object({\n * id: number(),\n * name: string(),\n * }).schemaName('User');\n *\n * UserSchema.introspect().schemaName; // 'User'\n * ```\n */\n public schemaName(name: string): this {\n return this.createFromProps({\n ...this.introspect(),\n schemaName: name\n }) as unknown as this;\n }\n\n /**\n * Brands the schema with a phantom type tag, preventing structural mixing\n * of semantically different values at the type level. Zero runtime cost.\n *\n * The optional `_name` parameter is only needed when using plain JavaScript\n * (where generic type parameters are unavailable). In TypeScript, prefer\n * the generic form: `schema.brand<'Email'>()`.\n *\n * @example\n * ```ts\n * const Email = string().brand<'Email'>();\n * const Username = string().brand<'Username'>();\n * type Email = InferType<typeof Email>; // string & { readonly [BRAND]: 'Email' }\n * type Username = InferType<typeof Username>; // string & { readonly [BRAND]: 'Username' }\n * ```\n */\n public brand<TBrand extends string | symbol>(_name?: TBrand) {\n return this.createFromProps({\n ...this.introspect()\n }) as any;\n }\n\n /**\n * Marks the inferred type as readonly. For objects, produces `Readonly<T>`.\n * For arrays, produces `ReadonlyArray<T>`. Primitives are unchanged.\n * Type-level only — no runtime enforcement.\n *\n * @example\n * ```ts\n * const schema = object({ name: string(), age: number() }).readonly();\n * type T = InferType<typeof schema>; // Readonly<{ name: string; age: number }>\n * ```\n *\n * @example\n * ```ts\n * const schema = array(string()).readonly();\n * type T = InferType<typeof schema>; // ReadonlyArray<string>\n * ```\n */\n public readonly() {\n return this.createFromProps({\n ...this.introspect(),\n isReadonly: true\n }) as any;\n }\n\n /**\n * Makes schema required (consider `null` and `undefined` as invalid objects for this schema)\n * @param errorMessage - optional custom error message or provider for the 'is required' validation error\n */\n public required(errorMessage?: ValidationErrorMessageProvider) {\n return this.createFromProps({\n ...this.introspect(),\n isRequired: true,\n ...(errorMessage !== undefined\n ? {\n requiredValidationErrorMessageProvider:\n this.assureValidationErrorMessageProvider(\n errorMessage,\n this.#defaultRequiredErrorMessageProvider\n )\n }\n : {})\n }) as any;\n }\n\n /**\n * Adds a `preprocessor` to a preprocessors list\n */\n public addPreprocessor(\n preprocessor: Preprocessor<TResult>,\n options?: { mutates?: boolean }\n ): this {\n if (typeof preprocessor !== 'function') {\n throw new Error('preprocessor must be a function');\n }\n return this.createFromProps({\n ...this.introspect(),\n preprocessors: [\n ...this.preprocessors,\n { fn: preprocessor, mutates: options?.mutates ?? true }\n ]\n });\n }\n\n /**\n * Remove all preprocessors for this schema.\n */\n public clearPreprocessors(): this {\n return this.createFromProps({\n ...this.introspect(),\n preprocessors: []\n });\n }\n\n /**\n * Adds a `validator` to validators list.\n */\n public addValidator(\n validator: Validator<TResult>,\n options?: { mutates?: boolean }\n ): this {\n if (typeof validator !== 'function') {\n throw new Error('validator must be a function');\n }\n return this.createFromProps({\n ...this.introspect(),\n validators: [\n ...this.validators,\n { fn: validator, mutates: options?.mutates ?? false }\n ]\n });\n }\n\n /**\n * Remove all validators for this schema.\n */\n public clearValidators(): this {\n return this.createFromProps({\n ...this.introspect(),\n validators: []\n });\n }\n\n /**\n * Perform synchronous schema validation on `object`.\n * Throws at runtime if any preprocessor, validator, or error message\n * provider returns a Promise — use {@link validateAsync} instead.\n * @internal Override this in subclasses. External callers use {@link validate}.\n */\n protected abstract _validate(\n object: any,\n context?: ValidationContext\n ): ValidationResult<any>;\n\n /**\n * Perform asynchronous schema validation on `object`.\n * Supports async preprocessors, validators, and error message providers.\n * @internal Override this in subclasses. External callers use {@link validateAsync}.\n */\n protected abstract _validateAsync(\n object: any,\n context?: ValidationContext\n ): Promise<ValidationResult<any>>;\n\n /**\n * Perform synchronous schema validation on `object`.\n * Throws at runtime if any preprocessor, validator, or error message\n * provider returns a Promise — use {@link validateAsync} instead.\n *\n * If a fallback has been set via {@link catch}, a failed validation result\n * is replaced by a successful result built from the fallback value, preserving\n * the specialized result shape (e.g. `getErrorsFor` / `getNestedErrors` methods).\n */\n public validate(\n /**\n * Object to validate\n */\n object: any,\n /**\n * Optional `ValidationContext` settings\n */\n context?: ValidationContext\n ): ValidationResult<any> {\n const result = this._validate(object, context);\n if (!result.valid && this.#hasCatch) {\n const catchValue = this.resolveCatchValue();\n // Re-validate the fallback value so the returned result has the same\n // specialized shape as a normal successful result (e.g. getErrorsFor /\n // getNestedErrors helper methods are present and reflect success semantics).\n const catchResult = this._validate(catchValue, context);\n if (catchResult.valid) {\n return catchResult;\n }\n // Fallback value did not pass validation (user error) – return a plain\n // valid result as best-effort so that .catch() still suppresses the error.\n // Note: in this case specialized result methods such as getErrorsFor() /\n // getNestedErrors() will NOT be present on the returned object. This is an\n // edge case caused by the caller supplying a catch value that itself fails\n // schema validation; the type system should prevent this under normal use.\n return { valid: true, object: catchValue };\n }\n return result;\n }\n\n /**\n * Perform asynchronous schema validation on `object`.\n * Supports async preprocessors, validators, and error message providers.\n *\n * If a fallback has been set via {@link catch}, a failed validation result\n * is replaced by a successful result built from the fallback value, preserving\n * the specialized result shape (e.g. `getErrorsFor` / `getNestedErrors` methods).\n */\n public async validateAsync(\n /**\n * Object to validate\n */\n object: any,\n /**\n * Optional `ValidationContext` settings\n */\n context?: ValidationContext\n ): Promise<ValidationResult<any>> {\n const result = await this._validateAsync(object, context);\n if (!result.valid && this.#hasCatch) {\n const catchValue = this.resolveCatchValue();\n // Re-validate the fallback value so the returned result has the same\n // specialized shape as a normal successful result (e.g. getErrorsFor /\n // getNestedErrors helper methods are present and reflect success semantics).\n const catchResult = await this._validateAsync(catchValue, context);\n if (catchResult.valid) {\n return catchResult;\n }\n // Fallback value did not pass validation (user error) – return a plain\n // valid result as best-effort so that .catch() still suppresses the error.\n // Note: in this case specialized result methods such as getErrorsFor() /\n // getNestedErrors() will NOT be present on the returned object. This is an\n // edge case caused by the caller supplying a catch value that itself fails\n // schema validation; the type system should prevent this under normal use.\n return { valid: true, object: catchValue };\n }\n return result;\n }\n\n /**\n * Synchronously resolves a `ValidationErrorMessageProvider` to a string.\n * Throws if the provider function returns a Promise.\n *\n * @param provider - the error message provider (string or sync function)\n * @param seenValue - the value that caused the validation error\n * @returns the resolved error message string\n * @throws Error if the provider returns a Promise (use {@link getValidationErrorMessage} with {@link validateAsync})\n */\n protected getValidationErrorMessageSync(\n provider: ValidationErrorMessageProvider<any>,\n seenValue: TResult\n ): string {\n if (typeof provider === 'string') {\n return provider;\n }\n\n if (typeof provider === 'function') {\n const result = provider(seenValue, this);\n if (result instanceof Promise) {\n throw new Error(\n 'Async error message providers require validateAsync(). Use a string or sync function instead.'\n );\n }\n return result;\n }\n\n throw new Error(\n 'Invalid error message provider must be a string or a function returning a string'\n );\n }\n\n /**\n * Resolves a `ValidationErrorMessageProvider` to a string error message.\n * Handles both string providers and function providers (sync or async).\n *\n * @param provider - the error message provider (string or function)\n * @param seenValue - the value that caused the validation error\n * @returns the resolved error message string\n */\n protected async getValidationErrorMessage(\n provider: ValidationErrorMessageProvider<any>,\n seenValue: TResult\n ): Promise<string> {\n if (typeof provider === 'string') {\n return provider;\n }\n\n if (typeof provider === 'function') {\n return provider(seenValue, this);\n }\n\n throw new Error(\n 'Invalid error message provider must be a string or a function returning a string or a promise of a string'\n );\n }\n\n /**\n * Ensures a `ValidationErrorMessageProvider` is valid.\n * If `provider` is `undefined`, falls back to `defaultValue`.\n * Function providers are bound to `this` for access to schema state.\n *\n * @param provider - the provider to validate, or `undefined`\n * @param defaultValue - fallback provider when `provider` is not supplied\n * @returns a valid `ValidationErrorMessageProvider`\n */\n protected assureValidationErrorMessageProvider(\n provider: ValidationErrorMessageProvider<any> | undefined,\n defaultValue: ValidationErrorMessageProvider<any>\n ): ValidationErrorMessageProvider<any> {\n if (typeof provider === 'string') {\n return provider;\n }\n if (typeof provider === 'function') {\n return provider.bind(this);\n }\n\n if (typeof defaultValue === 'function') {\n return defaultValue.bind(this);\n }\n\n return defaultValue;\n }\n\n /**\n * Sets extension metadata by key. Returns a new schema instance with the\n * extension data stored. The data survives fluent chaining.\n * @internal Used by extension authors inside `defineExtension()` callbacks.\n */\n public withExtension(key: string, value: unknown): this {\n return this.createFromProps({\n ...this.introspect(),\n extensions: {\n ...this.#extensions,\n [key]: value\n }\n });\n }\n\n /**\n * Retrieves extension metadata by key.\n * @internal Used by extension authors inside `defineExtension()` callbacks.\n */\n public getExtension(key: string): unknown {\n return this.#extensions[key];\n }\n\n /**\n * Synchronously validates the value and returns it if valid.\n * Throws a {@link SchemaValidationError} if validation fails.\n *\n * @param object - the value to parse\n * @param context - optional validation context\n * @returns the validated value\n * @throws SchemaValidationError if validation fails\n * @throws Error if the schema contains async preprocessors, validators, or error message providers\n */\n public parse(object: any, context?: ValidationContext): TResult {\n const result = this.validate(object, context);\n if (!result.valid) {\n throw new SchemaValidationError(result.errors || []);\n }\n return result.object as TResult;\n }\n\n /**\n * Asynchronously validates the value and returns it if valid.\n * Throws a {@link SchemaValidationError} if validation fails.\n *\n * @param object - the value to parse\n * @param context - optional validation context\n * @returns the validated value\n * @throws SchemaValidationError if validation fails\n */\n public async parseAsync(\n object: any,\n context?: ValidationContext\n ): Promise<TResult> {\n const result = await this.validateAsync(object, context);\n if (!result.valid) {\n throw new SchemaValidationError(result.errors || []);\n }\n return result.object as TResult;\n }\n\n /**\n * Alias for {@link validate}. Synchronously validates and returns a result object.\n * Provided for familiarity with the zod API.\n */\n public safeParse(\n object: any,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return this.validate(object, context) as ValidationResult<TResult>;\n }\n\n /**\n * Alias for {@link validateAsync}. Asynchronously validates and returns a result object.\n * Provided for familiarity with the zod API.\n */\n public safeParseAsync(\n object: any,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return this.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n protected constructor(props: SchemaBuilderProps<TResult>) {\n if (!(typeof props === 'object' && props))\n throw new Error('SchemaBuilder props must be an object');\n const { type, preprocessors, validators, isRequired } = props;\n this.type = type;\n if (typeof isRequired === 'boolean') this.isRequired = isRequired;\n if (typeof props.isNullable === 'boolean')\n this.#isNullable = props.isNullable;\n if (typeof props.isReadonly === 'boolean')\n this.#isReadonly = props.isReadonly;\n if (Array.isArray(preprocessors)) {\n this.#preprocessors = [...preprocessors];\n }\n\n if (Array.isArray(validators)) {\n this.#validators = [...validators];\n }\n\n this.#hasMutating =\n this.#preprocessors.some(p => p.mutates) ||\n this.#validators.some(v => v.mutates);\n\n this.#canSkipPreValidation =\n this.#preprocessors.length === 0 && this.#validators.length === 0;\n\n if (typeof props.extensions === 'object' && props.extensions) {\n this.#extensions = { ...props.extensions };\n }\n\n if (props.defaultValue !== undefined) {\n this.#defaultValue = props.defaultValue;\n }\n\n if (props.hasCatch) {\n this.#hasCatch = true;\n this.#catchValue = props.catchValue;\n }\n\n if (typeof props.description === 'string') {\n this.#description = props.description;\n }\n\n if (typeof props.schemaName === 'string') {\n this.#schemaName = props.schemaName;\n }\n\n if (props.example !== undefined) {\n this.#example = props.example;\n }\n\n this.#requiredErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.requiredValidationErrorMessageProvider,\n this.#defaultRequiredErrorMessageProvider\n );\n }\n}\n"],"mappings":"AAAA,IAAMA,EAAqB,OAAO,aAAa,EAEzCC,EAA+B,CAAC,MAAO,OAAQ,IAAI,EAoBnDC,EAAgD,CAClD,6BAA8BC,GAC1B,CAAC,CAACF,EAA6B,KAAKG,GAAKD,aAAiBC,CAAC,CACnE,EAuCaC,EAAc,CACvBC,EACAC,IACiB,CACjB,IAAIC,EAA8C,CAAC,EAC/CC,EAAoB,IAAI,IAE5BF,EAAU,OAAO,OAAO,CAAC,EAAGL,EAA2BK,GAAW,CAAC,CAAC,EAEpE,GAAM,CAAE,6BAAAG,CAA6B,EAC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AAOA,GAAU,UAAYA,GAC/B,MAAM,IAAI,MAAM,uCAAuC,EAC3D,GAAM,CAAE,KAAAC,EAAM,cAAAC,EAAe,WAAAC,EAAY,WAAAC,CAAW,EAAIJ,EACxD,KAAK,KAAOC,EACR,OAAOG,GAAe,YAAW,KAAK,WAAaA,GACnD,OAAOJ,EAAM,YAAe,YAC5B,KAAKzD,GAAcyD,EAAM,YACzB,OAAOA,EAAM,YAAe,YAC5B,KAAKxD,GAAcwD,EAAM,YACzB,MAAM,QAAQE,CAAa,IAC3B,KAAKvD,GAAiB,CAAC,GAAGuD,CAAa,GAGvC,MAAM,QAAQC,CAAU,IACxB,KAAKvD,GAAc,CAAC,GAAGuD,CAAU,GAGrC,KAAKtD,GACD,KAAKF,GAAe,KAAK0D,GAAKA,EAAE,OAAO,GACvC,KAAKzD,GAAY,KAAK0D,GAAKA,EAAE,OAAO,EAExC,KAAKxD,GACD,KAAKH,GAAe,SAAW,GAAK,KAAKC,GAAY,SAAW,EAEhE,OAAOoD,EAAM,YAAe,UAAYA,EAAM,aAC9C,KAAKjD,GAAc,CAAE,GAAGiD,EAAM,UAAW,GAGzCA,EAAM,eAAiB,SACvB,KAAK7C,GAAgB6C,EAAM,cAG3BA,EAAM,WACN,KAAK3C,GAAY,GACjB,KAAKD,GAAc4C,EAAM,YAGzB,OAAOA,EAAM,aAAgB,WAC7B,KAAKvD,GAAeuD,EAAM,aAG1B,OAAOA,EAAM,YAAe,WAC5B,KAAKtD,GAAcsD,EAAM,YAGzBA,EAAM,UAAY,SAClB,KAAK1C,GAAW0C,EAAM,SAG1B,KAAK9C,GACD,KAAK,qCACD8C,EAAM,uCACN,KAAK/C,EACT,CACR,CACJ","names":["TRANSACTION_SYMBOL","defaultNonTransactionalTypes","defaultTransactionOptions","child","t","transaction","initial","options","newProperties","deletedProperties","shouldNotWrapWithTransaction","isDirty","key","commit","result","value","childCommit","rollback","el","commitArray","isDirtyArray","val","index","proxy","target","property","k","prop","isTransaction","object","p","noopTransaction","obj","SchemaValidationError","errors","message","e","SYMBOL_SCHEMA_PROPERTY_DESCRIPTOR","SYMBOL_HAS_PROPERTIES","createHybridErrorArray","items","seenValue","descriptor","SchemaBuilder","#isRequired","#isNullable","#isReadonly","#description","#schemaName","#preprocessors","#validators","#hasMutating","#canSkipPreValidation","#extensions","#type","#defaultRequiredErrorMessageProvider","#requiredErrorMessageProvider","#defaultValue","#catchValue","#hasCatch","#example","#standardProps","self","value","result","#initPreValidation","object","context","doNotStopOnFirstError","resultingContext","needsTransaction","transaction","noopTransaction","#earlyFailResult","#validatorFailureErrors","index","name","validatorErrors","#buildPreValidationResult","trans","_e","i","state","preprocessingTransaction","preprocessedObject","currentPrepropIndex","entry","err","currentValidatorIndex","validatorResult","valid","text","_name","errorMessage","preprocessor","options","validator","catchValue","catchResult","provider","defaultValue","key","props","type","preprocessors","validators","isRequired","p","v"]}
@@ -1,2 +1,2 @@
1
- import{f as l}from"./chunk-CTP4RHDG.js";var n=class i extends l{#e;#b=function(){return`expected to be at least ${this.#e}`};#a=this.#b;#r;#N=function(){return`expected to be no more than or equal to ${this.#r}`};#u=this.#N;#s;#E=function(){return`expected to be equal to ${this.#s}`};#n=this.#E;#t=!0;#l=function(){return"is not expected to be NaN"};#o=this.#l;#d=!0;#T=function(){return"is expected to be a finite number"};#m=this.#T;#h=!0;#i=function(){return"is expected to be an integer"};#c=this.#i;static create(e){return new i({type:"number",...e})}constructor(e){super(e),typeof e.min=="number"&&(this.#e=e.min),this.#a=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#b),typeof e.max=="number"&&(this.#r=e.max),this.#u=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#N),typeof e.ensureNotNaN=="boolean"&&(this.#t=e.ensureNotNaN),this.#o=this.assureValidationErrorMessageProvider(e.ensureNotNaNErrorMessageProvider,this.#l),typeof e.ensureIsFinite=="boolean"&&(this.#d=e.ensureIsFinite),this.#m=this.assureValidationErrorMessageProvider(e.ensureIsFiniteErrorMessageProvider,this.#T),typeof e.isInteger=="boolean"&&(this.#h=e.isInteger),this.#c=this.assureValidationErrorMessageProvider(e.ensureIsIntegerErrorMessageProvider,this.#i),(typeof e.equalsTo=="number"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#n=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#E)}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#a,max:this.#r,maxValidationErrorMessageProvider:this.#u,ensureNotNaN:this.#t,ensureNotNaNErrorMessageProvider:this.#o,ensureIsFinite:this.#d,ensureIsFiniteErrorMessageProvider:this.#m,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#n,isInteger:this.#h,ensureIsIntegerErrorMessageProvider:this.#c,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#f(e){return typeof e!="number"?{message:`expected type number, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#n}:this.#t&&Number.isNaN(e)?{provider:this.#o}:this.#d&&!Number.isFinite(e)&&this.#t&&!Number.isNaN(e)?{provider:this.#m}:this.#h&&!Number.isNaN(e)&&Number.isFinite(e)&&!Number.isInteger(e)?{provider:this.#c}:typeof this.#e<"u"&&e<this.#e?{provider:this.#a}:typeof this.#r<"u"&&e>this.#r?{provider:this.#u}:null}#R(e){let{valid:r,transaction:s,errors:t}=e;if(!r)return{done:!0,result:{valid:r,errors:t}};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:a}};let u=this.#f(a);return u?"message"in u?{done:!0,result:{valid:!1,errors:[{message:u.message}]}}:{done:!1,provider:u.provider,objToValidate:a}:{done:!0,result:{valid:!0,object:s.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let t=this.#f(e);return t?"message"in t?{valid:!1,errors:[{message:t.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,e)}]}:{valid:!0,object:e}}let s=this.#R(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#R(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return i.create(e)}equals(e,r){if(typeof e!="number")throw new Error("number expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}isFloat(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}clearIsInteger(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}isInteger(e){return this.createFromProps({...this.introspect(),isInteger:!0,ensureIsIntegerErrorMessageProvider:e})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}notNaN(e){return this.createFromProps({...this.introspect(),ensureNotNaN:!0,ensureNotNaNErrorMessageProvider:e})}canBeNaN(){return this.createFromProps({...this.introspect(),ensureNotNaN:!1,ensureNotNaNErrorMessageProvider:this.#l})}isFinite(e){return this.createFromProps({...this.introspect(),ensureIsFinite:!0,ensureIsFiniteErrorMessageProvider:e})}canBeInfinite(){return this.createFromProps({...this.introspect(),ensureIsFinite:!1,ensureIsFiniteErrorMessageProvider:this.#T})}min(e,r){if(typeof e!="number")throw new Error("minValue must be a number");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(typeof e!="number")throw new Error("maxValue must be a number");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}};function d(i){return typeof i=="number"?n.create({isRequired:!0,equalsTo:i}):n.create({isRequired:!0})}export{n as a,d as b};
2
- //# sourceMappingURL=chunk-KESLT5EE.js.map
1
+ import{f as l}from"./chunk-3JMDGYDT.js";var n=class i extends l{#e;#b=function(){return`expected to be at least ${this.#e}`};#a=this.#b;#r;#N=function(){return`expected to be no more than or equal to ${this.#r}`};#u=this.#N;#s;#E=function(){return`expected to be equal to ${this.#s}`};#n=this.#E;#t=!0;#l=function(){return"is not expected to be NaN"};#o=this.#l;#d=!0;#T=function(){return"is expected to be a finite number"};#m=this.#T;#h=!0;#i=function(){return"is expected to be an integer"};#c=this.#i;static create(e){return new i({type:"number",...e})}constructor(e){super(e),typeof e.min=="number"&&(this.#e=e.min),this.#a=this.assureValidationErrorMessageProvider(e.minValidationErrorMessageProvider,this.#b),typeof e.max=="number"&&(this.#r=e.max),this.#u=this.assureValidationErrorMessageProvider(e.maxValidationErrorMessageProvider,this.#N),typeof e.ensureNotNaN=="boolean"&&(this.#t=e.ensureNotNaN),this.#o=this.assureValidationErrorMessageProvider(e.ensureNotNaNErrorMessageProvider,this.#l),typeof e.ensureIsFinite=="boolean"&&(this.#d=e.ensureIsFinite),this.#m=this.assureValidationErrorMessageProvider(e.ensureIsFiniteErrorMessageProvider,this.#T),typeof e.isInteger=="boolean"&&(this.#h=e.isInteger),this.#c=this.assureValidationErrorMessageProvider(e.ensureIsIntegerErrorMessageProvider,this.#i),(typeof e.equalsTo=="number"||typeof e.equalsTo>"u")&&(this.#s=e.equalsTo),this.#n=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#E)}introspect(){return{...super.introspect(),min:this.#e,minValidationErrorMessageProvider:this.#a,max:this.#r,maxValidationErrorMessageProvider:this.#u,ensureNotNaN:this.#t,ensureNotNaNErrorMessageProvider:this.#o,ensureIsFinite:this.#d,ensureIsFiniteErrorMessageProvider:this.#m,equalsTo:this.#s,equalsToValidationErrorMessageProvider:this.#n,isInteger:this.#h,ensureIsIntegerErrorMessageProvider:this.#c,preprocessors:this.preprocessors,validators:this.validators}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#f(e){return typeof e!="number"?{message:`expected type number, but saw ${typeof e}`}:typeof this.#s<"u"&&e!==this.#s?{provider:this.#n}:this.#t&&Number.isNaN(e)?{provider:this.#o}:this.#d&&!Number.isFinite(e)&&this.#t&&!Number.isNaN(e)?{provider:this.#m}:this.#h&&!Number.isNaN(e)&&Number.isFinite(e)&&!Number.isInteger(e)?{provider:this.#c}:typeof this.#e<"u"&&e<this.#e?{provider:this.#a}:typeof this.#r<"u"&&e>this.#r?{provider:this.#u}:null}#R(e){let{valid:r,transaction:s,errors:t}=e;if(!r)return{done:!0,result:{valid:r,errors:t}};let{object:{validatedObject:a}}=s;if(typeof a>"u"&&!this.isRequired||a===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:a}};let u=this.#f(a);return u?"message"in u?{done:!0,result:{valid:!1,errors:[{message:u.message}]}}:{done:!1,provider:u.provider,objToValidate:a}:{done:!0,result:{valid:!0,object:s.commit().validatedObject}}}validate(e,r){return super.validate(e,r)}async validateAsync(e,r){return super.validateAsync(e,r)}_validate(e,r){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let t=this.#f(e);return t?"message"in t?{valid:!1,errors:[{message:t.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,e)}]}:{valid:!0,object:e}}let s=this.#R(this.preValidateSync(e,r));return s.done?s.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,s.objToValidate)}]}}async _validateAsync(e,r){let s=this.#R(await super.preValidateAsync(e,r));return s.done?s.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(s.provider,s.objToValidate)}]}}createFromProps(e){return i.create(e)}equals(e,r){if(typeof e!="number")throw new Error("number expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:r})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}isFloat(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}clearIsInteger(){return this.createFromProps({...this.introspect(),isInteger:!1,ensureIsIntegerErrorMessageProvider:this.#i})}isInteger(e){return this.createFromProps({...this.introspect(),isInteger:!0,ensureIsIntegerErrorMessageProvider:e})}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}notNaN(e){return this.createFromProps({...this.introspect(),ensureNotNaN:!0,ensureNotNaNErrorMessageProvider:e})}canBeNaN(){return this.createFromProps({...this.introspect(),ensureNotNaN:!1,ensureNotNaNErrorMessageProvider:this.#l})}isFinite(e){return this.createFromProps({...this.introspect(),ensureIsFinite:!0,ensureIsFiniteErrorMessageProvider:e})}canBeInfinite(){return this.createFromProps({...this.introspect(),ensureIsFinite:!1,ensureIsFiniteErrorMessageProvider:this.#T})}coerce(){return this.addPreprocessor((e=>typeof e=="string"?Number(e):e),{mutates:!0})}min(e,r){if(typeof e!="number")throw new Error("minValue must be a number");return this.createFromProps({...this.introspect(),min:e,minValidationErrorMessageProvider:r})}clearMin(){let e=this.introspect();return delete e.min,this.createFromProps({...e})}max(e,r){if(typeof e!="number")throw new Error("maxValue must be a number");return this.createFromProps({...this.introspect(),max:e,maxValidationErrorMessageProvider:r})}clearMax(){let e=this.introspect();return delete e.max,this.createFromProps({...e})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}};function d(i){return typeof i=="number"?n.create({isRequired:!0,equalsTo:i}):n.create({isRequired:!0})}export{n as a,d as b};
2
+ //# sourceMappingURL=chunk-BUEVZ3KA.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/builders/NumberSchemaBuilder.ts"],"sourcesContent":["import {\n type BRAND,\n type PreprocessorEntry,\n SchemaBuilder,\n type ValidationContext,\n type ValidationErrorMessageProvider,\n type ValidationResult,\n type ValidatorEntry\n} from './SchemaBuilder.js';\n\ntype NumberSchemaBuilderCreateProps<\n T = number,\n R extends boolean = true\n> = Partial<ReturnType<NumberSchemaBuilder<T, R, any>['introspect']>>;\n\n/**\n * Number schema builder class. Allows to create Number schemas.\n * Can be required or optional, can be restricted to be equal to a certain value,\n * can be restricted to be in a certain range, can be restricted to be integer.\n *\n * **NOTE** this class is exported only to give opportunity to extend it\n * by inheriting. It is not recommended to create an instance of this class\n * directly. Use {@link number | number()} function instead.\n *\n * @example ```ts\n * const schema = number().equals(42);\n * const result = schema.validate(42);\n * // result.valid === true\n * // result.object === 42\n * ```\n * @example ```ts\n * const schema = number();\n * const result = schema.validate('42');\n * // result.valid === false\n * // result.errors[0].message === 'is expected to be a number'\n * ```\n * @example ```ts\n * const schema = number().min(0).max(100);\n * const result = schema.validate(42);\n * // result.valid === true\n * // result.object === 42\n * ```\n *\n * @example ```ts\n * const schema = number().min(0).max(100);\n * const result = schema.validate(142.5);\n * // result.valid === false\n * // result.errors[0].message === 'is expected to be less than or equal to 100'\n * ```\n *\n * @see {@link number}\n */\nexport class NumberSchemaBuilder<\n TResult = number,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n THasDefault extends boolean = false,\n TExtensions = {}\n> extends SchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n #min?: number;\n #defaultMinErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be at least ${this.#min}`;\n } as any;\n #minErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultMinErrorMessageProvider;\n\n #max?: number;\n #defaultMaxErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be no more than or equal to ${this.#max}`;\n };\n #maxErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultMaxErrorMessageProvider;\n\n #equalsTo?: number;\n #defaultEqualsToErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be equal to ${this.#equalsTo}`;\n };\n #equalsToErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEqualsToErrorMessageProvider;\n\n #ensureNotNaN = true;\n #defaultEnsureNotNaNErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is not expected to be NaN';\n };\n #ensureNotNaNErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureNotNaNErrorMessageProvider;\n\n #ensureIsFinite = true;\n #defaultEnsureIsFiniteErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is expected to be a finite number';\n };\n #ensureIsFiniteErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureIsFiniteErrorMessageProvider;\n\n #isInteger = true;\n #defaultEnsureIsIntegerErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is expected to be an integer';\n };\n #ensureIsIntegerErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureIsIntegerErrorMessageProvider;\n\n /**\n * @hidden\n */\n public static create(props: NumberSchemaBuilderCreateProps) {\n return new NumberSchemaBuilder({\n type: 'number',\n ...props\n });\n }\n\n protected constructor(props: NumberSchemaBuilderCreateProps) {\n super(props as any);\n\n if (typeof props.min === 'number') {\n this.#min = props.min;\n }\n\n this.#minErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.minValidationErrorMessageProvider as any,\n this.#defaultMinErrorMessageProvider\n );\n\n if (typeof props.max === 'number') {\n this.#max = props.max;\n }\n\n this.#maxErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.maxValidationErrorMessageProvider as any,\n this.#defaultMaxErrorMessageProvider\n );\n\n if (typeof props.ensureNotNaN === 'boolean') {\n this.#ensureNotNaN = props.ensureNotNaN;\n }\n\n this.#ensureNotNaNErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureNotNaNErrorMessageProvider as any,\n this.#defaultEnsureNotNaNErrorMessageProvider\n );\n\n if (typeof props.ensureIsFinite === 'boolean') {\n this.#ensureIsFinite = props.ensureIsFinite;\n }\n\n this.#ensureIsFiniteErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureIsFiniteErrorMessageProvider as any,\n this.#defaultEnsureIsFiniteErrorMessageProvider\n );\n\n if (typeof props.isInteger === 'boolean') {\n this.#isInteger = props.isInteger;\n }\n\n this.#ensureIsIntegerErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureIsIntegerErrorMessageProvider as any,\n this.#defaultEnsureIsIntegerErrorMessageProvider\n );\n\n if (\n typeof props.equalsTo === 'number' ||\n typeof props.equalsTo === 'undefined'\n ) {\n this.#equalsTo = props.equalsTo;\n }\n\n this.#equalsToErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.equalsToValidationErrorMessageProvider as any,\n this.#defaultEqualsToErrorMessageProvider\n );\n }\n\n public introspect() {\n return {\n ...super.introspect(),\n /**\n * Min valid value (if defined).\n */\n min: this.#min,\n /**\n * Min valid value error message provider.\n * If not provided, default error message will be used.\n */\n minValidationErrorMessageProvider: this.#minErrorMessageProvider,\n\n /**\n * Max valid value (if defined).\n */\n max: this.#max,\n /**\n * Max valid value error message provider.\n * If not provided, default error message will be used.\n */\n maxValidationErrorMessageProvider: this.#maxErrorMessageProvider,\n\n /**\n * Make sure that object is not `NaN`. `true` by default.\n */\n ensureNotNaN: this.#ensureNotNaN,\n /**\n * EnsureNotNaN error message provider.\n * If not provided, default error message will be used.\n */\n ensureNotNaNErrorMessageProvider:\n this.#ensureNotNaNErrorMessageProvider,\n\n /**\n * Make sure that object is not different kinds of `infinity`. `true` by default.\n */\n ensureIsFinite: this.#ensureIsFinite,\n /**\n * EnsureIsFinite error message provider.\n */\n ensureIsFiniteErrorMessageProvider:\n this.#ensureIsFiniteErrorMessageProvider,\n\n /**\n * If set, restrict object to be equal to a certain value.\n */\n\n equalsTo: this.#equalsTo,\n /**\n * EqualsTo error message provider.\n * If not provided, default error message will be used.\n */\n equalsToValidationErrorMessageProvider:\n this.#equalsToErrorMessageProvider,\n\n /**\n * Allow only integer values (floating point values will be rejected\n * as invalid)\n */\n isInteger: this.#isInteger,\n /**\n * EnsureIsInteger error message provider.\n */\n ensureIsIntegerErrorMessageProvider:\n this.#ensureIsIntegerErrorMessageProvider,\n\n /**\n * Array of preprocessor functions\n */\n preprocessors: this.preprocessors as PreprocessorEntry<TResult>[],\n /**\n * Array of validator functions\n */\n validators: this.validators as ValidatorEntry<TResult>[]\n };\n }\n\n /**\n * @inheritdoc\n */\n public hasType<T>(\n _notUsed?: T\n ): NumberSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n /**\n * @inheritdoc\n */\n public clearHasType(): NumberSchemaBuilder<\n number,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n #getConstraintViolation(\n objToValidate: any\n ): { message: string } | { provider: any } | null {\n if (typeof objToValidate !== 'number') {\n return {\n message: `expected type number, but saw ${typeof objToValidate}`\n };\n }\n\n if (\n typeof this.#equalsTo !== 'undefined' &&\n objToValidate !== this.#equalsTo\n ) {\n return { provider: this.#equalsToErrorMessageProvider };\n }\n\n if (this.#ensureNotNaN && Number.isNaN(objToValidate)) {\n return { provider: this.#ensureNotNaNErrorMessageProvider };\n }\n\n if (\n this.#ensureIsFinite &&\n !Number.isFinite(objToValidate) &&\n this.#ensureNotNaN &&\n !Number.isNaN(objToValidate)\n ) {\n return { provider: this.#ensureIsFiniteErrorMessageProvider };\n }\n\n if (\n this.#isInteger &&\n !Number.isNaN(objToValidate) &&\n Number.isFinite(objToValidate) &&\n !Number.isInteger(objToValidate)\n ) {\n return { provider: this.#ensureIsIntegerErrorMessageProvider };\n }\n\n if (typeof this.#min !== 'undefined') {\n if (objToValidate < this.#min)\n return { provider: this.#minErrorMessageProvider };\n }\n\n if (typeof this.#max !== 'undefined') {\n if (objToValidate > this.#max)\n return { provider: this.#maxErrorMessageProvider };\n }\n\n return null;\n }\n\n #buildResult(\n superResult: ReturnType<NumberSchemaBuilder['preValidateSync']>\n ):\n | { done: true; result: ValidationResult<TResult> }\n | {\n done: false;\n provider: any;\n objToValidate: any;\n } {\n const {\n valid,\n transaction: preValidationTransaction,\n errors\n } = superResult;\n\n if (!valid) {\n return { done: true, result: { valid, errors } };\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = preValidationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return {\n done: true,\n result: { valid: true, object: objToValidate }\n };\n }\n\n const violation = this.#getConstraintViolation(objToValidate);\n\n if (!violation) {\n return {\n done: true,\n result: {\n valid: true,\n object: preValidationTransaction!.commit().validatedObject\n }\n };\n }\n\n if ('message' in violation) {\n return {\n done: true,\n result: {\n valid: false,\n errors: [{ message: violation.message }]\n }\n };\n }\n\n return {\n done: false,\n provider: violation.provider,\n objToValidate\n };\n }\n\n /** {@inheritDoc SchemaBuilder.validate} */\n public validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return super.validate(object, context) as ValidationResult<TResult>;\n }\n\n /** {@inheritDoc SchemaBuilder.validateAsync} */\n public async validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return super.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n /**\n * Performs synchronous validation of number schema over `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n * @param context Optional `ValidationContext` settings.\n */\n protected _validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n // Fast path: no preprocessors or custom validators\n if (this.canSkipPreValidation) {\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue();\n } else if (\n !this.isRequired ||\n (object === null && this.isNullable)\n ) {\n return { valid: true, object: object };\n } else {\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n this.requiredErrorMessage,\n object\n )\n }\n ]\n };\n }\n }\n\n const violation = this.#getConstraintViolation(object);\n\n if (!violation) {\n return { valid: true, object: object as TResult };\n }\n\n if ('message' in violation) {\n return {\n valid: false,\n errors: [{ message: violation.message }]\n };\n }\n\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n violation.provider,\n object as TResult\n )\n }\n ]\n };\n }\n\n const r = this.#buildResult(this.preValidateSync(object, context));\n if (r.done) return r.result;\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n r.provider,\n r.objToValidate as TResult\n )\n }\n ]\n };\n }\n\n /**\n * Performs async validation of number schema over `object`.\n * Supports async preprocessors, validators, and error message providers.\n * @param context Optional `ValidationContext` settings.\n */\n protected async _validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n const r = this.#buildResult(\n await super.preValidateAsync(object, context)\n );\n if (r.done) return r.result;\n return {\n valid: false,\n errors: [\n {\n message: await this.getValidationErrorMessage(\n r.provider,\n r.objToValidate as TResult\n )\n }\n ]\n };\n }\n\n protected createFromProps<T, TReq extends boolean>(\n props: NumberSchemaBuilderCreateProps<T, TReq>\n ): this {\n return NumberSchemaBuilder.create(props as any) as any;\n }\n\n /**\n * Restricts number to be equal to `value`.\n */\n public equals<T extends number>(\n value: T,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ) {\n if (typeof value !== 'number') throw new Error('number expected');\n return this.createFromProps({\n ...this.introspect(),\n equalsTo: value,\n equalsToValidationErrorMessageProvider: errorMessage\n }) as any as NumberSchemaBuilder<\n T,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions;\n }\n\n /**\n * Clear `equals()` call.\n */\n public clearEquals(): NumberSchemaBuilder<\n number,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n equalsTo: undefined\n }) as any;\n }\n\n /**\n * @deprecated Use {@link clearIsInteger} instead.\n * Float values will be considered as valid after this call.\n */\n public isFloat(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: false,\n ensureIsIntegerErrorMessageProvider:\n this.#defaultEnsureIsIntegerErrorMessageProvider\n }) as any;\n }\n\n /**\n * Clear `isInteger()` call.\n */\n public clearIsInteger(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: false,\n ensureIsIntegerErrorMessageProvider:\n this.#defaultEnsureIsIntegerErrorMessageProvider\n }) as any;\n }\n\n /**\n * Only integer values will be considered as valid after this call.\n */\n public isInteger(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: true,\n ensureIsIntegerErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): NumberSchemaBuilder<TResult, true, TNullable, THasDefault, TExtensions> &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): NumberSchemaBuilder<\n TResult,\n false,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public default(\n value: TResult | (() => TResult)\n ): NumberSchemaBuilder<TResult, true, TNullable, true, TExtensions> &\n TExtensions {\n return super.default(value) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n false,\n TExtensions\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 ): NumberSchemaBuilder<\n TResult & { readonly [K in BRAND]: TBrand },\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * Marks the inferred type as `Readonly<number>`. Since numbers are\n * already immutable this is an identity operation, but it sets the\n * `isReadonly` introspection flag for tooling consistency.\n *\n * @see {@link SchemaBuilder.readonly}\n */\n public readonly(): NumberSchemaBuilder<\n Readonly<TResult>,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.readonly();\n }\n\n /**\n * Do not accept NaN value\n */\n public notNaN(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureNotNaN: true,\n ensureNotNaNErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Consider NaN value as valid\n */\n public canBeNaN(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureNotNaN: false,\n ensureNotNaNErrorMessageProvider:\n this.#defaultEnsureNotNaNErrorMessageProvider\n }) as any;\n }\n\n /**\n * Do not accept `Infinity`.\n */\n public isFinite(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureIsFinite: true,\n ensureIsFiniteErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Consider `Infinity` as valid.\n */\n public canBeInfinite(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureIsFinite: false,\n ensureIsFiniteErrorMessageProvider:\n this.#defaultEnsureIsFiniteErrorMessageProvider\n }) as any;\n }\n\n /**\n * Restrict number to be at least `minValue`.\n */\n public min(\n minValue: number,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n if (typeof minValue !== 'number')\n throw new Error('minValue must be a number');\n return this.createFromProps({\n ...this.introspect(),\n min: minValue,\n minValidationErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Clear `min()` call.\n */\n public clearMin(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n const schema = this.introspect();\n delete schema.min;\n return this.createFromProps({\n ...schema\n }) as any;\n }\n\n /**\n * Restrict number to be no more than `maxValue`.\n */\n public max(\n maxValue: number,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n if (typeof maxValue !== 'number')\n throw new Error('maxValue must be a number');\n return this.createFromProps({\n ...this.introspect(),\n max: maxValue,\n maxValidationErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Clear `max()` call.\n */\n public clearMax(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n const schema = this.introspect();\n delete schema.max;\n return this.createFromProps({\n ...schema\n }) as any;\n }\n\n /**\n * @hidden\n */\n public nullable(): NumberSchemaBuilder<\n TResult,\n TRequired,\n true,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.nullable() as any;\n }\n\n /**\n * @hidden\n */\n public notNullable(): NumberSchemaBuilder<\n TResult,\n TRequired,\n false,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.notNullable() as any;\n }\n}\n\n/**\n * Creates a number schema restricted to `equals` value.\n * @param equals string value\n */\nexport function number<T extends number>(\n equals: T\n): NumberSchemaBuilder<T, true>;\n\n/**\n * Creates a number schema.\n */\nexport function number(): NumberSchemaBuilder<number, true>;\n\n/**\n * Creates a number schema.\n */\nexport function number(equals?: number) {\n if (typeof equals === 'number') {\n return NumberSchemaBuilder.create({\n isRequired: true,\n equalsTo: equals\n });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AW,EAC/B,cAAOA,EAAO,IACP,KAAK,gBAAgB,CACxB,GAAGA,CACP,CAAC,CACL,CAKO,IACHC,EAIAJ,EAUY,CACZ,GAAI,OAAOI,GAAa,SACpB,MAAM,IAAI,MAAM,2BAA2B,EAC/C,OAAO,KAAK,gBAAgB,CACxB,GAAG,KAAK,WAAW,EACnB,IAAKA,EACL,kCAAmCJ,CACvC,CAAC,CACL,CAKO,UAOS,CACZ,IAAMG,EAAS,KAAK,WAAW,EAC/B,cAAOA,EAAO,IACP,KAAK,gBAAgB,CACxB,GAAGA,CACP,CAAC,CACL,CAKO,UAOS,CACZ,OAAO,MAAM,SAAS,CAC1B,CAKO,aAOS,CACZ,OAAO,MAAM,YAAY,CAC7B,CACJ,EAkBO,SAASE,EAAOC,EAAiB,CACpC,OAAI,OAAOA,GAAW,SACXzC,EAAoB,OAAO,CAC9B,WAAY,GACZ,SAAUyC,CACd,CAAC,EAEEzC,EAAoB,OAAO,CAC9B,WAAY,EAChB,CAAC,CACL","names":["NumberSchemaBuilder","_NumberSchemaBuilder","SchemaBuilder","#min","#defaultMinErrorMessageProvider","#minErrorMessageProvider","#max","#defaultMaxErrorMessageProvider","#maxErrorMessageProvider","#equalsTo","#defaultEqualsToErrorMessageProvider","#equalsToErrorMessageProvider","#ensureNotNaN","#defaultEnsureNotNaNErrorMessageProvider","#ensureNotNaNErrorMessageProvider","#ensureIsFinite","#defaultEnsureIsFiniteErrorMessageProvider","#ensureIsFiniteErrorMessageProvider","#isInteger","#defaultEnsureIsIntegerErrorMessageProvider","#ensureIsIntegerErrorMessageProvider","props","_notUsed","#getConstraintViolation","objToValidate","#buildResult","superResult","valid","preValidationTransaction","errors","violation","object","context","r","value","errorMessage","_name","minValue","schema","maxValue","number","equals"]}
1
+ {"version":3,"sources":["../src/builders/NumberSchemaBuilder.ts"],"sourcesContent":["import {\n type BRAND,\n type PreprocessorEntry,\n SchemaBuilder,\n type ValidationContext,\n type ValidationErrorMessageProvider,\n type ValidationResult,\n type ValidatorEntry\n} from './SchemaBuilder.js';\n\ntype NumberSchemaBuilderCreateProps<\n T = number,\n R extends boolean = true\n> = Partial<ReturnType<NumberSchemaBuilder<T, R, any>['introspect']>>;\n\n/**\n * Number schema builder class. Allows to create Number schemas.\n * Can be required or optional, can be restricted to be equal to a certain value,\n * can be restricted to be in a certain range, can be restricted to be integer.\n *\n * **NOTE** this class is exported only to give opportunity to extend it\n * by inheriting. It is not recommended to create an instance of this class\n * directly. Use {@link number | number()} function instead.\n *\n * @example ```ts\n * const schema = number().equals(42);\n * const result = schema.validate(42);\n * // result.valid === true\n * // result.object === 42\n * ```\n * @example ```ts\n * const schema = number();\n * const result = schema.validate('42');\n * // result.valid === false\n * // result.errors[0].message === 'is expected to be a number'\n * ```\n * @example ```ts\n * const schema = number().min(0).max(100);\n * const result = schema.validate(42);\n * // result.valid === true\n * // result.object === 42\n * ```\n *\n * @example ```ts\n * const schema = number().min(0).max(100);\n * const result = schema.validate(142.5);\n * // result.valid === false\n * // result.errors[0].message === 'is expected to be less than or equal to 100'\n * ```\n *\n * @see {@link number}\n */\nexport class NumberSchemaBuilder<\n TResult = number,\n TRequired extends boolean = true,\n TNullable extends boolean = false,\n THasDefault extends boolean = false,\n TExtensions = {}\n> extends SchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n> {\n #min?: number;\n #defaultMinErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be at least ${this.#min}`;\n } as any;\n #minErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultMinErrorMessageProvider;\n\n #max?: number;\n #defaultMaxErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be no more than or equal to ${this.#max}`;\n };\n #maxErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultMaxErrorMessageProvider;\n\n #equalsTo?: number;\n #defaultEqualsToErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return `expected to be equal to ${this.#equalsTo}`;\n };\n #equalsToErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEqualsToErrorMessageProvider;\n\n #ensureNotNaN = true;\n #defaultEnsureNotNaNErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is not expected to be NaN';\n };\n #ensureNotNaNErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureNotNaNErrorMessageProvider;\n\n #ensureIsFinite = true;\n #defaultEnsureIsFiniteErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is expected to be a finite number';\n };\n #ensureIsFiniteErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureIsFiniteErrorMessageProvider;\n\n #isInteger = true;\n #defaultEnsureIsIntegerErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = function (this: NumberSchemaBuilder) {\n return 'is expected to be an integer';\n };\n #ensureIsIntegerErrorMessageProvider: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n > = this.#defaultEnsureIsIntegerErrorMessageProvider;\n\n /**\n * @hidden\n */\n public static create(props: NumberSchemaBuilderCreateProps) {\n return new NumberSchemaBuilder({\n type: 'number',\n ...props\n });\n }\n\n protected constructor(props: NumberSchemaBuilderCreateProps) {\n super(props as any);\n\n if (typeof props.min === 'number') {\n this.#min = props.min;\n }\n\n this.#minErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.minValidationErrorMessageProvider as any,\n this.#defaultMinErrorMessageProvider\n );\n\n if (typeof props.max === 'number') {\n this.#max = props.max;\n }\n\n this.#maxErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.maxValidationErrorMessageProvider as any,\n this.#defaultMaxErrorMessageProvider\n );\n\n if (typeof props.ensureNotNaN === 'boolean') {\n this.#ensureNotNaN = props.ensureNotNaN;\n }\n\n this.#ensureNotNaNErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureNotNaNErrorMessageProvider as any,\n this.#defaultEnsureNotNaNErrorMessageProvider\n );\n\n if (typeof props.ensureIsFinite === 'boolean') {\n this.#ensureIsFinite = props.ensureIsFinite;\n }\n\n this.#ensureIsFiniteErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureIsFiniteErrorMessageProvider as any,\n this.#defaultEnsureIsFiniteErrorMessageProvider\n );\n\n if (typeof props.isInteger === 'boolean') {\n this.#isInteger = props.isInteger;\n }\n\n this.#ensureIsIntegerErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.ensureIsIntegerErrorMessageProvider as any,\n this.#defaultEnsureIsIntegerErrorMessageProvider\n );\n\n if (\n typeof props.equalsTo === 'number' ||\n typeof props.equalsTo === 'undefined'\n ) {\n this.#equalsTo = props.equalsTo;\n }\n\n this.#equalsToErrorMessageProvider =\n this.assureValidationErrorMessageProvider(\n props.equalsToValidationErrorMessageProvider as any,\n this.#defaultEqualsToErrorMessageProvider\n );\n }\n\n public introspect() {\n return {\n ...super.introspect(),\n /**\n * Min valid value (if defined).\n */\n min: this.#min,\n /**\n * Min valid value error message provider.\n * If not provided, default error message will be used.\n */\n minValidationErrorMessageProvider: this.#minErrorMessageProvider,\n\n /**\n * Max valid value (if defined).\n */\n max: this.#max,\n /**\n * Max valid value error message provider.\n * If not provided, default error message will be used.\n */\n maxValidationErrorMessageProvider: this.#maxErrorMessageProvider,\n\n /**\n * Make sure that object is not `NaN`. `true` by default.\n */\n ensureNotNaN: this.#ensureNotNaN,\n /**\n * EnsureNotNaN error message provider.\n * If not provided, default error message will be used.\n */\n ensureNotNaNErrorMessageProvider:\n this.#ensureNotNaNErrorMessageProvider,\n\n /**\n * Make sure that object is not different kinds of `infinity`. `true` by default.\n */\n ensureIsFinite: this.#ensureIsFinite,\n /**\n * EnsureIsFinite error message provider.\n */\n ensureIsFiniteErrorMessageProvider:\n this.#ensureIsFiniteErrorMessageProvider,\n\n /**\n * If set, restrict object to be equal to a certain value.\n */\n\n equalsTo: this.#equalsTo,\n /**\n * EqualsTo error message provider.\n * If not provided, default error message will be used.\n */\n equalsToValidationErrorMessageProvider:\n this.#equalsToErrorMessageProvider,\n\n /**\n * Allow only integer values (floating point values will be rejected\n * as invalid)\n */\n isInteger: this.#isInteger,\n /**\n * EnsureIsInteger error message provider.\n */\n ensureIsIntegerErrorMessageProvider:\n this.#ensureIsIntegerErrorMessageProvider,\n\n /**\n * Array of preprocessor functions\n */\n preprocessors: this.preprocessors as PreprocessorEntry<TResult>[],\n /**\n * Array of validator functions\n */\n validators: this.validators as ValidatorEntry<TResult>[]\n };\n }\n\n /**\n * @inheritdoc\n */\n public hasType<T>(\n _notUsed?: T\n ): NumberSchemaBuilder<T, true, TNullable, THasDefault, TExtensions> &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n /**\n * @inheritdoc\n */\n public clearHasType(): NumberSchemaBuilder<\n number,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect()\n } as any) as any;\n }\n\n #getConstraintViolation(\n objToValidate: any\n ): { message: string } | { provider: any } | null {\n if (typeof objToValidate !== 'number') {\n return {\n message: `expected type number, but saw ${typeof objToValidate}`\n };\n }\n\n if (\n typeof this.#equalsTo !== 'undefined' &&\n objToValidate !== this.#equalsTo\n ) {\n return { provider: this.#equalsToErrorMessageProvider };\n }\n\n if (this.#ensureNotNaN && Number.isNaN(objToValidate)) {\n return { provider: this.#ensureNotNaNErrorMessageProvider };\n }\n\n if (\n this.#ensureIsFinite &&\n !Number.isFinite(objToValidate) &&\n this.#ensureNotNaN &&\n !Number.isNaN(objToValidate)\n ) {\n return { provider: this.#ensureIsFiniteErrorMessageProvider };\n }\n\n if (\n this.#isInteger &&\n !Number.isNaN(objToValidate) &&\n Number.isFinite(objToValidate) &&\n !Number.isInteger(objToValidate)\n ) {\n return { provider: this.#ensureIsIntegerErrorMessageProvider };\n }\n\n if (typeof this.#min !== 'undefined') {\n if (objToValidate < this.#min)\n return { provider: this.#minErrorMessageProvider };\n }\n\n if (typeof this.#max !== 'undefined') {\n if (objToValidate > this.#max)\n return { provider: this.#maxErrorMessageProvider };\n }\n\n return null;\n }\n\n #buildResult(\n superResult: ReturnType<NumberSchemaBuilder['preValidateSync']>\n ):\n | { done: true; result: ValidationResult<TResult> }\n | {\n done: false;\n provider: any;\n objToValidate: any;\n } {\n const {\n valid,\n transaction: preValidationTransaction,\n errors\n } = superResult;\n\n if (!valid) {\n return { done: true, result: { valid, errors } };\n }\n\n const {\n object: { validatedObject: objToValidate }\n } = preValidationTransaction!;\n\n if (\n (typeof objToValidate === 'undefined' && !this.isRequired) ||\n (objToValidate === null && (!this.isRequired || this.isNullable))\n ) {\n return {\n done: true,\n result: { valid: true, object: objToValidate }\n };\n }\n\n const violation = this.#getConstraintViolation(objToValidate);\n\n if (!violation) {\n return {\n done: true,\n result: {\n valid: true,\n object: preValidationTransaction!.commit().validatedObject\n }\n };\n }\n\n if ('message' in violation) {\n return {\n done: true,\n result: {\n valid: false,\n errors: [{ message: violation.message }]\n }\n };\n }\n\n return {\n done: false,\n provider: violation.provider,\n objToValidate\n };\n }\n\n /** {@inheritDoc SchemaBuilder.validate} */\n public validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n return super.validate(object, context) as ValidationResult<TResult>;\n }\n\n /** {@inheritDoc SchemaBuilder.validateAsync} */\n public async validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n return super.validateAsync(object, context) as Promise<\n ValidationResult<TResult>\n >;\n }\n\n /**\n * Performs synchronous validation of number schema over `object`.\n * Throws if any preprocessor, validator, or error message provider returns a Promise.\n * @param context Optional `ValidationContext` settings.\n */\n protected _validate(\n object: TResult,\n context?: ValidationContext\n ): ValidationResult<TResult> {\n // Fast path: no preprocessors or custom validators\n if (this.canSkipPreValidation) {\n if (typeof object === 'undefined' || object === null) {\n if (typeof object === 'undefined' && this.hasDefault) {\n object = this.resolveDefaultValue();\n } else if (\n !this.isRequired ||\n (object === null && this.isNullable)\n ) {\n return { valid: true, object: object };\n } else {\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n this.requiredErrorMessage,\n object\n )\n }\n ]\n };\n }\n }\n\n const violation = this.#getConstraintViolation(object);\n\n if (!violation) {\n return { valid: true, object: object as TResult };\n }\n\n if ('message' in violation) {\n return {\n valid: false,\n errors: [{ message: violation.message }]\n };\n }\n\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n violation.provider,\n object as TResult\n )\n }\n ]\n };\n }\n\n const r = this.#buildResult(this.preValidateSync(object, context));\n if (r.done) return r.result;\n return {\n valid: false,\n errors: [\n {\n message: this.getValidationErrorMessageSync(\n r.provider,\n r.objToValidate as TResult\n )\n }\n ]\n };\n }\n\n /**\n * Performs async validation of number schema over `object`.\n * Supports async preprocessors, validators, and error message providers.\n * @param context Optional `ValidationContext` settings.\n */\n protected async _validateAsync(\n object: TResult,\n context?: ValidationContext\n ): Promise<ValidationResult<TResult>> {\n const r = this.#buildResult(\n await super.preValidateAsync(object, context)\n );\n if (r.done) return r.result;\n return {\n valid: false,\n errors: [\n {\n message: await this.getValidationErrorMessage(\n r.provider,\n r.objToValidate as TResult\n )\n }\n ]\n };\n }\n\n protected createFromProps<T, TReq extends boolean>(\n props: NumberSchemaBuilderCreateProps<T, TReq>\n ): this {\n return NumberSchemaBuilder.create(props as any) as any;\n }\n\n /**\n * Restricts number to be equal to `value`.\n */\n public equals<T extends number>(\n value: T,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ) {\n if (typeof value !== 'number') throw new Error('number expected');\n return this.createFromProps({\n ...this.introspect(),\n equalsTo: value,\n equalsToValidationErrorMessageProvider: errorMessage\n }) as any as NumberSchemaBuilder<\n T,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions;\n }\n\n /**\n * Clear `equals()` call.\n */\n public clearEquals(): NumberSchemaBuilder<\n number,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n equalsTo: undefined\n }) as any;\n }\n\n /**\n * @deprecated Use {@link clearIsInteger} instead.\n * Float values will be considered as valid after this call.\n */\n public isFloat(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: false,\n ensureIsIntegerErrorMessageProvider:\n this.#defaultEnsureIsIntegerErrorMessageProvider\n }) as any;\n }\n\n /**\n * Clear `isInteger()` call.\n */\n public clearIsInteger(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: false,\n ensureIsIntegerErrorMessageProvider:\n this.#defaultEnsureIsIntegerErrorMessageProvider\n }) as any;\n }\n\n /**\n * Only integer values will be considered as valid after this call.\n */\n public isInteger(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n isInteger: true,\n ensureIsIntegerErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * @hidden\n */\n public required(\n errorMessage?: ValidationErrorMessageProvider\n ): NumberSchemaBuilder<TResult, true, TNullable, THasDefault, TExtensions> &\n TExtensions {\n return super.required(errorMessage);\n }\n\n /**\n * @hidden\n */\n public optional(): NumberSchemaBuilder<\n TResult,\n false,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.optional();\n }\n\n /**\n * @hidden\n */\n public default(\n value: TResult | (() => TResult)\n ): NumberSchemaBuilder<TResult, true, TNullable, true, TExtensions> &\n TExtensions {\n return super.default(value) as any;\n }\n\n /**\n * @hidden\n */\n public clearDefault(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n false,\n TExtensions\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 ): NumberSchemaBuilder<\n TResult & { readonly [K in BRAND]: TBrand },\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.brand(_name);\n }\n\n /**\n * Marks the inferred type as `Readonly<number>`. Since numbers are\n * already immutable this is an identity operation, but it sets the\n * `isReadonly` introspection flag for tooling consistency.\n *\n * @see {@link SchemaBuilder.readonly}\n */\n public readonly(): NumberSchemaBuilder<\n Readonly<TResult>,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.readonly();\n }\n\n /**\n * Do not accept NaN value\n */\n public notNaN(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureNotNaN: true,\n ensureNotNaNErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Consider NaN value as valid\n */\n public canBeNaN(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureNotNaN: false,\n ensureNotNaNErrorMessageProvider:\n this.#defaultEnsureNotNaNErrorMessageProvider\n }) as any;\n }\n\n /**\n * Do not accept `Infinity`.\n */\n public isFinite(\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureIsFinite: true,\n ensureIsFiniteErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Consider `Infinity` as valid.\n */\n public canBeInfinite(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.createFromProps({\n ...this.introspect(),\n ensureIsFinite: false,\n ensureIsFiniteErrorMessageProvider:\n this.#defaultEnsureIsFiniteErrorMessageProvider\n }) as any;\n }\n\n /**\n * Adds a preprocessor that coerces a string value to a number\n * using `Number(value)`. Useful when the input is captured from\n * a string source (e.g. a parse-string schema, URL parameter,\n * or form input).\n *\n * @example ```ts\n * const schema = number().coerce();\n * const result = schema.validate('42');\n * // result.valid === true\n * // result.object === 42\n * ```\n */\n public coerce(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return this.addPreprocessor(\n ((v: any) => (typeof v === 'string' ? Number(v) : v)) as any,\n { mutates: true }\n ) as any;\n }\n\n /**\n * Restrict number to be at least `minValue`.\n */\n public min(\n minValue: number,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n if (typeof minValue !== 'number')\n throw new Error('minValue must be a number');\n return this.createFromProps({\n ...this.introspect(),\n min: minValue,\n minValidationErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Clear `min()` call.\n */\n public clearMin(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n const schema = this.introspect();\n delete schema.min;\n return this.createFromProps({\n ...schema\n }) as any;\n }\n\n /**\n * Restrict number to be no more than `maxValue`.\n */\n public max(\n maxValue: number,\n /**\n * Custom error message provider.\n */\n errorMessage?: ValidationErrorMessageProvider<\n NumberSchemaBuilder<TResult, TRequired>\n >\n ): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n if (typeof maxValue !== 'number')\n throw new Error('maxValue must be a number');\n return this.createFromProps({\n ...this.introspect(),\n max: maxValue,\n maxValidationErrorMessageProvider: errorMessage\n }) as any;\n }\n\n /**\n * Clear `max()` call.\n */\n public clearMax(): NumberSchemaBuilder<\n TResult,\n TRequired,\n TNullable,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n const schema = this.introspect();\n delete schema.max;\n return this.createFromProps({\n ...schema\n }) as any;\n }\n\n /**\n * @hidden\n */\n public nullable(): NumberSchemaBuilder<\n TResult,\n TRequired,\n true,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.nullable() as any;\n }\n\n /**\n * @hidden\n */\n public notNullable(): NumberSchemaBuilder<\n TResult,\n TRequired,\n false,\n THasDefault,\n TExtensions\n > &\n TExtensions {\n return super.notNullable() as any;\n }\n}\n\n/**\n * Creates a number schema restricted to `equals` value.\n * @param equals string value\n */\nexport function number<T extends number>(\n equals: T\n): NumberSchemaBuilder<T, true>;\n\n/**\n * Creates a number schema.\n */\nexport function number(): NumberSchemaBuilder<number, true>;\n\n/**\n * Creates a number schema.\n */\nexport function number(equals?: number) {\n if (typeof equals === 'number') {\n return NumberSchemaBuilder.create({\n isRequired: true,\n equalsTo: equals\n });\n }\n return NumberSchemaBuilder.create({\n isRequired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AW,EACnB,IAAKA,EACL,kCAAmCH,CACvC,CAAC,CACL,CAKO,UAOS,CACZ,IAAMI,EAAS,KAAK,WAAW,EAC/B,cAAOA,EAAO,IACP,KAAK,gBAAgB,CACxB,GAAGA,CACP,CAAC,CACL,CAKO,IACHC,EAIAL,EAUY,CACZ,GAAI,OAAOK,GAAa,SACpB,MAAM,IAAI,MAAM,2BAA2B,EAC/C,OAAO,KAAK,gBAAgB,CACxB,GAAG,KAAK,WAAW,EACnB,IAAKA,EACL,kCAAmCL,CACvC,CAAC,CACL,CAKO,UAOS,CACZ,IAAMI,EAAS,KAAK,WAAW,EAC/B,cAAOA,EAAO,IACP,KAAK,gBAAgB,CACxB,GAAGA,CACP,CAAC,CACL,CAKO,UAOS,CACZ,OAAO,MAAM,SAAS,CAC1B,CAKO,aAOS,CACZ,OAAO,MAAM,YAAY,CAC7B,CACJ,EAkBO,SAASE,EAAOC,EAAiB,CACpC,OAAI,OAAOA,GAAW,SACX1C,EAAoB,OAAO,CAC9B,WAAY,GACZ,SAAU0C,CACd,CAAC,EAEE1C,EAAoB,OAAO,CAC9B,WAAY,EAChB,CAAC,CACL","names":["NumberSchemaBuilder","_NumberSchemaBuilder","SchemaBuilder","#min","#defaultMinErrorMessageProvider","#minErrorMessageProvider","#max","#defaultMaxErrorMessageProvider","#maxErrorMessageProvider","#equalsTo","#defaultEqualsToErrorMessageProvider","#equalsToErrorMessageProvider","#ensureNotNaN","#defaultEnsureNotNaNErrorMessageProvider","#ensureNotNaNErrorMessageProvider","#ensureIsFinite","#defaultEnsureIsFiniteErrorMessageProvider","#ensureIsFiniteErrorMessageProvider","#isInteger","#defaultEnsureIsIntegerErrorMessageProvider","#ensureIsIntegerErrorMessageProvider","props","_notUsed","#getConstraintViolation","objToValidate","#buildResult","superResult","valid","preValidationTransaction","errors","violation","object","context","r","value","errorMessage","_name","v","minValue","schema","maxValue","number","equals"]}
@@ -1,2 +1,2 @@
1
- import{f as o}from"./chunk-CTP4RHDG.js";var i=class n extends o{#e;#t=function(){return`is expected to be equal ${this.#e}`};#a=this.#t;static create(e){return new n({type:"boolean",...e})}constructor(e){super(e),(typeof e.equalsTo=="boolean"||typeof e.equalsTo>"u")&&(this.#e=e.equalsTo),this.#a=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#t)}introspect(){return{...super.introspect(),equalsTo:this.#e,equalsToValidationErrorMessageProvider:this.#a}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#s(e){return typeof e!="boolean"?{message:"expected to be boolean"}:typeof this.#e<"u"&&e!==this.#e?{provider:this.#a}:null}#r(e){let{valid:a,transaction:t,errors:s}=e;if(!a)return{done:!0,result:{valid:a,errors:s}};let{object:{validatedObject:r}}=t;if(typeof r>"u"&&!this.isRequired||r===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:r}};let l=this.#s(r);return l?"message"in l?{done:!0,result:{valid:!1,errors:[{message:l.message}]}}:{done:!1,provider:l.provider,objToValidate:r}:{done:!0,result:{valid:!0,object:r}}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let s=this.#s(e);return s?"message"in s?{valid:!1,errors:[{message:s.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,e)}]}:{valid:!0,object:e}}let t=this.#r(this.preValidateSync(e,a));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,a){let t=this.#r(await super.preValidateAsync(e,a));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return n.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}equals(e,a){if(typeof e!="boolean")throw new Error("boolean expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:a})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},d=()=>i.create({isRequired:!0});export{i as a,d as b};
2
- //# sourceMappingURL=chunk-KFTO7TMB.js.map
1
+ import{f as o}from"./chunk-3JMDGYDT.js";var i=class n extends o{#e;#t=function(){return`is expected to be equal ${this.#e}`};#a=this.#t;static create(e){return new n({type:"boolean",...e})}constructor(e){super(e),(typeof e.equalsTo=="boolean"||typeof e.equalsTo>"u")&&(this.#e=e.equalsTo),this.#a=this.assureValidationErrorMessageProvider(e.equalsToValidationErrorMessageProvider,this.#t)}introspect(){return{...super.introspect(),equalsTo:this.#e,equalsToValidationErrorMessageProvider:this.#a}}hasType(e){return this.createFromProps({...this.introspect()})}clearHasType(){return this.createFromProps({...this.introspect()})}#s(e){return typeof e!="boolean"?{message:"expected to be boolean"}:typeof this.#e<"u"&&e!==this.#e?{provider:this.#a}:null}#r(e){let{valid:a,transaction:t,errors:s}=e;if(!a)return{done:!0,result:{valid:a,errors:s}};let{object:{validatedObject:r}}=t;if(typeof r>"u"&&!this.isRequired||r===null&&(!this.isRequired||this.isNullable))return{done:!0,result:{valid:!0,object:r}};let l=this.#s(r);return l?"message"in l?{done:!0,result:{valid:!1,errors:[{message:l.message}]}}:{done:!1,provider:l.provider,objToValidate:r}:{done:!0,result:{valid:!0,object:r}}}validate(e,a){return super.validate(e,a)}async validateAsync(e,a){return super.validateAsync(e,a)}_validate(e,a){if(this.canSkipPreValidation){if(typeof e>"u"||e===null)if(typeof e>"u"&&this.hasDefault)e=this.resolveDefaultValue();else return!this.isRequired||e===null&&this.isNullable?{valid:!0,object:e}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(this.requiredErrorMessage,e)}]};let s=this.#s(e);return s?"message"in s?{valid:!1,errors:[{message:s.message}]}:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(s.provider,e)}]}:{valid:!0,object:e}}let t=this.#r(this.preValidateSync(e,a));return t.done?t.result:{valid:!1,errors:[{message:this.getValidationErrorMessageSync(t.provider,t.objToValidate)}]}}async _validateAsync(e,a){let t=this.#r(await super.preValidateAsync(e,a));return t.done?t.result:{valid:!1,errors:[{message:await this.getValidationErrorMessage(t.provider,t.objToValidate)}]}}createFromProps(e){return n.create(e)}required(e){return super.required(e)}optional(){return super.optional()}default(e){return super.default(e)}clearDefault(){return super.clearDefault()}brand(e){return super.brand(e)}readonly(){return super.readonly()}equals(e,a){if(typeof e!="boolean")throw new Error("boolean expected");return this.createFromProps({...this.introspect(),equalsTo:e,equalsToValidationErrorMessageProvider:a})}clearEquals(){return this.createFromProps({...this.introspect(),equalsTo:void 0})}coerce(){return this.addPreprocessor((e=>e==="true"?!0:e==="false"?!1:e),{mutates:!0})}nullable(){return super.nullable()}notNullable(){return super.notNullable()}},d=()=>i.create({isRequired:!0});export{i as a,d as b};
2
+ //# sourceMappingURL=chunk-CFIJQ4GP.js.map