@oxog/vld 2.4.0 → 3.0.1

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 (127) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/README.md +113 -1
  3. package/dist/chunks/errors-core-BU14-Dk8.js +1 -0
  4. package/dist/cjs/chunks/errors-core-C0mA6tfa.cjs +1 -0
  5. package/dist/cjs/cli/bin.cjs +1 -1
  6. package/dist/cjs/codecs/index.cjs +1 -1
  7. package/dist/cjs/coercion/index.cjs +1 -1
  8. package/dist/cjs/compile.cjs +1 -1
  9. package/dist/cjs/errors.cjs +1 -1
  10. package/dist/cjs/index.cjs +1 -1
  11. package/dist/cjs/mini.cjs +1 -1
  12. package/dist/cjs/v3/index.cjs +1 -1
  13. package/dist/cjs/v4/core/index.cjs +1 -1
  14. package/dist/cjs/v4/index.cjs +1 -1
  15. package/dist/cjs/v4/mini/index.cjs +1 -1
  16. package/dist/cjs/v4-mini/index.cjs +1 -1
  17. package/dist/cjs/validators/any.cjs +1 -1
  18. package/dist/cjs/validators/array-v2.cjs +1 -0
  19. package/dist/cjs/validators/array.cjs +1 -1
  20. package/dist/cjs/validators/base.cjs +1 -1
  21. package/dist/cjs/validators/base64.cjs +1 -1
  22. package/dist/cjs/validators/bigint-v2.cjs +1 -0
  23. package/dist/cjs/validators/bigint.cjs +1 -1
  24. package/dist/cjs/validators/boolean.cjs +1 -1
  25. package/dist/cjs/validators/codec.cjs +1 -1
  26. package/dist/cjs/validators/composite-v2.cjs +1 -0
  27. package/dist/cjs/validators/custom.cjs +1 -1
  28. package/dist/cjs/validators/date-v2.cjs +1 -0
  29. package/dist/cjs/validators/date.cjs +1 -1
  30. package/dist/cjs/validators/discriminated-union.cjs +1 -1
  31. package/dist/cjs/validators/enum.cjs +1 -1
  32. package/dist/cjs/validators/file.cjs +1 -1
  33. package/dist/cjs/validators/function.cjs +1 -1
  34. package/dist/cjs/validators/hex.cjs +1 -1
  35. package/dist/cjs/validators/index.cjs +1 -1
  36. package/dist/cjs/validators/intersection.cjs +1 -1
  37. package/dist/cjs/validators/json.cjs +1 -1
  38. package/dist/cjs/validators/lazy.cjs +1 -1
  39. package/dist/cjs/validators/leaf-v2.cjs +1 -0
  40. package/dist/cjs/validators/literal.cjs +1 -1
  41. package/dist/cjs/validators/map.cjs +1 -1
  42. package/dist/cjs/validators/nan.cjs +1 -1
  43. package/dist/cjs/validators/never.cjs +1 -1
  44. package/dist/cjs/validators/null.cjs +1 -1
  45. package/dist/cjs/validators/number-v2.cjs +1 -0
  46. package/dist/cjs/validators/number.cjs +1 -1
  47. package/dist/cjs/validators/object-v2.cjs +1 -0
  48. package/dist/cjs/validators/object.cjs +1 -1
  49. package/dist/cjs/validators/promise.cjs +1 -1
  50. package/dist/cjs/validators/record.cjs +1 -1
  51. package/dist/cjs/validators/set.cjs +1 -1
  52. package/dist/cjs/validators/string-bool.cjs +1 -1
  53. package/dist/cjs/validators/string-formats.cjs +1 -1
  54. package/dist/cjs/validators/string-v2.cjs +1 -0
  55. package/dist/cjs/validators/string.cjs +1 -1
  56. package/dist/cjs/validators/symbol.cjs +1 -1
  57. package/dist/cjs/validators/template-literal.cjs +1 -1
  58. package/dist/cjs/validators/tuple.cjs +1 -1
  59. package/dist/cjs/validators/uint8array.cjs +1 -1
  60. package/dist/cjs/validators/undefined.cjs +1 -1
  61. package/dist/cjs/validators/union-v2.cjs +1 -0
  62. package/dist/cjs/validators/union.cjs +1 -1
  63. package/dist/cjs/validators/unknown.cjs +1 -1
  64. package/dist/cjs/validators/void.cjs +1 -1
  65. package/dist/cjs/validators/wrapper-v2.cjs +1 -0
  66. package/dist/cjs/validators/xor.cjs +1 -1
  67. package/dist/errors-core.d.ts +3 -0
  68. package/dist/errors.js +1 -1
  69. package/dist/index.d.ts +168 -12
  70. package/dist/index.js +1 -1
  71. package/dist/v3/index.js +1 -1
  72. package/dist/v4/core/index.js +1 -1
  73. package/dist/v4/index.js +1 -1
  74. package/dist/v4/mini/index.js +1 -1
  75. package/dist/v4-mini/index.js +1 -1
  76. package/dist/validators/array-v2.d.ts +113 -0
  77. package/dist/validators/array-v2.js +1 -0
  78. package/dist/validators/array.js +1 -1
  79. package/dist/validators/base.js +1 -1
  80. package/dist/validators/base64.js +1 -1
  81. package/dist/validators/bigint-v2.d.ts +105 -0
  82. package/dist/validators/bigint-v2.js +1 -0
  83. package/dist/validators/bigint.js +1 -1
  84. package/dist/validators/boolean.js +1 -1
  85. package/dist/validators/codec.js +1 -1
  86. package/dist/validators/composite-v2.d.ts +59 -0
  87. package/dist/validators/composite-v2.js +1 -0
  88. package/dist/validators/date-v2.d.ts +140 -0
  89. package/dist/validators/date-v2.js +1 -0
  90. package/dist/validators/date.js +1 -1
  91. package/dist/validators/enum.js +1 -1
  92. package/dist/validators/file.js +1 -1
  93. package/dist/validators/function.js +1 -1
  94. package/dist/validators/hex.js +1 -1
  95. package/dist/validators/intersection.js +1 -1
  96. package/dist/validators/leaf-v2.d.ts +138 -0
  97. package/dist/validators/leaf-v2.js +1 -0
  98. package/dist/validators/literal.js +1 -1
  99. package/dist/validators/map.js +1 -1
  100. package/dist/validators/nan.js +1 -1
  101. package/dist/validators/never.js +1 -1
  102. package/dist/validators/null.js +1 -1
  103. package/dist/validators/number-v2.d.ts +252 -0
  104. package/dist/validators/number-v2.js +1 -0
  105. package/dist/validators/number.js +1 -1
  106. package/dist/validators/object-v2.d.ts +40 -0
  107. package/dist/validators/object-v2.js +1 -0
  108. package/dist/validators/object.js +1 -1
  109. package/dist/validators/record.js +1 -1
  110. package/dist/validators/set.js +1 -1
  111. package/dist/validators/string-formats.js +1 -1
  112. package/dist/validators/string-v2.d.ts +274 -0
  113. package/dist/validators/string-v2.js +1 -0
  114. package/dist/validators/string.js +1 -1
  115. package/dist/validators/symbol.js +1 -1
  116. package/dist/validators/tuple.js +1 -1
  117. package/dist/validators/uint8array.js +1 -1
  118. package/dist/validators/undefined.js +1 -1
  119. package/dist/validators/union-v2.d.ts +28 -0
  120. package/dist/validators/union-v2.js +1 -0
  121. package/dist/validators/void.js +1 -1
  122. package/dist/validators/wrapper-v2.d.ts +74 -0
  123. package/dist/validators/wrapper-v2.js +1 -0
  124. package/dist/zod-error.d.ts +84 -0
  125. package/package.json +1 -1
  126. package/dist/chunks/errors-core-CerMg2rq.js +0 -1
  127. package/dist/cjs/chunks/errors-core-DrydF46s.cjs +0 -1
