@oxog/vld 2.2.5 → 2.2.7

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 (119) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +242 -1125
  3. package/dist/chunks/errors-core-CerMg2rq.js +1 -0
  4. package/dist/cjs/chunks/errors-core-DrydF46s.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/errors.cjs +1 -1
  9. package/dist/cjs/index.cjs +1 -1
  10. package/dist/cjs/mini.cjs +1 -1
  11. package/dist/cjs/v3/index.cjs +1 -1
  12. package/dist/cjs/v4/core/index.cjs +1 -1
  13. package/dist/cjs/v4/index.cjs +1 -1
  14. package/dist/cjs/v4/mini/index.cjs +1 -1
  15. package/dist/cjs/v4-mini/index.cjs +1 -1
  16. package/dist/cjs/validators/any.cjs +1 -1
  17. package/dist/cjs/validators/array.cjs +1 -1
  18. package/dist/cjs/validators/base.cjs +1 -1
  19. package/dist/cjs/validators/base64.cjs +1 -1
  20. package/dist/cjs/validators/bigint.cjs +1 -1
  21. package/dist/cjs/validators/boolean.cjs +1 -1
  22. package/dist/cjs/validators/codec.cjs +1 -1
  23. package/dist/cjs/validators/custom.cjs +1 -1
  24. package/dist/cjs/validators/date.cjs +1 -1
  25. package/dist/cjs/validators/discriminated-union.cjs +1 -1
  26. package/dist/cjs/validators/enum.cjs +1 -1
  27. package/dist/cjs/validators/file.cjs +1 -1
  28. package/dist/cjs/validators/function.cjs +1 -1
  29. package/dist/cjs/validators/hex.cjs +1 -1
  30. package/dist/cjs/validators/index.cjs +1 -1
  31. package/dist/cjs/validators/intersection.cjs +1 -1
  32. package/dist/cjs/validators/json.cjs +1 -1
  33. package/dist/cjs/validators/lazy.cjs +1 -1
  34. package/dist/cjs/validators/literal.cjs +1 -1
  35. package/dist/cjs/validators/map.cjs +1 -1
  36. package/dist/cjs/validators/nan.cjs +1 -1
  37. package/dist/cjs/validators/never.cjs +1 -1
  38. package/dist/cjs/validators/null.cjs +1 -1
  39. package/dist/cjs/validators/number.cjs +1 -1
  40. package/dist/cjs/validators/object.cjs +1 -1
  41. package/dist/cjs/validators/promise.cjs +1 -1
  42. package/dist/cjs/validators/record.cjs +1 -1
  43. package/dist/cjs/validators/set.cjs +1 -1
  44. package/dist/cjs/validators/string-bool.cjs +1 -1
  45. package/dist/cjs/validators/string-formats.cjs +1 -1
  46. package/dist/cjs/validators/string.cjs +1 -1
  47. package/dist/cjs/validators/symbol.cjs +1 -1
  48. package/dist/cjs/validators/template-literal.cjs +1 -1
  49. package/dist/cjs/validators/tuple.cjs +1 -1
  50. package/dist/cjs/validators/uint8array.cjs +1 -1
  51. package/dist/cjs/validators/undefined.cjs +1 -1
  52. package/dist/cjs/validators/union.cjs +1 -1
  53. package/dist/cjs/validators/unknown.cjs +1 -1
  54. package/dist/cjs/validators/void.cjs +1 -1
  55. package/dist/cjs/validators/xor.cjs +1 -1
  56. package/dist/coercion/index.js +1 -1
  57. package/dist/errors-core.d.ts +12 -1
  58. package/dist/errors.js +1 -1
  59. package/dist/index.d.ts +68 -5
  60. package/dist/index.js +1 -1
  61. package/dist/v3/index.js +1 -1
  62. package/dist/v4/core/index.js +1 -1
  63. package/dist/v4/index.js +1 -1
  64. package/dist/v4/mini/index.js +1 -1
  65. package/dist/v4-mini/index.js +1 -1
  66. package/dist/validators/array.js +1 -1
  67. package/dist/validators/base.d.ts +147 -9
  68. package/dist/validators/base.js +1 -1
  69. package/dist/validators/base64.js +1 -1
  70. package/dist/validators/bigint.d.ts +7 -0
  71. package/dist/validators/bigint.js +1 -1
  72. package/dist/validators/boolean.js +1 -1
  73. package/dist/validators/codec.js +1 -1
  74. package/dist/validators/custom.d.ts +20 -10
  75. package/dist/validators/custom.js +1 -1
  76. package/dist/validators/date.d.ts +2 -0
  77. package/dist/validators/date.js +1 -1
  78. package/dist/validators/discriminated-union.d.ts +2 -0
  79. package/dist/validators/discriminated-union.js +1 -1
  80. package/dist/validators/enum.d.ts +8 -2
  81. package/dist/validators/enum.js +1 -1
  82. package/dist/validators/file.js +1 -1
  83. package/dist/validators/function.js +1 -1
  84. package/dist/validators/hex.js +1 -1
  85. package/dist/validators/intersection.js +1 -1
  86. package/dist/validators/json.js +1 -1
  87. package/dist/validators/literal.d.ts +1 -0
  88. package/dist/validators/literal.js +1 -1
  89. package/dist/validators/map.d.ts +7 -0
  90. package/dist/validators/map.js +1 -1
  91. package/dist/validators/nan.js +1 -1
  92. package/dist/validators/never.js +1 -1
  93. package/dist/validators/null.js +1 -1
  94. package/dist/validators/number.d.ts +5 -0
  95. package/dist/validators/number.js +1 -1
  96. package/dist/validators/object.d.ts +6 -0
  97. package/dist/validators/object.js +1 -1
  98. package/dist/validators/promise.d.ts +6 -7
  99. package/dist/validators/promise.js +1 -1
  100. package/dist/validators/record.d.ts +2 -0
  101. package/dist/validators/record.js +1 -1
  102. package/dist/validators/set.d.ts +5 -0
  103. package/dist/validators/set.js +1 -1
  104. package/dist/validators/string-bool.js +1 -1
  105. package/dist/validators/string-formats.js +1 -1
  106. package/dist/validators/string.d.ts +2 -0
  107. package/dist/validators/string.js +1 -1
  108. package/dist/validators/symbol.js +1 -1
  109. package/dist/validators/template-literal.js +1 -1
  110. package/dist/validators/tuple.js +1 -1
  111. package/dist/validators/uint8array.js +1 -1
  112. package/dist/validators/undefined.js +1 -1
  113. package/dist/validators/union.d.ts +1 -0
  114. package/dist/validators/union.js +1 -1
  115. package/dist/validators/void.js +1 -1
  116. package/dist/validators/xor.js +1 -1
  117. package/package.json +2 -1
  118. package/dist/chunks/errors-core-Cqi4-9ew.js +0 -1
  119. package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +0 -1