@@ -0,0 +1 @@
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";import{V as s,c as r,g as a}from"../chunks/errors-core-BU14-Dk8.js";import{getMessages as i}from"../locales/runtime.js";class VldArrayCheck{}class VldArrayCheckMin extends VldArrayCheck{constructor(e,t){super(),this.minLength=e,this.kind="minLength",this._msg=t}get message(){return this._msg}check(e,t){e.length<this.minLength&&t.issues.push({code:"too_small",path:[],origin:"array",minimum:this.minLength,inclusive:!0,message:this._msg||`Array must have at least ${this.minLength} items`})}meta(){return{kind:"minLength",value:this.minLength,message:this._msg}}}class VldArrayCheckMax extends VldArrayCheck{constructor(e,t){super(),this.maxLength=e,this.kind="maxLength",this._msg=t}get message(){return this._msg}check(e,t){e.length>this.maxLength&&t.issues.push({code:"too_big",path:[],origin:"array",maximum:this.maxLength,inclusive:!0,message:this._msg||`Array must have at most ${this.maxLength} items`})}meta(){return{kind:"maxLength",value:this.maxLength,message:this._msg}}}class VldArrayCheckLength extends VldArrayCheck{constructor(e,t){super(),this.exactLength=e,this.kind="exactLength",this._msg=t}get message(){return this._msg}check(e,t){e.length!==this.exactLength&&t.issues.push({code:"too_big",path:[],origin:"array",exact:this.exactLength,message:this._msg||`Array must have exactly ${this.exactLength} items`})}meta(){return{kind:"exactLength",value:this.exactLength,message:this._msg}}}class VldArrayCheckUnique extends VldArrayCheck{constructor(e){super(),this.kind="unique",this._msg=e}get message(){return this._msg}check(e,t){const s=new Set;for(let r=0;r<e.items.length;r++){const a=e.items[r];if(s.has(a))return void t.issues.push({code:"custom",path:[r],message:this._msg||`Duplicate item at index ${r}`});s.add(a)}}meta(){return{kind:"unique",message:this._msg}}}function n(e){if(!0===e.isSimple)switch(e.validatorType){case t.STRING:return"string";case t.NUMBER:return"number";case t.BOOLEAN:return"boolean";default:return}}class VldArrayV2 extends e{constructor(e){super(t.ARRAY),this.__def=e}static create(e){return new VldArrayV2({type:"array",itemValidator:e,checks:Object.freeze([]),simpleItemMode:n(e),hasUnique:!1})}get element(){return this.__def.itemValidator}unwrap(){return this.__def.itemValidator}get isSimple(){return 0===this.__def.checks.length}parse(e){if(!Array.isArray(e))throw new s([r("array",a(e),this.__def.errorMessage)]);return this.parseKnownArray(e)}parseKnownArray(e){const t=this.__def,r=t.checks;if(r.length>0)for(let a=0;a<r.length;a++){const i=r[a];if("minLength"===i.kind&&e.length<i.minLength)throw new s([{code:"too_small",path:[],origin:"array",minimum:i.minLength,inclusive:!0,message:i.message||`Array must have at least ${i.minLength} items`}]);if("maxLength"===i.kind&&e.length>i.maxLength)throw new s([{code:"too_big",path:[],origin:"array",maximum:i.maxLength,inclusive:!0,message:i.message||`Array must have at most ${i.maxLength} items`}]);if("exactLength"===i.kind&&e.length!==i.exactLength)throw new s([{code:"too_big",path:[],origin:"array",exact:i.exactLength,message:i.message||`Array must have exactly ${i.exactLength} items`}]);if("unique"===i.kind&&t.hasUnique){const t=new Set;for(let r=0;r<e.length;r++){const a=e[r];if(t.has(a))throw new s([{code:"custom",path:[r],message:i.message||`Duplicate item at index ${r}`}]);t.add(a)}}}const a=e.length,n=new Array(a),h=t.simpleItemMode,c=t.itemValidator;if(void 0!==h)for(let t=0;t<a;t++){const s=e[t];switch(h){case"string":if("string"!=typeof s)throw new Error(i().arrayItem(t,i().invalidString));n[t]=s;break;case"number":if("number"!=typeof s||isNaN(s))throw new Error(i().arrayItem(t,i().invalidNumber));n[t]=s;break;case"boolean":if("boolean"!=typeof s)throw new Error(i().arrayItem(t,i().invalidBoolean));n[t]=s}}else for(let t=0;t<a;t++)n[t]=c.parse(e[t]);return n}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}withDef(e){const t={...this.__def,...e,type:"array"};return new this.constructor(t)}min(e,t){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckMin(e,t)]})}max(e,t){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckMax(e,t)]})}length(e,t){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckLength(e,t)]})}nonempty(e){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckMin(1,e)]})}unique(e){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckUnique(e)],hasUnique:!0})}between(e,t,s){return this.withDef({type:"array",checks:[...this.__def.checks,new VldArrayCheckMin(e,s),new VldArrayCheckMax(t,s)]})}}export{VldArrayCheck,VldArrayCheckLength,VldArrayCheckMax,VldArrayCheckMin,VldArrayCheckUnique,VldArrayV2};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as n,c as i,g as a}from"../chunks/errors-core-CerMg2rq.js";function s(e){return new n([{code:"invalid_array",path:[],message:e}])}function o(e,r){return new n([{code:"too_small",path:[],origin:"array",minimum:e,inclusive:!0,message:r}])}class VldArray extends e{constructor(e){super(r.ARRAY),this.config=e,this._simpleItemMode=this.getSimpleItemMode(e.itemValidator)}getSimpleItemMode(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";default:return}}static create(e){return new VldArray({itemValidator:e})}get element(){return this.config.itemValidator}unwrap(){return this.config.itemValidator}parse(e){if(!Array.isArray(e)){const r=this.config.errorMessage||t().invalidArray;throw new n([i("array",a(e),r)])}return this.parseArrayValue(e)}parseKnownArray(e){return this.parseArrayValue(e)}parseArrayValue(e){if(void 0!==this.config.exactLength&&e.length!==this.config.exactLength)throw o(this.config.exactLength,this.config.errorMessage||t().arrayLength(this.config.exactLength));if(void 0!==this.config.minLength&&e.length<this.config.minLength)throw o(this.config.minLength,this.config.errorMessage||t().arrayMin(this.config.minLength));if(void 0!==this.config.maxLength&&e.length>this.config.maxLength)throw r=this.config.maxLength,i=this.config.errorMessage||t().arrayMax(this.config.maxLength),new n([{code:"too_big",path:[],origin:"array",maximum:r,inclusive:!0,message:i}]);var r,i;const a=e.length,s=new Array(a),c=this._simpleItemMode;if(void 0!==c){for(let r=0;r<a;r++){const n=e[r];switch(c){case"string":if("string"!=typeof n)throw new Error(t().arrayItem(r,t().invalidString));s[r]=n;break;case"number":if("number"!=typeof n||isNaN(n))throw new Error(t().arrayItem(r,t().invalidNumber));s[r]=n;break;case"boolean":if("boolean"!=typeof n)throw new Error(t().arrayItem(r,t().invalidBoolean));s[r]=n}}return this.config.unique&&this.checkUnique(s),s}for(let r=0;r<a;r++)try{s[r]=this.config.itemValidator.parse(e[r])}catch(e){const n=e instanceof Error?e.message:String(e);throw new Error(t().arrayItem(r,n))}return this.config.unique&&this.checkUnique(s),s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return e instanceof n?{success:!1,error:e}:{success:!1,error:s(e.message)}}}encode(e){this.validateEncodedArray(e);const r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=this.config.itemValidator.encode(e[t]);return r}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:s(e.message)}}}async encodeAsync(e){this.validateEncodedArray(e);const r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=await this.config.itemValidator.encodeAsync(e[t]);return r}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:s(e.message)}}}validateEncodedArray(e){if(!Array.isArray(e))throw new Error(this.config.errorMessage||t().invalidArray);if(void 0!==this.config.exactLength&&e.length!==this.config.exactLength)throw new Error(this.config.errorMessage);if(void 0!==this.config.minLength&&e.length<this.config.minLength)throw new Error(this.config.errorMessage);if(void 0!==this.config.maxLength&&e.length>this.config.maxLength)throw new Error(this.config.errorMessage);this.config.unique&&this.checkUnique(e)}checkUnique(e){const r=new Set,t=new WeakMap;for(const n of e){let e;if("object"==typeof n&&null!==n){const r=t.get(n);if(void 0!==r)e=r;else{const r=this.stableStringify(n);e=r,t.set(n,r)}}else e=n;if(r.has(e))throw new Error("Array must contain unique items");r.add(e)}}stableStringify(e){const r=new WeakSet,t=(e,n=0)=>{if(n>100)return'"[Max Depth Exceeded]"';if(null===e)return"null";if(void 0===e)return"undefined";if("object"!=typeof e)return JSON.stringify(e);if(r.has(e))return'"[Circular]"';r.add(e);try{if(Array.isArray(e)){return`[${e.map(e=>t(e,n+1)).join(",")}]`}const r=Object.keys(e).sort();return`{${r.map(r=>`${JSON.stringify(r)}:${t(e[r],n+1)}`).join(",")}}`}finally{r.delete(e)}};try{return t(e)}catch{return String(e)}}min(e,r){return new VldArray({...this.config,minLength:e,errorMessage:r||t().arrayMin(e)})}max(e,r){return new VldArray({...this.config,maxLength:e,errorMessage:r||t().arrayMax(e)})}length(e,r){return new VldArray({...this.config,exactLength:e,minLength:void 0,maxLength:void 0,errorMessage:r||t().arrayLength(e)})}nonempty(e){return new VldArray({...this.config,minLength:1,errorMessage:e||t().arrayEmpty})}unique(e){return new VldArray({...this.config,unique:!0,errorMessage:e||"Array must contain unique items"})}between(e,r,t){return new VldArray({...this.config,minLength:e,maxLength:r,errorMessage:t||`Array length must be between ${e} and ${r}`})}}export{VldArray};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as n,c as i,g as a}from"../chunks/errors-core-BU14-Dk8.js";function s(e){return new n([{code:"invalid_array",path:[],message:e}])}function o(e,r){return new n([{code:"too_small",path:[],origin:"array",minimum:e,inclusive:!0,message:r}])}class VldArray extends e{constructor(e){super(r.ARRAY),this.config=e,this._simpleItemMode=this.getSimpleItemMode(e.itemValidator)}getSimpleItemMode(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";default:return}}static create(e){return new VldArray({itemValidator:e})}get element(){return this.config.itemValidator}unwrap(){return this.config.itemValidator}parse(e){if(!Array.isArray(e)){const r=this.config.errorMessage||t().invalidArray;throw new n([i("array",a(e),r)])}return this.parseArrayValue(e)}parseKnownArray(e){return this.parseArrayValue(e)}parseArrayValue(e){if(void 0!==this.config.exactLength&&e.length!==this.config.exactLength)throw o(this.config.exactLength,this.config.errorMessage||t().arrayLength(this.config.exactLength));if(void 0!==this.config.minLength&&e.length<this.config.minLength)throw o(this.config.minLength,this.config.errorMessage||t().arrayMin(this.config.minLength));if(void 0!==this.config.maxLength&&e.length>this.config.maxLength)throw r=this.config.maxLength,i=this.config.errorMessage||t().arrayMax(this.config.maxLength),new n([{code:"too_big",path:[],origin:"array",maximum:r,inclusive:!0,message:i}]);var r,i;const a=e.length,s=new Array(a),c=this._simpleItemMode;if(void 0!==c){for(let r=0;r<a;r++){const n=e[r];switch(c){case"string":if("string"!=typeof n)throw new Error(t().arrayItem(r,t().invalidString));s[r]=n;break;case"number":if("number"!=typeof n||isNaN(n))throw new Error(t().arrayItem(r,t().invalidNumber));s[r]=n;break;case"boolean":if("boolean"!=typeof n)throw new Error(t().arrayItem(r,t().invalidBoolean));s[r]=n}}return this.config.unique&&this.checkUnique(s),s}for(let r=0;r<a;r++)try{s[r]=this.config.itemValidator.parse(e[r])}catch(e){const n=e instanceof Error?e.message:String(e);throw new Error(t().arrayItem(r,n))}return this.config.unique&&this.checkUnique(s),s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return e instanceof n?{success:!1,error:e}:{success:!1,error:s(e.message)}}}encode(e){this.validateEncodedArray(e);const r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=this.config.itemValidator.encode(e[t]);return r}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:s(e.message)}}}async encodeAsync(e){this.validateEncodedArray(e);const r=new Array(e.length);for(let t=0;t<e.length;t++)r[t]=await this.config.itemValidator.encodeAsync(e[t]);return r}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:s(e.message)}}}validateEncodedArray(e){if(!Array.isArray(e))throw new Error(this.config.errorMessage||t().invalidArray);if(void 0!==this.config.exactLength&&e.length!==this.config.exactLength)throw new Error(this.config.errorMessage);if(void 0!==this.config.minLength&&e.length<this.config.minLength)throw new Error(this.config.errorMessage);if(void 0!==this.config.maxLength&&e.length>this.config.maxLength)throw new Error(this.config.errorMessage);this.config.unique&&this.checkUnique(e)}checkUnique(e){const r=new Set,t=new WeakMap;for(const n of e){let e;if("object"==typeof n&&null!==n){const r=t.get(n);if(void 0!==r)e=r;else{const r=this.stableStringify(n);e=r,t.set(n,r)}}else e=n;if(r.has(e))throw new Error("Array must contain unique items");r.add(e)}}stableStringify(e){const r=new WeakSet,t=(e,n=0)=>{if(n>100)return'"[Max Depth Exceeded]"';if(null===e)return"null";if(void 0===e)return"undefined";if("object"!=typeof e)return JSON.stringify(e);if(r.has(e))return'"[Circular]"';r.add(e);try{if(Array.isArray(e)){return`[${e.map(e=>t(e,n+1)).join(",")}]`}const r=Object.keys(e).sort();return`{${r.map(r=>`${JSON.stringify(r)}:${t(e[r],n+1)}`).join(",")}}`}finally{r.delete(e)}};try{return t(e)}catch{return String(e)}}min(e,r){return new VldArray({...this.config,minLength:e,errorMessage:r||t().arrayMin(e)})}max(e,r){return new VldArray({...this.config,maxLength:e,errorMessage:r||t().arrayMax(e)})}length(e,r){return new VldArray({...this.config,exactLength:e,minLength:void 0,maxLength:void 0,errorMessage:r||t().arrayLength(e)})}nonempty(e){return new VldArray({...this.config,minLength:1,errorMessage:e||t().arrayEmpty})}unique(e){return new VldArray({...this.config,unique:!0,errorMessage:e||"Array must contain unique items"})}between(e,r,t){return new VldArray({...this.config,minLength:e,maxLength:r,errorMessage:t||`Array length must be between ${e} and ${r}`})}}export{VldArray};
@@ -1 +1 @@
1
- import{globalRegistry as e}from"../registry.js";import{V as t}from"../chunks/errors-core-CerMg2rq.js";function s(e){if(e instanceof t)return e;const s=e instanceof Error?e.message:String(e);return new t([{code:"custom",path:[],message:s}])}const r={STRING:"string",STRING_FORMAT:"stringFormat",STRING_BOOL:"stringBool",NUMBER:"number",BOOLEAN:"boolean",DATE:"date",BIGINT:"bigint",UNDEFINED:"undefined",NULL:"null",UNKNOWN:"unknown",ANY:"any",VOID:"void",NEVER:"never",SYMBOL:"symbol",NAN:"nan",HEX:"hex",BASE64:"base64",UINT8_ARRAY:"uint8Array",COERCE_STRING:"coerceString",COERCE_NUMBER:"coerceNumber",COERCE_BOOLEAN:"coerceBoolean",COERCE_DATE:"coerceDate",COERCE_BIGINT:"coerceBigint",OBJECT:"object",ARRAY:"array",TUPLE:"tuple",SET:"set",MAP:"map",RECORD:"record",UNION:"union",DISCRIMINATED_UNION:"discriminatedUnion",INTERSECTION:"intersection",XOR:"xor",ENUM:"enum",LITERAL:"literal",LAZY:"lazy",CUSTOM:"custom",FUNCTION:"function",FILE:"file",JSON:"json",TEMPLATE_LITERAL:"templateLiteral",PROMISE:"promise",OPTIONAL:"optional",NULLABLE:"nullable",NULLISH:"nullish",EXACT_OPTIONAL:"exactOptional",DEFAULT:"default",CATCH:"catch",REFINE:"refine",TRANSFORM:"transform",PIPE:"pipe",PREPROCESS:"preprocess",SUPER_REFINE:"superRefine",BRAND:"brand",READONLY:"readonly",META:"meta",PREFAULT:"prefault",PREFault:"prefault",CODEC:"codec"};function a(e,t){if("string"==typeof e)return e;if("function"==typeof e){const s=e(void 0);return"string"==typeof s?s:"object"==typeof s&&s?.message?s.message:t}if("object"==typeof e&&null!==e){if("string"==typeof e.error)return e.error;if("function"==typeof e.error)return e.error({})||t;if("string"==typeof e.message)return e.message}return t}function i(e){return null!==e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}let n;function o(e){n=e}function h(e){return"function"==typeof e?e():function(e){if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);if(null!==e&&"object"==typeof e){const t=Object.getPrototypeOf(e);if(t===Object.prototype||null===t)return{...e}}return e}(e)}function u(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";case r.BIGINT:return"bigint";case r.SYMBOL:return"symbol";default:return}}function l(e,t){switch(e){case"string":return"string"==typeof t?t:void 0;case"number":return"number"!=typeof t||isNaN(t)?void 0:t;case"boolean":return"boolean"==typeof t?t:void 0;case"bigint":return"bigint"==typeof t?t:void 0;case"symbol":return"symbol"==typeof t?t:void 0;default:return}}class VldBase{constructor(e="unknown"){this.validatorType=e}get type(){return this.validatorType}get _def(){return{typeName:"Zod"+this.validatorType.charAt(0).toUpperCase()+this.validatorType.slice(1),...this.config||{}}}get def(){return this._def}get _zod(){return this._def}get"~standard"(){return{version:1,vendor:"vld",validate:e=>{const t=this.safeParse(e);return t.success?{value:t.data}:{issues:[{message:t.error.message}]}},types:void 0}}async parseAsync(e){return this.parse(e)}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}decode(e){return this.parse(e)}safeDecode(e){return this.safeParse(e)}async decodeAsync(e){return this.parseAsync(e)}async safeDecodeAsync(e){return this.safeParseAsync(e)}encode(e){return this.parse(e)}safeEncode(e){const t=this.safeParse(e);return t.success?{success:!0,data:t.data}:t}async encodeAsync(e){return this.parseAsync(e)}async safeEncodeAsync(e){const t=await this.safeParseAsync(e);return t.success?{success:!0,data:t.data}:t}spa(e){return this.safeParseAsync(e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}clone(){return this}isValid(e){return this.safeParse(e).success}parseOrDefault(e,t){const s=this.safeParse(e);if(s.success)return s.data;const r=this.safeParse(t);if(!r.success)throw new Error(`Invalid default value provided: ${r.error.message}`);return r.data}refine(e,t){return new VldRefine(this,e,t)}superRefine(e){return new VldSuperRefine(this,e)}transform(e){return new VldTransform(this,e)}default(e){return new VldDefault(this,e)}prefault(e){return new VldPrefault(this,e)}nonoptional(e){return new VldRefine(this,e=>void 0!==e,a(e,"Expected non-optional value"))}array(){return n.array(this)}or(e){return n.union(this,e)}and(e){return n.intersection(this,e)}overwrite(e){return new VldTransform(this,e)}with(...e){return new VldSuperRefine(this,(t,s)=>{const r={value:t,issues:[]},a=[];for(const t of e){const e="function"==typeof t?t:t._zod?.check;if(!e)continue;const s=e(r);i(s)&&a.push(Promise.resolve(s))}const n=()=>{for(const e of r.issues)s.addIssue(void 0===e.code?{message:e.message||"Custom check failed"}:{message:e.message||"Custom check failed",code:e.code})};if(a.length>0)return Promise.all(a).then(n);n()})}toJSONSchema(e){return n.toJSONSchema(this,e)}catch(e){return new VldCatch(this,e)}optional(){return new VldOptional(this)}nullable(){return new VldNullable(this)}nullish(){return new VldNullish(this)}exactOptional(){return new VldExactOptional(this)}pipe(e){return new VldPipe(this,e)}readonly(){return new VldReadonly(this)}brand(){return new VldBrand(this)}apply(e){return e(this)}check(e,t){return this.refine(e,t)}meta(t){if(void 0===t)return e.get(this)??this.baseValidator?.meta?.()??this.schema?.meta?.()??this.inner?.meta?.();const s=new VldMeta(this,t);return e.add(s,t),s}register(e,t){return e.add(this,t),this}describe(e){return this.meta({description:e})}get description(){return this.meta()?.description??this.baseValidator?.description??this.schema?.description??this.inner?.description}}class VldMeta extends VldBase{constructor(e,t){super(r.META),this.baseValidator=e,this.metadata=t}parse(e){return this.baseValidator.parse(e)}safeParse(e){return this.baseValidator.safeParse(e)}getMeta(){return{...this.metadata}}meta(t){if(void 0===t)return{...this.metadata,...e.get(this)};const s=new VldMeta(this.baseValidator,{...this.metadata,...t});return e.add(s,s.getMeta()),s}describe(e){return this.meta({description:e})}}class VldReadonly extends VldBase{constructor(e){super(r.READONLY),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldBrand extends VldBase{constructor(e){super(r.BRAND),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldRefine extends VldBase{constructor(e,t,s){super(r.REFINE),this.baseValidator=e,this.predicate=t,this.customMessage=s??"Refinement check failed","object"==typeof s&&null!==s&&"path"in s&&Array.isArray(s.path)&&(this.refinePath=s.path)}_createIssue(e){if("function"==typeof this.customMessage){const t=this.customMessage(e);return"string"==typeof t?{code:"custom",path:this.refinePath??[],message:t}:{code:"custom",path:t?.path??this.refinePath??[],message:t?.message??"Refinement check failed"}}if("object"==typeof this.customMessage&&null!==this.customMessage){const e=this.customMessage.message??this.customMessage.error,t="function"==typeof e?e({}):"string"==typeof e?e:"Refinement check failed";return{code:"custom",path:this.customMessage.path??this.refinePath??[],message:t}}return{code:"custom",path:this.refinePath??[],message:"string"==typeof this.customMessage?this.customMessage:"Refinement check failed"}}parse(e){const s=this.baseValidator.parse(e),r=this.predicate(s);if(i(r))throw new Error("Use parseAsync for async refinements");if(!r)throw new t([this._createIssue(s)]);return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const s=await this.baseValidator.parseAsync(e);if(!await this.predicate(s))throw new t([this._createIssue(s)]);return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldRefine(e,this.predicate,this.customMessage)}min(e,t){return this._wrap(this.baseValidator.min?.(e,t)??this.baseValidator)}max(e,t){return this._wrap(this.baseValidator.max?.(e,t)??this.baseValidator)}length(e,t){return this._wrap(this.baseValidator.length?.(e,t)??this.baseValidator)}email(e){return this._wrap(this.baseValidator.email?.(e)??this.baseValidator)}url(e){return this._wrap(this.baseValidator.url?.(e)??this.baseValidator)}uuid(e){return this._wrap(this.baseValidator.uuid?.(e)??this.baseValidator)}regex(e,t){return this._wrap(this.baseValidator.regex?.(e,t)??this.baseValidator)}startsWith(e,t){return this._wrap(this.baseValidator.startsWith?.(e,t)??this.baseValidator)}endsWith(e,t){return this._wrap(this.baseValidator.endsWith?.(e,t)??this.baseValidator)}includes(e,t){return this._wrap(this.baseValidator.includes?.(e,t)??this.baseValidator)}ip(e){return this._wrap(this.baseValidator.ip?.(e)??this.baseValidator)}ipv4(e){return this._wrap(this.baseValidator.ipv4?.(e)??this.baseValidator)}ipv6(e){return this._wrap(this.baseValidator.ipv6?.(e)??this.baseValidator)}nonempty(e){return this._wrap(this.baseValidator.nonempty?.(e)??this.baseValidator)}trim(){return this._wrap(this.baseValidator.trim?.()??this.baseValidator)}toLowerCase(){return this._wrap(this.baseValidator.toLowerCase?.()??this.baseValidator)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this.baseValidator.toUpperCase?.()??this.baseValidator)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this.baseValidator.positive?.(e)??this.baseValidator)}negative(e){return this._wrap(this.baseValidator.negative?.(e)??this.baseValidator)}nonnegative(e){return this._wrap(this.baseValidator.nonnegative?.(e)??this.baseValidator)}nonpositive(e){return this._wrap(this.baseValidator.nonpositive?.(e)??this.baseValidator)}int(e){return this._wrap(this.baseValidator.int?.(e)??this.baseValidator)}finite(e){return this._wrap(this.baseValidator.finite?.(e)??this.baseValidator)}safe(e){return this._wrap(this.baseValidator.safe?.(e)??this.baseValidator)}multipleOf(e,t){return this._wrap(this.baseValidator.multipleOf?.(e,t)??this.baseValidator)}step(e,t){return this._wrap(this.baseValidator.step?.(e,t)??this.baseValidator)}gt(e,t){return this._wrap(this.baseValidator.gt?.(e,t)??this.baseValidator)}gte(e,t){return this._wrap(this.baseValidator.gte?.(e,t)??this.baseValidator)}lt(e,t){return this._wrap(this.baseValidator.lt?.(e,t)??this.baseValidator)}lte(e,t){return this._wrap(this.baseValidator.lte?.(e,t)??this.baseValidator)}extend(e){return this._wrap(this.baseValidator.extend?.(e)??this.baseValidator)}merge(e){return this._wrap(this.baseValidator.merge?.(e)??this.baseValidator)}pick(...e){return this._wrap(this.baseValidator.pick?.(...e)??this.baseValidator)}omit(...e){return this._wrap(this.baseValidator.omit?.(...e)??this.baseValidator)}partial(){return this._wrap(this.baseValidator.partial?.()??this.baseValidator)}required(){return this._wrap(this.baseValidator.required?.()??this.baseValidator)}strict(e){return this._wrap(this.baseValidator.strict?.(e)??this.baseValidator)}passthrough(){return this._wrap(this.baseValidator.passthrough?.()??this.baseValidator)}strip(){return this._wrap(this.baseValidator.strip?.()??this.baseValidator)}catchall(e){return this._wrap(this.baseValidator.catchall?.(e)??this.baseValidator)}get shape(){return this.baseValidator.shape}get keyof(){return this.baseValidator.keyof}unwrap(){return this.baseValidator.unwrap?this.baseValidator.unwrap():this.baseValidator}get element(){return this.baseValidator.element}}class VldTransform extends VldBase{constructor(e,t){super(r.TRANSFORM),this.baseValidator=e,this.transformer=t}parse(e){const t=this.baseValidator.parse(e);try{const e=this.transformer(t);if(i(e))throw new Error("Use parseAsync for async transforms");return e}catch(e){throw new Error(`Transform failed: ${e.message}`)}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const t=await this.baseValidator.parseAsync(e);try{return await this.transformer(t)}catch(e){throw new Error(`Transform failed: ${e.message}`)}}}class VldDefault extends VldBase{constructor(e,t){super(r.DEFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?h(this.defaultValue):this.baseValidator.parse(e)}safeParse(e){return void 0===e?{success:!0,data:h(this.defaultValue)}:this.baseValidator.safeParse(e)}prefault(e){return new VldPrefault(this.baseValidator,void 0===e?this.defaultValue:e)}unwrap(){return this.baseValidator}removeDefault(){return this.baseValidator}}class VldPrefault extends VldBase{constructor(e,t){super(r.PREFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?this.baseValidator.parse(h(this.defaultValue)):this.baseValidator.parse(e)}safeParse(e){return void 0===e?this.baseValidator.safeParse(h(this.defaultValue)):this.baseValidator.safeParse(e)}prefault(e){return void 0===e?this:new VldPrefault(this.baseValidator,e)}unwrap(){return this.baseValidator}}class VldCatch extends VldBase{constructor(e,t){super(r.CATCH),this.baseValidator=e,this.fallbackValue=t,this.simpleMode=u(e);const s=e.safeParse(t);if(!s.success)throw new Error(`Invalid fallback value: ${s.error.message}`)}parse(e){const t=l(this.simpleMode,e);if(void 0!==t)return t;if(void 0!==this.simpleMode)return this.fallbackValue;try{return this.baseValidator.parse(e)}catch{return this.fallbackValue}}safeParse(e){const t=l(this.simpleMode,e);if(void 0!==t)return{success:!0,data:t};if(void 0!==this.simpleMode)return{success:!0,data:this.fallbackValue};const s=this.baseValidator.safeParse(e);return s.success?s:{success:!0,data:this.fallbackValue}}}class VldOptional extends VldBase{constructor(e){super(r.OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}parseSimpleValue(e){return l(this.simpleMode,e)}static create(e){return new VldOptional(e)}parse(e){if(void 0===e)return;const t=this.parseSimpleValue(e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=this.parseSimpleValue(e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldExactOptional extends VldBase{constructor(e){super(r.EXACT_OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldExactOptional(e)}parse(e){if(void 0===e)return;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullable extends VldBase{constructor(e){super(r.NULLABLE),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullable(e)}parse(e){if(null===e)return null;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null===e)return{success:!0,data:null};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullish extends VldBase{constructor(e){super(r.NULLISH),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullish(e)}parse(e){if(null==e)return e;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null==e)return{success:!0,data:e};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldPipe extends VldBase{constructor(e,t){super(r.PIPE),this.first=e,this.second=t}parse(e){const t=this.first.parse(e);return this.second.parse(t)}safeParse(e){const t=this.first.safeParse(e);return t.success?this.second.safeParse(t.data):{success:!1,error:t.error}}}class VldSuperRefine extends VldBase{constructor(e,t){super(r.SUPER_REFINE),this._inner=e,this._refinement=t}parse(e){const s=this._inner.parse(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(s,a)instanceof Promise)throw new Error("Use parseAsync for async refinements");if(r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}safeParse(e){const r=this._inner.safeParse(e);if(!r.success)return{success:!1,error:s(r.error)};const a=[],i={addIssue:e=>{a.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(r.data,i)instanceof Promise)throw new Error("Use safeParseAsync for async refinements");return a.length>0?{success:!1,error:new t(a,a.map(e=>e.message).join("; "))}:r}async parseAsync(e){const s=await this._inner.parseAsync(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(await this._refinement(s,a),r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldSuperRefine(e,this._refinement)}min(e,t){return this._wrap(this._inner.min?.(e,t)??this._inner)}max(e,t){return this._wrap(this._inner.max?.(e,t)??this._inner)}length(e,t){return this._wrap(this._inner.length?.(e,t)??this._inner)}email(e){return this._wrap(this._inner.email?.(e)??this._inner)}url(e){return this._wrap(this._inner.url?.(e)??this._inner)}uuid(e){return this._wrap(this._inner.uuid?.(e)??this._inner)}regex(e,t){return this._wrap(this._inner.regex?.(e,t)??this._inner)}startsWith(e,t){return this._wrap(this._inner.startsWith?.(e,t)??this._inner)}endsWith(e,t){return this._wrap(this._inner.endsWith?.(e,t)??this._inner)}includes(e,t){return this._wrap(this._inner.includes?.(e,t)??this._inner)}ip(e){return this._wrap(this._inner.ip?.(e)??this._inner)}ipv4(e){return this._wrap(this._inner.ipv4?.(e)??this._inner)}ipv6(e){return this._wrap(this._inner.ipv6?.(e)??this._inner)}nonempty(e){return this._wrap(this._inner.nonempty?.(e)??this._inner)}trim(){return this._wrap(this._inner.trim?.()??this._inner)}toLowerCase(){return this._wrap(this._inner.toLowerCase?.()??this._inner)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this._inner.toUpperCase?.()??this._inner)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this._inner.positive?.(e)??this._inner)}negative(e){return this._wrap(this._inner.negative?.(e)??this._inner)}nonnegative(e){return this._wrap(this._inner.nonnegative?.(e)??this._inner)}nonpositive(e){return this._wrap(this._inner.nonpositive?.(e)??this._inner)}int(e){return this._wrap(this._inner.int?.(e)??this._inner)}finite(e){return this._wrap(this._inner.finite?.(e)??this._inner)}safe(e){return this._wrap(this._inner.safe?.(e)??this._inner)}multipleOf(e,t){return this._wrap(this._inner.multipleOf?.(e,t)??this._inner)}step(e,t){return this._wrap(this._inner.step?.(e,t)??this._inner)}gt(e,t){return this._wrap(this._inner.gt?.(e,t)??this._inner)}gte(e,t){return this._wrap(this._inner.gte?.(e,t)??this._inner)}lt(e,t){return this._wrap(this._inner.lt?.(e,t)??this._inner)}lte(e,t){return this._wrap(this._inner.lte?.(e,t)??this._inner)}extend(e){return this._wrap(this._inner.extend?.(e)??this._inner)}merge(e){return this._wrap(this._inner.merge?.(e)??this._inner)}pick(...e){return this._wrap(this._inner.pick?.(...e)??this._inner)}omit(...e){return this._wrap(this._inner.omit?.(...e)??this._inner)}partial(){return this._wrap(this._inner.partial?.()??this._inner)}required(){return this._wrap(this._inner.required?.()??this._inner)}strict(e){return this._wrap(this._inner.strict?.(e)??this._inner)}passthrough(){return this._wrap(this._inner.passthrough?.()??this._inner)}strip(){return this._wrap(this._inner.strip?.()??this._inner)}catchall(e){return this._wrap(this._inner.catchall?.(e)??this._inner)}get shape(){return this._inner.shape}get keyof(){return this._inner.keyof}unwrap(){return this._inner.unwrap?this._inner.unwrap():this._inner}get element(){return this._inner.element}}class VldPreprocess extends VldBase{constructor(e,t){super(r.PREPROCESS),this._preprocessor=e,this._schema=t}static create(e,t){return new VldPreprocess(e,t)}parse(e){const t=this._preprocessor(e);return this._schema.parse(t)}safeParse(e){try{const t=this._preprocessor(e);return this._schema.safeParse(t)}catch(e){return{success:!1,error:s(e)}}}}export{r as VLD_VALIDATOR_TYPES,VldBase,VldBrand,VldCatch,VldDefault,VldExactOptional,VldMeta,VldNullable,VldNullish,VldOptional,VldPipe,VldPrefault,VldPreprocess,VldReadonly,VldRefine,VldSuperRefine,VldTransform,o as configureSchemaCompositionFactories,s as ensureVldError,i as isPromiseLike,a as resolveErrorMessage};
1
+ import{globalRegistry as e}from"../registry.js";import{V as t}from"../chunks/errors-core-BU14-Dk8.js";function s(e){if(e instanceof t)return e;const s=e instanceof Error?e.message:String(e);return new t([{code:"custom",path:[],message:s}])}const r={STRING:"string",STRING_FORMAT:"stringFormat",STRING_BOOL:"stringBool",NUMBER:"number",BOOLEAN:"boolean",DATE:"date",BIGINT:"bigint",UNDEFINED:"undefined",NULL:"null",UNKNOWN:"unknown",ANY:"any",VOID:"void",NEVER:"never",SYMBOL:"symbol",NAN:"nan",HEX:"hex",BASE64:"base64",UINT8_ARRAY:"uint8Array",COERCE_STRING:"coerceString",COERCE_NUMBER:"coerceNumber",COERCE_BOOLEAN:"coerceBoolean",COERCE_DATE:"coerceDate",COERCE_BIGINT:"coerceBigint",OBJECT:"object",ARRAY:"array",TUPLE:"tuple",SET:"set",MAP:"map",RECORD:"record",UNION:"union",DISCRIMINATED_UNION:"discriminatedUnion",INTERSECTION:"intersection",XOR:"xor",ENUM:"enum",LITERAL:"literal",LAZY:"lazy",CUSTOM:"custom",FUNCTION:"function",FILE:"file",JSON:"json",TEMPLATE_LITERAL:"templateLiteral",PROMISE:"promise",OPTIONAL:"optional",NULLABLE:"nullable",NULLISH:"nullish",EXACT_OPTIONAL:"exactOptional",DEFAULT:"default",CATCH:"catch",REFINE:"refine",TRANSFORM:"transform",PIPE:"pipe",PREPROCESS:"preprocess",SUPER_REFINE:"superRefine",BRAND:"brand",READONLY:"readonly",META:"meta",PREFAULT:"prefault",PREFault:"prefault",CODEC:"codec"};function a(e,t){if("string"==typeof e)return e;if("function"==typeof e){const s=e(void 0);return"string"==typeof s?s:"object"==typeof s&&s?.message?s.message:t}if("object"==typeof e&&null!==e){if("string"==typeof e.error)return e.error;if("function"==typeof e.error)return e.error({})||t;if("string"==typeof e.message)return e.message}return t}function i(e){return null!==e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then}let n;function o(e){n=e}function h(e){return"function"==typeof e?e():function(e){if(Array.isArray(e))return[...e];if(e instanceof Map)return new Map(e);if(e instanceof Set)return new Set(e);if(null!==e&&"object"==typeof e){const t=Object.getPrototypeOf(e);if(t===Object.prototype||null===t)return{...e}}return e}(e)}function u(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";case r.BIGINT:return"bigint";case r.SYMBOL:return"symbol";default:return}}function l(e,t){switch(e){case"string":return"string"==typeof t?t:void 0;case"number":return"number"!=typeof t||isNaN(t)?void 0:t;case"boolean":return"boolean"==typeof t?t:void 0;case"bigint":return"bigint"==typeof t?t:void 0;case"symbol":return"symbol"==typeof t?t:void 0;default:return}}class VldBase{constructor(e="unknown"){this.validatorType=e}get type(){return this.validatorType}get _def(){return{typeName:"Zod"+this.validatorType.charAt(0).toUpperCase()+this.validatorType.slice(1),...this.config||{}}}get def(){return this._def}get _zod(){return this._def}get"~standard"(){return{version:1,vendor:"vld",validate:e=>{const t=this.safeParse(e);return t.success?{value:t.data}:{issues:[{message:t.error.message}]}},types:void 0}}async parseAsync(e){return this.parse(e)}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}decode(e){return this.parse(e)}safeDecode(e){return this.safeParse(e)}async decodeAsync(e){return this.parseAsync(e)}async safeDecodeAsync(e){return this.safeParseAsync(e)}encode(e){return this.parse(e)}safeEncode(e){const t=this.safeParse(e);return t.success?{success:!0,data:t.data}:t}async encodeAsync(e){return this.parseAsync(e)}async safeEncodeAsync(e){const t=await this.safeParseAsync(e);return t.success?{success:!0,data:t.data}:t}spa(e){return this.safeParseAsync(e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}clone(){return this}isValid(e){return this.safeParse(e).success}parseOrDefault(e,t){const s=this.safeParse(e);if(s.success)return s.data;const r=this.safeParse(t);if(!r.success)throw new Error(`Invalid default value provided: ${r.error.message}`);return r.data}refine(e,t){return new VldRefine(this,e,t)}superRefine(e){return new VldSuperRefine(this,e)}transform(e){return new VldTransform(this,e)}default(e){return new VldDefault(this,e)}prefault(e){return new VldPrefault(this,e)}nonoptional(e){return new VldRefine(this,e=>void 0!==e,a(e,"Expected non-optional value"))}array(){return n.array(this)}or(e){return n.union(this,e)}and(e){return n.intersection(this,e)}overwrite(e){return new VldTransform(this,e)}with(...e){return new VldSuperRefine(this,(t,s)=>{const r={value:t,issues:[]},a=[];for(const t of e){const e="function"==typeof t?t:t._zod?.check;if(!e)continue;const s=e(r);i(s)&&a.push(Promise.resolve(s))}const n=()=>{for(const e of r.issues)s.addIssue(void 0===e.code?{message:e.message||"Custom check failed"}:{message:e.message||"Custom check failed",code:e.code})};if(a.length>0)return Promise.all(a).then(n);n()})}toJSONSchema(e){return n.toJSONSchema(this,e)}catch(e){return new VldCatch(this,e)}optional(){return new VldOptional(this)}nullable(){return new VldNullable(this)}nullish(){return new VldNullish(this)}exactOptional(){return new VldExactOptional(this)}pipe(e){return new VldPipe(this,e)}readonly(){return new VldReadonly(this)}brand(){return new VldBrand(this)}apply(e){return e(this)}check(e,t){return this.refine(e,t)}meta(t){if(void 0===t)return e.get(this)??this.baseValidator?.meta?.()??this.schema?.meta?.()??this.inner?.meta?.();const s=new VldMeta(this,t);return e.add(s,t),s}register(e,t){return e.add(this,t),this}describe(e){return this.meta({description:e})}get description(){return this.meta()?.description??this.baseValidator?.description??this.schema?.description??this.inner?.description}}class VldMeta extends VldBase{constructor(e,t){super(r.META),this.baseValidator=e,this.metadata=t}parse(e){return this.baseValidator.parse(e)}safeParse(e){return this.baseValidator.safeParse(e)}getMeta(){return{...this.metadata}}meta(t){if(void 0===t)return{...this.metadata,...e.get(this)};const s=new VldMeta(this.baseValidator,{...this.metadata,...t});return e.add(s,s.getMeta()),s}describe(e){return this.meta({description:e})}}class VldReadonly extends VldBase{constructor(e){super(r.READONLY),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldBrand extends VldBase{constructor(e){super(r.BRAND),this.baseValidator=e}parse(e){return this.baseValidator.parse(e)}safeParse(e){const t=this.baseValidator.safeParse(e);return t.success?{success:!0,data:t.data}:{success:!1,error:t.error}}}class VldRefine extends VldBase{constructor(e,t,s){super(r.REFINE),this.baseValidator=e,this.predicate=t,this.customMessage=s??"Refinement check failed","object"==typeof s&&null!==s&&"path"in s&&Array.isArray(s.path)&&(this.refinePath=s.path)}_createIssue(e){if("function"==typeof this.customMessage){const t=this.customMessage(e);return"string"==typeof t?{code:"custom",path:this.refinePath??[],message:t}:{code:"custom",path:t?.path??this.refinePath??[],message:t?.message??"Refinement check failed"}}if("object"==typeof this.customMessage&&null!==this.customMessage){const e=this.customMessage.message??this.customMessage.error,t="function"==typeof e?e({}):"string"==typeof e?e:"Refinement check failed";return{code:"custom",path:this.customMessage.path??this.refinePath??[],message:t}}return{code:"custom",path:this.refinePath??[],message:"string"==typeof this.customMessage?this.customMessage:"Refinement check failed"}}parse(e){const s=this.baseValidator.parse(e),r=this.predicate(s);if(i(r))throw new Error("Use parseAsync for async refinements");if(!r)throw new t([this._createIssue(s)]);return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const s=await this.baseValidator.parseAsync(e);if(!await this.predicate(s))throw new t([this._createIssue(s)]);return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldRefine(e,this.predicate,this.customMessage)}min(e,t){return this._wrap(this.baseValidator.min?.(e,t)??this.baseValidator)}max(e,t){return this._wrap(this.baseValidator.max?.(e,t)??this.baseValidator)}length(e,t){return this._wrap(this.baseValidator.length?.(e,t)??this.baseValidator)}email(e){return this._wrap(this.baseValidator.email?.(e)??this.baseValidator)}url(e){return this._wrap(this.baseValidator.url?.(e)??this.baseValidator)}uuid(e){return this._wrap(this.baseValidator.uuid?.(e)??this.baseValidator)}regex(e,t){return this._wrap(this.baseValidator.regex?.(e,t)??this.baseValidator)}startsWith(e,t){return this._wrap(this.baseValidator.startsWith?.(e,t)??this.baseValidator)}endsWith(e,t){return this._wrap(this.baseValidator.endsWith?.(e,t)??this.baseValidator)}includes(e,t){return this._wrap(this.baseValidator.includes?.(e,t)??this.baseValidator)}ip(e){return this._wrap(this.baseValidator.ip?.(e)??this.baseValidator)}ipv4(e){return this._wrap(this.baseValidator.ipv4?.(e)??this.baseValidator)}ipv6(e){return this._wrap(this.baseValidator.ipv6?.(e)??this.baseValidator)}nonempty(e){return this._wrap(this.baseValidator.nonempty?.(e)??this.baseValidator)}trim(){return this._wrap(this.baseValidator.trim?.()??this.baseValidator)}toLowerCase(){return this._wrap(this.baseValidator.toLowerCase?.()??this.baseValidator)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this.baseValidator.toUpperCase?.()??this.baseValidator)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this.baseValidator.positive?.(e)??this.baseValidator)}negative(e){return this._wrap(this.baseValidator.negative?.(e)??this.baseValidator)}nonnegative(e){return this._wrap(this.baseValidator.nonnegative?.(e)??this.baseValidator)}nonpositive(e){return this._wrap(this.baseValidator.nonpositive?.(e)??this.baseValidator)}int(e){return this._wrap(this.baseValidator.int?.(e)??this.baseValidator)}finite(e){return this._wrap(this.baseValidator.finite?.(e)??this.baseValidator)}safe(e){return this._wrap(this.baseValidator.safe?.(e)??this.baseValidator)}multipleOf(e,t){return this._wrap(this.baseValidator.multipleOf?.(e,t)??this.baseValidator)}step(e,t){return this._wrap(this.baseValidator.step?.(e,t)??this.baseValidator)}gt(e,t){return this._wrap(this.baseValidator.gt?.(e,t)??this.baseValidator)}gte(e,t){return this._wrap(this.baseValidator.gte?.(e,t)??this.baseValidator)}lt(e,t){return this._wrap(this.baseValidator.lt?.(e,t)??this.baseValidator)}lte(e,t){return this._wrap(this.baseValidator.lte?.(e,t)??this.baseValidator)}extend(e){return this._wrap(this.baseValidator.extend?.(e)??this.baseValidator)}merge(e){return this._wrap(this.baseValidator.merge?.(e)??this.baseValidator)}pick(...e){return this._wrap(this.baseValidator.pick?.(...e)??this.baseValidator)}omit(...e){return this._wrap(this.baseValidator.omit?.(...e)??this.baseValidator)}partial(){return this._wrap(this.baseValidator.partial?.()??this.baseValidator)}required(){return this._wrap(this.baseValidator.required?.()??this.baseValidator)}strict(e){return this._wrap(this.baseValidator.strict?.(e)??this.baseValidator)}passthrough(){return this._wrap(this.baseValidator.passthrough?.()??this.baseValidator)}strip(){return this._wrap(this.baseValidator.strip?.()??this.baseValidator)}catchall(e){return this._wrap(this.baseValidator.catchall?.(e)??this.baseValidator)}get shape(){return this.baseValidator.shape}get keyof(){return this.baseValidator.keyof}unwrap(){return this.baseValidator.unwrap?this.baseValidator.unwrap():this.baseValidator}get element(){return this.baseValidator.element}}class VldTransform extends VldBase{constructor(e,t){super(r.TRANSFORM),this.baseValidator=e,this.transformer=t}parse(e){const t=this.baseValidator.parse(e);try{const e=this.transformer(t);if(i(e))throw new Error("Use parseAsync for async transforms");return e}catch(e){throw new Error(`Transform failed: ${e.message}`)}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const t=await this.baseValidator.parseAsync(e);try{return await this.transformer(t)}catch(e){throw new Error(`Transform failed: ${e.message}`)}}}class VldDefault extends VldBase{constructor(e,t){super(r.DEFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?h(this.defaultValue):this.baseValidator.parse(e)}safeParse(e){return void 0===e?{success:!0,data:h(this.defaultValue)}:this.baseValidator.safeParse(e)}prefault(e){return new VldPrefault(this.baseValidator,void 0===e?this.defaultValue:e)}unwrap(){return this.baseValidator}removeDefault(){return this.baseValidator}}class VldPrefault extends VldBase{constructor(e,t){super(r.PREFAULT),this.baseValidator=e,this.defaultValue=t}parse(e){return void 0===e?this.baseValidator.parse(h(this.defaultValue)):this.baseValidator.parse(e)}safeParse(e){return void 0===e?this.baseValidator.safeParse(h(this.defaultValue)):this.baseValidator.safeParse(e)}prefault(e){return void 0===e?this:new VldPrefault(this.baseValidator,e)}unwrap(){return this.baseValidator}}class VldCatch extends VldBase{constructor(e,t){super(r.CATCH),this.baseValidator=e,this.fallbackValue=t,this.simpleMode=u(e);const s=e.safeParse(t);if(!s.success)throw new Error(`Invalid fallback value: ${s.error.message}`)}parse(e){const t=l(this.simpleMode,e);if(void 0!==t)return t;if(void 0!==this.simpleMode)return this.fallbackValue;try{return this.baseValidator.parse(e)}catch{return this.fallbackValue}}safeParse(e){const t=l(this.simpleMode,e);if(void 0!==t)return{success:!0,data:t};if(void 0!==this.simpleMode)return{success:!0,data:this.fallbackValue};const s=this.baseValidator.safeParse(e);return s.success?s:{success:!0,data:this.fallbackValue}}}class VldOptional extends VldBase{constructor(e){super(r.OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}parseSimpleValue(e){return l(this.simpleMode,e)}static create(e){return new VldOptional(e)}parse(e){if(void 0===e)return;const t=this.parseSimpleValue(e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=this.parseSimpleValue(e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldExactOptional extends VldBase{constructor(e){super(r.EXACT_OPTIONAL),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldExactOptional(e)}parse(e){if(void 0===e)return;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(void 0===e)return{success:!0,data:void 0};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullable extends VldBase{constructor(e){super(r.NULLABLE),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullable(e)}parse(e){if(null===e)return null;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null===e)return{success:!0,data:null};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldNullish extends VldBase{constructor(e){super(r.NULLISH),this.baseValidator=e,this.simpleMode=u(e)}static create(e){return new VldNullish(e)}parse(e){if(null==e)return e;const t=l(this.simpleMode,e);return void 0!==t?t:this.baseValidator.parse(e)}safeParse(e){if(null==e)return{success:!0,data:e};const t=l(this.simpleMode,e);return void 0!==t?{success:!0,data:t}:this.baseValidator.safeParse(e)}unwrap(){return this.baseValidator}}class VldPipe extends VldBase{constructor(e,t){super(r.PIPE),this.first=e,this.second=t}parse(e){const t=this.first.parse(e);return this.second.parse(t)}safeParse(e){const t=this.first.safeParse(e);return t.success?this.second.safeParse(t.data):{success:!1,error:t.error}}}class VldSuperRefine extends VldBase{constructor(e,t){super(r.SUPER_REFINE),this._inner=e,this._refinement=t}parse(e){const s=this._inner.parse(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(s,a)instanceof Promise)throw new Error("Use parseAsync for async refinements");if(r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}safeParse(e){const r=this._inner.safeParse(e);if(!r.success)return{success:!1,error:s(r.error)};const a=[],i={addIssue:e=>{a.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(this._refinement(r.data,i)instanceof Promise)throw new Error("Use safeParseAsync for async refinements");return a.length>0?{success:!1,error:new t(a,a.map(e=>e.message).join("; "))}:r}async parseAsync(e){const s=await this._inner.parseAsync(e),r=[],a={addIssue:e=>{r.push({code:e.code||"custom",path:e.path??[],message:e.message||"Validation error"})},path:[]};if(await this._refinement(s,a),r.length>0)throw new t(r,r.map(e=>e.message).join("; "));return s}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}_wrap(e){return new VldSuperRefine(e,this._refinement)}min(e,t){return this._wrap(this._inner.min?.(e,t)??this._inner)}max(e,t){return this._wrap(this._inner.max?.(e,t)??this._inner)}length(e,t){return this._wrap(this._inner.length?.(e,t)??this._inner)}email(e){return this._wrap(this._inner.email?.(e)??this._inner)}url(e){return this._wrap(this._inner.url?.(e)??this._inner)}uuid(e){return this._wrap(this._inner.uuid?.(e)??this._inner)}regex(e,t){return this._wrap(this._inner.regex?.(e,t)??this._inner)}startsWith(e,t){return this._wrap(this._inner.startsWith?.(e,t)??this._inner)}endsWith(e,t){return this._wrap(this._inner.endsWith?.(e,t)??this._inner)}includes(e,t){return this._wrap(this._inner.includes?.(e,t)??this._inner)}ip(e){return this._wrap(this._inner.ip?.(e)??this._inner)}ipv4(e){return this._wrap(this._inner.ipv4?.(e)??this._inner)}ipv6(e){return this._wrap(this._inner.ipv6?.(e)??this._inner)}nonempty(e){return this._wrap(this._inner.nonempty?.(e)??this._inner)}trim(){return this._wrap(this._inner.trim?.()??this._inner)}toLowerCase(){return this._wrap(this._inner.toLowerCase?.()??this._inner)}lowercase(){return this.toLowerCase()}toUpperCase(){return this._wrap(this._inner.toUpperCase?.()??this._inner)}uppercase(){return this.toUpperCase()}positive(e){return this._wrap(this._inner.positive?.(e)??this._inner)}negative(e){return this._wrap(this._inner.negative?.(e)??this._inner)}nonnegative(e){return this._wrap(this._inner.nonnegative?.(e)??this._inner)}nonpositive(e){return this._wrap(this._inner.nonpositive?.(e)??this._inner)}int(e){return this._wrap(this._inner.int?.(e)??this._inner)}finite(e){return this._wrap(this._inner.finite?.(e)??this._inner)}safe(e){return this._wrap(this._inner.safe?.(e)??this._inner)}multipleOf(e,t){return this._wrap(this._inner.multipleOf?.(e,t)??this._inner)}step(e,t){return this._wrap(this._inner.step?.(e,t)??this._inner)}gt(e,t){return this._wrap(this._inner.gt?.(e,t)??this._inner)}gte(e,t){return this._wrap(this._inner.gte?.(e,t)??this._inner)}lt(e,t){return this._wrap(this._inner.lt?.(e,t)??this._inner)}lte(e,t){return this._wrap(this._inner.lte?.(e,t)??this._inner)}extend(e){return this._wrap(this._inner.extend?.(e)??this._inner)}merge(e){return this._wrap(this._inner.merge?.(e)??this._inner)}pick(...e){return this._wrap(this._inner.pick?.(...e)??this._inner)}omit(...e){return this._wrap(this._inner.omit?.(...e)??this._inner)}partial(){return this._wrap(this._inner.partial?.()??this._inner)}required(){return this._wrap(this._inner.required?.()??this._inner)}strict(e){return this._wrap(this._inner.strict?.(e)??this._inner)}passthrough(){return this._wrap(this._inner.passthrough?.()??this._inner)}strip(){return this._wrap(this._inner.strip?.()??this._inner)}catchall(e){return this._wrap(this._inner.catchall?.(e)??this._inner)}get shape(){return this._inner.shape}get keyof(){return this._inner.keyof}unwrap(){return this._inner.unwrap?this._inner.unwrap():this._inner}get element(){return this._inner.element}}class VldPreprocess extends VldBase{constructor(e,t){super(r.PREPROCESS),this._preprocessor=e,this._schema=t}static create(e,t){return new VldPreprocess(e,t)}parse(e){const t=this._preprocessor(e);return this._schema.parse(t)}safeParse(e){try{const t=this._preprocessor(e);return this._schema.safeParse(t)}catch(e){return{success:!1,error:s(e)}}}}export{r as VLD_VALIDATOR_TYPES,VldBase,VldBrand,VldCatch,VldDefault,VldExactOptional,VldMeta,VldNullable,VldNullish,VldOptional,VldPipe,VldPrefault,VldPreprocess,VldReadonly,VldRefine,VldSuperRefine,VldTransform,o as configureSchemaCompositionFactories,s as ensureVldError,i as isPromiseLike,a as resolveErrorMessage};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as r}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as a}from"../chunks/errors-core-CerMg2rq.js";class VldBase64 extends e{constructor(e=!1){super(s.BASE64),this.urlSafe=e}parse(e){const s=this.safeParse(e);if(!s.success)throw s.error;return s.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new a([r("invalid_type",[],t().expectedString)])};return(this.urlSafe?VldBase64.BASE64_URL_REGEX:VldBase64.BASE64_REGEX).test(e)?!this.urlSafe&&e.length>0&&e.length%4!=0?{success:!1,error:new a([r("custom",[],t().invalidBase64)])}:{success:!0,data:e}:{success:!1,error:new a([r("custom",[],t().invalidBase64)])}}urlSafeMode(){return new VldBase64(!0)}static create(e=!1){return new VldBase64(e)}}VldBase64.BASE64_REGEX=/^[A-Za-z0-9+/]*={0,2}$/,VldBase64.BASE64_URL_REGEX=/^[A-Za-z0-9_-]*={0,2}$/;export{VldBase64};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as r}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as a}from"../chunks/errors-core-BU14-Dk8.js";class VldBase64 extends e{constructor(e=!1){super(s.BASE64),this.urlSafe=e}parse(e){const s=this.safeParse(e);if(!s.success)throw s.error;return s.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new a([r("invalid_type",[],t().expectedString)])};return(this.urlSafe?VldBase64.BASE64_URL_REGEX:VldBase64.BASE64_REGEX).test(e)?!this.urlSafe&&e.length>0&&e.length%4!=0?{success:!1,error:new a([r("custom",[],t().invalidBase64)])}:{success:!0,data:e}:{success:!1,error:new a([r("custom",[],t().invalidBase64)])}}urlSafeMode(){return new VldBase64(!0)}static create(e=!1){return new VldBase64(e)}}VldBase64.BASE64_REGEX=/^[A-Za-z0-9+/]*={0,2}$/,VldBase64.BASE64_URL_REGEX=/^[A-Za-z0-9_-]*={0,2}$/;export{VldBase64};
@@ -0,0 +1,105 @@
1
+ /**
2
+ * VldBigIntV2 — OPTIMIZED: check returns Issue | null.
3
+ */
4
+ import { VldBase, type ErrorParam, type ParseResult } from './base.js';
5
+ import { type VldIssue } from '../errors-core.js';
6
+ export declare abstract class VldBigIntCheck {
7
+ abstract readonly kind: 'min' | 'max' | 'gt' | 'lt' | 'multipleOf' | 'positive' | 'negative' | 'nonnegative' | 'nonpositive';
8
+ abstract check(value: bigint): VldIssue | null;
9
+ abstract meta(): Record<string, any>;
10
+ }
11
+ export declare class VldBigIntCheckMin extends VldBigIntCheck {
12
+ private _msg?;
13
+ readonly kind: "min";
14
+ private _threshold;
15
+ constructor(threshold: bigint | number | string, _msg?: string | undefined);
16
+ check(value: bigint): VldIssue | null;
17
+ meta(): {
18
+ kind: string;
19
+ value: bigint;
20
+ message: string | undefined;
21
+ };
22
+ }
23
+ export declare class VldBigIntCheckMax extends VldBigIntCheck {
24
+ private _msg?;
25
+ readonly kind: "max";
26
+ private _threshold;
27
+ constructor(threshold: bigint | number | string, _msg?: string | undefined);
28
+ check(value: bigint): VldIssue | null;
29
+ meta(): {
30
+ kind: string;
31
+ value: bigint;
32
+ message: string | undefined;
33
+ };
34
+ }
35
+ export declare class VldBigIntCheckGt extends VldBigIntCheck {
36
+ private _msg?;
37
+ readonly kind: "gt";
38
+ private _threshold;
39
+ constructor(threshold: bigint | number | string, _msg?: string | undefined);
40
+ check(value: bigint): VldIssue | null;
41
+ meta(): {
42
+ kind: string;
43
+ value: bigint;
44
+ message: string | undefined;
45
+ };
46
+ }
47
+ export declare class VldBigIntCheckLt extends VldBigIntCheck {
48
+ private _msg?;
49
+ readonly kind: "lt";
50
+ private _threshold;
51
+ constructor(threshold: bigint | number | string, _msg?: string | undefined);
52
+ check(value: bigint): VldIssue | null;
53
+ meta(): {
54
+ kind: string;
55
+ value: bigint;
56
+ message: string | undefined;
57
+ };
58
+ }
59
+ export declare class VldBigIntCheckMultipleOf extends VldBigIntCheck {
60
+ private _msg?;
61
+ readonly kind: "multipleOf";
62
+ private _divisor;
63
+ constructor(divisor: bigint | number | string, _msg?: string | undefined);
64
+ check(value: bigint): VldIssue | null;
65
+ meta(): {
66
+ kind: string;
67
+ value: bigint;
68
+ message: string | undefined;
69
+ };
70
+ }
71
+ export interface VldBigIntDef {
72
+ readonly type: 'bigint';
73
+ readonly checks: ReadonlyArray<VldBigIntCheck>;
74
+ readonly jsonSchema?: {
75
+ minimum?: string;
76
+ maximum?: string;
77
+ multipleOf?: string;
78
+ format?: string;
79
+ } | undefined;
80
+ readonly errorMessage?: string | undefined;
81
+ readonly isSimple: boolean;
82
+ }
83
+ export declare class VldBigIntV2 extends VldBase<bigint, bigint> {
84
+ readonly __def: VldBigIntDef;
85
+ constructor(def?: VldBigIntDef);
86
+ static create(): VldBigIntV2;
87
+ get isSimple(): boolean;
88
+ parse(value: unknown): bigint;
89
+ parseKnownBigInt(value: bigint): bigint;
90
+ safeParse(value: unknown): ParseResult<bigint>;
91
+ protected withDef(def: Partial<VldBigIntDef> & {
92
+ type: 'bigint';
93
+ }): VldBigIntV2;
94
+ min(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
95
+ max(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
96
+ positive(message?: ErrorParam): VldBigIntV2;
97
+ negative(message?: ErrorParam): VldBigIntV2;
98
+ nonnegative(message?: ErrorParam): VldBigIntV2;
99
+ nonpositive(message?: ErrorParam): VldBigIntV2;
100
+ gt(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
101
+ lt(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
102
+ gte(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
103
+ lte(value: bigint | number | string, message?: ErrorParam): VldBigIntV2;
104
+ multipleOf(divisor: bigint | number | string, message?: ErrorParam): VldBigIntV2;
105
+ }
@@ -0,0 +1 @@
1
+ import{VldBase as t,VLD_VALIDATOR_TYPES as e}from"./base.js";import{V as s,c as i,g as h}from"../chunks/errors-core-BU14-Dk8.js";class VldBigIntCheck{}function n(t){return"bigint"==typeof t?t:BigInt(t)}class VldBigIntCheckMin extends VldBigIntCheck{constructor(t,e){super(),this._msg=e,this.kind="min",this._threshold=n(t)}check(t){return t<this._threshold?{code:"too_small",path:[],origin:"bigint",message:this._msg||`BigInt must be >= ${this._threshold}`}:null}meta(){return{kind:"min",value:this._threshold,message:this._msg}}}class VldBigIntCheckMax extends VldBigIntCheck{constructor(t,e){super(),this._msg=e,this.kind="max",this._threshold=n(t)}check(t){return t>this._threshold?{code:"too_big",path:[],origin:"bigint",message:this._msg||`BigInt must be <= ${this._threshold}`}:null}meta(){return{kind:"max",value:this._threshold,message:this._msg}}}class VldBigIntCheckGt extends VldBigIntCheck{constructor(t,e){super(),this._msg=e,this.kind="gt",this._threshold=n(t)}check(t){return t<=this._threshold?{code:"too_small",path:[],origin:"bigint",message:this._msg||`BigInt must be > ${this._threshold}`}:null}meta(){return{kind:"gt",value:this._threshold,message:this._msg}}}class VldBigIntCheckLt extends VldBigIntCheck{constructor(t,e){super(),this._msg=e,this.kind="lt",this._threshold=n(t)}check(t){return t>=this._threshold?{code:"too_big",path:[],origin:"bigint",message:this._msg||`BigInt must be < ${this._threshold}`}:null}meta(){return{kind:"lt",value:this._threshold,message:this._msg}}}class VldBigIntCheckMultipleOf extends VldBigIntCheck{constructor(t,e){super(),this._msg=e,this.kind="multipleOf",this._divisor=n(t)}check(t){return 0n===this._divisor?null:t%this._divisor!==0n?{code:"custom",path:[],message:this._msg||`BigInt must be a multiple of ${this._divisor}`}:null}meta(){return{kind:"multipleOf",value:this._divisor,message:this._msg}}}const c=Object.freeze({type:"bigint",checks:Object.freeze([]),isSimple:!0});class VldBigIntV2 extends t{constructor(t=c){super(e.BIGINT),this.__def=t}static create(){return new VldBigIntV2}get isSimple(){return this.__def.isSimple}parse(t){if("bigint"!=typeof t)throw new s([i("bigint",h(t),this.__def.errorMessage)]);return this.__def.isSimple?t:this.parseKnownBigInt(t)}parseKnownBigInt(t){const e=this.__def.checks;for(let i=0;i<e.length;i++){const h=e[i].check(t);if(null!==h)throw new s([h])}return t}safeParse(t){try{return{success:!0,data:this.parse(t)}}catch(t){return{success:!1,error:t instanceof s?t:new s([{code:"custom",path:[],message:String(t)}])}}}withDef(t){const e=(s=t.checks??this.__def.checks,i=t.jsonSchema??this.__def.jsonSchema,h=t.errorMessage??this.__def.errorMessage,Object.freeze({type:"bigint",checks:s,jsonSchema:i,errorMessage:h,isSimple:0===s.length}));var s,i,h;return new this.constructor(e)}min(t,e){const s=n(t);return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckMin(t,e)],jsonSchema:{...this.__def.jsonSchema,minimum:s.toString()}})}max(t,e){const s=n(t);return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckMax(t,e)],jsonSchema:{...this.__def.jsonSchema,maximum:s.toString()}})}positive(t){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckGt(0n,t)]})}negative(t){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckLt(0n,t)]})}nonnegative(t){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckMin(0n,t)]})}nonpositive(t){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckMax(0n,t)]})}gt(t,e){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckGt(t,e)]})}lt(t,e){return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckLt(t,e)]})}gte(t,e){return this.min(t,e)}lte(t,e){return this.max(t,e)}multipleOf(t,e){const s=n(t);return this.withDef({type:"bigint",checks:[...this.__def.checks,new VldBigIntCheckMultipleOf(t,e)],jsonSchema:{...this.__def.jsonSchema,multipleOf:s.toString()}})}}export{VldBigIntCheck,VldBigIntCheckGt,VldBigIntCheckLt,VldBigIntCheckMax,VldBigIntCheckMin,VldBigIntCheckMultipleOf,VldBigIntV2};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as i}from"./base.js";import{getMessages as n}from"../locales/runtime.js";import{V as t}from"../chunks/errors-core-CerMg2rq.js";function s(e){return new t([{code:"invalid_type",path:[],message:e}])}class VldBigInt extends e{constructor(e){super(e?.validatorType||i.BIGINT),this.config={checks:e?.checks||[],errorMessage:e?.errorMessage,jsonSchema:e?.jsonSchema},this._checks=this.config.checks,this._fastCheckMode=this.detectFastCheckMode()}get jsonSchema(){return this.config.jsonSchema}get isSimple(){return 0===this._checks.length}get minValue(){return this.config.jsonSchema?.minimum?BigInt(this.config.jsonSchema.minimum):null}get maxValue(){return this.config.jsonSchema?.maximum?BigInt(this.config.jsonSchema.maximum):null}get format(){return this.config.jsonSchema?.format??null}static create(){return new VldBigInt}detectFastCheckMode(){if(0===this._checks.length)return"none";if(1!==this._checks.length)return;const e=this.config.jsonSchema;return 0n===e?.exclusiveMinimum&&void 0===e.minimum&&void 0===e.maximum?"positive":0n===e?.exclusiveMaximum&&void 0===e.minimum&&void 0===e.maximum?"negative":0n===e?.minimum&&void 0===e.maximum&&void 0===e.exclusiveMaximum?"nonnegative":0n===e?.maximum&&void 0===e.minimum&&void 0===e.exclusiveMinimum?"nonpositive":void 0}getValidationError(){return new Error(this.config.errorMessage||n().invalidBigint)}parse(e){if("bigint"!=typeof e)throw this.getValidationError();return this.parseKnownBigInt(e)}parseKnownBigInt(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0n)return e;throw this.getValidationError();case"negative":if(e<0n)return e;throw this.getValidationError();case"nonnegative":if(e>=0n)return e;throw this.getValidationError();case"nonpositive":if(e<=0n)return e;throw this.getValidationError()}for(const i of this._checks)if(!i(e))throw this.getValidationError();return e}safeParse(e){if("bigint"!=typeof e)return{success:!1,error:s(this.getValidationError().message)};try{return{success:!0,data:this.parseKnownBigInt(e)}}catch(e){return{success:!1,error:s(e.message)}}}min(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i>=e],errorMessage:i||`BigInt must be at least ${e}`,jsonSchema:{...this.config.jsonSchema,minimum:e}})}max(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i<=e],errorMessage:i||`BigInt must be at most ${e}`,jsonSchema:{...this.config.jsonSchema,maximum:e}})}positive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>0n],errorMessage:e||"BigInt must be positive",jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0n}})}negative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<0n],errorMessage:e||"BigInt must be negative",jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0n}})}nonnegative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>=0n],errorMessage:e||"BigInt must be non-negative",jsonSchema:{...this.config.jsonSchema,minimum:0n}})}nonpositive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<=0n],errorMessage:e||"BigInt must be non-positive",jsonSchema:{...this.config.jsonSchema,maximum:0n}})}gt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>n],errorMessage:i||`BigInt must be greater than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:n}})}lt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<n],errorMessage:i||`BigInt must be less than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:n}})}gte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.min(n,i)}lte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.max(n,i)}multipleOf(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i%e===0n],errorMessage:i||`BigInt must be a multiple of ${e}`,jsonSchema:{...this.config.jsonSchema,multipleOf:e}})}}export{VldBigInt};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as i}from"./base.js";import{getMessages as n}from"../locales/runtime.js";import{V as t}from"../chunks/errors-core-BU14-Dk8.js";function s(e){return new t([{code:"invalid_type",path:[],message:e}])}class VldBigInt extends e{constructor(e){super(e?.validatorType||i.BIGINT),this.config={checks:e?.checks||[],errorMessage:e?.errorMessage,jsonSchema:e?.jsonSchema},this._checks=this.config.checks,this._fastCheckMode=this.detectFastCheckMode()}get jsonSchema(){return this.config.jsonSchema}get isSimple(){return 0===this._checks.length}get minValue(){return this.config.jsonSchema?.minimum?BigInt(this.config.jsonSchema.minimum):null}get maxValue(){return this.config.jsonSchema?.maximum?BigInt(this.config.jsonSchema.maximum):null}get format(){return this.config.jsonSchema?.format??null}static create(){return new VldBigInt}detectFastCheckMode(){if(0===this._checks.length)return"none";if(1!==this._checks.length)return;const e=this.config.jsonSchema;return 0n===e?.exclusiveMinimum&&void 0===e.minimum&&void 0===e.maximum?"positive":0n===e?.exclusiveMaximum&&void 0===e.minimum&&void 0===e.maximum?"negative":0n===e?.minimum&&void 0===e.maximum&&void 0===e.exclusiveMaximum?"nonnegative":0n===e?.maximum&&void 0===e.minimum&&void 0===e.exclusiveMinimum?"nonpositive":void 0}getValidationError(){return new Error(this.config.errorMessage||n().invalidBigint)}parse(e){if("bigint"!=typeof e)throw this.getValidationError();return this.parseKnownBigInt(e)}parseKnownBigInt(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0n)return e;throw this.getValidationError();case"negative":if(e<0n)return e;throw this.getValidationError();case"nonnegative":if(e>=0n)return e;throw this.getValidationError();case"nonpositive":if(e<=0n)return e;throw this.getValidationError()}for(const i of this._checks)if(!i(e))throw this.getValidationError();return e}safeParse(e){if("bigint"!=typeof e)return{success:!1,error:s(this.getValidationError().message)};try{return{success:!0,data:this.parseKnownBigInt(e)}}catch(e){return{success:!1,error:s(e.message)}}}min(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i>=e],errorMessage:i||`BigInt must be at least ${e}`,jsonSchema:{...this.config.jsonSchema,minimum:e}})}max(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i<=e],errorMessage:i||`BigInt must be at most ${e}`,jsonSchema:{...this.config.jsonSchema,maximum:e}})}positive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>0n],errorMessage:e||"BigInt must be positive",jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0n}})}negative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<0n],errorMessage:e||"BigInt must be negative",jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0n}})}nonnegative(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>=0n],errorMessage:e||"BigInt must be non-negative",jsonSchema:{...this.config.jsonSchema,minimum:0n}})}nonpositive(e){return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<=0n],errorMessage:e||"BigInt must be non-positive",jsonSchema:{...this.config.jsonSchema,maximum:0n}})}gt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e>n],errorMessage:i||`BigInt must be greater than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:n}})}lt(e,i){const n="bigint"==typeof e?e:BigInt(e);return new VldBigInt({...this.config,checks:[...this.config.checks,e=>e<n],errorMessage:i||`BigInt must be less than ${n}`,jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:n}})}gte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.min(n,i)}lte(e,i){const n="bigint"==typeof e?e:BigInt(e);return this.max(n,i)}multipleOf(e,i){return new VldBigInt({...this.config,checks:[...this.config.checks,i=>i%e===0n],errorMessage:i||`BigInt must be a multiple of ${e}`,jsonSchema:{...this.config.jsonSchema,multipleOf:e}})}}export{VldBigInt};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{V as r,c as t,g as a}from"../chunks/errors-core-CerMg2rq.js";class VldBoolean extends e{constructor(e,r){super(r||s.BOOLEAN),this.errorMessage=e}get isSimple(){return!0}static create(){return new VldBoolean}parse(e){if("boolean"!=typeof e)throw new r([t("boolean",a(e),this.errorMessage)]);return e}parseKnownBoolean(e){return e}safeParse(e){return"boolean"==typeof e?{success:!0,data:e}:{success:!1,error:new r([t("boolean",a(e),this.errorMessage)])}}true(e){return new VldTrue(e||"Value must be true")}false(e){return new VldFalse(e||"Value must be false")}}class VldTrue extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}parseKnownBoolean(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}safeParse(e){return!0!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!0}}}class VldFalse extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}parseKnownBoolean(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}safeParse(e){return!1!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!1}}}export{VldBoolean};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{V as r,c as t,g as a}from"../chunks/errors-core-BU14-Dk8.js";class VldBoolean extends e{constructor(e,r){super(r||s.BOOLEAN),this.errorMessage=e}get isSimple(){return!0}static create(){return new VldBoolean}parse(e){if("boolean"!=typeof e)throw new r([t("boolean",a(e),this.errorMessage)]);return e}parseKnownBoolean(e){return e}safeParse(e){return"boolean"==typeof e?{success:!0,data:e}:{success:!1,error:new r([t("boolean",a(e),this.errorMessage)])}}true(e){return new VldTrue(e||"Value must be true")}false(e){return new VldFalse(e||"Value must be false")}}class VldTrue extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}parseKnownBoolean(e){if(!0!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!0}safeParse(e){return!0!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!0}}}class VldFalse extends VldBoolean{constructor(e){super(e),this.message=e}get isSimple(){return!1}parse(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}parseKnownBoolean(e){if(!1!==e)throw new r([{code:"custom",path:[],message:this.message}]);return!1}safeParse(e){return!1!==e?{success:!1,error:new r([{code:"custom",path:[],message:this.message}])}:{success:!0,data:!1}}}export{VldBoolean};
@@ -1 +1 @@
1
- import{VldBase as r,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as e}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as c}from"../chunks/errors-core-CerMg2rq.js";class VldCodec extends r{constructor(r,e,t){super(s.CODEC),this.inputValidator=r,this.outputValidator=e,this.codecTransform=t}parse(r){const s=this.safeParse(r);if(!s.success)throw s.error;return s.data}safeParse(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.decode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}invert(){return new VldCodec(this.outputValidator,this.inputValidator,{decode:this.codecTransform.encode,encode:this.codecTransform.decode})}encode(r){const s=this.safeEncode(r);if(!s.success)throw s.error;return s.data}safeEncode(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.encode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}async parseAsync(r){const s=await this.safeParseAsync(r);if(!s.success)throw s.error;return s.data}async safeParseAsync(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.decode(s.data);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}async encodeAsync(r){const s=await this.safeEncodeAsync(r);if(!s.success)throw s.error;return s.data}async safeEncodeAsync(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.encode(s.data);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}static create(r,s,e){return new VldCodec(r,s,e)}static invert(r){return r.invert()}}export{VldCodec};
1
+ import{VldBase as r,VLD_VALIDATOR_TYPES as s}from"./base.js";import{createIssue as e}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as c}from"../chunks/errors-core-BU14-Dk8.js";class VldCodec extends r{constructor(r,e,t){super(s.CODEC),this.inputValidator=r,this.outputValidator=e,this.codecTransform=t}parse(r){const s=this.safeParse(r);if(!s.success)throw s.error;return s.data}safeParse(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.decode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}invert(){return new VldCodec(this.outputValidator,this.inputValidator,{decode:this.codecTransform.encode,encode:this.codecTransform.decode})}encode(r){const s=this.safeEncode(r);if(!s.success)throw s.error;return s.data}safeEncode(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=this.codecTransform.encode(s.data);if(r instanceof Promise)throw new c([e("custom",[],t().codecAsyncNotSupported)]);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}async parseAsync(r){const s=await this.safeParseAsync(r);if(!s.success)throw s.error;return s.data}async safeParseAsync(r){const s=this.inputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.decode(s.data);return this.outputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecDecodeFailed)])}}}async encodeAsync(r){const s=await this.safeEncodeAsync(r);if(!s.success)throw s.error;return s.data}async safeEncodeAsync(r){const s=this.outputValidator.safeParse(r);if(!s.success)return{success:!1,error:s.error};try{const r=await this.codecTransform.encode(s.data);return this.inputValidator.safeParse(r)}catch(r){return r instanceof c?{success:!1,error:r}:{success:!1,error:new c([e("custom",[],t().codecEncodeFailed)])}}}static create(r,s,e){return new VldCodec(r,s,e)}static invert(r){return r.invert()}}export{VldCodec};
@@ -0,0 +1,59 @@
1
+ /**
2
+ * V2 composite validators: VldTupleV2, VldSetV2, VldMapV2, VldIntersectionV2.
3
+ * Single-def pattern applied to remaining composite types.
4
+ */
5
+ import { VldBase, type ParseResult } from './base.js';
6
+ export interface VldTupleDef {
7
+ readonly type: 'tuple';
8
+ readonly validators: ReadonlyArray<VldBase<any, any>>;
9
+ readonly validatorTypes: ReadonlyArray<string>;
10
+ }
11
+ export declare class VldTupleV2<T extends readonly VldBase<any, any>[]> extends VldBase<unknown[], unknown[]> {
12
+ readonly __def: VldTupleDef;
13
+ constructor(validators: T);
14
+ static create<T extends readonly VldBase<any, any>[]>(...validators: T): VldTupleV2<T>;
15
+ parse(value: unknown): unknown[];
16
+ parseKnownTuple(value: unknown[]): unknown[];
17
+ safeParse(value: unknown): ParseResult<unknown[]>;
18
+ get items(): ReadonlyArray<VldBase<any, any>>;
19
+ }
20
+ export interface VldSetDef {
21
+ readonly type: 'set';
22
+ readonly valueValidator: VldBase<unknown, any>;
23
+ readonly errorMessage?: string | undefined;
24
+ readonly isSimple: boolean;
25
+ }
26
+ export declare class VldSetV2<T> extends VldBase<Set<T>, Set<T>> {
27
+ readonly __def: VldSetDef;
28
+ constructor(valueValidator: VldBase<unknown, T>, errorMessage?: string);
29
+ static create<T>(valueValidator: VldBase<unknown, T>): VldSetV2<T>;
30
+ parse(value: unknown): Set<T>;
31
+ safeParse(value: unknown): ParseResult<Set<T>>;
32
+ get isSimple(): boolean;
33
+ }
34
+ export interface VldMapDef {
35
+ readonly type: 'map';
36
+ readonly keyValidator: VldBase<unknown, any>;
37
+ readonly valueValidator: VldBase<unknown, any>;
38
+ readonly isSimple: boolean;
39
+ }
40
+ export declare class VldMapV2<K, V> extends VldBase<Map<K, V>, Map<K, V>> {
41
+ readonly __def: VldMapDef;
42
+ constructor(keyValidator: VldBase<unknown, K>, valueValidator: VldBase<unknown, V>);
43
+ static create<K, V>(keyValidator: VldBase<unknown, K>, valueValidator: VldBase<unknown, V>): VldMapV2<K, V>;
44
+ parse(value: unknown): Map<K, V>;
45
+ safeParse(value: unknown): ParseResult<Map<K, V>>;
46
+ get isSimple(): boolean;
47
+ }
48
+ export interface VldIntersectionDef {
49
+ readonly type: 'intersection';
50
+ readonly left: VldBase<any, any>;
51
+ readonly right: VldBase<any, any>;
52
+ }
53
+ export declare class VldIntersectionV2<A, B> extends VldBase<A & B, A & B> {
54
+ readonly __def: VldIntersectionDef;
55
+ constructor(left: VldBase<any, A>, right: VldBase<any, B>);
56
+ static create<A, B>(left: VldBase<any, A>, right: VldBase<any, B>): VldIntersectionV2<A, B>;
57
+ parse(value: unknown): A & B;
58
+ safeParse(value: unknown): ParseResult<A & B>;
59
+ }
@@ -0,0 +1 @@
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";import{V as s,c as r,g as a}from"../chunks/errors-core-BU14-Dk8.js";class VldTupleV2 extends e{constructor(e){super(t.TUPLE),this.__def=Object.freeze({type:"tuple",validators:Object.freeze([...e]),validatorTypes:Object.freeze(e.map(e=>e.validatorType))})}static create(...e){return new VldTupleV2(e)}parse(e){if(!Array.isArray(e))throw new s([r("tuple",a(e),void 0)]);return this.parseKnownTuple(e)}parseKnownTuple(e){const t=this.__def.validators,s=t.length;if(e.length<s)throw new Error(`Tuple must have at least ${s} items, got ${e.length}`);const r=new Array(s);for(let a=0;a<s;a++)r[a]=t[a].parse(e[a]);return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}get items(){return this.__def.validators}}class VldSetV2 extends e{constructor(e,s){super(t.SET),this.__def=Object.freeze({type:"set",valueValidator:e,errorMessage:s,isSimple:!0===e.isSimple})}static create(e){return new VldSetV2(e)}parse(e){if(!(e instanceof Set))throw new s([r("set",a(e),this.__def.errorMessage)]);if(this.__def.isSimple)return e;const t=new Set;for(const s of e)t.add(this.__def.valueValidator.parse(s));return t}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}get isSimple(){return this.__def.isSimple}}class VldMapV2 extends e{constructor(e,s){super(t.MAP);const r=!0===e.isSimple,a=!0===s.isSimple;this.__def=Object.freeze({type:"map",keyValidator:e,valueValidator:s,isSimple:r&&a})}static create(e,t){return new VldMapV2(e,t)}parse(e){if(!(e instanceof Map))throw new s([r("map",a(e),void 0)]);if(this.__def.isSimple)return e;const t=new Map;for(const[s,r]of e)t.set(this.__def.keyValidator.parse(s),this.__def.valueValidator.parse(r));return t}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}get isSimple(){return this.__def.isSimple}}class VldIntersectionV2 extends e{constructor(e,s){super(t.INTERSECTION),this.__def=Object.freeze({type:"intersection",left:e,right:s})}static create(e,t){return new VldIntersectionV2(e,t)}parse(e){return{...this.__def.left.parse(e),...this.__def.right.parse(e)}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}}export{VldIntersectionV2,VldMapV2,VldSetV2,VldTupleV2};
@@ -0,0 +1,140 @@
1
+ /**
2
+ * VldDateV2 — OPTIMIZED: check returns Issue | null.
3
+ */
4
+ import { VldBase, type ErrorParam, type ParseResult } from './base.js';
5
+ import { type VldIssue } from '../errors-core.js';
6
+ export declare abstract class VldDateCheck {
7
+ abstract readonly kind: 'min' | 'max' | 'gt' | 'lt' | 'past' | 'future' | 'today' | 'weekday' | 'weekend';
8
+ abstract check(value: Date): VldIssue | null;
9
+ abstract meta(): Record<string, any>;
10
+ }
11
+ export declare class VldDateCheckMin extends VldDateCheck {
12
+ private _msg?;
13
+ readonly kind: "min";
14
+ private _threshold;
15
+ constructor(threshold: Date | string | number, _msg?: string | undefined);
16
+ check(value: Date): VldIssue | null;
17
+ meta(): {
18
+ kind: string;
19
+ value: Date;
20
+ message: string | undefined;
21
+ };
22
+ }
23
+ export declare class VldDateCheckMax extends VldDateCheck {
24
+ private _msg?;
25
+ readonly kind: "max";
26
+ private _threshold;
27
+ constructor(threshold: Date | string | number, _msg?: string | undefined);
28
+ check(value: Date): VldIssue | null;
29
+ meta(): {
30
+ kind: string;
31
+ value: Date;
32
+ message: string | undefined;
33
+ };
34
+ }
35
+ export declare class VldDateCheckGt extends VldDateCheck {
36
+ private _msg?;
37
+ readonly kind: "gt";
38
+ private _threshold;
39
+ constructor(threshold: Date | number, _msg?: string | undefined);
40
+ check(value: Date): VldIssue | null;
41
+ meta(): {
42
+ kind: string;
43
+ value: Date;
44
+ message: string | undefined;
45
+ };
46
+ }
47
+ export declare class VldDateCheckLt extends VldDateCheck {
48
+ private _msg?;
49
+ readonly kind: "lt";
50
+ private _threshold;
51
+ constructor(threshold: Date | number, _msg?: string | undefined);
52
+ check(value: Date): VldIssue | null;
53
+ meta(): {
54
+ kind: string;
55
+ value: Date;
56
+ message: string | undefined;
57
+ };
58
+ }
59
+ export declare class VldDateCheckPast extends VldDateCheck {
60
+ private _msg?;
61
+ readonly kind: "past";
62
+ constructor(_msg?: string | undefined);
63
+ check(value: Date): VldIssue | null;
64
+ meta(): {
65
+ kind: string;
66
+ message: string | undefined;
67
+ };
68
+ }
69
+ export declare class VldDateCheckFuture extends VldDateCheck {
70
+ private _msg?;
71
+ readonly kind: "future";
72
+ constructor(_msg?: string | undefined);
73
+ check(value: Date): VldIssue | null;
74
+ meta(): {
75
+ kind: string;
76
+ message: string | undefined;
77
+ };
78
+ }
79
+ export declare class VldDateCheckToday extends VldDateCheck {
80
+ private _msg?;
81
+ readonly kind: "today";
82
+ constructor(_msg?: string | undefined);
83
+ check(value: Date): VldIssue | null;
84
+ meta(): {
85
+ kind: string;
86
+ message: string | undefined;
87
+ };
88
+ }
89
+ export declare class VldDateCheckWeekday extends VldDateCheck {
90
+ private _msg?;
91
+ readonly kind: "weekday";
92
+ constructor(_msg?: string | undefined);
93
+ check(value: Date): VldIssue | null;
94
+ meta(): {
95
+ kind: string;
96
+ message: string | undefined;
97
+ };
98
+ }
99
+ export declare class VldDateCheckWeekend extends VldDateCheck {
100
+ private _msg?;
101
+ readonly kind: "weekend";
102
+ constructor(_msg?: string | undefined);
103
+ check(value: Date): VldIssue | null;
104
+ meta(): {
105
+ kind: string;
106
+ message: string | undefined;
107
+ };
108
+ }
109
+ export interface VldDateDef {
110
+ readonly type: 'date';
111
+ readonly checks: ReadonlyArray<VldDateCheck>;
112
+ readonly jsonSchema?: {
113
+ minimum?: string;
114
+ maximum?: string;
115
+ format?: string;
116
+ } | undefined;
117
+ readonly errorMessage?: string | undefined;
118
+ readonly isSimple: boolean;
119
+ }
120
+ export declare class VldDateV2 extends VldBase<Date, Date> {
121
+ readonly __def: VldDateDef;
122
+ constructor(def?: VldDateDef);
123
+ static create(): VldDateV2;
124
+ get isSimple(): boolean;
125
+ parse(value: unknown): Date;
126
+ parseKnownDate(value: Date): Date;
127
+ safeParse(value: unknown): ParseResult<Date>;
128
+ protected withDef(def: Partial<VldDateDef> & {
129
+ type: 'date';
130
+ }): VldDateV2;
131
+ min(date: Date | string | number, message?: ErrorParam): VldDateV2;
132
+ max(date: Date | string | number, message?: ErrorParam): VldDateV2;
133
+ past(message?: ErrorParam): VldDateV2;
134
+ future(message?: ErrorParam): VldDateV2;
135
+ today(message?: ErrorParam): VldDateV2;
136
+ weekday(message?: ErrorParam): VldDateV2;
137
+ weekend(message?: ErrorParam): VldDateV2;
138
+ gt(value: Date | number, message?: ErrorParam): VldDateV2;
139
+ lt(value: Date | number, message?: ErrorParam): VldDateV2;
140
+ }
@@ -0,0 +1 @@
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";import{V as s,c as h,g as a}from"../chunks/errors-core-BU14-Dk8.js";class VldDateCheck{}function r(e){return e instanceof Date?e:new Date(e)}class VldDateCheckMin extends VldDateCheck{constructor(e,t){super(),this._msg=t,this.kind="min",this._threshold=r(e)}check(e){return e.getTime()<this._threshold.getTime()?{code:"too_small",path:[],origin:"date",message:this._msg||`Date must be >= ${this._threshold.toISOString()}`}:null}meta(){return{kind:"min",value:this._threshold,message:this._msg}}}class VldDateCheckMax extends VldDateCheck{constructor(e,t){super(),this._msg=t,this.kind="max",this._threshold=r(e)}check(e){return e.getTime()>this._threshold.getTime()?{code:"too_big",path:[],origin:"date",message:this._msg||`Date must be <= ${this._threshold.toISOString()}`}:null}meta(){return{kind:"max",value:this._threshold,message:this._msg}}}class VldDateCheckGt extends VldDateCheck{constructor(e,t){super(),this._msg=t,this.kind="gt",this._threshold=r(e)}check(e){return e.getTime()<=this._threshold.getTime()?{code:"too_small",path:[],origin:"date",message:this._msg||`Date must be > ${this._threshold.toISOString()}`}:null}meta(){return{kind:"gt",value:this._threshold,message:this._msg}}}class VldDateCheckLt extends VldDateCheck{constructor(e,t){super(),this._msg=t,this.kind="lt",this._threshold=r(e)}check(e){return e.getTime()>=this._threshold.getTime()?{code:"too_big",path:[],origin:"date",message:this._msg||`Date must be < ${this._threshold.toISOString()}`}:null}meta(){return{kind:"lt",value:this._threshold,message:this._msg}}}class VldDateCheckPast extends VldDateCheck{constructor(e){super(),this._msg=e,this.kind="past"}check(e){return e.getTime()>=Date.now()?{code:"custom",path:[],message:this._msg||"Date must be in the past"}:null}meta(){return{kind:"past",message:this._msg}}}class VldDateCheckFuture extends VldDateCheck{constructor(e){super(),this._msg=e,this.kind="future"}check(e){return e.getTime()<=Date.now()?{code:"custom",path:[],message:this._msg||"Date must be in the future"}:null}meta(){return{kind:"future",message:this._msg}}}class VldDateCheckToday extends VldDateCheck{constructor(e){super(),this._msg=e,this.kind="today"}check(e){const t=new Date;return e.toDateString()!==t.toDateString()?{code:"custom",path:[],message:this._msg||"Date must be today"}:null}meta(){return{kind:"today",message:this._msg}}}class VldDateCheckWeekday extends VldDateCheck{constructor(e){super(),this._msg=e,this.kind="weekday"}check(e){const t=e.getDay();return 0===t||6===t?{code:"custom",path:[],message:this._msg||"Date must be a weekday"}:null}meta(){return{kind:"weekday",message:this._msg}}}class VldDateCheckWeekend extends VldDateCheck{constructor(e){super(),this._msg=e,this.kind="weekend"}check(e){const t=e.getDay();return 0!==t&&6!==t?{code:"custom",path:[],message:this._msg||"Date must be a weekend"}:null}meta(){return{kind:"weekend",message:this._msg}}}const c=Object.freeze({type:"date",checks:Object.freeze([]),isSimple:!0});class VldDateV2 extends e{constructor(e=c){super(t.DATE),this.__def=e}static create(){return new VldDateV2}get isSimple(){return this.__def.isSimple}parse(e){let t;if(e instanceof Date){if(Number.isNaN(e.getTime()))throw new s([h("date","Invalid Date",this.__def.errorMessage)]);t=e}else{if("string"!=typeof e&&"number"!=typeof e)throw new s([h("date",a(e),this.__def.errorMessage)]);if(t=new Date(e),Number.isNaN(t.getTime()))throw new s([h("date",a(e),this.__def.errorMessage)])}return this.__def.isSimple?t:this.parseKnownDate(t)}parseKnownDate(e){const t=this.__def.checks;for(let h=0;h<t.length;h++){const a=t[h].check(e);if(null!==a)throw new s([a])}return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:String(e)}])}}}withDef(e){const t=(s=e.checks??this.__def.checks,h=e.jsonSchema??this.__def.jsonSchema,a=e.errorMessage??this.__def.errorMessage,Object.freeze({type:"date",checks:s,jsonSchema:h,errorMessage:a,isSimple:0===s.length}));var s,h,a;return new this.constructor(t)}min(e,t){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckMin(e,t)],jsonSchema:{...this.__def.jsonSchema,minimum:r(e).toISOString()}})}max(e,t){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckMax(e,t)],jsonSchema:{...this.__def.jsonSchema,maximum:r(e).toISOString()}})}past(e){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckPast(e)]})}future(e){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckFuture(e)]})}today(e){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckToday(e)]})}weekday(e){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckWeekday(e)]})}weekend(e){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckWeekend(e)]})}gt(e,t){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckGt(e,t)]})}lt(e,t){return this.withDef({type:"date",checks:[...this.__def.checks,new VldDateCheckLt(e,t)]})}}export{VldDateCheck,VldDateCheckFuture,VldDateCheckGt,VldDateCheckLt,VldDateCheckMax,VldDateCheckMin,VldDateCheckPast,VldDateCheckToday,VldDateCheckWeekday,VldDateCheckWeekend,VldDateV2};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";import{getMessages as n}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-CerMg2rq.js";function i(e){return new s([{code:"invalid_date",path:[],message:e}])}class VldDate extends e{constructor(e){super(e?.validatorType||t.DATE),this.config={checks:e?.checks||[],errorMessage:e?.errorMessage,jsonSchema:e?.jsonSchema},this._checks=this.config.checks,this._isSimple=0===this._checks.length}get jsonSchema(){return this.config.jsonSchema}get minDate(){const e=this.config.jsonSchema?.formatMinimum??this.config.jsonSchema?.minimum;return e?new Date(e):null}get maxDate(){const e=this.config.jsonSchema?.formatMaximum??this.config.jsonSchema?.maximum;return e?new Date(e):null}static create(){return new VldDate}parse(e){let t;if(e instanceof Date)t=e;else{if("string"!=typeof e&&"number"!=typeof e)throw new Error(this.config.errorMessage||n().invalidDate);t=new Date(e)}if(isNaN(t.getTime()))throw new Error(this.config.errorMessage||n().invalidDate);return this.parseValidDate(t)}parseKnownDate(e){if(isNaN(e.getTime()))throw new Error(this.config.errorMessage||n().invalidDate);return this.parseValidDate(e)}parseValidDate(e){if(this._isSimple)return e;for(const t of this._checks)if(!t.fn(e))throw new Error(t.message);return e}safeParse(e){if(e instanceof Date)try{return{success:!0,data:this.parseKnownDate(e)}}catch(e){return{success:!1,error:i(e.message)}}try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:i(e.message)}}}min(e,t){const s=e instanceof Date?e:new Date(e);if(isNaN(s.getTime()))throw new Error(`Invalid date provided to min(): ${e}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>=s,message:t||n().dateMin(s)}],jsonSchema:{...this.config.jsonSchema,formatMinimum:s.toISOString()}})}max(e,t){const s=e instanceof Date?e:new Date(e);if(isNaN(s.getTime()))throw new Error(`Invalid date provided to max(): ${e}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e<=s,message:t||n().dateMax(s)}],jsonSchema:{...this.config.jsonSchema,formatMaximum:s.toISOString()}})}between(e,t,n){const s=e instanceof Date?e:new Date(e),i=t instanceof Date?t:new Date(t);if(isNaN(s.getTime()))throw new Error(`Invalid min date provided to between(): ${e}`);if(isNaN(i.getTime()))throw new Error(`Invalid max date provided to between(): ${t}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>=s&&e<=i,message:n||`Date must be between ${s.toISOString()} and ${i.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatMinimum:s.toISOString(),formatMaximum:i.toISOString()}})}past(e){const t=new Date;return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e<t,message:e||"Date must be in the past"}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMaximum:t.toISOString()}})}future(e){const t=new Date;return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>t,message:e||"Date must be in the future"}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMinimum:t.toISOString()}})}today(e){const t=new Date,n=t.getFullYear(),s=t.getMonth(),i=t.getDate();return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getFullYear()===n&&e.getMonth()===s&&e.getDate()===i,message:e||"Date must be today"}]})}weekday(e){return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>{const t=e.getDay();return t>=1&&t<=5},message:e||"Date must be a weekday"}]})}weekend(e){return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>{const t=e.getDay();return 0===t||6===t},message:e||"Date must be a weekend"}]})}gt(e,t){const n=e instanceof Date?e:new Date(e);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getTime()>n.getTime(),message:t||`Date must be greater than ${n.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMinimum:n.toISOString()}})}lt(e,t){const n=e instanceof Date?e:new Date(e);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getTime()<n.getTime(),message:t||`Date must be less than ${n.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMaximum:n.toISOString()}})}}export{VldDate};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as t}from"./base.js";import{getMessages as n}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-BU14-Dk8.js";function i(e){return new s([{code:"invalid_date",path:[],message:e}])}class VldDate extends e{constructor(e){super(e?.validatorType||t.DATE),this.config={checks:e?.checks||[],errorMessage:e?.errorMessage,jsonSchema:e?.jsonSchema},this._checks=this.config.checks,this._isSimple=0===this._checks.length}get jsonSchema(){return this.config.jsonSchema}get minDate(){const e=this.config.jsonSchema?.formatMinimum??this.config.jsonSchema?.minimum;return e?new Date(e):null}get maxDate(){const e=this.config.jsonSchema?.formatMaximum??this.config.jsonSchema?.maximum;return e?new Date(e):null}static create(){return new VldDate}parse(e){let t;if(e instanceof Date)t=e;else{if("string"!=typeof e&&"number"!=typeof e)throw new Error(this.config.errorMessage||n().invalidDate);t=new Date(e)}if(isNaN(t.getTime()))throw new Error(this.config.errorMessage||n().invalidDate);return this.parseValidDate(t)}parseKnownDate(e){if(isNaN(e.getTime()))throw new Error(this.config.errorMessage||n().invalidDate);return this.parseValidDate(e)}parseValidDate(e){if(this._isSimple)return e;for(const t of this._checks)if(!t.fn(e))throw new Error(t.message);return e}safeParse(e){if(e instanceof Date)try{return{success:!0,data:this.parseKnownDate(e)}}catch(e){return{success:!1,error:i(e.message)}}try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:i(e.message)}}}min(e,t){const s=e instanceof Date?e:new Date(e);if(isNaN(s.getTime()))throw new Error(`Invalid date provided to min(): ${e}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>=s,message:t||n().dateMin(s)}],jsonSchema:{...this.config.jsonSchema,formatMinimum:s.toISOString()}})}max(e,t){const s=e instanceof Date?e:new Date(e);if(isNaN(s.getTime()))throw new Error(`Invalid date provided to max(): ${e}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e<=s,message:t||n().dateMax(s)}],jsonSchema:{...this.config.jsonSchema,formatMaximum:s.toISOString()}})}between(e,t,n){const s=e instanceof Date?e:new Date(e),i=t instanceof Date?t:new Date(t);if(isNaN(s.getTime()))throw new Error(`Invalid min date provided to between(): ${e}`);if(isNaN(i.getTime()))throw new Error(`Invalid max date provided to between(): ${t}`);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>=s&&e<=i,message:n||`Date must be between ${s.toISOString()} and ${i.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatMinimum:s.toISOString(),formatMaximum:i.toISOString()}})}past(e){const t=new Date;return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e<t,message:e||"Date must be in the past"}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMaximum:t.toISOString()}})}future(e){const t=new Date;return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e>t,message:e||"Date must be in the future"}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMinimum:t.toISOString()}})}today(e){const t=new Date,n=t.getFullYear(),s=t.getMonth(),i=t.getDate();return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getFullYear()===n&&e.getMonth()===s&&e.getDate()===i,message:e||"Date must be today"}]})}weekday(e){return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>{const t=e.getDay();return t>=1&&t<=5},message:e||"Date must be a weekday"}]})}weekend(e){return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>{const t=e.getDay();return 0===t||6===t},message:e||"Date must be a weekend"}]})}gt(e,t){const n=e instanceof Date?e:new Date(e);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getTime()>n.getTime(),message:t||`Date must be greater than ${n.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMinimum:n.toISOString()}})}lt(e,t){const n=e instanceof Date?e:new Date(e);return new VldDate({...this.config,checks:[...this.config.checks,{fn:e=>e.getTime()<n.getTime(),message:t||`Date must be less than ${n.toISOString()}`}],jsonSchema:{...this.config.jsonSchema,formatExclusiveMaximum:n.toISOString()}})}}export{VldDate};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as s}from"../locales/runtime.js";import{V as t}from"../chunks/errors-core-CerMg2rq.js";class VldEnum extends e{constructor(e,s){super(r.ENUM),this._values=e,this.errorMessage=s,this._valueSet=e.length>6?new Set(e):void 0}createError(e){const r={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||s().enumExpected([...this._values],JSON.stringify(e))};return new t([r])}get values(){return this._values}get options(){return this._values}get enum(){const e={};for(const r of this._values)e[r]=r;return e}static create(e){return new VldEnum(e)}parse(e){if("string"!=typeof e&&"number"!=typeof e)throw this.createError(e);const r=this._values;switch(r.length){case 1:if(e===r[0])return e;break;case 2:if(e===r[0]||e===r[1])return e;break;case 3:if(e===r[0]||e===r[1]||e===r[2])return e;break;case 4:if(e===r[0]||e===r[1]||e===r[2]||e===r[3])return e;break;case 5:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4])return e;break;case 6:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4]||e===r[5])return e;break;default:if(this._valueSet.has(e))return e}throw this.createError(e)}safeParse(e){if("string"!=typeof e&&"number"!=typeof e)return{success:!1,error:this.createError(e)};const r=this._values;switch(r.length){case 1:if(e===r[0])return{success:!0,data:e};break;case 2:if(e===r[0]||e===r[1])return{success:!0,data:e};break;case 3:if(e===r[0]||e===r[1]||e===r[2])return{success:!0,data:e};break;case 4:if(e===r[0]||e===r[1]||e===r[2]||e===r[3])return{success:!0,data:e};break;case 5:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4])return{success:!0,data:e};break;case 6:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4]||e===r[5])return{success:!0,data:e};break;default:if(this._valueSet.has(e))return{success:!0,data:e}}return{success:!1,error:this.createError(e)}}exclude(...e){const r=1===e.length&&Array.isArray(e[0])?e[0]:e,s=this._values.filter(e=>!r.includes(e));if(0===s.length)throw new Error("Cannot exclude all enum values");return new VldEnum(s,this.errorMessage)}extract(...e){const r=1===e.length&&Array.isArray(e[0])?e[0]:e,s=this._values.filter(e=>r.includes(e));if(0===s.length)throw new Error("Cannot extract non-existent enum values");return new VldEnum(s,this.errorMessage)}}export{VldEnum};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as s}from"../locales/runtime.js";import{V as t}from"../chunks/errors-core-BU14-Dk8.js";class VldEnum extends e{constructor(e,s){super(r.ENUM),this._values=e,this.errorMessage=s,this._valueSet=e.length>6?new Set(e):void 0}createError(e){const r={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||s().enumExpected([...this._values],JSON.stringify(e))};return new t([r])}get values(){return this._values}get options(){return this._values}get enum(){const e={};for(const r of this._values)e[r]=r;return e}static create(e){return new VldEnum(e)}parse(e){if("string"!=typeof e&&"number"!=typeof e)throw this.createError(e);const r=this._values;switch(r.length){case 1:if(e===r[0])return e;break;case 2:if(e===r[0]||e===r[1])return e;break;case 3:if(e===r[0]||e===r[1]||e===r[2])return e;break;case 4:if(e===r[0]||e===r[1]||e===r[2]||e===r[3])return e;break;case 5:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4])return e;break;case 6:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4]||e===r[5])return e;break;default:if(this._valueSet.has(e))return e}throw this.createError(e)}safeParse(e){if("string"!=typeof e&&"number"!=typeof e)return{success:!1,error:this.createError(e)};const r=this._values;switch(r.length){case 1:if(e===r[0])return{success:!0,data:e};break;case 2:if(e===r[0]||e===r[1])return{success:!0,data:e};break;case 3:if(e===r[0]||e===r[1]||e===r[2])return{success:!0,data:e};break;case 4:if(e===r[0]||e===r[1]||e===r[2]||e===r[3])return{success:!0,data:e};break;case 5:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4])return{success:!0,data:e};break;case 6:if(e===r[0]||e===r[1]||e===r[2]||e===r[3]||e===r[4]||e===r[5])return{success:!0,data:e};break;default:if(this._valueSet.has(e))return{success:!0,data:e}}return{success:!1,error:this.createError(e)}}exclude(...e){const r=1===e.length&&Array.isArray(e[0])?e[0]:e,s=this._values.filter(e=>!r.includes(e));if(0===s.length)throw new Error("Cannot exclude all enum values");return new VldEnum(s,this.errorMessage)}extract(...e){const r=1===e.length&&Array.isArray(e[0])?e[0]:e,s=this._values.filter(e=>r.includes(e));if(0===s.length)throw new Error("Cannot extract non-existent enum values");return new VldEnum(s,this.errorMessage)}}export{VldEnum};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{getMessages as i}from"../locales/runtime.js";import{V as r}from"../chunks/errors-core-CerMg2rq.js";class VldFile extends e{constructor(e=[]){super(s.FILE),this.checks=e}static create(){return new VldFile}isFileLike(e){return"object"==typeof e&&null!==e&&("undefined"!=typeof File&&e instanceof File||"size"in e&&"type"in e)}parse(e){if(this.isFileLike(e))return this.parseKnownFile(e);if("undefined"==typeof File)throw new Error(i().fileNotSupported||"File API not supported in this environment");throw new Error(i().invalidFile||"Expected a File object")}parseKnownFile(e){return this.runChecks(e)}runChecks(e){const s=i();for(const i of this.checks)switch(i.type){case"min":if(e.size<i.value)throw new Error(i.message||s.fileMinSize?.(i.value)||`File size must be at least ${i.value} bytes`);break;case"max":if(e.size>i.value)throw new Error(i.message||s.fileMaxSize?.(i.value)||`File size must not exceed ${i.value} bytes`);break;case"mime":if(!i.value.includes(e.type))throw new Error(i.message||s.fileMimeType?.(i.value)||`Invalid file type. Expected: ${i.value.join(", ")}`)}return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r([{code:"invalid_type",path:[],message:s}]))}}var s}min(e,s){return new VldFile([...this.checks,{type:"min",value:e,message:s}])}max(e,s){return new VldFile([...this.checks,{type:"max",value:e,message:s}])}mime(e,s){const i=Array.isArray(e)?e:[e];return new VldFile([...this.checks,{type:"mime",value:i,message:s}])}size(e,s,i){return this.min(e,i).max(s,i)}}function t(){return VldFile.create()}export{VldFile,t as file};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as s}from"./base.js";import{getMessages as i}from"../locales/runtime.js";import{V as r}from"../chunks/errors-core-BU14-Dk8.js";class VldFile extends e{constructor(e=[]){super(s.FILE),this.checks=e}static create(){return new VldFile}isFileLike(e){return"object"==typeof e&&null!==e&&("undefined"!=typeof File&&e instanceof File||"size"in e&&"type"in e)}parse(e){if(this.isFileLike(e))return this.parseKnownFile(e);if("undefined"==typeof File)throw new Error(i().fileNotSupported||"File API not supported in this environment");throw new Error(i().invalidFile||"Expected a File object")}parseKnownFile(e){return this.runChecks(e)}runChecks(e){const s=i();for(const i of this.checks)switch(i.type){case"min":if(e.size<i.value)throw new Error(i.message||s.fileMinSize?.(i.value)||`File size must be at least ${i.value} bytes`);break;case"max":if(e.size>i.value)throw new Error(i.message||s.fileMaxSize?.(i.value)||`File size must not exceed ${i.value} bytes`);break;case"mime":if(!i.value.includes(e.type))throw new Error(i.message||s.fileMimeType?.(i.value)||`Invalid file type. Expected: ${i.value.join(", ")}`)}return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r([{code:"invalid_type",path:[],message:s}]))}}var s}min(e,s){return new VldFile([...this.checks,{type:"min",value:e,message:s}])}max(e,s){return new VldFile([...this.checks,{type:"max",value:e,message:s}])}mime(e,s){const i=Array.isArray(e)?e:[e];return new VldFile([...this.checks,{type:"mime",value:i,message:s}])}size(e,s,i){return this.min(e,i).max(s,i)}}function t(){return VldFile.create()}export{VldFile,t as file};
@@ -1 +1 @@
1
- import{VldBase as r,VLD_VALIDATOR_TYPES as e}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as n}from"../chunks/errors-core-CerMg2rq.js";class VldFunction extends r{constructor(){super(e.FUNCTION)}static create(){return new VldFunction}parse(r){if("function"!=typeof r)throw new Error(t().invalidFunction||"Expected a function");return r}parseKnownFunction(r){return r}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:(e=r.message,new n([{code:"invalid_type",path:[],message:e}]))}}var e}}function s(){return VldFunction.create()}export{VldFunction,s as functionValidator};
1
+ import{VldBase as r,VLD_VALIDATOR_TYPES as e}from"./base.js";import{getMessages as t}from"../locales/runtime.js";import{V as n}from"../chunks/errors-core-BU14-Dk8.js";class VldFunction extends r{constructor(){super(e.FUNCTION)}static create(){return new VldFunction}parse(r){if("function"!=typeof r)throw new Error(t().invalidFunction||"Expected a function");return r}parseKnownFunction(r){return r}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:(e=r.message,new n([{code:"invalid_type",path:[],message:e}]))}}var e}}function s(){return VldFunction.create()}export{VldFunction,s as functionValidator};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{createIssue as s}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as o}from"../chunks/errors-core-CerMg2rq.js";class VldHex extends e{constructor(e=!1){super(r.HEX),this.lowercase=e}parse(e){const r=this.safeParse(e);if(!r.success)throw r.error;return r.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new o([s("invalid_type",[],t().expectedString)])};if(!VldHex.HEX_REGEX.test(e))return{success:!1,error:new o([s("custom",[],t().invalidHex)])};if(e.length%2!=0)return{success:!1,error:new o([s("custom",[],t().invalidHex)])};return{success:!0,data:this.lowercase?e.toLowerCase():e}}lowercaseMode(){return new VldHex(!0)}static create(e=!1){return new VldHex(e)}}VldHex.HEX_REGEX=/^[0-9a-fA-F]*$/;export{VldHex};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{createIssue as s}from"../errors.js";import{getMessages as t}from"../locales/runtime.js";import{V as o}from"../chunks/errors-core-BU14-Dk8.js";class VldHex extends e{constructor(e=!1){super(r.HEX),this.lowercase=e}parse(e){const r=this.safeParse(e);if(!r.success)throw r.error;return r.data}safeParse(e){if("string"!=typeof e)return{success:!1,error:new o([s("invalid_type",[],t().expectedString)])};if(!VldHex.HEX_REGEX.test(e))return{success:!1,error:new o([s("custom",[],t().invalidHex)])};if(e.length%2!=0)return{success:!1,error:new o([s("custom",[],t().invalidHex)])};return{success:!0,data:this.lowercase?e.toLowerCase():e}}lowercaseMode(){return new VldHex(!0)}static create(e=!1){return new VldHex(e)}}VldHex.HEX_REGEX=/^[0-9a-fA-F]*$/;export{VldHex};
@@ -1 +1 @@
1
- import{VldBase as t,VLD_VALIDATOR_TYPES as e}from"./base.js";import{i as r}from"../chunks/security-Dy24T8N7.js";import{getMessages as o}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-CerMg2rq.js";function n(t){return null!==t&&"object"==typeof t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t)}function c(t,e){const o={...t},s=Object.keys(e);for(let i=0;i<s.length;i++){const a=s[i];if(r(a))continue;if(!Object.prototype.hasOwnProperty.call(e,a))continue;const u=e[a],p=t[a];n(u)&&n(p)?o[a]=c(p,u):o[a]=u}return o}class VldIntersection extends t{constructor(t,r){super(e.INTERSECTION),this.validatorA=t,this.validatorB=r}static create(t,e){return new VldIntersection(t,e)}parse(t){try{const e=this.validatorA.parse(t),r=this.validatorB.parse(t),o=n(e),s=n(r);if(o&&s)return c(e,r);if(!o&&!s){if(e===r)return e;throw new Error("Values must be identical for intersection of primitive types")}throw new Error("Cannot create intersection of object and primitive types. Both validators must produce the same type category.")}catch(t){throw new Error(o().intersectionError(t.message))}}safeParse(t){try{return{success:!0,data:this.parse(t)}}catch(t){return{success:!1,error:(e=t.message,new s([{code:"invalid_type",path:[],message:e}]))}}var e}}export{VldIntersection};
1
+ import{VldBase as t,VLD_VALIDATOR_TYPES as e}from"./base.js";import{i as r}from"../chunks/security-Dy24T8N7.js";import{getMessages as o}from"../locales/runtime.js";import{V as s}from"../chunks/errors-core-BU14-Dk8.js";function n(t){return null!==t&&"object"==typeof t&&t.constructor===Object&&"[object Object]"===Object.prototype.toString.call(t)}function c(t,e){const o={...t},s=Object.keys(e);for(let i=0;i<s.length;i++){const a=s[i];if(r(a))continue;if(!Object.prototype.hasOwnProperty.call(e,a))continue;const u=e[a],p=t[a];n(u)&&n(p)?o[a]=c(p,u):o[a]=u}return o}class VldIntersection extends t{constructor(t,r){super(e.INTERSECTION),this.validatorA=t,this.validatorB=r}static create(t,e){return new VldIntersection(t,e)}parse(t){try{const e=this.validatorA.parse(t),r=this.validatorB.parse(t),o=n(e),s=n(r);if(o&&s)return c(e,r);if(!o&&!s){if(e===r)return e;throw new Error("Values must be identical for intersection of primitive types")}throw new Error("Cannot create intersection of object and primitive types. Both validators must produce the same type category.")}catch(t){throw new Error(o().intersectionError(t.message))}}safeParse(t){try{return{success:!0,data:this.parse(t)}}catch(t){return{success:!1,error:(e=t.message,new s([{code:"invalid_type",path:[],message:e}]))}}var e}}export{VldIntersection};