@@ -1 +1 @@
1
- "use strict";var i=require("./base.cjs"),r=require("./object.cjs"),t=require("./literal.cjs"),e=require("./enum.cjs");function s(i){if(i instanceof t.VldLiteral)return[...i.values];if(i instanceof e.VldEnum)return[...i.values];throw new Error("Discriminator must be a literal or enum schema")}require("../registry.cjs"),require("../locales/runtime.cjs"),require("../locales/en.cjs"),require("../chunks/security-aXZVI7qW.cjs"),require("../chunks/errors-core-DKPohm9I.cjs");class VldDiscriminatedUnion extends i.VldBase{constructor(t,e){super(i.VLD_VALIDATOR_TYPES.DISCRIMINATED_UNION),this._discriminator=t,this._options=e,this._discriminatorMap=new Map,this._stringDiscriminatorMap=Object.create(null);for(const i of e){if(!(i instanceof r.VldObject))throw new Error("All options in a discriminated union must be objects");const t=i.config?.shape?.[this._discriminator];if(!t)throw new Error(`Missing discriminator key "${this._discriminator}" in one of the options`);const e=s(t);for(const r of e){if(this._discriminatorMap.has(r))throw new Error(`Duplicate discriminator value "${String(r)}" found in discriminated union`);this._discriminatorMap.set(r,i),"string"==typeof r&&(this._stringDiscriminatorMap[r]=i)}}this._validValues=Array.from(this._discriminatorMap.keys())}static create(i,r){return new VldDiscriminatedUnion(i,r)}parse(i){if("object"!=typeof i||null===i)throw new Error("Expected object, received "+(null===i?"null":typeof i));const r=i[this._discriminator],t="string"==typeof r?this._stringDiscriminatorMap[r]:this._discriminatorMap.get(r);if(!t)throw new Error(`Invalid discriminator value for "${this._discriminator}". Expected one of: ${JSON.stringify(this._validValues)}, received: ${JSON.stringify(r)}`);return t.parseTrustedKnownObject(i,this._discriminator)}safeParse(i){if("object"!=typeof i||null===i)return{success:!1,error:new Error("Expected object, received "+(null===i?"null":typeof i))};const r=i[this._discriminator],t="string"==typeof r?this._stringDiscriminatorMap[r]:this._discriminatorMap.get(r);if(!t)return{success:!1,error:new Error(`Invalid discriminator value for "${this._discriminator}". Expected one of: ${JSON.stringify(this._validValues)}, received: ${JSON.stringify(r)}`)};try{return{success:!0,data:t.parseTrustedKnownObject(i,this._discriminator)}}catch(i){return{success:!1,error:i}}}getDiscriminator(){return this._discriminator}getOptions(){return this._options}}exports.VldDiscriminatedUnion=VldDiscriminatedUnion;
1
+ "use strict";var i=require("./base.cjs"),r=require("./object.cjs"),t=require("./literal.cjs"),e=require("./enum.cjs");function s(i){if(i instanceof t.VldLiteral)return[...i.values];if(i instanceof e.VldEnum)return[...i.values];throw new Error("Discriminator must be a literal or enum schema")}require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs"),require("../locales/runtime.cjs"),require("../locales/en.cjs"),require("../chunks/security-aXZVI7qW.cjs");class VldDiscriminatedUnion extends i.VldBase{constructor(t,e){super(i.VLD_VALIDATOR_TYPES.DISCRIMINATED_UNION),this._discriminator=t,this._options=e,this._discriminatorMap=new Map,this._stringDiscriminatorMap=Object.create(null);for(const i of e){if(!(i instanceof r.VldObject))throw new Error("All options in a discriminated union must be objects");const t=i.config?.shape?.[this._discriminator];if(!t)throw new Error(`Missing discriminator key "${this._discriminator}" in one of the options`);const e=s(t);for(const r of e){if(this._discriminatorMap.has(r))throw new Error(`Duplicate discriminator value "${String(r)}" found in discriminated union`);this._discriminatorMap.set(r,i),"string"==typeof r&&(this._stringDiscriminatorMap[r]=i)}}this._validValues=Array.from(this._discriminatorMap.keys())}get options(){return this._options}get discriminator(){return this._discriminator}static create(i,r){return new VldDiscriminatedUnion(i,r)}parse(i){if("object"!=typeof i||null===i)throw new Error("Expected object, received "+(null===i?"null":typeof i));const r=i[this._discriminator],t="string"==typeof r?this._stringDiscriminatorMap[r]:this._discriminatorMap.get(r);if(!t)throw new Error(`Invalid discriminator value for "${this._discriminator}". Expected one of: ${JSON.stringify(this._validValues)}, received: ${JSON.stringify(r)}`);return t.parseTrustedKnownObject(i,this._discriminator)}safeParse(r){if("object"!=typeof r||null===r)return{success:!1,error:i.ensureVldError("Expected object, received "+(null===r?"null":typeof r))};const t=r[this._discriminator],e="string"==typeof t?this._stringDiscriminatorMap[t]:this._discriminatorMap.get(t);if(!e)return{success:!1,error:i.ensureVldError(`Invalid discriminator value for "${this._discriminator}". Expected one of: ${JSON.stringify(this._validValues)}, received: ${JSON.stringify(t)}`)};try{return{success:!0,data:e.parseTrustedKnownObject(r,this._discriminator)}}catch(r){return{success:!1,error:i.ensureVldError(r)}}}getDiscriminator(){return this._discriminator}getOptions(){return this._options}}exports.VldDiscriminatedUnion=VldDiscriminatedUnion;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldEnum extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.ENUM),this._values=r,this.errorMessage=s,this._valueSet=r.length>6?new Set(r):void 0}createError(e){const t={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||r.getMessages().enumExpected([...this._values],JSON.stringify(e))};return new s.VldError([t])}get values(){return this._values}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=this._values.filter(r=>!e.includes(r));if(0===r.length)throw new Error("Cannot exclude all enum values");return new VldEnum(r,this.errorMessage)}extract(...e){const r=this._values.filter(r=>e.includes(r));if(0===r.length)throw new Error("Cannot extract non-existent enum values");return new VldEnum(r,this.errorMessage)}}exports.VldEnum=VldEnum;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldEnum extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.ENUM),this._values=r,this.errorMessage=s,this._valueSet=r.length>6?new Set(r):void 0}createError(e){const t={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||r.getMessages().enumExpected([...this._values],JSON.stringify(e))};return new s.VldError([t])}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)}}exports.VldEnum=VldEnum;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldFile extends e.VldBase{constructor(s=[]){super(e.VLD_VALIDATOR_TYPES.FILE),this.checks=s}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(s.getMessages().fileNotSupported||"File API not supported in this environment");throw new Error(s.getMessages().invalidFile||"Expected a File object")}parseKnownFile(e){return this.runChecks(e)}runChecks(e){const r=s.getMessages();for(const s of this.checks)switch(s.type){case"min":if(e.size<s.value)throw new Error(s.message||r.fileMinSize?.(s.value)||`File size must be at least ${s.value} bytes`);break;case"max":if(e.size>s.value)throw new Error(s.message||r.fileMaxSize?.(s.value)||`File size must not exceed ${s.value} bytes`);break;case"mime":if(!s.value.includes(e.type))throw new Error(s.message||r.fileMimeType?.(s.value)||`Invalid file type. Expected: ${s.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.VldError([{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 r=Array.isArray(e)?e:[e];return new VldFile([...this.checks,{type:"mime",value:r,message:s}])}size(e,s,r){return this.min(e,r).max(s,r)}}exports.VldFile=VldFile,exports.file=function(){return VldFile.create()};
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldFile extends e.VldBase{constructor(s=[]){super(e.VLD_VALIDATOR_TYPES.FILE),this.checks=s}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(s.getMessages().fileNotSupported||"File API not supported in this environment");throw new Error(s.getMessages().invalidFile||"Expected a File object")}parseKnownFile(e){return this.runChecks(e)}runChecks(e){const r=s.getMessages();for(const s of this.checks)switch(s.type){case"min":if(e.size<s.value)throw new Error(s.message||r.fileMinSize?.(s.value)||`File size must be at least ${s.value} bytes`);break;case"max":if(e.size>s.value)throw new Error(s.message||r.fileMaxSize?.(s.value)||`File size must not exceed ${s.value} bytes`);break;case"mime":if(!s.value.includes(e.type))throw new Error(s.message||r.fileMimeType?.(s.value)||`Invalid file type. Expected: ${s.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.VldError([{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 r=Array.isArray(e)?e:[e];return new VldFile([...this.checks,{type:"mime",value:r,message:s}])}size(e,s,r){return this.min(e,r).max(s,r)}}exports.VldFile=VldFile,exports.file=function(){return VldFile.create()};
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldFunction extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.FUNCTION)}static create(){return new VldFunction}parse(e){if("function"!=typeof e)throw new Error(r.getMessages().invalidFunction||"Expected a function");return e}parseKnownFunction(e){return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldFunction=VldFunction,exports.functionValidator=function(){return VldFunction.create()};
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldFunction extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.FUNCTION)}static create(){return new VldFunction}parse(e){if("function"!=typeof e)throw new Error(r.getMessages().invalidFunction||"Expected a function");return e}parseKnownFunction(e){return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldFunction=VldFunction,exports.functionValidator=function(){return VldFunction.create()};
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../errors.cjs"),s=require("../locales/runtime.cjs"),t=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldHex extends e.VldBase{constructor(r=!1){super(e.VLD_VALIDATOR_TYPES.HEX),this.lowercase=r}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 t.VldError([r.createIssue("invalid_type",[],s.getMessages().expectedString)])};if(!VldHex.HEX_REGEX.test(e))return{success:!1,error:new t.VldError([r.createIssue("custom",[],s.getMessages().invalidHex)])};if(e.length%2!=0)return{success:!1,error:new t.VldError([r.createIssue("custom",[],s.getMessages().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]*$/,exports.VldHex=VldHex;
1
+ "use strict";var e=require("./base.cjs"),r=require("../errors.cjs"),s=require("../locales/runtime.cjs"),t=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldHex extends e.VldBase{constructor(r=!1){super(e.VLD_VALIDATOR_TYPES.HEX),this.lowercase=r}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 t.VldError([r.createIssue("invalid_type",[],s.getMessages().expectedString)])};if(!VldHex.HEX_REGEX.test(e))return{success:!1,error:new t.VldError([r.createIssue("custom",[],s.getMessages().invalidHex)])};if(e.length%2!=0)return{success:!1,error:new t.VldError([r.createIssue("custom",[],s.getMessages().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]*$/,exports.VldHex=VldHex;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("./string.cjs"),s=require("./number.cjs"),l=require("./boolean.cjs"),t=require("./date.cjs"),o=require("./string-bool.cjs"),i=require("./array.cjs"),d=require("./object.cjs"),p=require("./union.cjs"),u=require("./intersection.cjs"),n=require("./literal.cjs"),V=require("./enum.cjs"),x=require("./tuple.cjs"),c=require("./record.cjs"),a=require("./set.cjs"),j=require("./map.cjs"),m=require("./bigint.cjs"),q=require("./symbol.cjs"),v=require("./any.cjs"),b=require("./unknown.cjs"),f=require("./void.cjs"),g=require("./never.cjs"),h=require("./null.cjs"),y=require("./undefined.cjs"),N=require("./nan.cjs"),B=require("./lazy.cjs"),S=require("./discriminated-union.cjs"),U=require("./xor.cjs"),k=require("./json.cjs"),L=require("./template-literal.cjs"),R=require("./custom.cjs"),D=require("./file.cjs"),F=require("./function.cjs"),O=require("./promise.cjs"),P=require("./string-formats.cjs");require("../registry.cjs"),require("../locales/runtime.cjs"),require("../locales/en.cjs"),require("../chunks/ip-validation-BZqPamPC.cjs"),require("../chunks/errors-core-DKPohm9I.cjs"),require("../chunks/security-aXZVI7qW.cjs"),exports.VldBase=e.VldBase,exports.VldBrand=e.VldBrand,exports.VldCatch=e.VldCatch,exports.VldDefault=e.VldDefault,exports.VldExactOptional=e.VldExactOptional,exports.VldNullable=e.VldNullable,exports.VldNullish=e.VldNullish,exports.VldOptional=e.VldOptional,exports.VldPipe=e.VldPipe,exports.VldPreprocess=e.VldPreprocess,exports.VldReadonly=e.VldReadonly,exports.VldRefine=e.VldRefine,exports.VldSuperRefine=e.VldSuperRefine,exports.VldTransform=e.VldTransform,exports.VldString=r.VldString,exports.VldNumber=s.VldNumber,exports.VldBoolean=l.VldBoolean,exports.VldDate=t.VldDate,exports.VldStringBool=o.VldStringBool,exports.VldArray=i.VldArray,exports.VldObject=d.VldObject,exports.VldUnion=p.VldUnion,exports.VldIntersection=u.VldIntersection,exports.VldLiteral=n.VldLiteral,exports.VldEnum=V.VldEnum,exports.VldTuple=x.VldTuple,exports.VldRecord=c.VldRecord,exports.VldSet=a.VldSet,exports.VldMap=j.VldMap,exports.VldBigInt=m.VldBigInt,exports.VldSymbol=q.VldSymbol,exports.VldAny=v.VldAny,exports.VldUnknown=b.VldUnknown,exports.VldVoid=f.VldVoid,exports.VldNever=g.VldNever,exports.VldNull=h.VldNull,exports.VldUndefined=y.VldUndefined,exports.VldNan=N.VldNan,exports.VldLazy=B.VldLazy,exports.VldDiscriminatedUnion=S.VldDiscriminatedUnion,exports.VldXor=U.VldXor,exports.VldJson=k.VldJson,exports.VldTemplateLiteral=L.VldTemplateLiteral,exports.templateLiteral=L.templateLiteral,exports.VldCustom=R.VldCustom,exports.custom=R.custom,exports.VldFile=D.VldFile,exports.file=D.file,exports.VldFunction=F.VldFunction,exports.functionValidator=F.functionValidator,exports.VldPromise=O.VldPromise,exports.promise=O.promise,exports.base64=P.base64,exports.base64url=P.base64url,exports.cidrv4=P.cidrv4,exports.cidrv6=P.cidrv6,exports.cuid=P.cuid,exports.cuid2=P.cuid2,exports.e164=P.e164,exports.email=P.email,exports.emoji=P.emoji,exports.guid=P.guid,exports.hash=P.hash,exports.hex=P.hex,exports.hostname=P.hostname,exports.httpUrl=P.httpUrl,exports.ipv4=P.ipv4,exports.ipv6=P.ipv6,exports.iso=P.iso,exports.jwt=P.jwt,exports.ksuid=P.ksuid,exports.mac=P.mac,exports.nanoid=P.nanoid,exports.regexes=P.regexes,exports.stringFormat=P.stringFormat,exports.ulid=P.ulid,exports.url=P.url,exports.uuid=P.uuid,exports.uuidv4=P.uuidv4,exports.uuidv6=P.uuidv6,exports.uuidv7=P.uuidv7,exports.xid=P.xid;
1
+ "use strict";var e=require("./base.cjs"),r=require("./string.cjs"),s=require("./number.cjs"),l=require("./boolean.cjs"),t=require("./date.cjs"),o=require("./string-bool.cjs"),i=require("./array.cjs"),d=require("./object.cjs"),p=require("./union.cjs"),u=require("./intersection.cjs"),n=require("./literal.cjs"),V=require("./enum.cjs"),x=require("./tuple.cjs"),c=require("./record.cjs"),a=require("./set.cjs"),j=require("./map.cjs"),m=require("./bigint.cjs"),q=require("./symbol.cjs"),v=require("./any.cjs"),b=require("./unknown.cjs"),f=require("./void.cjs"),g=require("./never.cjs"),h=require("./null.cjs"),y=require("./undefined.cjs"),N=require("./nan.cjs"),B=require("./lazy.cjs"),S=require("./discriminated-union.cjs"),U=require("./xor.cjs"),k=require("./json.cjs"),L=require("./template-literal.cjs"),R=require("./custom.cjs"),D=require("./file.cjs"),F=require("./function.cjs"),O=require("./promise.cjs"),P=require("./string-formats.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs"),require("../locales/runtime.cjs"),require("../locales/en.cjs"),require("../chunks/ip-validation-BZqPamPC.cjs"),require("../chunks/security-aXZVI7qW.cjs"),exports.VldBase=e.VldBase,exports.VldBrand=e.VldBrand,exports.VldCatch=e.VldCatch,exports.VldDefault=e.VldDefault,exports.VldExactOptional=e.VldExactOptional,exports.VldNullable=e.VldNullable,exports.VldNullish=e.VldNullish,exports.VldOptional=e.VldOptional,exports.VldPipe=e.VldPipe,exports.VldPreprocess=e.VldPreprocess,exports.VldReadonly=e.VldReadonly,exports.VldRefine=e.VldRefine,exports.VldSuperRefine=e.VldSuperRefine,exports.VldTransform=e.VldTransform,exports.VldString=r.VldString,exports.VldNumber=s.VldNumber,exports.VldBoolean=l.VldBoolean,exports.VldDate=t.VldDate,exports.VldStringBool=o.VldStringBool,exports.VldArray=i.VldArray,exports.VldObject=d.VldObject,exports.VldUnion=p.VldUnion,exports.VldIntersection=u.VldIntersection,exports.VldLiteral=n.VldLiteral,exports.VldEnum=V.VldEnum,exports.VldTuple=x.VldTuple,exports.VldRecord=c.VldRecord,exports.VldSet=a.VldSet,exports.VldMap=j.VldMap,exports.VldBigInt=m.VldBigInt,exports.VldSymbol=q.VldSymbol,exports.VldAny=v.VldAny,exports.VldUnknown=b.VldUnknown,exports.VldVoid=f.VldVoid,exports.VldNever=g.VldNever,exports.VldNull=h.VldNull,exports.VldUndefined=y.VldUndefined,exports.VldNan=N.VldNan,exports.VldLazy=B.VldLazy,exports.VldDiscriminatedUnion=S.VldDiscriminatedUnion,exports.VldXor=U.VldXor,exports.VldJson=k.VldJson,exports.VldTemplateLiteral=L.VldTemplateLiteral,exports.templateLiteral=L.templateLiteral,exports.VldCustom=R.VldCustom,exports.custom=R.custom,exports.VldFile=D.VldFile,exports.file=D.file,exports.VldFunction=F.VldFunction,exports.functionValidator=F.functionValidator,exports.VldPromise=O.VldPromise,exports.promise=O.promise,exports.base64=P.base64,exports.base64url=P.base64url,exports.cidrv4=P.cidrv4,exports.cidrv6=P.cidrv6,exports.cuid=P.cuid,exports.cuid2=P.cuid2,exports.e164=P.e164,exports.email=P.email,exports.emoji=P.emoji,exports.guid=P.guid,exports.hash=P.hash,exports.hex=P.hex,exports.hostname=P.hostname,exports.httpUrl=P.httpUrl,exports.ipv4=P.ipv4,exports.ipv6=P.ipv6,exports.iso=P.iso,exports.jwt=P.jwt,exports.ksuid=P.ksuid,exports.mac=P.mac,exports.nanoid=P.nanoid,exports.regexes=P.regexes,exports.stringFormat=P.stringFormat,exports.ulid=P.ulid,exports.url=P.url,exports.uuid=P.uuid,exports.uuidv4=P.uuidv4,exports.uuidv6=P.uuidv6,exports.uuidv7=P.uuidv7,exports.xid=P.xid;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../chunks/security-aXZVI7qW.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");function c(e){return null!==e&&"object"==typeof e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e)}function o(e,t){const s={...e},n=Object.keys(t);for(let i=0;i<n.length;i++){const a=n[i];if(r.isDangerousKey(a))continue;if(!Object.prototype.hasOwnProperty.call(t,a))continue;const u=t[a],l=e[a];c(u)&&c(l)?s[a]=o(l,u):s[a]=u}return s}require("../registry.cjs"),require("../locales/en.cjs");class VldIntersection extends e.VldBase{constructor(r,t){super(e.VLD_VALIDATOR_TYPES.INTERSECTION),this.validatorA=r,this.validatorB=t}static create(e,r){return new VldIntersection(e,r)}parse(e){try{const r=this.validatorA.parse(e),t=this.validatorB.parse(e),s=c(r),n=c(t);if(s&&n)return o(r,t);if(!s&&!n){if(r===t)return r;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(e){throw new Error(t.getMessages().intersectionError(e.message))}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldIntersection=VldIntersection;
1
+ "use strict";var e=require("./base.cjs"),r=require("../chunks/security-aXZVI7qW.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");function c(e){return null!==e&&"object"==typeof e&&e.constructor===Object&&"[object Object]"===Object.prototype.toString.call(e)}function o(e,t){const s={...e},n=Object.keys(t);for(let i=0;i<n.length;i++){const a=n[i];if(r.isDangerousKey(a))continue;if(!Object.prototype.hasOwnProperty.call(t,a))continue;const u=t[a],l=e[a];c(u)&&c(l)?s[a]=o(l,u):s[a]=u}return s}require("../registry.cjs"),require("../locales/en.cjs");class VldIntersection extends e.VldBase{constructor(r,t){super(e.VLD_VALIDATOR_TYPES.INTERSECTION),this.validatorA=r,this.validatorB=t}static create(e,r){return new VldIntersection(e,r)}parse(e){try{const r=this.validatorA.parse(e),t=this.validatorB.parse(e),s=c(r),n=c(t);if(s&&n)return o(r,t);if(!s&&!n){if(r===t)return r;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(e){throw new Error(t.getMessages().intersectionError(e.message))}}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new s.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldIntersection=VldIntersection;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldJson extends e.VldBase{constructor(s){super(e.VLD_VALIDATOR_TYPES.JSON),this.schema=s}static create(e){return new VldJson(e)}parse(e){let r;if("string"==typeof e)try{r=JSON.parse(e)}catch{throw new Error(s.getMessages().invalidJson)}else r=e;return this.schema?this.schema.parse(r):r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e}}}withSchema(e){return new VldJson(e)}}exports.VldJson=VldJson;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs"),require("../locales/en.cjs");class VldJson extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.JSON),this.schema=r}static create(e){return new VldJson(e)}parse(e){let s;if("string"==typeof e)try{s=JSON.parse(e)}catch{throw new Error(r.getMessages().invalidJson)}else s=e;return this.schema?this.schema.parse(s):s}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}withSchema(e){return new VldJson(e)}}exports.VldJson=VldJson;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs");require("../registry.cjs");class VldLazy extends e.VldBase{constructor(t){super(e.VLD_VALIDATOR_TYPES.LAZY),this._schemaGetter=t,this._cachedSchema=null}static create(e){return new VldLazy(e)}_getSchema(){if(this._cachedSchema)return this._cachedSchema;const e=this._schemaGetter();return this._cachedSchema=e,e}unwrap(){return this._getSchema()}parse(e){return this._getSchema().parse(e)}safeParse(e){return this._getSchema().safeParse(e)}}exports.VldLazy=VldLazy;
1
+ "use strict";var e=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs");class VldLazy extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.LAZY),this._schemaGetter=r,this._cachedSchema=null}static create(e){return new VldLazy(e)}_getSchema(){if(this._cachedSchema)return this._cachedSchema;const e=this._schemaGetter();return this._cachedSchema=e,e}unwrap(){return this._getSchema()}parse(e){return this._getSchema().parse(e)}safeParse(e){return this._getSchema().safeParse(e)}}exports.VldLazy=VldLazy;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");function t(e){const r=JSON.stringify(e,(e,r)=>"bigint"==typeof r?r.toString():r);return void 0===r?String(e):r}require("../registry.cjs"),require("../locales/en.cjs");class VldLiteral extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.LITERAL),this._values=r,this.errorMessage=s}get literal(){return this._values[0]}get values(){return this._values}get isSimple(){return 1===this._values.length}get expectedDisplay(){return t(1===this._values.length?this._values[0]:this._values)}static create(e){const r=Array.isArray(e)?e:[e];if(0===r.length)throw new Error("Cannot create literal schema with no valid values");return new VldLiteral(r)}parse(e){if(!this._values.includes(e))throw this._createLiteralError(e);return e}_createLiteralError(e){const i={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||r.getMessages().literalExpected(this.expectedDisplay,t(e))};return new s.VldError([i])}safeParse(e){return this._values.includes(e)?{success:!0,data:e}:{success:!1,error:this._createLiteralError(e)}}}exports.VldLiteral=VldLiteral;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");function t(e){const r=JSON.stringify(e,(e,r)=>"bigint"==typeof r?r.toString():r);return void 0===r?String(e):r}require("../registry.cjs"),require("../locales/en.cjs");class VldLiteral extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.LITERAL),this._values=r,this.errorMessage=s}get literal(){return this._values[0]}get value(){return this._values[0]}get values(){return this._values}get isSimple(){return 1===this._values.length}get expectedDisplay(){return t(1===this._values.length?this._values[0]:this._values)}static create(e){const r=Array.isArray(e)?e:[e];if(0===r.length)throw new Error("Cannot create literal schema with no valid values");return new VldLiteral(r)}parse(e){if(!this._values.includes(e))throw this._createLiteralError(e);return e}_createLiteralError(e){const a={code:"invalid_value",path:[],values:[...this._values],message:this.errorMessage||r.getMessages().literalExpected(this.expectedDisplay,t(e))};return new s.VldError([a])}safeParse(e){return this._values.includes(e)?{success:!0,data:e}:{success:!1,error:this._createLiteralError(e)}}}exports.VldLiteral=VldLiteral;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),t=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldMap extends e.VldBase{constructor(r,t,s){super(e.VLD_VALIDATOR_TYPES.MAP),this.keyValidator=r,this.valueValidator=t,this.errorMessage=s,this._simpleKeyMode=this.getSimpleItemMode(r),this._simpleValueMode=this.getSimpleItemMode(t),this._simpleKeyValue="literal"===this._simpleKeyMode?r.literal:void 0,this._simpleValueValue="literal"===this._simpleValueMode?t.literal:void 0}get keySchema(){return this.keyValidator}get valueSchema(){return this.valueValidator}static create(e,r){return new VldMap(e,r)}getSimpleItemMode(r){if(!0===r.isSimple)switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e,t,s){switch(e){case"string":return r.getMessages().invalidString;case"number":return r.getMessages().invalidNumber;case"boolean":return r.getMessages().invalidBoolean;case"bigint":return r.getMessages().invalidBigint;case"symbol":return r.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof s;case"undefinedValue":return r.getMessages().expectedUndefined;case"literal":return r.getMessages().literalExpected(JSON.stringify(t),JSON.stringify(s));default:return r.getMessages().invalidMap}}parseSimpleItem(e,r,t){switch(e){case"string":if("string"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"number":if("number"!=typeof t||isNaN(t))throw new Error(this.getSimpleItemError(e,r,t));return t;case"boolean":if("boolean"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"bigint":if("bigint"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"symbol":if("symbol"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"null":if(null!==t)throw new Error(this.getSimpleItemError(e,r,t));return null;case"undefinedValue":if(void 0!==t)throw new Error(this.getSimpleItemError(e,r,t));return;case"literal":if(t!==r)throw new Error(this.getSimpleItemError(e,r,t));return r;case"passthrough":return t}}parse(e){if(!(e instanceof Map))throw new Error(this.errorMessage||r.getMessages().invalidMap);return this.parseKnownMap(e)}parseKnownMap(e){const r=new Map,t=this._simpleKeyMode,s=this._simpleValueMode;if("string"===t&&"number"===s){for(const[i,a]of e){if("string"!=typeof i)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,i));if("number"!=typeof a||isNaN(a))throw new Error(this.getSimpleItemError(s,this._simpleValueValue,a));r.set(i,a)}return r}if("string"===t&&"string"===s){for(const[i,a]of e){if("string"!=typeof i)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,i));if("string"!=typeof a)throw new Error(this.getSimpleItemError(s,this._simpleValueValue,a));r.set(i,a)}return r}if(void 0!==t&&void 0!==s){const i=t,a=s;for(const[t,s]of e){const e=this.parseSimpleItem(i,this._simpleKeyValue,t),l=this.parseSimpleItem(a,this._simpleValueValue,s);r.set(e,l)}return r}for(const[i,a]of e)try{const e=void 0===t?this.keyValidator.parse(i):this.parseSimpleItem(t,this._simpleKeyValue,i),l=void 0===s?this.valueValidator.parse(a):this.parseSimpleItem(s,this._simpleValueValue,a);r.set(e,l)}catch(e){throw new Error(e.message)}return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new t.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldMap=VldMap;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),t=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldMap extends e.VldBase{constructor(r,t,s,i=[]){super(e.VLD_VALIDATOR_TYPES.MAP),this.keyValidator=r,this.valueValidator=t,this.errorMessage=s,this._checks=i,this._simpleKeyMode=this.getSimpleItemMode(r),this._simpleValueMode=this.getSimpleItemMode(t),this._simpleKeyValue="literal"===this._simpleKeyMode?r.literal:void 0,this._simpleValueValue="literal"===this._simpleValueMode?t.literal:void 0}get keySchema(){return this.keyValidator}get valueSchema(){return this.valueValidator}get keyType(){return this.keyValidator}get valueType(){return this.valueValidator}static create(e,r){return new VldMap(e,r)}getSimpleItemMode(r){if(!0===r.isSimple)switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e,t,s){switch(e){case"string":return r.getMessages().invalidString;case"number":return r.getMessages().invalidNumber;case"boolean":return r.getMessages().invalidBoolean;case"bigint":return r.getMessages().invalidBigint;case"symbol":return r.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof s;case"undefinedValue":return r.getMessages().expectedUndefined;case"literal":return r.getMessages().literalExpected(JSON.stringify(t),JSON.stringify(s));default:return r.getMessages().invalidMap}}parseSimpleItem(e,r,t){switch(e){case"string":if("string"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"number":if("number"!=typeof t||isNaN(t))throw new Error(this.getSimpleItemError(e,r,t));return t;case"boolean":if("boolean"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"bigint":if("bigint"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"symbol":if("symbol"!=typeof t)throw new Error(this.getSimpleItemError(e,r,t));return t;case"null":if(null!==t)throw new Error(this.getSimpleItemError(e,r,t));return null;case"undefinedValue":if(void 0!==t)throw new Error(this.getSimpleItemError(e,r,t));return;case"literal":if(t!==r)throw new Error(this.getSimpleItemError(e,r,t));return r;case"passthrough":return t}}parse(e){if(!(e instanceof Map))throw new Error(this.errorMessage||r.getMessages().invalidMap);return this.parseKnownMap(e)}parseKnownMap(e){const r=new Map,t=this._simpleKeyMode,s=this._simpleValueMode;if("string"===t&&"number"===s)for(const[i,a]of e){if("string"!=typeof i)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,i));if("number"!=typeof a||isNaN(a))throw new Error(this.getSimpleItemError(s,this._simpleValueValue,a));r.set(i,a)}else if("string"===t&&"string"===s)for(const[i,a]of e){if("string"!=typeof i)throw new Error(this.getSimpleItemError(t,this._simpleKeyValue,i));if("string"!=typeof a)throw new Error(this.getSimpleItemError(s,this._simpleValueValue,a));r.set(i,a)}else if(void 0!==t&&void 0!==s){const i=t,a=s;for(const[t,s]of e){const e=this.parseSimpleItem(i,this._simpleKeyValue,t),n=this.parseSimpleItem(a,this._simpleValueValue,s);r.set(e,n)}}else for(const[i,a]of e)try{const e=void 0===t?this.keyValidator.parse(i):this.parseSimpleItem(t,this._simpleKeyValue,i),n=void 0===s?this.valueValidator.parse(a):this.parseSimpleItem(s,this._simpleValueValue,a);r.set(e,n)}catch(e){throw new Error(e.message)}for(const e of this._checks)if(!e.fn(r))throw new Error(e.message);return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new t.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}min(e,r){return new VldMap(this.keyValidator,this.valueValidator,this.errorMessage,[...this._checks,{fn:r=>r.size>=e,message:r||`Map must contain at least ${e} entries`}])}max(e,r){return new VldMap(this.keyValidator,this.valueValidator,this.errorMessage,[...this._checks,{fn:r=>r.size<=e,message:r||`Map must contain at most ${e} entries`}])}size(e,r){return new VldMap(this.keyValidator,this.valueValidator,this.errorMessage,[...this._checks,{fn:r=>r.size===e,message:r||`Map must contain exactly ${e} entries`}])}nonempty(e){return this.min(1,e||"Map cannot be empty")}}exports.VldMap=VldMap;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs");class VldNan extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.NAN)}static create(){return new VldNan}parse(e){if("number"!=typeof e||!Number.isNaN(e))throw new Error("Expected NaN, received "+("number"==typeof e?"a valid number":typeof e));return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_number",path:[],message:s}]))}}var s}}exports.VldNan=VldNan;
1
+ "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs");class VldNan extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.NAN)}static create(){return new VldNan}parse(e){if("number"!=typeof e||!Number.isNaN(e))throw new Error("Expected NaN, received "+("number"==typeof e?"a valid number":typeof e));return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_number",path:[],message:s}]))}}var s}}exports.VldNan=VldNan;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldNever extends e.VldBase{static create(){return new VldNever}parse(e){throw new Error(r.getMessages().neverType)}safeParse(e){return{success:!1,error:new s.VldError([{code:"invalid_type",path:[],message:r.getMessages().neverType}])}}}exports.VldNever=VldNever;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldNever extends e.VldBase{static create(){return new VldNever}parse(e){throw new Error(r.getMessages().neverType)}safeParse(e){return{success:!1,error:new s.VldError([{code:"invalid_type",path:[],message:r.getMessages().neverType}])}}}exports.VldNever=VldNever;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs");class VldNull extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.NULL)}static create(){return new VldNull}get isSimple(){return!0}parse(e){if(null!==e)throw new Error("Expected null, received "+typeof e);return null}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_type",path:[],message:s}]))}}var s}}exports.VldNull=VldNull;
1
+ "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs");class VldNull extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.NULL)}static create(){return new VldNull}get isSimple(){return!0}parse(e){if(null!==e)throw new Error("Expected null, received "+typeof e);return null}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_type",path:[],message:s}]))}}var s}}exports.VldNull=VldNull;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldNumber extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.NUMBER),this.config={checks:s?.checks||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._isSimple=0===this._checks.length,this._fastCheckMode=this.detectFastCheckMode(),this._checkMetas=this.config.checkMetas}detectFastCheckMode(){const e=this.config.jsonSchema;return 0===this._checks.length?"none":1===this._checks.length&&0===e?.exclusiveMinimum&&"integer"!==e.type?"positive":2===this._checks.length&&0===e?.exclusiveMinimum&&"integer"===e.type?"positive-int":void 0}get hasCustomChecks(){return!this._isSimple}get isSimple(){return this._isSimple}static create(){return new VldNumber}parse(e){if("number"!=typeof e||!Number.isFinite(e))throw new r.VldError([r.createInvalidTypeIssue("number",r.getTypeName(e),this.config.errorMessage)]);switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0)return e;throw new r.VldError([this._createCheckIssue("gt",0,this.config.errorMessage)]);case"positive-int":if(e>0&&Number.isInteger(e))return e;throw new r.VldError([this._createCheckIssue("int",void 0,this.config.errorMessage)])}return this.parseKnownNumber(e)}_createCheckIssue(e,s,r){switch(e){case"min":return{code:"too_small",path:[],origin:"number",minimum:s,inclusive:!0,message:r||`Too small: expected number to be >=${s}`};case"max":return{code:"too_big",path:[],origin:"number",maximum:s,inclusive:!0,message:r||`Too big: expected number to be <=${s}`};case"gt":return{code:"too_small",path:[],origin:"number",minimum:s,inclusive:!1,message:r||`Too small: expected number to be >${s}`};case"lt":return{code:"too_big",path:[],origin:"number",maximum:s,inclusive:!1,message:r||`Too big: expected number to be <${s}`};case"int":return{code:"invalid_type",path:[],expected:"int",received:"number",message:r||"Invalid input: expected int, received number"};default:return{code:"custom",path:[],message:r||"Invalid number"}}}_findFailingCheck(e){const s=this._checks,r=this._checkMetas;for(let i=0;i<s.length;i++)if(!s[i](e))return r?.[i]??{kind:"other",message:this.config.errorMessage};return null}parseKnownNumber(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0)return e;throw new r.VldError([this._createCheckIssue("gt",0,this.config.errorMessage)]);case"positive-int":if(e>0&&Number.isInteger(e))return e;throw new r.VldError([this._createCheckIssue("int",void 0,this.config.errorMessage)])}const s=this._findFailingCheck(e);if(s)throw new r.VldError([this._createCheckIssue(s.kind,s.value,s.message)]);return e}safeParse(e){if("number"!=typeof e||!Number.isFinite(e))return{success:!1,error:new r.VldError([r.createInvalidTypeIssue("number",r.getTypeName(e),this.config.errorMessage)])};try{const s=this._findFailingCheck(e);if(s)return{success:!1,error:new r.VldError([this._createCheckIssue(s.kind,s.value,s.message)])}}catch(e){return e instanceof r.VldError?{success:!1,error:e}:{success:!1,error:new r.VldError([{code:"custom",path:[],message:e.message}])}}return{success:!0,data:e}}min(r,i){return new VldNumber({checks:[...this.config.checks,e=>e>=r],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMin(r)),jsonSchema:{...this.config.jsonSchema,minimum:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,inclusive:!0,message:e.resolveErrorMessage(i,s.getMessages().numberMin(r))}]})}max(r,i){return new VldNumber({checks:[...this.config.checks,e=>e<=r],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMax(r)),jsonSchema:{...this.config.jsonSchema,maximum:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,inclusive:!0,message:e.resolveErrorMessage(i,s.getMessages().numberMax(r))}]})}int(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isInteger(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberInt),jsonSchema:{...this.config.jsonSchema,type:"integer"},checkMetas:[...this.config.checkMetas??[],{kind:"int",message:e.resolveErrorMessage(r,s.getMessages().numberInt)}]})}positive(r){return new VldNumber({checks:[...this.config.checks,e=>e>0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberPositive),jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0},checkMetas:[...this.config.checkMetas??[],{kind:"gt",value:0,inclusive:!1,message:e.resolveErrorMessage(r,s.getMessages().numberPositive)}]})}negative(r){return new VldNumber({checks:[...this.config.checks,e=>e<0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNegative),jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0},checkMetas:[...this.config.checkMetas??[],{kind:"lt",value:0,inclusive:!1,message:e.resolveErrorMessage(r,s.getMessages().numberNegative)}]})}nonnegative(r){return new VldNumber({checks:[...this.config.checks,e=>e>=0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNonnegative),jsonSchema:{...this.config.jsonSchema,minimum:0},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:0,inclusive:!0,message:e.resolveErrorMessage(r,s.getMessages().numberNonnegative)}]})}nonpositive(r){return new VldNumber({checks:[...this.config.checks,e=>e<=0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNonpositive),jsonSchema:{...this.config.jsonSchema,maximum:0},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:0,inclusive:!0,message:e.resolveErrorMessage(r,s.getMessages().numberNonpositive)}]})}finite(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberFinite),jsonSchema:this.config.jsonSchema})}safe(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberSafe),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}multipleOf(r,i){return new VldNumber({checks:[...this.config.checks,e=>{const s=Math.abs(e%r);return s<Number.EPSILON||Math.abs(s-Math.abs(r))<Number.EPSILON}],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMultipleOf(r)),jsonSchema:{...this.config.jsonSchema,multipleOf:r}})}step(e,s){return this.multipleOf(e,s)}between(s,r,i){return new VldNumber({checks:[...this.config.checks,e=>e>=s&&e<=r],errorMessage:e.resolveErrorMessage(i,`Number must be between ${s} and ${r}`),jsonSchema:{...this.config.jsonSchema,minimum:s,maximum:r}})}even(s){return new VldNumber({checks:[...this.config.checks,e=>!!Number.isInteger(e)&&e%2==0],errorMessage:e.resolveErrorMessage(s,"Number must be even"),jsonSchema:{...this.config.jsonSchema,type:"integer",multipleOf:2}})}odd(s){return new VldNumber({checks:[...this.config.checks,e=>!!Number.isInteger(e)&&e%2!=0],errorMessage:e.resolveErrorMessage(s,"Number must be odd"),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}gt(s,r){return new VldNumber({checks:[...this.config.checks,e=>e>s],errorMessage:e.resolveErrorMessage(r,`Number must be greater than ${s}`),jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:s},checkMetas:[...this.config.checkMetas??[],{kind:"gt",value:s,inclusive:!1,message:e.resolveErrorMessage(r,`Number must be greater than ${s}`)}]})}lt(s,r){return new VldNumber({checks:[...this.config.checks,e=>e<s],errorMessage:e.resolveErrorMessage(r,`Number must be less than ${s}`),jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:s},checkMetas:[...this.config.checkMetas??[],{kind:"lt",value:s,inclusive:!1,message:e.resolveErrorMessage(r,`Number must be less than ${s}`)}]})}gte(e,s){return this.min(e,s)}lte(e,s){return this.max(e,s)}uint32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=0&&e<=4294967295],errorMessage:e.resolveErrorMessage(s,"Expected an unsigned 32-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:0,maximum:4294967295}})}uint64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=0],errorMessage:e.resolveErrorMessage(s,"Expected an unsigned 64-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:0}})}int32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=-2147483648&&e<=2147483647],errorMessage:e.resolveErrorMessage(s,"Expected a signed 32-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:-2147483648,maximum:2147483647}})}int64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)],errorMessage:e.resolveErrorMessage(s,"Expected a signed 64-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}float32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)&&Math.abs(e)<=34e37],errorMessage:e.resolveErrorMessage(s,"Expected a 32-bit float"),jsonSchema:{...this.config.jsonSchema,minimum:-34e37,maximum:34e37}})}float64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)],errorMessage:e.resolveErrorMessage(s,"Expected a 64-bit float"),jsonSchema:this.config.jsonSchema})}}exports.VldNumber=VldNumber;
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldNumber extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.NUMBER),this.config={checks:s?.checks||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._isSimple=0===this._checks.length,this._fastCheckMode=this.detectFastCheckMode(),this._checkMetas=this.config.checkMetas}detectFastCheckMode(){const e=this.config.jsonSchema;return 0===this._checks.length?"none":1===this._checks.length&&0===e?.exclusiveMinimum&&"integer"!==e.type?"positive":2===this._checks.length&&0===e?.exclusiveMinimum&&"integer"===e.type?"positive-int":void 0}get hasCustomChecks(){return!this._isSimple}get isSimple(){return this._isSimple}get minValue(){return this.config.jsonSchema?.minimum??this.config.jsonSchema?.exclusiveMinimum??null}get maxValue(){return this.config.jsonSchema?.maximum??this.config.jsonSchema?.exclusiveMaximum??null}get isInt(){return"integer"===this.config.jsonSchema?.type}get isFinite(){return!0}get format(){return this.config.jsonSchema?.format??null}static create(){return new VldNumber}parse(e){if("number"!=typeof e||!Number.isFinite(e))throw new r.VldError([r.createInvalidTypeIssue("number",r.getTypeName(e),this.config.errorMessage)]);switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0)return e;throw new r.VldError([this._createCheckIssue("gt",0,this.config.errorMessage)]);case"positive-int":if(e>0&&Number.isInteger(e))return e;throw new r.VldError([this._createCheckIssue("int",void 0,this.config.errorMessage)])}return this.parseKnownNumber(e)}_createCheckIssue(e,s,r){switch(e){case"min":return{code:"too_small",path:[],origin:"number",minimum:s,inclusive:!0,message:r||`Too small: expected number to be >=${s}`};case"max":return{code:"too_big",path:[],origin:"number",maximum:s,inclusive:!0,message:r||`Too big: expected number to be <=${s}`};case"gt":return{code:"too_small",path:[],origin:"number",minimum:s,inclusive:!1,message:r||`Too small: expected number to be >${s}`};case"lt":return{code:"too_big",path:[],origin:"number",maximum:s,inclusive:!1,message:r||`Too big: expected number to be <${s}`};case"int":return{code:"invalid_type",path:[],expected:"int",received:"number",message:r||"Invalid input: expected int, received number"};default:return{code:"custom",path:[],message:r||"Invalid number"}}}_findFailingCheck(e){const s=this._checks,r=this._checkMetas;for(let i=0;i<s.length;i++)if(!s[i](e))return r?.[i]??{kind:"other",message:this.config.errorMessage};return null}parseKnownNumber(e){switch(this._fastCheckMode){case"none":return e;case"positive":if(e>0)return e;throw new r.VldError([this._createCheckIssue("gt",0,this.config.errorMessage)]);case"positive-int":if(e>0&&Number.isInteger(e))return e;throw new r.VldError([this._createCheckIssue("int",void 0,this.config.errorMessage)])}const s=this._findFailingCheck(e);if(s)throw new r.VldError([this._createCheckIssue(s.kind,s.value,s.message)]);return e}safeParse(e){if("number"!=typeof e||!Number.isFinite(e))return{success:!1,error:new r.VldError([r.createInvalidTypeIssue("number",r.getTypeName(e),this.config.errorMessage)])};try{const s=this._findFailingCheck(e);if(s)return{success:!1,error:new r.VldError([this._createCheckIssue(s.kind,s.value,s.message)])}}catch(e){return e instanceof r.VldError?{success:!1,error:e}:{success:!1,error:new r.VldError([{code:"custom",path:[],message:e.message}])}}return{success:!0,data:e}}min(r,i){return new VldNumber({checks:[...this.config.checks,e=>e>=r],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMin(r)),jsonSchema:{...this.config.jsonSchema,minimum:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,inclusive:!0,message:e.resolveErrorMessage(i,s.getMessages().numberMin(r))}]})}max(r,i){return new VldNumber({checks:[...this.config.checks,e=>e<=r],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMax(r)),jsonSchema:{...this.config.jsonSchema,maximum:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,inclusive:!0,message:e.resolveErrorMessage(i,s.getMessages().numberMax(r))}]})}int(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isInteger(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberInt),jsonSchema:{...this.config.jsonSchema,type:"integer"},checkMetas:[...this.config.checkMetas??[],{kind:"int",message:e.resolveErrorMessage(r,s.getMessages().numberInt)}]})}positive(r){return new VldNumber({checks:[...this.config.checks,e=>e>0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberPositive),jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:0},checkMetas:[...this.config.checkMetas??[],{kind:"gt",value:0,inclusive:!1,message:e.resolveErrorMessage(r,s.getMessages().numberPositive)}]})}negative(r){return new VldNumber({checks:[...this.config.checks,e=>e<0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNegative),jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:0},checkMetas:[...this.config.checkMetas??[],{kind:"lt",value:0,inclusive:!1,message:e.resolveErrorMessage(r,s.getMessages().numberNegative)}]})}nonnegative(r){return new VldNumber({checks:[...this.config.checks,e=>e>=0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNonnegative),jsonSchema:{...this.config.jsonSchema,minimum:0},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:0,inclusive:!0,message:e.resolveErrorMessage(r,s.getMessages().numberNonnegative)}]})}nonpositive(r){return new VldNumber({checks:[...this.config.checks,e=>e<=0],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberNonpositive),jsonSchema:{...this.config.jsonSchema,maximum:0},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:0,inclusive:!0,message:e.resolveErrorMessage(r,s.getMessages().numberNonpositive)}]})}finite(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberFinite),jsonSchema:this.config.jsonSchema})}safe(r){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)],errorMessage:e.resolveErrorMessage(r,s.getMessages().numberSafe),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}multipleOf(r,i){return new VldNumber({checks:[...this.config.checks,e=>{const s=Math.abs(e%r);return s<Number.EPSILON||Math.abs(s-Math.abs(r))<Number.EPSILON}],errorMessage:e.resolveErrorMessage(i,s.getMessages().numberMultipleOf(r)),jsonSchema:{...this.config.jsonSchema,multipleOf:r}})}step(e,s){return this.multipleOf(e,s)}between(s,r,i){return new VldNumber({checks:[...this.config.checks,e=>e>=s&&e<=r],errorMessage:e.resolveErrorMessage(i,`Number must be between ${s} and ${r}`),jsonSchema:{...this.config.jsonSchema,minimum:s,maximum:r}})}even(s){return new VldNumber({checks:[...this.config.checks,e=>!!Number.isInteger(e)&&e%2==0],errorMessage:e.resolveErrorMessage(s,"Number must be even"),jsonSchema:{...this.config.jsonSchema,type:"integer",multipleOf:2}})}odd(s){return new VldNumber({checks:[...this.config.checks,e=>!!Number.isInteger(e)&&e%2!=0],errorMessage:e.resolveErrorMessage(s,"Number must be odd"),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}gt(s,r){return new VldNumber({checks:[...this.config.checks,e=>e>s],errorMessage:e.resolveErrorMessage(r,`Number must be greater than ${s}`),jsonSchema:{...this.config.jsonSchema,exclusiveMinimum:s},checkMetas:[...this.config.checkMetas??[],{kind:"gt",value:s,inclusive:!1,message:e.resolveErrorMessage(r,`Number must be greater than ${s}`)}]})}lt(s,r){return new VldNumber({checks:[...this.config.checks,e=>e<s],errorMessage:e.resolveErrorMessage(r,`Number must be less than ${s}`),jsonSchema:{...this.config.jsonSchema,exclusiveMaximum:s},checkMetas:[...this.config.checkMetas??[],{kind:"lt",value:s,inclusive:!1,message:e.resolveErrorMessage(r,`Number must be less than ${s}`)}]})}gte(e,s){return this.min(e,s)}lte(e,s){return this.max(e,s)}uint32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=0&&e<=4294967295],errorMessage:e.resolveErrorMessage(s,"Expected an unsigned 32-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:0,maximum:4294967295}})}uint64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=0],errorMessage:e.resolveErrorMessage(s,"Expected an unsigned 64-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:0}})}int32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)&&e>=-2147483648&&e<=2147483647],errorMessage:e.resolveErrorMessage(s,"Expected a signed 32-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer",minimum:-2147483648,maximum:2147483647}})}int64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isSafeInteger(e)],errorMessage:e.resolveErrorMessage(s,"Expected a signed 64-bit integer"),jsonSchema:{...this.config.jsonSchema,type:"integer"}})}float32(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)&&Math.abs(e)<=34e37],errorMessage:e.resolveErrorMessage(s,"Expected a 32-bit float"),jsonSchema:{...this.config.jsonSchema,minimum:-34e37,maximum:34e37}})}float64(s){return new VldNumber({checks:[...this.config.checks,e=>Number.isFinite(e)],errorMessage:e.resolveErrorMessage(s,"Expected a 64-bit float"),jsonSchema:this.config.jsonSchema})}}exports.VldNumber=VldNumber;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),t=require("./enum.cjs"),r=require("../chunks/security-aXZVI7qW.cjs"),i=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldObject extends e.VldBase{createSafeParseError(e){return new i.VldError([{code:"invalid_object",path:[],message:e}])}constructor(s){super(e.VLD_VALIDATOR_TYPES.OBJECT),this._config=s,this._shapeKeys=Object.keys(s.shape),this._shapeKeysSet=new Set(this._shapeKeys),this._validators=this._shapeKeys.map(e=>this.tryGetFieldValidator(e)),this._validatorTypes=this._shapeKeys.map((e,s)=>this._validators[s]?.validatorType||this.getValidatorType(e)),this._simpleFieldModes=this._validators.map((e,s)=>this.getSimpleFieldMode(e,this._validatorTypes[s])),this._simpleFieldValues=this._validators.map((e,s)=>"literal"===this._simpleFieldModes[s]?e.literal:void 0),this._canUseSimpleObjectFastPath=!s.strict&&!s.passthrough&&!s.catchall&&this._shapeKeys.length>0&&this._simpleFieldModes.every(e=>void 0!==e),this._canUseSafeParseFastPath=this._validators.every(s=>s instanceof e.VldBase)&&(void 0===s.catchall||s.catchall instanceof e.VldBase)}tryGetFieldValidator(e){try{const s=Object.getOwnPropertyDescriptor(this._config.shape,e);if(s?.get)return;return this.resolveFieldValidator(e)}catch{return}}resolveFieldValidator(e){try{const s=this._config.shape[e];if(!s||"function"!=typeof s.safeParse)return;return s}catch{return}}getFieldValidator(e,s){const t=(void 0===s?void 0:this._validators[s])||this.resolveFieldValidator(e);if(!t)throw new Error(`Invalid validator for field "${e}"`);return t}getValidatorType(s){try{const t=this._config.shape[s];return t?.validatorType||e.VLD_VALIDATOR_TYPES.UNKNOWN}catch{return e.VLD_VALIDATOR_TYPES.UNKNOWN}}getSimpleFieldMode(s,t){if(s&&!0===s.isSimple)switch(t){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleFieldError(e,t,r){switch(e){case"string":return s.getMessages().invalidString;case"number":return s.getMessages().invalidNumber;case"boolean":return s.getMessages().invalidBoolean;case"bigint":return s.getMessages().invalidBigint;case"symbol":return s.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof r;case"undefinedValue":return s.getMessages().expectedUndefined;case"literal":return s.getMessages().literalExpected(JSON.stringify(t),JSON.stringify(r));default:return s.getMessages().invalidObject}}parseCheckedField(s,t,r){if(t===e.VLD_VALIDATOR_TYPES.STRING&&"string"==typeof r){const e=s.parseKnownString;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.NUMBER&&"number"==typeof r&&!isNaN(r)){const e=s.parseKnownNumber;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.BOOLEAN&&"boolean"==typeof r){const e=s.parseKnownBoolean;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.BIGINT&&"bigint"==typeof r){const e=s.parseKnownBigInt;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.SYMBOL&&"symbol"==typeof r){const e=s.parseKnownSymbol;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.FUNCTION&&"function"==typeof r){const e=s.parseKnownFunction;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.FILE&&"object"==typeof r&&null!==r&&("size"in r&&"type"in r||"undefined"!=typeof File&&r instanceof File)){const e=s.parseKnownFile;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.DATE&&r instanceof Date){const e=s.parseKnownDate;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.OBJECT&&"object"==typeof r&&null!==r&&!Array.isArray(r)){const e=s.parseKnownObject;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.ARRAY&&Array.isArray(r)){const e=s.parseKnownArray;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.TUPLE&&Array.isArray(r)){const e=s.parseKnownTuple;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.RECORD&&"object"==typeof r&&null!==r&&!Array.isArray(r)){const e=s.parseKnownRecord;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.SET&&r instanceof Set){const e=s.parseKnownSet;if("function"==typeof e)return e.call(s,r)}if(t===e.VLD_VALIDATOR_TYPES.MAP&&r instanceof Map){const e=s.parseKnownMap;if("function"==typeof e)return e.call(s,r)}return s.parse(r)}parseSimpleObjectValue(e,t,r=!1){if(2===this._shapeKeys.length&&"string"===this._simpleFieldModes[0]&&"number"===this._simpleFieldModes[1]){const t=this._shapeKeys[0],r=e[t];if("string"!=typeof r)throw new Error(s.getMessages().objectField(t,s.getMessages().invalidString));const i=this._shapeKeys[1],n=e[i];if("number"!=typeof n||isNaN(n))throw new Error(s.getMessages().objectField(i,s.getMessages().invalidNumber));const a={};return a[t]=r,a[i]=n,a}if(3===this._shapeKeys.length&&"literal"===this._simpleFieldModes[0]&&"string"===this._simpleFieldModes[1]&&"number"===this._simpleFieldModes[2]){const i=this._shapeKeys[0],n=e[i],a=this._simpleFieldValues[0];if((!r||i!==t)&&n!==a)throw new Error(s.getMessages().objectField(i,this.getSimpleFieldError("literal",a,n)));const o=this._shapeKeys[1],c=e[o];if("string"!=typeof c)throw new Error(s.getMessages().objectField(o,s.getMessages().invalidString));const l=this._shapeKeys[2],h=e[l];if("number"!=typeof h||isNaN(h))throw new Error(s.getMessages().objectField(l,s.getMessages().invalidNumber));const f={};return f[i]=a,f[o]=c,f[l]=h,f}const i={};for(let n=0;n<this._shapeKeys.length;n++){const a=this._shapeKeys[n],o=e[a],c=this._simpleFieldModes[n];switch(c){case"string":if("string"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidString));i[a]=o;break;case"number":if("number"!=typeof o||isNaN(o))throw new Error(s.getMessages().objectField(a,s.getMessages().invalidNumber));i[a]=o;break;case"boolean":if("boolean"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidBoolean));i[a]=o;break;case"bigint":if("bigint"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidBigint));i[a]=o;break;case"symbol":if("symbol"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidSymbol));i[a]=o;break;case"null":if(null!==o)throw new Error(s.getMessages().objectField(a,this.getSimpleFieldError(c,void 0,o)));i[a]=null;break;case"undefinedValue":if(void 0!==o)throw new Error(s.getMessages().objectField(a,s.getMessages().expectedUndefined));i[a]=void 0;break;case"literal":if(r&&a===t){i[a]=this._simpleFieldValues[n];break}if(o!==this._simpleFieldValues[n])throw new Error(s.getMessages().objectField(a,this.getSimpleFieldError(c,this._simpleFieldValues[n],o)));i[a]=this._simpleFieldValues[n];break;case"passthrough":i[a]=o;break;default:throw new Error(s.getMessages().objectField(a,s.getMessages().invalidObject))}}return i}get config(){return this._config}get shapeKeys(){return this._shapeKeys}get shapeKeysSet(){return this._shapeKeysSet}static create(e){return new VldObject({shape:e})}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.parseObjectValue(e)}parseKnownObject(e,s){return this.parseObjectValue(e,s)}parseTrustedKnownObject(e,s){return this.parseObjectValue(e,s,!0)}parseObjectValue(e,t,i=!1){if(this._canUseSimpleObjectFastPath)return this.parseSimpleObjectValue(e,t,i);const n={};let a="";try{for(let r=0;r<this._shapeKeys.length;r++){if(a=this._shapeKeys[r],i&&a===t&&"literal"===this._simpleFieldModes[r]){n[a]=this._simpleFieldValues[r];continue}const o=this._simpleFieldModes[r];if(void 0!==o){const t=e[a];switch(o){case"string":if("string"!=typeof t)throw new Error(s.getMessages().invalidString);n[a]=t;continue;case"number":if("number"!=typeof t||isNaN(t))throw new Error(s.getMessages().invalidNumber);n[a]=t;continue;case"boolean":if("boolean"!=typeof t)throw new Error(s.getMessages().invalidBoolean);n[a]=t;continue;case"bigint":if("bigint"!=typeof t)throw new Error(s.getMessages().invalidBigint);n[a]=t;continue;case"symbol":if("symbol"!=typeof t)throw new Error(s.getMessages().invalidSymbol);n[a]=t;continue;case"null":if(null!==t)throw new Error(this.getSimpleFieldError(o,void 0,t));n[a]=null;continue;case"undefinedValue":if(void 0!==t)throw new Error(s.getMessages().expectedUndefined);n[a]=void 0;continue;case"literal":if(t!==this._simpleFieldValues[r])throw new Error(this.getSimpleFieldError(o,this._simpleFieldValues[r],t));n[a]=this._simpleFieldValues[r];continue;case"passthrough":n[a]=t;continue}continue}const c=this.getFieldValidator(a,r);n[a]=this.parseCheckedField(c,this._validatorTypes[r],e[a])}}catch(e){throw new Error(s.getMessages().objectField(a,e.message))}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(e);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const r=t[s];this._shapeKeysSet.has(r)||e.push(r)}if(e.length>0)throw new Error(s.getMessages().unexpectedKeys(e))}if(this._config.passthrough)for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||r.isDangerousKey(i)||(n[i]=e[i])}if(this._config.catchall)for(let i=0;i<t.length;i++){const a=t[i];if(!this._shapeKeysSet.has(a)&&!r.isDangerousKey(a))try{n[a]=this._config.catchall.parse(e[a])}catch(e){throw new Error(s.getMessages().objectField(a,e.message))}}}return n}safeParse(t){if("object"!=typeof t||null===t||Array.isArray(t))return{success:!1,error:this.createSafeParseError(this._config.errorMessage||s.getMessages().invalidObject)};const i=t;if(this._canUseSimpleObjectFastPath)try{return{success:!0,data:this.parseSimpleObjectValue(i)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}if(this._canUseSafeParseFastPath)try{return{success:!0,data:this.parseObjectValue(i)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}const n={};for(let t=0;t<this._shapeKeys.length;t++){const r=this._shapeKeys[t],a=i[r],o=this._simpleFieldModes[t];if(void 0!==o){if("string"===o&&"string"==typeof a||"number"===o&&"number"==typeof a&&!isNaN(a)||"boolean"===o&&"boolean"==typeof a||"bigint"===o&&"bigint"==typeof a||"symbol"===o&&"symbol"==typeof a||"null"===o&&null===a||"undefinedValue"===o&&void 0===a||"literal"===o&&a===this._simpleFieldValues[t]||"passthrough"===o){n[r]="literal"===o?this._simpleFieldValues[t]:"null"===o?null:a;continue}return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(r,this.getSimpleFieldError(o,this._simpleFieldValues[t],a)))}}let c;try{c=this.getFieldValidator(r,t)}catch(e){const t=e instanceof Error?e.message:String(e);return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(r,t))}}try{if(c instanceof e.VldBase)n[r]=this.parseCheckedField(c,this._validatorTypes[t],a);else{const e=c.safeParse(a);if(!e.success)return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(r,e.error.message))};n[r]=e.data}}catch(e){const t=e instanceof Error?e.message:String(e);return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(r,t))}}}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(i);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const r=t[s];this._shapeKeysSet.has(r)||e.push(r)}if(e.length>0)return{success:!1,error:this.createSafeParseError(s.getMessages().unexpectedKeys(e))}}if(this._config.passthrough)for(let e=0;e<t.length;e++){const s=t[e];this._shapeKeysSet.has(s)||r.isDangerousKey(s)||(n[s]=i[s])}if(this._config.catchall){const a=this._config.catchall;for(let o=0;o<t.length;o++){const c=t[o];if(!this._shapeKeysSet.has(c)&&!r.isDangerousKey(c))try{if(a instanceof e.VldBase)n[c]=a.parse(i[c]);else{const e=a.safeParse(i[c]);if(!e.success)return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(c,e.error.message))};n[c]=e.data}}catch(e){const t=e instanceof Error?e.message:String(e);return{success:!1,error:this.createSafeParseError(s.getMessages().objectField(c,t))}}}}}return{success:!0,data:n}}encode(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.encodeObjectSync(e)}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}async encodeAsync(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.encodeObjectAsync(e)}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}encodeObjectSync(e){const s={};for(let t=0;t<this._shapeKeys.length;t++){const r=this._shapeKeys[t],i=this.getFieldValidator(r,t).encode(e[r]);(void 0!==i||Object.prototype.hasOwnProperty.call(e,r))&&(s[r]=i)}return this.encodeExtraKeysSync(e,s),s}async encodeObjectAsync(e){const s={};for(let t=0;t<this._shapeKeys.length;t++){const r=this._shapeKeys[t],i=await this.getFieldValidator(r,t).encodeAsync(e[r]);(void 0!==i||Object.prototype.hasOwnProperty.call(e,r))&&(s[r]=i)}const t=this.getEncodedExtraKeys(e);for(const i of t)r.isDangerousKey(i)||(this._config.catchall?s[i]=await this._config.catchall.encodeAsync(e[i]):this._config.passthrough&&(s[i]=e[i]));return s}getEncodedExtraKeys(e){const t=Object.keys(e).filter(e=>!this._shapeKeysSet.has(e));if(this._config.strict&&t.length>0)throw new Error(s.getMessages().unexpectedKeys(t));return t}encodeExtraKeysSync(e,s){for(const t of this.getEncodedExtraKeys(e))r.isDangerousKey(t)||(this._config.catchall?s[t]=this._config.catchall.encode(e[t]):this._config.passthrough&&(s[t]=e[t]))}strict(e){return new VldObject({...this._config,strict:!0,passthrough:!1,errorMessage:e})}passthrough(){return new VldObject({...this._config,strict:!1,passthrough:!0})}loose(){return this.passthrough()}strip(){const e={...this._config,strict:!1,passthrough:!1};return delete e.catchall,new VldObject(e)}partial(){const s={};for(const t in this._config.shape)s[t]=new e.VldOptional(this._config.shape[t]);return new VldObject({...this._config,shape:s})}deepPartial(){const s={};for(const t in this._config.shape){const r=this._config.shape[t];s[t]=r instanceof VldObject?new e.VldOptional(r.deepPartial()):new e.VldOptional(r)}return new VldObject({...this._config,shape:s})}pick(...e){const s={};for(const t of e)t in this._config.shape&&(s[t]=this._config.shape[t]);return new VldObject({...this._config,shape:s})}omit(...e){const s={},t=new Set(e);for(const e in this._config.shape)t.has(e)||(s[e]=this._config.shape[e]);return new VldObject({...this._config,shape:s})}extend(e){return new VldObject({...this._config,shape:{...this._config.shape,...e}})}merge(e){return new VldObject({...this._config,shape:{...this._config.shape,...e.config.shape}})}required(){const s={};for(const t in this._config.shape){const r=this._config.shape[t];if(r instanceof e.VldOptional){const e=r.baseValidator;if(!e||"function"!=typeof e.parse)throw new Error(`Invalid VldOptional structure for field "${t}": missing or invalid baseValidator`);s[t]=e}else s[t]=r}return new VldObject({...this._config,shape:s})}catchall(e){return new VldObject({...this._config,catchall:e,passthrough:!1})}get shape(){return this._config.shape}keyof(){const e=Object.keys(this._config.shape);if(0===e.length)throw new Error("Cannot create keyof enum from empty object");return t.VldEnum.create(e)}safeExtend(e){const t=new Set(Object.keys(this._config.shape)),r=Object.keys(e),i=[];for(const e of r)t.has(e)&&i.push(e);if(i.length>0)throw new Error(`safeExtend: ${s.getMessages().safeExtendOverlap(i)}`);return new VldObject({...this._config,shape:{...this._config.shape,...e}})}}exports.VldObject=VldObject;
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),t=require("./enum.cjs"),i=require("../chunks/security-aXZVI7qW.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldObject extends e.VldBase{createSafeParseError(e,t){if(e instanceof r.VldError)return void 0!==t?new r.VldError(e.issues.map(e=>({...e,path:e.path?[t,...e.path]:[t],message:e.message.startsWith("Invalid field")?e.message:s.getMessages().objectField(String(t),e.message)}))):e;const i=e instanceof Error?e.message:String(e);return new r.VldError([{code:"invalid_type",path:void 0!==t?[t]:[],message:void 0===t||i.startsWith("Invalid field")?i:s.getMessages().objectField(String(t),i)}])}constructor(s){super(e.VLD_VALIDATOR_TYPES.OBJECT),this._config=s,this._shapeKeys=Object.keys(s.shape),this._shapeKeysSet=new Set(this._shapeKeys),this._validators=this._shapeKeys.map(e=>this.tryGetFieldValidator(e)),this._validatorTypes=this._shapeKeys.map((e,s)=>this._validators[s]?.validatorType||this.getValidatorType(e)),this._simpleFieldModes=this._validators.map((e,s)=>this.getSimpleFieldMode(e,this._validatorTypes[s])),this._simpleFieldValues=this._validators.map((e,s)=>"literal"===this._simpleFieldModes[s]?e.literal:void 0),this._canUseSimpleObjectFastPath=!s.strict&&!s.passthrough&&!s.catchall&&this._shapeKeys.length>0&&this._simpleFieldModes.every(e=>void 0!==e),this._canUseSafeParseFastPath=this._validators.every(s=>s instanceof e.VldBase)&&(void 0===s.catchall||s.catchall instanceof e.VldBase)}tryGetFieldValidator(e){try{const s=Object.getOwnPropertyDescriptor(this._config.shape,e);if(s?.get)return;return this.resolveFieldValidator(e)}catch{return}}resolveFieldValidator(e){try{const s=this._config.shape[e];if(!s||"function"!=typeof s.safeParse)return;return s}catch{return}}getFieldValidator(e,s){const t=(void 0===s?void 0:this._validators[s])||this.resolveFieldValidator(e);if(!t)throw new Error(`Invalid validator for field "${e}"`);return t}getValidatorType(s){try{const t=this._config.shape[s];return t?.validatorType||e.VLD_VALIDATOR_TYPES.UNKNOWN}catch{return e.VLD_VALIDATOR_TYPES.UNKNOWN}}getSimpleFieldMode(s,t){if(s&&!0===s.isSimple)switch(t){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleFieldError(e,t,i){switch(e){case"string":return s.getMessages().invalidString;case"number":return s.getMessages().invalidNumber;case"boolean":return s.getMessages().invalidBoolean;case"bigint":return s.getMessages().invalidBigint;case"symbol":return s.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof i;case"undefinedValue":return s.getMessages().expectedUndefined;case"literal":return s.getMessages().literalExpected(JSON.stringify(t),JSON.stringify(i));default:return s.getMessages().invalidObject}}parseCheckedField(s,t,i){if(t===e.VLD_VALIDATOR_TYPES.STRING&&"string"==typeof i){const e=s.parseKnownString;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.NUMBER&&"number"==typeof i&&!isNaN(i)){const e=s.parseKnownNumber;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.BOOLEAN&&"boolean"==typeof i){const e=s.parseKnownBoolean;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.BIGINT&&"bigint"==typeof i){const e=s.parseKnownBigInt;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.SYMBOL&&"symbol"==typeof i){const e=s.parseKnownSymbol;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.FUNCTION&&"function"==typeof i){const e=s.parseKnownFunction;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.FILE&&"object"==typeof i&&null!==i&&("size"in i&&"type"in i||"undefined"!=typeof File&&i instanceof File)){const e=s.parseKnownFile;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.DATE&&i instanceof Date){const e=s.parseKnownDate;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.OBJECT&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const e=s.parseKnownObject;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.ARRAY&&Array.isArray(i)){const e=s.parseKnownArray;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.TUPLE&&Array.isArray(i)){const e=s.parseKnownTuple;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.RECORD&&"object"==typeof i&&null!==i&&!Array.isArray(i)){const e=s.parseKnownRecord;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.SET&&i instanceof Set){const e=s.parseKnownSet;if("function"==typeof e)return e.call(s,i)}if(t===e.VLD_VALIDATOR_TYPES.MAP&&i instanceof Map){const e=s.parseKnownMap;if("function"==typeof e)return e.call(s,i)}return s.parse(i)}parseSimpleObjectValue(e,t,i=!1){if(2===this._shapeKeys.length&&"string"===this._simpleFieldModes[0]&&"number"===this._simpleFieldModes[1]){const t=this._shapeKeys[0],i=e[t];if("string"!=typeof i)throw new Error(s.getMessages().objectField(t,s.getMessages().invalidString));const r=this._shapeKeys[1],n=e[r];if("number"!=typeof n||isNaN(n))throw new Error(s.getMessages().objectField(r,s.getMessages().invalidNumber));const a={};return a[t]=i,a[r]=n,a}if(3===this._shapeKeys.length&&"literal"===this._simpleFieldModes[0]&&"string"===this._simpleFieldModes[1]&&"number"===this._simpleFieldModes[2]){const r=this._shapeKeys[0],n=e[r],a=this._simpleFieldValues[0];if((!i||r!==t)&&n!==a)throw new Error(s.getMessages().objectField(r,this.getSimpleFieldError("literal",a,n)));const o=this._shapeKeys[1],c=e[o];if("string"!=typeof c)throw new Error(s.getMessages().objectField(o,s.getMessages().invalidString));const l=this._shapeKeys[2],h=e[l];if("number"!=typeof h||isNaN(h))throw new Error(s.getMessages().objectField(l,s.getMessages().invalidNumber));const f={};return f[r]=a,f[o]=c,f[l]=h,f}const r={};for(let n=0;n<this._shapeKeys.length;n++){const a=this._shapeKeys[n],o=e[a],c=this._simpleFieldModes[n];switch(c){case"string":if("string"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidString));r[a]=o;break;case"number":if("number"!=typeof o||isNaN(o))throw new Error(s.getMessages().objectField(a,s.getMessages().invalidNumber));r[a]=o;break;case"boolean":if("boolean"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidBoolean));r[a]=o;break;case"bigint":if("bigint"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidBigint));r[a]=o;break;case"symbol":if("symbol"!=typeof o)throw new Error(s.getMessages().objectField(a,s.getMessages().invalidSymbol));r[a]=o;break;case"null":if(null!==o)throw new Error(s.getMessages().objectField(a,this.getSimpleFieldError(c,void 0,o)));r[a]=null;break;case"undefinedValue":if(void 0!==o)throw new Error(s.getMessages().objectField(a,s.getMessages().expectedUndefined));r[a]=void 0;break;case"literal":if(i&&a===t){r[a]=this._simpleFieldValues[n];break}if(o!==this._simpleFieldValues[n])throw new Error(s.getMessages().objectField(a,this.getSimpleFieldError(c,this._simpleFieldValues[n],o)));r[a]=this._simpleFieldValues[n];break;case"passthrough":r[a]=o;break;default:throw new Error(s.getMessages().objectField(a,s.getMessages().invalidObject))}}return r}get config(){return this._config}get shapeKeys(){return this._shapeKeys}get shapeKeysSet(){return this._shapeKeysSet}static create(e){return new VldObject({shape:e})}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.parseObjectValue(e)}parseKnownObject(e,s){return this.parseObjectValue(e,s)}parseTrustedKnownObject(e,s){return this.parseObjectValue(e,s,!0)}parseObjectValue(e,t,n=!1){if(this._canUseSimpleObjectFastPath)return this.parseSimpleObjectValue(e,t,n);const a={};let o="";try{for(let i=0;i<this._shapeKeys.length;i++){if(o=this._shapeKeys[i],n&&o===t&&"literal"===this._simpleFieldModes[i]){a[o]=this._simpleFieldValues[i];continue}const r=this._simpleFieldModes[i];if(void 0!==r){const t=e[o];switch(r){case"string":if("string"!=typeof t)throw new Error(s.getMessages().invalidString);a[o]=t;continue;case"number":if("number"!=typeof t||isNaN(t))throw new Error(s.getMessages().invalidNumber);a[o]=t;continue;case"boolean":if("boolean"!=typeof t)throw new Error(s.getMessages().invalidBoolean);a[o]=t;continue;case"bigint":if("bigint"!=typeof t)throw new Error(s.getMessages().invalidBigint);a[o]=t;continue;case"symbol":if("symbol"!=typeof t)throw new Error(s.getMessages().invalidSymbol);a[o]=t;continue;case"null":if(null!==t)throw new Error(this.getSimpleFieldError(r,void 0,t));a[o]=null;continue;case"undefinedValue":if(void 0!==t)throw new Error(s.getMessages().expectedUndefined);a[o]=void 0;continue;case"literal":if(t!==this._simpleFieldValues[i])throw new Error(this.getSimpleFieldError(r,this._simpleFieldValues[i],t));a[o]=this._simpleFieldValues[i];continue;case"passthrough":a[o]=t;continue}continue}const c=this.getFieldValidator(o,i);a[o]=this.parseCheckedField(c,this._validatorTypes[i],e[o])}}catch(e){if(e instanceof r.VldError)throw new r.VldError(e.issues.map(e=>({...e,path:e.path?[o,...e.path]:[o],message:s.getMessages().objectField(o,e.message.startsWith("Invalid field")?e.message.replace(/^Invalid field "[^"]+": /,""):e.message)})));const t=e instanceof Error?e.message:String(e);throw new r.VldError([{code:"invalid_type",path:[o],message:t.startsWith("Invalid field")?t:s.getMessages().objectField(o,t)}])}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(e);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}if(e.length>0)throw new Error(s.getMessages().unexpectedKeys(e))}if(this._config.passthrough)for(let s=0;s<t.length;s++){const r=t[s];this._shapeKeysSet.has(r)||i.isDangerousKey(r)||(a[r]=e[r])}if(this._config.catchall)for(let r=0;r<t.length;r++){const n=t[r];if(!this._shapeKeysSet.has(n)&&!i.isDangerousKey(n))try{a[n]=this._config.catchall.parse(e[n])}catch(e){throw new Error(s.getMessages().objectField(n,e.message))}}}return a}safeParse(t){if("object"!=typeof t||null===t||Array.isArray(t))return{success:!1,error:this.createSafeParseError(this._config.errorMessage||s.getMessages().invalidObject)};const n=t;if(this._canUseSimpleObjectFastPath)try{return{success:!0,data:this.parseSimpleObjectValue(n)}}catch{}if(this._canUseSafeParseFastPath)try{return{success:!0,data:this.parseObjectValue(n)}}catch{}const a={},o=[];for(let t=0;t<this._shapeKeys.length;t++){const i=this._shapeKeys[t],r=n[i],c=this._simpleFieldModes[t];if(void 0!==c){if("string"===c&&"string"==typeof r||"number"===c&&"number"==typeof r&&!isNaN(r)||"boolean"===c&&"boolean"==typeof r||"bigint"===c&&"bigint"==typeof r||"symbol"===c&&"symbol"==typeof r||"null"===c&&null===r||"undefinedValue"===c&&void 0===r||"literal"===c&&r===this._simpleFieldValues[t]||"passthrough"===c){a[i]="literal"===c?this._simpleFieldValues[t]:"null"===c?null:r;continue}o.push({code:"invalid_type",path:[i],message:s.getMessages().objectField(i,this.getSimpleFieldError(c,this._simpleFieldValues[t],r))});continue}let l;try{l=this.getFieldValidator(i,t)}catch(e){const s=this.createSafeParseError(e,i);o.push(...s.issues);continue}try{if(l instanceof e.VldBase)a[i]=this.parseCheckedField(l,this._validatorTypes[t],r);else{const e=l.safeParse(r);if(e.success)a[i]=e.data;else{const s=this.createSafeParseError(e.error,i);o.push(...s.issues)}}}catch(e){const s=this.createSafeParseError(e,i);o.push(...s.issues)}}if(this._config.strict||this._config.passthrough||this._config.catchall){const t=Object.keys(n);if(this._config.strict){const e=[];for(let s=0;s<t.length;s++){const i=t[s];this._shapeKeysSet.has(i)||e.push(i)}e.length>0&&o.push(...e.map(e=>({code:"unrecognized_keys",path:[e],message:s.getMessages().unexpectedKeys([e])})))}if(this._config.passthrough)for(let e=0;e<t.length;e++){const s=t[e];this._shapeKeysSet.has(s)||i.isDangerousKey(s)||(a[s]=n[s])}if(this._config.catchall){const s=this._config.catchall;for(let r=0;r<t.length;r++){const c=t[r];if(!this._shapeKeysSet.has(c)&&!i.isDangerousKey(c))try{if(s instanceof e.VldBase)a[c]=s.parse(n[c]);else{const e=s.safeParse(n[c]);if(e.success)a[c]=e.data;else{const s=this.createSafeParseError(e.error,c);o.push(...s.issues)}}}catch(e){const s=this.createSafeParseError(e,c);o.push(...s.issues)}}}}return o.length>0?{success:!1,error:new r.VldError(o)}:{success:!0,data:a}}encode(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.encodeObjectSync(e)}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}async encodeAsync(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this._config.errorMessage||s.getMessages().invalidObject);return this.encodeObjectAsync(e)}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:this.createSafeParseError(e.message)}}}encodeObjectSync(e){const s={};for(let t=0;t<this._shapeKeys.length;t++){const i=this._shapeKeys[t],r=this.getFieldValidator(i,t).encode(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(s[i]=r)}return this.encodeExtraKeysSync(e,s),s}async encodeObjectAsync(e){const s={};for(let t=0;t<this._shapeKeys.length;t++){const i=this._shapeKeys[t],r=await this.getFieldValidator(i,t).encodeAsync(e[i]);(void 0!==r||Object.prototype.hasOwnProperty.call(e,i))&&(s[i]=r)}const t=this.getEncodedExtraKeys(e);for(const r of t)i.isDangerousKey(r)||(this._config.catchall?s[r]=await this._config.catchall.encodeAsync(e[r]):this._config.passthrough&&(s[r]=e[r]));return s}getEncodedExtraKeys(e){const t=Object.keys(e).filter(e=>!this._shapeKeysSet.has(e));if(this._config.strict&&t.length>0)throw new Error(s.getMessages().unexpectedKeys(t));return t}encodeExtraKeysSync(e,s){for(const t of this.getEncodedExtraKeys(e))i.isDangerousKey(t)||(this._config.catchall?s[t]=this._config.catchall.encode(e[t]):this._config.passthrough&&(s[t]=e[t]))}strict(e){return new VldObject({...this._config,strict:!0,passthrough:!1,errorMessage:e})}passthrough(){return new VldObject({...this._config,strict:!1,passthrough:!0})}loose(){return this.passthrough()}strip(){const e={...this._config,strict:!1,passthrough:!1};return delete e.catchall,new VldObject(e)}partial(){const s={};for(const t in this._config.shape)s[t]=new e.VldOptional(this._config.shape[t]);return new VldObject({...this._config,shape:s})}deepPartial(){const s={};for(const t in this._config.shape){const i=this._config.shape[t];s[t]=i instanceof VldObject?new e.VldOptional(i.deepPartial()):new e.VldOptional(i)}return new VldObject({...this._config,shape:s})}pick(...e){const s={};let t=[];t=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?e.flat():Object.keys(e[0]).filter(s=>e[0][s]);for(const e of t)e in this._config.shape&&(s[e]=this._config.shape[e]);return new VldObject({...this._config,shape:s})}omit(...e){let s;s=1!==e.length||"object"!=typeof e[0]||null===e[0]||Array.isArray(e[0])?new Set(e.flat()):new Set(Object.keys(e[0]).filter(s=>e[0][s]));const t={};for(const e in this._config.shape)s.has(e)||(t[e]=this._config.shape[e]);return new VldObject({...this._config,shape:t})}extend(e){return new VldObject({...this._config,shape:{...this._config.shape,...e}})}merge(e){return new VldObject({...this._config,shape:{...this._config.shape,...e.config.shape}})}required(){const s={};for(const t in this._config.shape){const i=this._config.shape[t];if(i instanceof e.VldOptional){const e=i.baseValidator;if(!e||"function"!=typeof e.parse)throw new Error(`Invalid VldOptional structure for field "${t}": missing or invalid baseValidator`);s[t]=e}else s[t]=i}return new VldObject({...this._config,shape:s})}catchall(e){return new VldObject({...this._config,catchall:e,passthrough:!1})}get shape(){return this._config.shape}keyof(){const e=Object.keys(this._config.shape);if(0===e.length)throw new Error("Cannot create keyof enum from empty object");return t.VldEnum.create(e)}safeExtend(e){const t=new Set(Object.keys(this._config.shape)),i=Object.keys(e),r=[];for(const e of i)t.has(e)&&r.push(e);if(r.length>0)throw new Error(`safeExtend: ${s.getMessages().safeExtendOverlap(r)}`);return new VldObject({...this._config,shape:{...this._config.shape,...e}})}}exports.VldObject=VldObject;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs");require("../registry.cjs");class VldPromise{constructor(s){this.inner=s,this.validatorType=e.VLD_VALIDATOR_TYPES.PROMISE}get"~standard"(){return{version:1,vendor:"vld",validate:async e=>{const s=await this.safeParseAsync(e);return s.success?{value:s.data}:{issues:[{message:s.error.message}]}},types:void 0}}_isThenable(e){return null!==e&&"function"==typeof e.then}unwrap(){return this.inner}async parse(e){if(!this._isThenable(e))throw new Error("Expected a Promise value");const s=await Promise.resolve(e);return this.inner.parseAsync?this.inner.parseAsync(s):this.inner.parse(s)}parseAsync(e){return this.parse(e)}async safeParse(e){if(!this._isThenable(e))return{success:!1,error:new Error("Expected a Promise value")};try{const s=await Promise.resolve(e);if(this.inner.safeParseAsync)return await this.inner.safeParseAsync(s);const r=this.inner.safeParse(s);return r.success?{success:!0,data:r.data}:r}catch(e){return{success:!1,error:e instanceof Error?e:new Error(String(e))}}}safeParseAsync(e){return this.safeParse(e)}}exports.VldPromise=VldPromise,exports.promise=function(e){return new VldPromise(e)};
1
+ "use strict";var e=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs");class VldPromise extends e.VldBase{constructor(s){super(e.VLD_VALIDATOR_TYPES.PROMISE),this.inner=s}get"~standard"(){return{version:1,vendor:"vld",validate:async e=>{const s=await this.safeParse(e);return s.success?{value:s.data}:{issues:[{message:s.error.message}]}},types:void 0}}_isThenable(e){return null!==e&&"function"==typeof e.then}unwrap(){return this.inner}async parse(e){if(!this._isThenable(e))throw new Error("Expected a Promise value");const s=await Promise.resolve(e);return this.inner.parseAsync?this.inner.parseAsync(s):this.inner.parse(s)}parseAsync(e){return this.parse(e)}safeParse(s){return this._isThenable(s)?(async()=>{try{const e=await Promise.resolve(s);if(this.inner.safeParseAsync)return await this.inner.safeParseAsync(e);const r=this.inner.safeParse(e);return r.success?{success:!0,data:r.data}:r}catch(s){return{success:!1,error:e.ensureVldError(s)}}})():Promise.resolve({success:!1,error:e.ensureVldError("Expected a Promise value")})}safeParseAsync(e){return this.safeParse(e)}}exports.VldPromise=VldPromise,exports.promise=function(e){return new VldPromise(e)};
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/security-aXZVI7qW.cjs"),t=require("../chunks/errors-core-DKPohm9I.cjs");function a(e){return new t.VldError([{code:"invalid_object",path:[],message:e}])}require("../registry.cjs"),require("../locales/en.cjs");class VldRecord extends e.VldBase{constructor(r,s,t){super(e.VLD_VALIDATOR_TYPES.RECORD),this.valueValidator=r,this.keyValidator=s,this.errorMessage=t,this._simpleValueMode=this.getSimpleValueMode(r),this._simpleValue="literal"===this._simpleValueMode?r.literal:void 0}get valueSchema(){return this.valueValidator}get keySchema(){return this.keyValidator}static create(e,r){return new VldRecord(e,r)}getSimpleValueMode(r){if(!0===r.isSimple)switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleValueError(e){switch(this._simpleValueMode){case"string":return r.getMessages().invalidString;case"number":return r.getMessages().invalidNumber;case"boolean":return r.getMessages().invalidBoolean;case"bigint":return r.getMessages().invalidBigint;case"symbol":return r.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof e;case"undefinedValue":return r.getMessages().expectedUndefined;case"literal":return r.getMessages().literalExpected(JSON.stringify(this._simpleValue),JSON.stringify(e));default:return r.getMessages().invalidRecord}}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this.errorMessage||r.getMessages().invalidRecord);return this.parseKnownRecord(e)}parseKnownRecord(e){if(void 0!==this.keyValidator)return this.parseKeyedRecord(e);const t={},a=Object.keys(e),i=this._simpleValueMode;for(let o=0;o<a.length;o++){const n=a[o];if(s.isDangerousKey(n))continue;const l=e[n];if(void 0!==i)switch(i){case"string":if("string"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidString));t[n]=l;continue;case"number":if("number"!=typeof l||isNaN(l))throw new Error(r.getMessages().objectField(n,r.getMessages().invalidNumber));t[n]=l;continue;case"boolean":if("boolean"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidBoolean));t[n]=l;continue;case"bigint":if("bigint"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidBigint));t[n]=l;continue;case"symbol":if("symbol"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidSymbol));t[n]=l;continue;case"null":if(null!==l)throw new Error(r.getMessages().objectField(n,this.getSimpleValueError(l)));t[n]=null;continue;case"undefinedValue":if(void 0!==l)throw new Error(r.getMessages().objectField(n,r.getMessages().expectedUndefined));t[n]=void 0;continue;case"literal":if(l!==this._simpleValue)throw new Error(r.getMessages().objectField(n,this.getSimpleValueError(l)));t[n]=this._simpleValue;continue;case"passthrough":t[n]=l;continue}try{t[n]=this.valueValidator.parse(l)}catch(e){throw new Error(r.getMessages().objectField(n,e.message))}}return t}parseKeyedRecord(e){const a={},i=Reflect.ownKeys(e);for(const o of i){if(!Object.prototype.propertyIsEnumerable.call(e,o))continue;if("string"==typeof o&&s.isDangerousKey(o))continue;const i=this.keyValidator.safeParse(o);if(!i.success)throw new t.VldError([{code:"invalid_key",path:[String(o)],message:i.error.message}]);if("string"!=typeof i.data&&"number"!=typeof i.data&&"symbol"!=typeof i.data)throw new t.VldError([{code:"invalid_key",path:[String(o)],message:"Record key transform must return a property key"}]);if("string"!=typeof i.data||!s.isDangerousKey(i.data))try{a[i.data]=this.valueValidator.parse(e[o])}catch(e){throw new Error(r.getMessages().objectField(String(o),e.message))}}return a}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:a(e.message)}}}partial(){const e=this.valueValidator.optional();return new VldRecord(e,this.keyValidator)}loose(){return new VldLooseRecord(this.valueValidator,this.keyValidator)}}class VldLooseRecord extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.RECORD),this.valueValidator=r,this.keyValidator=s}get valueSchema(){return this.valueValidator}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(r.getMessages().invalidRecord);const t={},a=e;for(const e of Reflect.ownKeys(a)){if(!Object.prototype.propertyIsEnumerable.call(a,e))continue;if("string"==typeof e&&s.isDangerousKey(e))continue;const r=this.keyValidator?.safeParse(e);if(r&&!r.success)continue;const i=r?.data??e;if("string"!=typeof i&&"number"!=typeof i&&"symbol"!=typeof i)continue;if("string"==typeof i&&s.isDangerousKey(i))continue;const o=this.valueValidator.safeParse(a[e]);o.success&&(t[i]=o.data)}return t}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:a(e.message)}}}partial(){const e=this.valueValidator.optional();return new VldLooseRecord(e,this.keyValidator)}loose(){return this}}exports.VldRecord=VldRecord;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/security-aXZVI7qW.cjs"),t=require("../chunks/errors-core-DrydF46s.cjs");function a(e){return new t.VldError([{code:"invalid_object",path:[],message:e}])}require("../registry.cjs"),require("../locales/en.cjs");class VldRecord extends e.VldBase{constructor(r,s,t){super(e.VLD_VALIDATOR_TYPES.RECORD),this.valueValidator=r,this.keyValidator=s,this.errorMessage=t,this._simpleValueMode=this.getSimpleValueMode(r),this._simpleValue="literal"===this._simpleValueMode?r.literal:void 0}get valueSchema(){return this.valueValidator}get keySchema(){return this.keyValidator}get valueType(){return this.valueValidator}get keyType(){return this.keyValidator}static create(e,r){return new VldRecord(e,r)}getSimpleValueMode(r){if(!0===r.isSimple)switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleValueError(e){switch(this._simpleValueMode){case"string":return r.getMessages().invalidString;case"number":return r.getMessages().invalidNumber;case"boolean":return r.getMessages().invalidBoolean;case"bigint":return r.getMessages().invalidBigint;case"symbol":return r.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof e;case"undefinedValue":return r.getMessages().expectedUndefined;case"literal":return r.getMessages().literalExpected(JSON.stringify(this._simpleValue),JSON.stringify(e));default:return r.getMessages().invalidRecord}}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(this.errorMessage||r.getMessages().invalidRecord);return this.parseKnownRecord(e)}parseKnownRecord(e){if(void 0!==this.keyValidator)return this.parseKeyedRecord(e);const t={},a=Object.keys(e),i=this._simpleValueMode;for(let o=0;o<a.length;o++){const n=a[o];if(s.isDangerousKey(n))continue;const l=e[n];if(void 0!==i)switch(i){case"string":if("string"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidString));t[n]=l;continue;case"number":if("number"!=typeof l||isNaN(l))throw new Error(r.getMessages().objectField(n,r.getMessages().invalidNumber));t[n]=l;continue;case"boolean":if("boolean"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidBoolean));t[n]=l;continue;case"bigint":if("bigint"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidBigint));t[n]=l;continue;case"symbol":if("symbol"!=typeof l)throw new Error(r.getMessages().objectField(n,r.getMessages().invalidSymbol));t[n]=l;continue;case"null":if(null!==l)throw new Error(r.getMessages().objectField(n,this.getSimpleValueError(l)));t[n]=null;continue;case"undefinedValue":if(void 0!==l)throw new Error(r.getMessages().objectField(n,r.getMessages().expectedUndefined));t[n]=void 0;continue;case"literal":if(l!==this._simpleValue)throw new Error(r.getMessages().objectField(n,this.getSimpleValueError(l)));t[n]=this._simpleValue;continue;case"passthrough":t[n]=l;continue}try{t[n]=this.valueValidator.parse(l)}catch(e){throw new Error(r.getMessages().objectField(n,e.message))}}return t}parseKeyedRecord(e){const a={},i=Reflect.ownKeys(e);for(const o of i){if(!Object.prototype.propertyIsEnumerable.call(e,o))continue;if("string"==typeof o&&s.isDangerousKey(o))continue;const i=this.keyValidator.safeParse(o);if(!i.success)throw new t.VldError([{code:"invalid_key",path:[String(o)],message:i.error.message}]);if("string"!=typeof i.data&&"number"!=typeof i.data&&"symbol"!=typeof i.data)throw new t.VldError([{code:"invalid_key",path:[String(o)],message:"Record key transform must return a property key"}]);if("string"!=typeof i.data||!s.isDangerousKey(i.data))try{a[i.data]=this.valueValidator.parse(e[o])}catch(e){throw new Error(r.getMessages().objectField(String(o),e.message))}}return a}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:a(e.message)}}}partial(){const e=this.valueValidator.optional();return new VldRecord(e,this.keyValidator)}loose(){return new VldLooseRecord(this.valueValidator,this.keyValidator)}}class VldLooseRecord extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.RECORD),this.valueValidator=r,this.keyValidator=s}get valueSchema(){return this.valueValidator}parse(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new Error(r.getMessages().invalidRecord);const t={},a=e;for(const e of Reflect.ownKeys(a)){if(!Object.prototype.propertyIsEnumerable.call(a,e))continue;if("string"==typeof e&&s.isDangerousKey(e))continue;const r=this.keyValidator?.safeParse(e);if(r&&!r.success)continue;const i=r?.data??e;if("string"!=typeof i&&"number"!=typeof i&&"symbol"!=typeof i)continue;if("string"==typeof i&&s.isDangerousKey(i))continue;const o=this.valueValidator.safeParse(a[e]);o.success&&(t[i]=o.data)}return t}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:a(e.message)}}}partial(){const e=this.valueValidator.optional();return new VldLooseRecord(e,this.keyValidator)}loose(){return this}}exports.VldRecord=VldRecord;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),t=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldSet extends e.VldBase{constructor(r,t){super(e.VLD_VALIDATOR_TYPES.SET),this.itemValidator=r,this.errorMessage=t,this._simpleItemMode=this.getSimpleItemMode(r),this._simpleItemValue="literal"===this._simpleItemMode?r.literal:void 0}get itemSchema(){return this.itemValidator}static create(e){return new VldSet(e)}getSimpleItemMode(r){if(!0===r.isSimple)switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e){switch(this._simpleItemMode){case"string":return r.getMessages().invalidString;case"number":return r.getMessages().invalidNumber;case"boolean":return r.getMessages().invalidBoolean;case"bigint":return r.getMessages().invalidBigint;case"symbol":return r.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof e;case"undefinedValue":return r.getMessages().expectedUndefined;case"literal":return r.getMessages().literalExpected(JSON.stringify(this._simpleItemValue),JSON.stringify(e));default:return r.getMessages().invalidSet}}parse(e){if(!(e instanceof Set))throw new Error(this.errorMessage||r.getMessages().invalidSet);return this.parseKnownSet(e)}parseKnownSet(e){const r=new Set,t=this._simpleItemMode;if("string"===t){for(const t of e){if("string"!=typeof t)throw new Error(this.getSimpleItemError(t));r.add(t)}return r}if("number"===t){for(const t of e){if("number"!=typeof t||isNaN(t))throw new Error(this.getSimpleItemError(t));r.add(t)}return r}if("boolean"===t){for(const t of e){if("boolean"!=typeof t)throw new Error(this.getSimpleItemError(t));r.add(t)}return r}if("bigint"===t){for(const t of e){if("bigint"!=typeof t)throw new Error(this.getSimpleItemError(t));r.add(t)}return r}if("symbol"===t){for(const t of e){if("symbol"!=typeof t)throw new Error(this.getSimpleItemError(t));r.add(t)}return r}if("null"===t){for(const t of e){if(null!==t)throw new Error(this.getSimpleItemError(t));r.add(null)}return r}if("undefinedValue"===t){for(const t of e){if(void 0!==t)throw new Error(this.getSimpleItemError(t));r.add(void 0)}return r}if("literal"===t){for(const t of e){if(t!==this._simpleItemValue)throw new Error(this.getSimpleItemError(t));r.add(this._simpleItemValue)}return r}if("passthrough"===t){for(const t of e)r.add(t);return r}for(const t of e)try{r.add(this.itemValidator.parse(t))}catch(e){throw new Error(e.message)}return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(r=e.message,new t.VldError([{code:"invalid_type",path:[],message:r}]))}}var r}}exports.VldSet=VldSet;
1
+ "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldSet extends e.VldBase{constructor(t,r,s=[]){super(e.VLD_VALIDATOR_TYPES.SET),this.itemValidator=t,this.errorMessage=r,this._checks=s,this._simpleItemMode=this.getSimpleItemMode(t),this._simpleItemValue="literal"===this._simpleItemMode?t.literal:void 0}get itemSchema(){return this.itemValidator}static create(e){return new VldSet(e)}getSimpleItemMode(t){if(!0===t.isSimple)switch(t.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e){switch(this._simpleItemMode){case"string":return t.getMessages().invalidString;case"number":return t.getMessages().invalidNumber;case"boolean":return t.getMessages().invalidBoolean;case"bigint":return t.getMessages().invalidBigint;case"symbol":return t.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof e;case"undefinedValue":return t.getMessages().expectedUndefined;case"literal":return t.getMessages().literalExpected(JSON.stringify(this._simpleItemValue),JSON.stringify(e));default:return t.getMessages().invalidSet}}parse(e){if(!(e instanceof Set))throw new Error(this.errorMessage||t.getMessages().invalidSet);return this.parseKnownSet(e)}parseKnownSet(e){const t=new Set,r=this._simpleItemMode;if("string"===r)for(const r of e){if("string"!=typeof r)throw new Error(this.getSimpleItemError(r));t.add(r)}else if("number"===r)for(const r of e){if("number"!=typeof r||isNaN(r))throw new Error(this.getSimpleItemError(r));t.add(r)}else if("boolean"===r)for(const r of e){if("boolean"!=typeof r)throw new Error(this.getSimpleItemError(r));t.add(r)}else if("bigint"===r)for(const r of e){if("bigint"!=typeof r)throw new Error(this.getSimpleItemError(r));t.add(r)}else if("symbol"===r)for(const r of e){if("symbol"!=typeof r)throw new Error(this.getSimpleItemError(r));t.add(r)}else if("null"===r)for(const r of e){if(null!==r)throw new Error(this.getSimpleItemError(r));t.add(null)}else if("undefinedValue"===r)for(const r of e){if(void 0!==r)throw new Error(this.getSimpleItemError(r));t.add(void 0)}else if("literal"===r)for(const r of e){if(r!==this._simpleItemValue)throw new Error(this.getSimpleItemError(r));t.add(this._simpleItemValue)}else if("passthrough"===r)for(const r of e)t.add(r);else for(const r of e)try{t.add(this.itemValidator.parse(r))}catch(e){throw new Error(e.message)}for(const e of this._checks)if(!e.fn(t))throw new Error(e.message);return t}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(t=e.message,new r.VldError([{code:"invalid_type",path:[],message:t}]))}}var t}min(e,t){return new VldSet(this.itemValidator,this.errorMessage,[...this._checks,{fn:t=>t.size>=e,message:t||`Set must contain at least ${e} elements`}])}max(e,t){return new VldSet(this.itemValidator,this.errorMessage,[...this._checks,{fn:t=>t.size<=e,message:t||`Set must contain at most ${e} elements`}])}size(e,t){return new VldSet(this.itemValidator,this.errorMessage,[...this._checks,{fn:t=>t.size===e,message:t||`Set must contain exactly ${e} elements`}])}nonempty(e){return this.min(1,e||"Set cannot be empty")}}exports.VldSet=VldSet;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs");require("../registry.cjs"),require("../locales/en.cjs");const s=["true","1","yes","on","y","enabled"],r=["false","0","no","off","n","disabled"];class VldStringBool extends e.VldBase{constructor(t){super(e.VLD_VALIDATOR_TYPES.STRING_BOOL),this.options=t,this.truthyValues=t.truthy??s,this.falsyValues=t.falsy??r;const i=this.normalizeValues(this.truthyValues),n=this.normalizeValues(this.falsyValues);this.normalizedTruthySet=new Set(i),this.normalizedFalsySet=new Set(n),this.validValuesText=[...i,...n].join(", ")}static create(e={}){return new VldStringBool(e)}normalizeValue(e){return this.options.caseSensitive?e:e.toLowerCase()}normalizeValues(e){return this.options.caseSensitive?e:e.map(e=>e.toLowerCase())}parse(e){if("string"!=typeof e){if("boolean"==typeof e)return e;throw new Error(t.getMessages().stringExpected(typeof e,"string"))}const s=this.normalizeValue(e);if(this.normalizedTruthySet.has(s))return!0;if(this.normalizedFalsySet.has(s))return!1;throw new Error(t.getMessages().stringBoolExpected(this.validValuesText,e))}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e}}}withTruthy(e){return new VldStringBool({...this.options,truthy:e})}withFalsy(e){return new VldStringBool({...this.options,falsy:e})}caseSensitive(){return new VldStringBool({...this.options,caseSensitive:!0})}caseInsensitive(){return new VldStringBool({...this.options,caseSensitive:!1})}}exports.VldStringBool=VldStringBool;
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs"),require("../locales/en.cjs");const t=["true","1","yes","on","y","enabled"],r=["false","0","no","off","n","disabled"];class VldStringBool extends e.VldBase{constructor(s){super(e.VLD_VALIDATOR_TYPES.STRING_BOOL),this.options=s,this.truthyValues=s.truthy??t,this.falsyValues=s.falsy??r;const i=this.normalizeValues(this.truthyValues),n=this.normalizeValues(this.falsyValues);this.normalizedTruthySet=new Set(i),this.normalizedFalsySet=new Set(n),this.validValuesText=[...i,...n].join(", ")}static create(e={}){return new VldStringBool(e)}normalizeValue(e){return this.options.caseSensitive?e:e.toLowerCase()}normalizeValues(e){return this.options.caseSensitive?e:e.map(e=>e.toLowerCase())}parse(e){if("string"!=typeof e){if("boolean"==typeof e)return e;throw new Error(s.getMessages().stringExpected(typeof e,"string"))}const t=this.normalizeValue(e);if(this.normalizedTruthySet.has(t))return!0;if(this.normalizedFalsySet.has(t))return!1;throw new Error(s.getMessages().stringBoolExpected(this.validValuesText,e))}safeParse(s){try{return{success:!0,data:this.parse(s)}}catch(s){return{success:!1,error:e.ensureVldError(s)}}}withTruthy(e){return new VldStringBool({...this.options,truthy:e})}withFalsy(e){return new VldStringBool({...this.options,falsy:e})}caseSensitive(){return new VldStringBool({...this.options,caseSensitive:!0})}caseInsensitive(){return new VldStringBool({...this.options,caseSensitive:!1})}}exports.VldStringBool=VldStringBool;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),a=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function d(e,t){return e.lastIndex=0,e.test(t)}function s(e,t){return new RegExp(`^[A-Za-z0-9+/]{${e}}${t}$`)}function o(e){return new RegExp(`^[A-Za-z0-9_-]{${e}}$`)}function n(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"!=typeof e.precision?`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`:-1===e.precision?t:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`}function c(e){return void 0===e?/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/:new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)}const u={cuid:/^[cC][0-9a-z]{6,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,xid:/^[0-9a-vA-V]{20}$/,ksuid:/^[A-Za-z0-9]{27}$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,duration:/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,extendedDuration:/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,guid:/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,creditCard:/^\d(?:[ -]?\d){11,18}$/,uuid:c,uuid4:c(4),uuid6:c(6),uuid7:c(7),email:/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+.-]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$/,html5Email:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,rfc5322Email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/,unicodeEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,idnEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,browserEmail:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,emoji:()=>/^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mac:function(e=":"){const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^(?:[0-9A-F]{2}${t}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${t}){5}[0-9a-f]{2}$`)},cidrv4:/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cidrv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,base64url:/^[A-Za-z0-9_-]*$/,hostname:/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,domain:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,httpProtocol:/^https?$/,e164:/^\+[1-9]\d{6,14}$/,date:new RegExp(`^${i}$`),time:function(e={}){return new RegExp(`^${n(e)}$`)},datetime:function(e={}){const t=["Z"];return e.local&&t.push(""),e.offset&&t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),new RegExp(`^${i}T${n(e)}(?:${t.join("|")})$`)},string:function(e){const t=e?`[\\s\\S]{${e.minimum??0},${e.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},bigint:/^-?\d+n?$/,integer:/^-?\d+$/,number:/^-?\d+(?:\.\d+)?$/,boolean:/^(?:true|false)$/i,null:/^null$/i,undefined:/^undefined$/i,lowercase:/^[^A-Z]*$/,uppercase:/^[^a-z]*$/,hex:/^[0-9a-fA-F]*$/,md5_hex:/^[0-9a-fA-F]{32}$/,md5_base64:s(22,"=="),md5_base64url:o(22),sha1_hex:/^[0-9a-fA-F]{40}$/,sha1_base64:s(27,"="),sha1_base64url:o(27),sha256_hex:/^[0-9a-fA-F]{64}$/,sha256_base64:s(43,"="),sha256_base64url:o(43),sha384_hex:/^[0-9a-fA-F]{96}$/,sha384_base64:s(64,""),sha384_base64url:o(64),sha512_hex:/^[0-9a-fA-F]{128}$/,sha512_base64:s(86,"=="),sha512_base64url:o(86),jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,httpUrl:/^https?:\/\/[^\s/$.?#].[^\s]*$/,md5:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i};class VldStringFormat extends e.VldBase{constructor(t,r,a,i=e=>e,d){super(e.VLD_VALIDATOR_TYPES.STRING_FORMAT),this._format=t,this._validator=r,this._errorMessage=a,this._normalize=i,this._patternSource=d}static create(e,t,r,a,i){return new VldStringFormat(e,t,r,a,i)}_createFormatIssue(){const e={code:"invalid_format",path:[],origin:"string",format:this._format,message:this._errorMessage||`Invalid ${this._format}`};return this._patternSource&&(e.pattern=this._patternSource),new a.VldError([e])}parse(e){if("string"!=typeof e)throw new a.VldError([a.createInvalidTypeIssue("string",a.getTypeName(e),t.getMessages().invalidString)]);if(!this._validator(e))throw this._createFormatIssue();return this._normalize(e)}safeParse(e){return"string"!=typeof e?{success:!1,error:new a.VldError([a.createInvalidTypeIssue("string",a.getTypeName(e),t.getMessages().invalidString)])}:this._validator(e)?{success:!0,data:this._normalize(e)}:{success:!1,error:this._createFormatIssue()}}}const l=/[ -]/g;function m(e){return!!u.creditCard.test(e)&&function(e){let t=0,r=!1;for(let a=e.length-1;a>=0;a--){let i=e.charCodeAt(a)-48;r&&(i*=2,i>9&&(i-=9)),t+=i,r=!r}return t%10==0}(e.replace(l,""))}const f={ZodISODate:VldStringFormat,ZodISODateTime:VldStringFormat,ZodISODuration:VldStringFormat,ZodISOTime:VldStringFormat,date:()=>VldStringFormat.create("date",e=>d(u.date,e)),time:(e={})=>{const t=u.time(e);return VldStringFormat.create("time",e=>d(t,e))},datetime:(e={})=>{const t=u.datetime(e);return VldStringFormat.create("datetime",e=>d(t,e))},dateTime:(e={local:!0})=>{const t=u.datetime(e);return VldStringFormat.create("datetime",e=>d(t,e))},duration:()=>VldStringFormat.create("duration",e=>d(u.duration,e))};exports.VldStringFormat=VldStringFormat,exports.base64=()=>VldStringFormat.create("base64",e=>d(u.base64,e)),exports.base64url=()=>VldStringFormat.create("base64url",e=>d(u.base64url,e)),exports.cidrv4=()=>VldStringFormat.create("cidrv4",e=>d(u.cidrv4,e)),exports.cidrv6=()=>VldStringFormat.create("cidrv6",e=>{const t=e.lastIndexOf("/");if(t<=0)return!1;const a=Number(e.slice(t+1));return Number.isInteger(a)&&a>=0&&a<=128&&r.isValidIPv6(e.slice(0,t))}),exports.creditCard=e=>VldStringFormat.create("credit_card",m,e?.message,void 0,u.creditCard.source),exports.cuid=()=>VldStringFormat.create("cuid",e=>d(u.cuid,e)),exports.cuid2=()=>VldStringFormat.create("cuid2",e=>d(u.cuid2,e)),exports.e164=()=>VldStringFormat.create("e164",e=>d(u.e164,e)),exports.email=e=>{const t=e?.pattern??u.email;return VldStringFormat.create("email",e=>d(t,e),void 0,void 0,t.source)},exports.emoji=()=>VldStringFormat.create("emoji",e=>d(u.emoji(),e)),exports.guid=()=>VldStringFormat.create("guid",e=>d(u.guid,e)),exports.hash=e=>VldStringFormat.create("hash",t=>u[e]?.test(t)??!1,`Invalid ${e} hash`),exports.hex=()=>VldStringFormat.create("hex",e=>d(u.hex,e)),exports.hostname=()=>VldStringFormat.create("hostname",e=>d(u.hostname,e)),exports.httpUrl=()=>VldStringFormat.create("httpUrl",e=>d(u.httpUrl,e)),exports.ipv4=()=>VldStringFormat.create("ipv4",e=>d(u.ipv4,e)),exports.ipv6=()=>VldStringFormat.create("ipv6",e=>d(u.ipv6,e)),exports.isValidCreditCard=m,exports.iso=f,exports.jwt=()=>VldStringFormat.create("jwt",e=>d(u.jwt,e)),exports.ksuid=()=>VldStringFormat.create("ksuid",e=>d(u.ksuid,e)),exports.mac=e=>{const t=u.mac(e?.delimiter);return VldStringFormat.create("mac",e=>d(t,e))},exports.nanoid=()=>VldStringFormat.create("nanoid",e=>d(u.nanoid,e)),exports.regexes=u,exports.stringFormat=(e,t)=>{const r=t instanceof RegExp?e=>d(t,e):t;return VldStringFormat.create(e,r)},exports.ulid=()=>VldStringFormat.create("ulid",e=>d(u.ulid,e)),exports.url=(e={})=>VldStringFormat.create("url",t=>{const r=(e=>{try{return new URL(e)}catch{return}})(t);return void 0!==r&&(!e.hostname||d(e.hostname,r.hostname))&&(!e.protocol||d(e.protocol,r.protocol.slice(0,-1)))},void 0,e.normalize?e=>new URL(e).href:void 0),exports.uuid=e=>{const t=c(void 0===e?.version?void 0:Number(e.version.slice(1)));return VldStringFormat.create("uuid",e=>d(t,e))},exports.uuidv4=()=>VldStringFormat.create("uuid",e=>d(u.uuid4,e)),exports.uuidv6=()=>VldStringFormat.create("uuid",e=>d(u.uuid6,e)),exports.uuidv7=()=>VldStringFormat.create("uuid",e=>d(u.uuid7,e)),exports.xid=()=>VldStringFormat.create("xid",e=>d(u.xid,e));
1
+ "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),a=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))";function d(e,t){return e.lastIndex=0,e.test(t)}function s(e,t){return new RegExp(`^[A-Za-z0-9+/]{${e}}${t}$`)}function o(e){return new RegExp(`^[A-Za-z0-9_-]{${e}}$`)}function n(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"!=typeof e.precision?`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`:-1===e.precision?t:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`}function c(e){return void 0===e?/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/:new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)}const u={cuid:/^[cC][0-9a-z]{6,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,xid:/^[0-9a-vA-V]{20}$/,ksuid:/^[A-Za-z0-9]{27}$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,duration:/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,extendedDuration:/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,guid:/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,creditCard:/^\d(?:[ -]?\d){11,18}$/,uuid:c,uuid4:c(4),uuid6:c(6),uuid7:c(7),email:/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+.-]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9-]*\.)+[A-Za-z]{2,}$/,html5Email:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,rfc5322Email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/,unicodeEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,idnEmail:/^[^\s@"]{1,64}@[^\s@]{1,255}$/u,browserEmail:/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,emoji:()=>/^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mac:function(e=":"){const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`^(?:[0-9A-F]{2}${t}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${t}){5}[0-9a-f]{2}$`)},cidrv4:/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,cidrv6:/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,base64url:/^[A-Za-z0-9_-]*$/,hostname:/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,domain:/^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/,httpProtocol:/^https?$/,e164:/^\+[1-9]\d{6,14}$/,date:new RegExp(`^${i}$`),time:function(e={}){return new RegExp(`^${n(e)}$`)},datetime:function(e={}){const t=["Z"];return e.local&&t.push(""),e.offset&&t.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)"),new RegExp(`^${i}T${n(e)}(?:${t.join("|")})$`)},string:function(e){const t=e?`[\\s\\S]{${e.minimum??0},${e.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},bigint:/^-?\d+n?$/,integer:/^-?\d+$/,number:/^-?\d+(?:\.\d+)?$/,boolean:/^(?:true|false)$/i,null:/^null$/i,undefined:/^undefined$/i,lowercase:/^[^A-Z]*$/,uppercase:/^[^a-z]*$/,hex:/^[0-9a-fA-F]*$/,md5_hex:/^[0-9a-fA-F]{32}$/,md5_base64:s(22,"=="),md5_base64url:o(22),sha1_hex:/^[0-9a-fA-F]{40}$/,sha1_base64:s(27,"="),sha1_base64url:o(27),sha256_hex:/^[0-9a-fA-F]{64}$/,sha256_base64:s(43,"="),sha256_base64url:o(43),sha384_hex:/^[0-9a-fA-F]{96}$/,sha384_base64:s(64,""),sha384_base64url:o(64),sha512_hex:/^[0-9a-fA-F]{128}$/,sha512_base64:s(86,"=="),sha512_base64url:o(86),jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,httpUrl:/^https?:\/\/[^\s/$.?#].[^\s]*$/,md5:/^[a-f0-9]{32}$/i,sha1:/^[a-f0-9]{40}$/i,sha256:/^[a-f0-9]{64}$/i,sha384:/^[a-f0-9]{96}$/i,sha512:/^[a-f0-9]{128}$/i};class VldStringFormat extends e.VldBase{constructor(t,r,a,i=e=>e,d){super(e.VLD_VALIDATOR_TYPES.STRING_FORMAT),this._format=t,this._validator=r,this._errorMessage=a,this._normalize=i,this._patternSource=d}static create(e,t,r,a,i){return new VldStringFormat(e,t,r,a,i)}_createFormatIssue(){const e={code:"invalid_format",path:[],origin:"string",format:this._format,message:this._errorMessage||`Invalid ${this._format}`};return this._patternSource&&(e.pattern=this._patternSource),new a.VldError([e])}parse(e){if("string"!=typeof e)throw new a.VldError([a.createInvalidTypeIssue("string",a.getTypeName(e),t.getMessages().invalidString)]);if(!this._validator(e))throw this._createFormatIssue();return this._normalize(e)}safeParse(e){return"string"!=typeof e?{success:!1,error:new a.VldError([a.createInvalidTypeIssue("string",a.getTypeName(e),t.getMessages().invalidString)])}:this._validator(e)?{success:!0,data:this._normalize(e)}:{success:!1,error:this._createFormatIssue()}}}const l=/[ -]/g;function m(e){return!!u.creditCard.test(e)&&function(e){let t=0,r=!1;for(let a=e.length-1;a>=0;a--){let i=e.charCodeAt(a)-48;r&&(i*=2,i>9&&(i-=9)),t+=i,r=!r}return t%10==0}(e.replace(l,""))}const f={ZodISODate:VldStringFormat,ZodISODateTime:VldStringFormat,ZodISODuration:VldStringFormat,ZodISOTime:VldStringFormat,date:()=>VldStringFormat.create("date",e=>d(u.date,e)),time:(e={})=>{const t=u.time(e);return VldStringFormat.create("time",e=>d(t,e))},datetime:(e={})=>{const t=u.datetime(e);return VldStringFormat.create("datetime",e=>d(t,e))},dateTime:(e={local:!0})=>{const t=u.datetime(e);return VldStringFormat.create("datetime",e=>d(t,e))},duration:()=>VldStringFormat.create("duration",e=>d(u.duration,e))};exports.VldStringFormat=VldStringFormat,exports.base64=()=>VldStringFormat.create("base64",e=>d(u.base64,e)),exports.base64url=()=>VldStringFormat.create("base64url",e=>d(u.base64url,e)),exports.cidrv4=()=>VldStringFormat.create("cidrv4",e=>d(u.cidrv4,e)),exports.cidrv6=()=>VldStringFormat.create("cidrv6",e=>{const t=e.lastIndexOf("/");if(t<=0)return!1;const a=Number(e.slice(t+1));return Number.isInteger(a)&&a>=0&&a<=128&&r.isValidIPv6(e.slice(0,t))}),exports.creditCard=e=>VldStringFormat.create("credit_card",m,e?.message,void 0,u.creditCard.source),exports.cuid=()=>VldStringFormat.create("cuid",e=>d(u.cuid,e)),exports.cuid2=()=>VldStringFormat.create("cuid2",e=>d(u.cuid2,e)),exports.e164=()=>VldStringFormat.create("e164",e=>d(u.e164,e)),exports.email=e=>{const t=e?.pattern??u.email;return VldStringFormat.create("email",e=>d(t,e),void 0,void 0,t.source)},exports.emoji=()=>VldStringFormat.create("emoji",e=>d(u.emoji(),e)),exports.guid=()=>VldStringFormat.create("guid",e=>d(u.guid,e)),exports.hash=e=>VldStringFormat.create("hash",t=>u[e]?.test(t)??!1,`Invalid ${e} hash`),exports.hex=()=>VldStringFormat.create("hex",e=>d(u.hex,e)),exports.hostname=()=>VldStringFormat.create("hostname",e=>d(u.hostname,e)),exports.httpUrl=()=>VldStringFormat.create("httpUrl",e=>d(u.httpUrl,e)),exports.ipv4=()=>VldStringFormat.create("ipv4",e=>d(u.ipv4,e)),exports.ipv6=()=>VldStringFormat.create("ipv6",e=>d(u.ipv6,e)),exports.isValidCreditCard=m,exports.iso=f,exports.jwt=()=>VldStringFormat.create("jwt",e=>d(u.jwt,e)),exports.ksuid=()=>VldStringFormat.create("ksuid",e=>d(u.ksuid,e)),exports.mac=e=>{const t=u.mac(e?.delimiter);return VldStringFormat.create("mac",e=>d(t,e))},exports.nanoid=()=>VldStringFormat.create("nanoid",e=>d(u.nanoid,e)),exports.regexes=u,exports.stringFormat=(e,t)=>{const r=t instanceof RegExp?e=>d(t,e):t;return VldStringFormat.create(e,r)},exports.ulid=()=>VldStringFormat.create("ulid",e=>d(u.ulid,e)),exports.url=(e={})=>VldStringFormat.create("url",t=>{const r=(e=>{try{return new URL(e)}catch{return}})(t);return void 0!==r&&(!e.hostname||d(e.hostname,r.hostname))&&(!e.protocol||d(e.protocol,r.protocol.slice(0,-1)))},void 0,e.normalize?e=>new URL(e).href:void 0),exports.uuid=e=>{const t=c(void 0===e?.version?void 0:Number(e.version.slice(1)));return VldStringFormat.create("uuid",e=>d(t,e))},exports.uuidv4=()=>VldStringFormat.create("uuid",e=>d(u.uuid4,e)),exports.uuidv6=()=>VldStringFormat.create("uuid",e=>d(u.uuid6,e)),exports.uuidv7=()=>VldStringFormat.create("uuid",e=>d(u.uuid7,e)),exports.xid=()=>VldStringFormat.create("xid",e=>d(u.xid,e));
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),t=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i={email:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,url:/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,uuidv4:/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv6:/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv7:/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,emoji:/^(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*$/u,base64:/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,base64url:/^[A-Za-z0-9_-]*$/,jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,nanoid:/^[A-Za-z0-9_-]{21}$/,cuid:/^c[^\s-]{8,}$/i,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,cidrv4:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/,cidrv6:/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^(?:[0-9a-fA-F]{1,4}:){1,7}:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e164:/^\+[1-9]\d{1,14}$/,xid:/^[A-HJKMNP-TV-Z0-9]{20}$/,guid:/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i,ksuid:/^[0-9A-Za-z]{27}$/,isoDate:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,isoTime:/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,isoDateTime:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z?$/,isoDuration:/^-?P(?!$)(?:\d+(?:\.\d+)?Y)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?W)?(?:\d+(?:\.\d+)?D)?(?:T(?=\d)(?:\d+(?:\.\d+)?H)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?S)?)?$/};class VldString extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.STRING),this.config={checks:s?.checks||[],transforms:s?.transforms||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._transforms=this.config.transforms,this._isSimple=0===this._checks.length&&0===this._transforms.length,this._checkMetas=this.config.checkMetas}static create(){return new VldString}get isSimple(){return this._isSimple}_createCheckIssue(e){switch(e.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:e.value,inclusive:!0,message:e.message||`Too small: expected string to have >=${e.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:e.value,inclusive:!0,message:e.message||`Too big: expected string to have <=${e.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:e.value,message:e.message||`Too big: expected string to have exactly ${e.value} characters`};case"format":{const s={code:"invalid_format",path:[],origin:"string",format:e.format,message:e.message||`Invalid ${e.format}`};return void 0!==e.pattern&&(s.pattern=e.pattern),s}case"regex":{const s={code:"invalid_format",path:[],origin:"string",format:"regex",message:e.message||"Invalid string: does not match pattern"};return void 0!==e.pattern&&(s.pattern=e.pattern),s}default:return{code:"custom",path:[],message:e.message||"Invalid string"}}}_runChecks(e){const s=this._checks,r=this._checkMetas;for(let t=0;t<s.length;t++)if(!s[t](e))return r?.[t]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(e){if("string"!=typeof e)throw new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)]);return this._isSimple?e:this.parseKnownString(e)}parseKnownString(e){if(this._isSimple)return e;const s=this._transforms;let r=e;switch(s.length){case 0:break;case 1:r=s[0](r);break;case 2:r=s[1](s[0](r));break;case 3:r=s[2](s[1](s[0](r)));break;default:for(let e=0;e<s.length;e++)r=s[e](r)}const i=this._runChecks(r);if(i)throw new t.VldError([this._createCheckIssue(i)]);return r}safeParse(e){if("string"!=typeof e)return{success:!1,error:new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:e};try{return{success:!0,data:this.parseKnownString(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:(s=e.message,new t.VldError([{code:"invalid_string",path:[],message:s}]))}}var s}min(r,t){return new VldString({checks:[...this.config.checks,e=>e.length>=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMin(r)),jsonSchema:{...this.config.jsonSchema,minLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMin(r))}]})}max(r,t){return new VldString({checks:[...this.config.checks,e=>e.length<=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMax(r)),jsonSchema:{...this.config.jsonSchema,maxLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMax(r))}]})}length(r,t){return new VldString({checks:[...this.config.checks,e=>e.length===r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringLength(r)),jsonSchema:{...this.config.jsonSchema,exactLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringLength(r))}]})}email(r){return new VldString({checks:[...this.config.checks,e=>i.email.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:e.resolveErrorMessage(r,s.getMessages().stringEmail)}]})}url(r){return new VldString({checks:[...this.config.checks,e=>i.url.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:e.resolveErrorMessage(r,s.getMessages().stringUrl)}]})}uuid(r){return new VldString({checks:[...this.config.checks,e=>i.uuid.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:e.resolveErrorMessage(r,s.getMessages().stringUuid)}]})}format(s,r,t){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,`Invalid ${r}`),jsonSchema:{...this.config.jsonSchema,format:r,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:r,pattern:s.source,message:e.resolveErrorMessage(t,`Invalid ${r}`)}]})}uuidv4(e){return this.format(i.uuidv4,"uuid",e)}uuidv6(e){return this.format(i.uuidv6,"uuid",e)}uuidv7(e){return this.format(i.uuidv7,"uuid",e)}emoji(e){return this.format(i.emoji,"emoji",e)}base64(e){return this.format(i.base64,"base64",e)}base64url(e){return this.format(i.base64url,"base64url",e)}jwt(e){return this.format(i.jwt,"jwt",e)}nanoid(e){return this.format(i.nanoid,"nanoid",e)}cuid(e){return this.format(i.cuid,"cuid",e)}cuid2(e){return this.format(i.cuid2,"cuid2",e)}ulid(e){return this.format(i.ulid,"ulid",e)}cidrv4(e){return this.format(i.cidrv4,"cidrv4",e)}cidrv6(e){return this.format(i.cidrv6,"cidrv6",e)}e164(e){return this.format(i.e164,"e164",e)}xid(e){return this.format(i.xid,"xid",e)}guid(e){return this.format(i.guid,"guid",e)}ksuid(e){return this.format(i.ksuid,"ksuid",e)}date(e){return this.format(i.isoDate,"date",e)}time(e){return this.format(i.isoTime,"time",e)}datetime(e){return this.format(i.isoDateTime,"datetime",e)}duration(e){return this.format(i.isoDuration,"duration",e)}regex(r,t){return new VldString({checks:[...this.config.checks,e=>r.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:r.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:r.source,message:e.resolveErrorMessage(t,s.getMessages().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}lowercase(){return this.toLowerCase()}toUpperCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(e){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.normalize(e)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.startsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringStartsWith(r)),jsonSchema:this.config.jsonSchema})}endsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.endsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringEndsWith(r)),jsonSchema:this.config.jsonSchema})}includes(r,t){return new VldString({checks:[...this.config.checks,e=>e.includes(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIncludes(r)),jsonSchema:this.config.jsonSchema})}ip(t){return new VldString({checks:[...this.config.checks,e=>!(e.length>100)&&(i.ipv4.test(e)||r.isValidIPv6(e))],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:e.resolveErrorMessage(t,s.getMessages().stringIp)}]})}ipv4(r){return new VldString({checks:[...this.config.checks,e=>i.ipv4.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:e.resolveErrorMessage(r,s.getMessages().stringIpv4)}]})}ipv6(t){return new VldString({checks:[...this.config.checks,e=>r.isValidIPv6(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:e.resolveErrorMessage(t,s.getMessages().stringIpv6)}]})}nonempty(r){return new VldString({checks:[...this.config.checks,e=>e.length>0],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:e.resolveErrorMessage(r,s.getMessages().stringEmpty)}]})}}exports.VldString=VldString;
1
+ "use strict";var e=require("./base.cjs"),s=require("../locales/runtime.cjs"),r=require("../chunks/ip-validation-BZqPamPC.cjs"),t=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");const i={email:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,url:/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,uuidv4:/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv6:/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,uuidv7:/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,emoji:/^(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F)(?:\u200D(?:\p{Emoji_Presentation}|\p{Emoji}\uFE0F))*$/u,base64:/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,base64url:/^[A-Za-z0-9_-]*$/,jwt:/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$/,nanoid:/^[A-Za-z0-9_-]{21}$/,cuid:/^c[^\s-]{8,}$/i,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,cidrv4:/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(?:3[0-2]|[12]?[0-9])$/,cidrv6:/^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$|^(?:[0-9a-fA-F]{1,4}:){1,7}:\/(?:12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e164:/^\+[1-9]\d{1,14}$/,xid:/^[A-HJKMNP-TV-Z0-9]{20}$/,guid:/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i,ksuid:/^[0-9A-Za-z]{27}$/,isoDate:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/,isoTime:/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?$/,isoDateTime:/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z?$/,isoDuration:/^-?P(?!$)(?:\d+(?:\.\d+)?Y)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?W)?(?:\d+(?:\.\d+)?D)?(?:T(?=\d)(?:\d+(?:\.\d+)?H)?(?:\d+(?:\.\d+)?M)?(?:\d+(?:\.\d+)?S)?)?$/};class VldString extends e.VldBase{constructor(s){super(s?.validatorType||e.VLD_VALIDATOR_TYPES.STRING),this.config={checks:s?.checks||[],transforms:s?.transforms||[],errorMessage:s?.errorMessage,jsonSchema:s?.jsonSchema,checkMetas:s?.checkMetas},this._checks=this.config.checks,this._transforms=this.config.transforms,this._isSimple=0===this._checks.length&&0===this._transforms.length,this._checkMetas=this.config.checkMetas}static create(){return new VldString}get isSimple(){return this._isSimple}get minLength(){return this.config.jsonSchema?.minLength??null}get maxLength(){return this.config.jsonSchema?.maxLength??null}_createCheckIssue(e){switch(e.kind){case"min":return{code:"too_small",path:[],origin:"string",minimum:e.value,inclusive:!0,message:e.message||`Too small: expected string to have >=${e.value} characters`};case"max":return{code:"too_big",path:[],origin:"string",maximum:e.value,inclusive:!0,message:e.message||`Too big: expected string to have <=${e.value} characters`};case"length":return{code:"too_big",path:[],origin:"string",exact:e.value,message:e.message||`Too big: expected string to have exactly ${e.value} characters`};case"format":{const s={code:"invalid_format",path:[],origin:"string",format:e.format,message:e.message||`Invalid ${e.format}`};return void 0!==e.pattern&&(s.pattern=e.pattern),s}case"regex":{const s={code:"invalid_format",path:[],origin:"string",format:"regex",message:e.message||"Invalid string: does not match pattern"};return void 0!==e.pattern&&(s.pattern=e.pattern),s}default:return{code:"custom",path:[],message:e.message||"Invalid string"}}}_runChecks(e){const s=this._checks,r=this._checkMetas;for(let t=0;t<s.length;t++)if(!s[t](e))return r?.[t]??this._fallbackMeta();return null}_fallbackMeta(){return{kind:"other",message:this.config.errorMessage}}parse(e){if("string"!=typeof e)throw new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)]);return this._isSimple?e:this.parseKnownString(e)}parseKnownString(e){if(this._isSimple)return e;const s=this._transforms;let r=e;switch(s.length){case 0:break;case 1:r=s[0](r);break;case 2:r=s[1](s[0](r));break;case 3:r=s[2](s[1](s[0](r)));break;default:for(let e=0;e<s.length;e++)r=s[e](r)}const i=this._runChecks(r);if(i)throw new t.VldError([this._createCheckIssue(i)]);return r}safeParse(e){if("string"!=typeof e)return{success:!1,error:new t.VldError([t.createInvalidTypeIssue("string",t.getTypeName(e),this.config.errorMessage)])};if(this._isSimple)return{success:!0,data:e};try{return{success:!0,data:this.parseKnownString(e)}}catch(e){return e instanceof t.VldError?{success:!1,error:e}:{success:!1,error:(s=e.message,new t.VldError([{code:"invalid_string",path:[],message:s}]))}}var s}min(r,t){return new VldString({checks:[...this.config.checks,e=>e.length>=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMin(r)),jsonSchema:{...this.config.jsonSchema,minLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMin(r))}]})}max(r,t){return new VldString({checks:[...this.config.checks,e=>e.length<=r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringMax(r)),jsonSchema:{...this.config.jsonSchema,maxLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"max",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringMax(r))}]})}length(r,t){return new VldString({checks:[...this.config.checks,e=>e.length===r],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringLength(r)),jsonSchema:{...this.config.jsonSchema,exactLength:r},checkMetas:[...this.config.checkMetas??[],{kind:"length",value:r,message:e.resolveErrorMessage(t,s.getMessages().stringLength(r))}]})}email(r){return new VldString({checks:[...this.config.checks,e=>i.email.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmail),jsonSchema:{...this.config.jsonSchema,format:"email"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"email",message:e.resolveErrorMessage(r,s.getMessages().stringEmail)}]})}url(r){return new VldString({checks:[...this.config.checks,e=>i.url.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUrl),jsonSchema:{...this.config.jsonSchema,format:"uri"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"url",message:e.resolveErrorMessage(r,s.getMessages().stringUrl)}]})}uuid(r){return new VldString({checks:[...this.config.checks,e=>i.uuid.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringUuid),jsonSchema:{...this.config.jsonSchema,format:"uuid"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"uuid",message:e.resolveErrorMessage(r,s.getMessages().stringUuid)}]})}format(s,r,t){return new VldString({checks:[...this.config.checks,e=>s.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,`Invalid ${r}`),jsonSchema:{...this.config.jsonSchema,format:r,pattern:s.source},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:r,pattern:s.source,message:e.resolveErrorMessage(t,`Invalid ${r}`)}]})}uuidv4(e){return this.format(i.uuidv4,"uuid",e)}uuidv6(e){return this.format(i.uuidv6,"uuid",e)}uuidv7(e){return this.format(i.uuidv7,"uuid",e)}emoji(e){return this.format(i.emoji,"emoji",e)}base64(e){return this.format(i.base64,"base64",e)}base64url(e){return this.format(i.base64url,"base64url",e)}jwt(e){return this.format(i.jwt,"jwt",e)}nanoid(e){return this.format(i.nanoid,"nanoid",e)}cuid(e){return this.format(i.cuid,"cuid",e)}cuid2(e){return this.format(i.cuid2,"cuid2",e)}ulid(e){return this.format(i.ulid,"ulid",e)}cidrv4(e){return this.format(i.cidrv4,"cidrv4",e)}cidrv6(e){return this.format(i.cidrv6,"cidrv6",e)}e164(e){return this.format(i.e164,"e164",e)}xid(e){return this.format(i.xid,"xid",e)}guid(e){return this.format(i.guid,"guid",e)}ksuid(e){return this.format(i.ksuid,"ksuid",e)}date(e){return this.format(i.isoDate,"date",e)}time(e){return this.format(i.isoTime,"time",e)}datetime(e){return this.format(i.isoDateTime,"datetime",e)}duration(e){return this.format(i.isoDuration,"duration",e)}regex(r,t){return new VldString({checks:[...this.config.checks,e=>r.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringRegex),jsonSchema:{...this.config.jsonSchema,pattern:r.source},checkMetas:[...this.config.checkMetas??[],{kind:"regex",pattern:r.source,message:e.resolveErrorMessage(t,s.getMessages().stringRegex)}]})}trim(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.trim()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}toLowerCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}lowercase(){return this.toLowerCase()}toUpperCase(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toUpperCase()],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}uppercase(){return this.toUpperCase()}normalize(e){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,s=>s.normalize(e)],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}slugify(){return new VldString({checks:this.config.checks,transforms:[...this.config.transforms,e=>e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")],errorMessage:this.config.errorMessage,jsonSchema:this.config.jsonSchema})}startsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.startsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringStartsWith(r)),jsonSchema:this.config.jsonSchema})}endsWith(r,t){return new VldString({checks:[...this.config.checks,e=>e.endsWith(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringEndsWith(r)),jsonSchema:this.config.jsonSchema})}includes(r,t){return new VldString({checks:[...this.config.checks,e=>e.includes(r)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIncludes(r)),jsonSchema:this.config.jsonSchema})}ip(t){return new VldString({checks:[...this.config.checks,e=>!(e.length>100)&&(i.ipv4.test(e)||r.isValidIPv6(e))],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIp),jsonSchema:{...this.config.jsonSchema,format:"ip"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ip",message:e.resolveErrorMessage(t,s.getMessages().stringIp)}]})}ipv4(r){return new VldString({checks:[...this.config.checks,e=>i.ipv4.test(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringIpv4),jsonSchema:{...this.config.jsonSchema,format:"ipv4"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv4",message:e.resolveErrorMessage(r,s.getMessages().stringIpv4)}]})}ipv6(t){return new VldString({checks:[...this.config.checks,e=>r.isValidIPv6(e)],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(t,s.getMessages().stringIpv6),jsonSchema:{...this.config.jsonSchema,format:"ipv6"},checkMetas:[...this.config.checkMetas??[],{kind:"format",format:"ipv6",message:e.resolveErrorMessage(t,s.getMessages().stringIpv6)}]})}nonempty(r){return new VldString({checks:[...this.config.checks,e=>e.length>0],transforms:this.config.transforms,errorMessage:e.resolveErrorMessage(r,s.getMessages().stringEmpty),jsonSchema:{...this.config.jsonSchema,minLength:Math.max(this.config.jsonSchema?.minLength||0,1)},checkMetas:[...this.config.checkMetas??[],{kind:"min",value:1,message:e.resolveErrorMessage(r,s.getMessages().stringEmpty)}]})}}exports.VldString=VldString;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldSymbol extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.SYMBOL),this.errorMessage=r}static create(){return new VldSymbol}get isSimple(){return!0}parse(e){if("symbol"!=typeof e)throw new Error(this.errorMessage||r.getMessages().invalidSymbol);return e}parseKnownSymbol(e){return e}safeParse(e){return"symbol"==typeof e?{success:!0,data:e}:{success:!1,error:(t=this.errorMessage||r.getMessages().invalidSymbol,new s.VldError([{code:"invalid_type",path:[],message:t}]))};var t}}exports.VldSymbol=VldSymbol;
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldSymbol extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.SYMBOL),this.errorMessage=r}static create(){return new VldSymbol}get isSimple(){return!0}parse(e){if("symbol"!=typeof e)throw new Error(this.errorMessage||r.getMessages().invalidSymbol);return e}parseKnownSymbol(e){return e}safeParse(e){return"symbol"==typeof e?{success:!0,data:e}:{success:!1,error:(t=this.errorMessage||r.getMessages().invalidSymbol,new s.VldError([{code:"invalid_type",path:[],message:t}]))};var t}}exports.VldSymbol=VldSymbol;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldTemplateLiteral extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.TEMPLATE_LITERAL),this.pattern=r}static create(...e){let r="^";for(const s of e)r+="string"==typeof s?s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):t(s);return r+="$",new VldTemplateLiteral(new RegExp(r))}parse(e){if("string"!=typeof e)throw new Error(r.getMessages().invalidString);if(!this.pattern.test(e))throw new Error(r.getMessages().stringPatternInvalid);return e}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e}}}}function t(r){switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:case e.VLD_VALIDATOR_TYPES.STRING_FORMAT:return"(.+)";case e.VLD_VALIDATOR_TYPES.NUMBER:case e.VLD_VALIDATOR_TYPES.COERCE_NUMBER:return"(-?\\d+(?:\\.\\d+)?)";case e.VLD_VALIDATOR_TYPES.BIGINT:case e.VLD_VALIDATOR_TYPES.COERCE_BIGINT:return"(-?\\d+)";case e.VLD_VALIDATOR_TYPES.BOOLEAN:case e.VLD_VALIDATOR_TYPES.COERCE_BOOLEAN:return"(true|false)";case e.VLD_VALIDATOR_TYPES.NULL:return"(null)";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"(undefined)";case e.VLD_VALIDATOR_TYPES.LITERAL:{const e=r;if(void 0!==e.literal){return"("+String(e.literal).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+")"}break}}return"(.+)"}exports.VldTemplateLiteral=VldTemplateLiteral,exports.templateLiteral=function(...e){return VldTemplateLiteral.create(...e)};
1
+ "use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs");require("../registry.cjs"),require("../chunks/errors-core-DrydF46s.cjs"),require("../locales/en.cjs");class VldTemplateLiteral extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.TEMPLATE_LITERAL),this.pattern=r}static create(...e){let r="^";for(const s of e)r+="string"==typeof s?s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):t(s);return r+="$",new VldTemplateLiteral(new RegExp(r))}parse(e){if("string"!=typeof e)throw new Error(r.getMessages().invalidString);if(!this.pattern.test(e))throw new Error(r.getMessages().stringPatternInvalid);return e}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}}function t(r){switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:case e.VLD_VALIDATOR_TYPES.STRING_FORMAT:return"(.+)";case e.VLD_VALIDATOR_TYPES.NUMBER:case e.VLD_VALIDATOR_TYPES.COERCE_NUMBER:return"(-?\\d+(?:\\.\\d+)?)";case e.VLD_VALIDATOR_TYPES.BIGINT:case e.VLD_VALIDATOR_TYPES.COERCE_BIGINT:return"(-?\\d+)";case e.VLD_VALIDATOR_TYPES.BOOLEAN:case e.VLD_VALIDATOR_TYPES.COERCE_BOOLEAN:return"(true|false)";case e.VLD_VALIDATOR_TYPES.NULL:return"(null)";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"(undefined)";case e.VLD_VALIDATOR_TYPES.LITERAL:{const e=r;if(void 0!==e.literal){return"("+String(e.literal).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+")"}break}}return"(.+)"}exports.VldTemplateLiteral=VldTemplateLiteral,exports.templateLiteral=function(...e){return VldTemplateLiteral.create(...e)};
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");function r(e){return new s.VldError([{code:"invalid_array",path:[],message:e}])}require("../registry.cjs"),require("../locales/en.cjs");class VldTuple extends e.VldBase{constructor(t,s,r=null){super(e.VLD_VALIDATOR_TYPES.TUPLE),this.validators=t,this.errorMessage=s,this.restValidator=r,this._length=t.length,this._validatorTypes=t.map(e=>e.validatorType),this._simpleItemModes=t.map((e,t)=>this.getSimpleItemMode(e,this._validatorTypes[t])),this._simpleItemValues=t.map((e,t)=>"literal"===this._simpleItemModes[t]?e.literal:void 0)}get items(){return this.validators}getSimpleItemMode(t,s){if(!0===t.isSimple)switch(s){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e,s,r){switch(e){case"string":return t.getMessages().invalidString;case"number":return t.getMessages().invalidNumber;case"boolean":return t.getMessages().invalidBoolean;case"bigint":return t.getMessages().invalidBigint;case"symbol":return t.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof r;case"undefinedValue":return t.getMessages().expectedUndefined;case"literal":return t.getMessages().literalExpected(JSON.stringify(s),JSON.stringify(r));default:return t.getMessages().invalidTuple}}static create(...e){return new VldTuple(e)}rest(e){return new VldTuple(this.validators,this.errorMessage,e)}parse(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);return this.parseKnownTuple(e)}parseKnownTuple(e){if(null===this.restValidator&&e.length!==this._length||null!==this.restValidator&&e.length<this._length)throw new Error(this.errorMessage||t.getMessages().tupleLength(this._length,e.length));const s=new Array(e.length);for(let r=0;r<this._length;r++){const a=this._simpleItemModes[r],i=e[r];if(void 0!==a)switch(a){case"string":if("string"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidString));s[r]=i;continue;case"number":if("number"!=typeof i||isNaN(i))throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidNumber));s[r]=i;continue;case"boolean":if("boolean"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidBoolean));s[r]=i;continue;case"bigint":if("bigint"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidBigint));s[r]=i;continue;case"symbol":if("symbol"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidSymbol));s[r]=i;continue;case"null":if(null!==i)throw new Error(t.getMessages().arrayItem(r,this.getSimpleItemError(a,void 0,i)));s[r]=null;continue;case"undefinedValue":if(void 0!==i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().expectedUndefined));s[r]=void 0;continue;case"literal":{const e=this._simpleItemValues[r];if(i!==e)throw new Error(t.getMessages().arrayItem(r,this.getSimpleItemError(a,e,i)));s[r]=e;continue}case"passthrough":s[r]=i;continue}try{const e=this.validators[r];s[r]=e.parse(i)}catch(e){throw new Error(t.getMessages().arrayItem(r,e.message))}}if(this.restValidator)for(let r=this._length;r<e.length;r++)try{s[r]=this.restValidator.parse(e[r])}catch(e){throw new Error(t.getMessages().arrayItem(r,e.message))}return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:r(e.message)}}}encode(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);this.validateEncodedLength(e.length);const s=new Array(e.length);for(let t=0;t<this._length;t++)s[t]=this.validators[t].encode(e[t]);if(this.restValidator)for(let t=this._length;t<e.length;t++)s[t]=this.restValidator.encode(e[t]);return s}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:r(e.message)}}}async encodeAsync(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);this.validateEncodedLength(e.length);const s=new Array(e.length);for(let t=0;t<this._length;t++)s[t]=await this.validators[t].encodeAsync(e[t]);if(this.restValidator)for(let t=this._length;t<e.length;t++)s[t]=await this.restValidator.encodeAsync(e[t]);return s}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:r(e.message)}}}validateEncodedLength(e){if(null===this.restValidator&&e!==this._length||null!==this.restValidator&&e<this._length)throw new Error(this.errorMessage||t.getMessages().tupleLength(this._length,e))}}exports.VldTuple=VldTuple;
1
+ "use strict";var e=require("./base.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");function r(e){return new s.VldError([{code:"invalid_array",path:[],message:e}])}require("../registry.cjs"),require("../locales/en.cjs");class VldTuple extends e.VldBase{constructor(t,s,r=null){super(e.VLD_VALIDATOR_TYPES.TUPLE),this.validators=t,this.errorMessage=s,this.restValidator=r,this._length=t.length,this._validatorTypes=t.map(e=>e.validatorType),this._simpleItemModes=t.map((e,t)=>this.getSimpleItemMode(e,this._validatorTypes[t])),this._simpleItemValues=t.map((e,t)=>"literal"===this._simpleItemModes[t]?e.literal:void 0)}get items(){return this.validators}getSimpleItemMode(t,s){if(!0===t.isSimple)switch(s){case e.VLD_VALIDATOR_TYPES.STRING:return"string";case e.VLD_VALIDATOR_TYPES.NUMBER:return"number";case e.VLD_VALIDATOR_TYPES.BOOLEAN:return"boolean";case e.VLD_VALIDATOR_TYPES.BIGINT:return"bigint";case e.VLD_VALIDATOR_TYPES.SYMBOL:return"symbol";case e.VLD_VALIDATOR_TYPES.NULL:return"null";case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return"undefinedValue";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}getSimpleItemError(e,s,r){switch(e){case"string":return t.getMessages().invalidString;case"number":return t.getMessages().invalidNumber;case"boolean":return t.getMessages().invalidBoolean;case"bigint":return t.getMessages().invalidBigint;case"symbol":return t.getMessages().invalidSymbol;case"null":return"Expected null, received "+typeof r;case"undefinedValue":return t.getMessages().expectedUndefined;case"literal":return t.getMessages().literalExpected(JSON.stringify(s),JSON.stringify(r));default:return t.getMessages().invalidTuple}}static create(...e){return new VldTuple(e)}rest(e){return new VldTuple(this.validators,this.errorMessage,e)}parse(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);return this.parseKnownTuple(e)}parseKnownTuple(e){if(null===this.restValidator&&e.length!==this._length||null!==this.restValidator&&e.length<this._length)throw new Error(this.errorMessage||t.getMessages().tupleLength(this._length,e.length));const s=new Array(e.length);for(let r=0;r<this._length;r++){const a=this._simpleItemModes[r],i=e[r];if(void 0!==a)switch(a){case"string":if("string"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidString));s[r]=i;continue;case"number":if("number"!=typeof i||isNaN(i))throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidNumber));s[r]=i;continue;case"boolean":if("boolean"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidBoolean));s[r]=i;continue;case"bigint":if("bigint"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidBigint));s[r]=i;continue;case"symbol":if("symbol"!=typeof i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().invalidSymbol));s[r]=i;continue;case"null":if(null!==i)throw new Error(t.getMessages().arrayItem(r,this.getSimpleItemError(a,void 0,i)));s[r]=null;continue;case"undefinedValue":if(void 0!==i)throw new Error(t.getMessages().arrayItem(r,t.getMessages().expectedUndefined));s[r]=void 0;continue;case"literal":{const e=this._simpleItemValues[r];if(i!==e)throw new Error(t.getMessages().arrayItem(r,this.getSimpleItemError(a,e,i)));s[r]=e;continue}case"passthrough":s[r]=i;continue}try{const e=this.validators[r];s[r]=e.parse(i)}catch(e){throw new Error(t.getMessages().arrayItem(r,e.message))}}if(this.restValidator)for(let r=this._length;r<e.length;r++)try{s[r]=this.restValidator.parse(e[r])}catch(e){throw new Error(t.getMessages().arrayItem(r,e.message))}return s}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:r(e.message)}}}encode(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);this.validateEncodedLength(e.length);const s=new Array(e.length);for(let t=0;t<this._length;t++)s[t]=this.validators[t].encode(e[t]);if(this.restValidator)for(let t=this._length;t<e.length;t++)s[t]=this.restValidator.encode(e[t]);return s}safeEncode(e){try{return{success:!0,data:this.encode(e)}}catch(e){return{success:!1,error:r(e.message)}}}async encodeAsync(e){if(!Array.isArray(e))throw new Error(this.errorMessage||t.getMessages().invalidTuple);this.validateEncodedLength(e.length);const s=new Array(e.length);for(let t=0;t<this._length;t++)s[t]=await this.validators[t].encodeAsync(e[t]);if(this.restValidator)for(let t=this._length;t<e.length;t++)s[t]=await this.restValidator.encodeAsync(e[t]);return s}async safeEncodeAsync(e){try{return{success:!0,data:await this.encodeAsync(e)}}catch(e){return{success:!1,error:r(e.message)}}}validateEncodedLength(e){if(null===this.restValidator&&e!==this._length||null!==this.restValidator&&e<this._length)throw new Error(this.errorMessage||t.getMessages().tupleLength(this._length,e))}}exports.VldTuple=VldTuple;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../errors.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldUint8Array extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.UINT8_ARRAY),this.config=r||{}}parse(e){const r=this.safeParse(e);if(!r.success)throw r.error;return r.data}safeParse(e){return e instanceof Uint8Array?void 0!==this.config.exactLength&&e.length!==this.config.exactLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayExactLength(this.config.exactLength))])}:void 0!==this.config.minLength&&e.length<this.config.minLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayMinLength(this.config.minLength))])}:void 0!==this.config.maxLength&&e.length>this.config.maxLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayMaxLength(this.config.maxLength))])}:{success:!0,data:e}:{success:!1,error:new s.VldError([r.createIssue("invalid_type",[],t.getMessages().expectedUint8Array)])}}min(e){return new VldUint8Array({...this.config,minLength:e})}max(e){return new VldUint8Array({...this.config,maxLength:e})}length(e){return new VldUint8Array({exactLength:e,minLength:void 0,maxLength:void 0})}static create(){return new VldUint8Array}}exports.VldUint8Array=VldUint8Array;
1
+ "use strict";var e=require("./base.cjs"),r=require("../errors.cjs"),t=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs"),require("../pigment.cjs"),require("../locales/en.cjs");class VldUint8Array extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.UINT8_ARRAY),this.config=r||{}}parse(e){const r=this.safeParse(e);if(!r.success)throw r.error;return r.data}safeParse(e){return e instanceof Uint8Array?void 0!==this.config.exactLength&&e.length!==this.config.exactLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayExactLength(this.config.exactLength))])}:void 0!==this.config.minLength&&e.length<this.config.minLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayMinLength(this.config.minLength))])}:void 0!==this.config.maxLength&&e.length>this.config.maxLength?{success:!1,error:new s.VldError([r.createIssue("custom",[],t.getMessages().uint8ArrayMaxLength(this.config.maxLength))])}:{success:!0,data:e}:{success:!1,error:new s.VldError([r.createIssue("invalid_type",[],t.getMessages().expectedUint8Array)])}}min(e){return new VldUint8Array({...this.config,minLength:e})}max(e){return new VldUint8Array({...this.config,maxLength:e})}length(e){return new VldUint8Array({exactLength:e,minLength:void 0,maxLength:void 0})}static create(){return new VldUint8Array}}exports.VldUint8Array=VldUint8Array;
@@ -1 +1 @@
1
- "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DKPohm9I.cjs");require("../registry.cjs");class VldUndefined extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.UNDEFINED)}static create(){return new VldUndefined}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error("Expected undefined, received "+typeof e)}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_type",path:[],message:s}]))}}var s}}exports.VldUndefined=VldUndefined;
1
+ "use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-DrydF46s.cjs");require("../registry.cjs");class VldUndefined extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.UNDEFINED)}static create(){return new VldUndefined}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error("Expected undefined, received "+typeof e)}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:(s=e.message,new r.VldError([{code:"invalid_type",path:[],message:s}]))}}var s}}exports.VldUndefined=VldUndefined;