@oxog/vld 2.4.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -1
- package/README.md +113 -1
- package/dist/chunks/errors-core-BU14-Dk8.js +1 -0
- package/dist/cjs/chunks/errors-core-C0mA6tfa.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -1
- package/dist/cjs/codecs/index.cjs +1 -1
- package/dist/cjs/coercion/index.cjs +1 -1
- package/dist/cjs/compile.cjs +1 -1
- package/dist/cjs/errors.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/mini.cjs +1 -1
- package/dist/cjs/v3/index.cjs +1 -1
- package/dist/cjs/v4/core/index.cjs +1 -1
- package/dist/cjs/v4/index.cjs +1 -1
- package/dist/cjs/v4/mini/index.cjs +1 -1
- package/dist/cjs/v4-mini/index.cjs +1 -1
- package/dist/cjs/validators/any.cjs +1 -1
- package/dist/cjs/validators/array-v2.cjs +1 -0
- package/dist/cjs/validators/array.cjs +1 -1
- package/dist/cjs/validators/base.cjs +1 -1
- package/dist/cjs/validators/base64.cjs +1 -1
- package/dist/cjs/validators/bigint-v2.cjs +1 -0
- package/dist/cjs/validators/bigint.cjs +1 -1
- package/dist/cjs/validators/boolean.cjs +1 -1
- package/dist/cjs/validators/codec.cjs +1 -1
- package/dist/cjs/validators/composite-v2.cjs +1 -0
- package/dist/cjs/validators/custom.cjs +1 -1
- package/dist/cjs/validators/date-v2.cjs +1 -0
- package/dist/cjs/validators/date.cjs +1 -1
- package/dist/cjs/validators/discriminated-union.cjs +1 -1
- package/dist/cjs/validators/enum.cjs +1 -1
- package/dist/cjs/validators/file.cjs +1 -1
- package/dist/cjs/validators/function.cjs +1 -1
- package/dist/cjs/validators/hex.cjs +1 -1
- package/dist/cjs/validators/index.cjs +1 -1
- package/dist/cjs/validators/intersection.cjs +1 -1
- package/dist/cjs/validators/json.cjs +1 -1
- package/dist/cjs/validators/lazy.cjs +1 -1
- package/dist/cjs/validators/leaf-v2.cjs +1 -0
- package/dist/cjs/validators/literal.cjs +1 -1
- package/dist/cjs/validators/map.cjs +1 -1
- package/dist/cjs/validators/nan.cjs +1 -1
- package/dist/cjs/validators/never.cjs +1 -1
- package/dist/cjs/validators/null.cjs +1 -1
- package/dist/cjs/validators/number-v2.cjs +1 -0
- package/dist/cjs/validators/number.cjs +1 -1
- package/dist/cjs/validators/object-v2.cjs +1 -0
- package/dist/cjs/validators/object.cjs +1 -1
- package/dist/cjs/validators/promise.cjs +1 -1
- package/dist/cjs/validators/record.cjs +1 -1
- package/dist/cjs/validators/set.cjs +1 -1
- package/dist/cjs/validators/string-bool.cjs +1 -1
- package/dist/cjs/validators/string-formats.cjs +1 -1
- package/dist/cjs/validators/string-v2.cjs +1 -0
- package/dist/cjs/validators/string.cjs +1 -1
- package/dist/cjs/validators/symbol.cjs +1 -1
- package/dist/cjs/validators/template-literal.cjs +1 -1
- package/dist/cjs/validators/tuple.cjs +1 -1
- package/dist/cjs/validators/uint8array.cjs +1 -1
- package/dist/cjs/validators/undefined.cjs +1 -1
- package/dist/cjs/validators/union-v2.cjs +1 -0
- package/dist/cjs/validators/union.cjs +1 -1
- package/dist/cjs/validators/unknown.cjs +1 -1
- package/dist/cjs/validators/void.cjs +1 -1
- package/dist/cjs/validators/wrapper-v2.cjs +1 -0
- package/dist/cjs/validators/xor.cjs +1 -1
- package/dist/errors-core.d.ts +3 -0
- package/dist/errors.js +1 -1
- package/dist/index.d.ts +168 -12
- package/dist/index.js +1 -1
- package/dist/v3/index.js +1 -1
- package/dist/v4/core/index.js +1 -1
- package/dist/v4/index.js +1 -1
- package/dist/v4/mini/index.js +1 -1
- package/dist/v4-mini/index.js +1 -1
- package/dist/validators/array-v2.d.ts +113 -0
- package/dist/validators/array-v2.js +1 -0
- package/dist/validators/array.js +1 -1
- package/dist/validators/base.js +1 -1
- package/dist/validators/base64.js +1 -1
- package/dist/validators/bigint-v2.d.ts +105 -0
- package/dist/validators/bigint-v2.js +1 -0
- package/dist/validators/bigint.js +1 -1
- package/dist/validators/boolean.js +1 -1
- package/dist/validators/codec.js +1 -1
- package/dist/validators/composite-v2.d.ts +59 -0
- package/dist/validators/composite-v2.js +1 -0
- package/dist/validators/date-v2.d.ts +140 -0
- package/dist/validators/date-v2.js +1 -0
- package/dist/validators/date.js +1 -1
- package/dist/validators/enum.js +1 -1
- package/dist/validators/file.js +1 -1
- package/dist/validators/function.js +1 -1
- package/dist/validators/hex.js +1 -1
- package/dist/validators/intersection.js +1 -1
- package/dist/validators/leaf-v2.d.ts +138 -0
- package/dist/validators/leaf-v2.js +1 -0
- package/dist/validators/literal.js +1 -1
- package/dist/validators/map.js +1 -1
- package/dist/validators/nan.js +1 -1
- package/dist/validators/never.js +1 -1
- package/dist/validators/null.js +1 -1
- package/dist/validators/number-v2.d.ts +252 -0
- package/dist/validators/number-v2.js +1 -0
- package/dist/validators/number.js +1 -1
- package/dist/validators/object-v2.d.ts +40 -0
- package/dist/validators/object-v2.js +1 -0
- package/dist/validators/object.js +1 -1
- package/dist/validators/record.js +1 -1
- package/dist/validators/set.js +1 -1
- package/dist/validators/string-formats.js +1 -1
- package/dist/validators/string-v2.d.ts +274 -0
- package/dist/validators/string-v2.js +1 -0
- package/dist/validators/string.js +1 -1
- package/dist/validators/symbol.js +1 -1
- package/dist/validators/tuple.js +1 -1
- package/dist/validators/uint8array.js +1 -1
- package/dist/validators/undefined.js +1 -1
- package/dist/validators/union-v2.d.ts +28 -0
- package/dist/validators/union-v2.js +1 -0
- package/dist/validators/void.js +1 -1
- package/dist/validators/wrapper-v2.d.ts +74 -0
- package/dist/validators/wrapper-v2.js +1 -0
- package/dist/zod-error.d.ts +84 -0
- package/package.json +1 -1
- package/dist/chunks/errors-core-CerMg2rq.js +0 -1
- package/dist/cjs/chunks/errors-core-DrydF46s.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-C0mA6tfa.cjs"),s=require("../locales/runtime.cjs");function t(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"undefined";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}function n(r){switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return e=>"string"==typeof e;case e.VLD_VALIDATOR_TYPES.NUMBER:return e=>"number"==typeof e&&!isNaN(e);case e.VLD_VALIDATOR_TYPES.BOOLEAN:return e=>"boolean"==typeof e;case e.VLD_VALIDATOR_TYPES.BIGINT:return e=>"bigint"==typeof e;case e.VLD_VALIDATOR_TYPES.SYMBOL:return e=>"symbol"==typeof e;case e.VLD_VALIDATOR_TYPES.NAN:return e=>"number"==typeof e&&Number.isNaN(e);case e.VLD_VALIDATOR_TYPES.ARRAY:return Array.isArray;case e.VLD_VALIDATOR_TYPES.OBJECT:return e=>"object"==typeof e&&null!==e&&!Array.isArray(e);case e.VLD_VALIDATOR_TYPES.NULL:return e=>null===e;case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return e=>void 0===e;case e.VLD_VALIDATOR_TYPES.ENUM:return e=>"string"==typeof e||"number"==typeof e;case e.VLD_VALIDATOR_TYPES.LITERAL:{const e=r.literal;return r=>r===e}case e.VLD_VALIDATOR_TYPES.NEVER:return()=>!1;case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:default:return()=>!0}}require("../registry.cjs"),require("../locales/en.cjs");class VldUnionV2 extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.UNION),this.__def=function(e,r){const s=e.map(n),a=e.map(t),c=e.map((e,r)=>"literal"===a[r]?e.literal:void 0);return{type:"union",validators:e,typeCheckers:s,simpleModes:a,simpleValues:c,errorMessage:r}}(r,s)}static create(...e){return new VldUnionV2(e)}get options(){return this.__def.validators}parse(e){const r=[],{validators:t,typeCheckers:n,simpleModes:a,simpleValues:c}=this.__def;for(let s=0;s<t.length;s++){const u=t[s],V=n[s];if(V&&!V(e))continue;const i=a[s];if(void 0!==i)switch(i){case"string":case"number":case"boolean":case"bigint":case"symbol":case"passthrough":return e;case"null":return null;case"undefined":return;case"literal":return c[s]}try{return u.parse(e)}catch(e){r.push(e instanceof Error?e.message:String(e))}}throw new Error(this.__def.errorMessage||s.getMessages().unionNoMatch(r))}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof r.VldError?e:new r.VldError([{code:"custom",path:[],message:e.message}])}}}}exports.VldUnionV2=VldUnionV2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs");require("../registry.cjs"),require("../chunks/errors-core-
|
|
1
|
+
"use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs");require("../registry.cjs"),require("../chunks/errors-core-C0mA6tfa.cjs"),require("../locales/en.cjs");class VldUnion extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.UNION),this.validators=r,this.errorMessage=s,this.typeCheckers=r.map(e=>this.createTypeChecker(e)),this.simpleModes=r.map(e=>this.createSimpleMode(e)),this.simpleValues=r.map((e,r)=>"literal"===this.simpleModes[r]?e.literal:void 0)}get options(){return this.validators}createSimpleMode(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"undefined";case e.VLD_VALIDATOR_TYPES.LITERAL:return"literal";case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:return"passthrough";default:return}}parseSimpleValue(e,r,s){switch(e){case"string":case"number":case"boolean":case"bigint":case"symbol":case"passthrough":return s;case"null":return null;case"undefined":default:return;case"literal":return this.simpleValues[r]}}createTypeChecker(r){switch(r.validatorType){case e.VLD_VALIDATOR_TYPES.STRING:return e=>"string"==typeof e;case e.VLD_VALIDATOR_TYPES.NUMBER:return e=>"number"==typeof e&&!isNaN(e);case e.VLD_VALIDATOR_TYPES.BOOLEAN:return e=>"boolean"==typeof e;case e.VLD_VALIDATOR_TYPES.BIGINT:return e=>"bigint"==typeof e;case e.VLD_VALIDATOR_TYPES.SYMBOL:return e=>"symbol"==typeof e;case e.VLD_VALIDATOR_TYPES.NAN:return e=>"number"==typeof e&&Number.isNaN(e);case e.VLD_VALIDATOR_TYPES.ARRAY:return Array.isArray;case e.VLD_VALIDATOR_TYPES.OBJECT:return e=>"object"==typeof e&&null!==e&&!Array.isArray(e);case e.VLD_VALIDATOR_TYPES.NULL:return e=>null===e;case e.VLD_VALIDATOR_TYPES.UNDEFINED:case e.VLD_VALIDATOR_TYPES.VOID:return e=>void 0===e;case e.VLD_VALIDATOR_TYPES.ENUM:return e=>"string"==typeof e||"number"==typeof e;case e.VLD_VALIDATOR_TYPES.LITERAL:{const e=r.literal;return r=>r===e}case e.VLD_VALIDATOR_TYPES.NEVER:return()=>!1;case e.VLD_VALIDATOR_TYPES.ANY:case e.VLD_VALIDATOR_TYPES.UNKNOWN:default:return()=>!0}}static create(...e){return new VldUnion(e)}parse(e){const s=[];for(let r=0;r<this.validators.length;r++){const t=this.validators[r],a=this.typeCheckers[r];if(a&&!a(e))continue;const n=this.simpleModes[r];if(void 0!==n)return this.parseSimpleValue(n,r,e);try{return t.parse(e)}catch(e){const r=e instanceof Error?e.message:String(e);s.push(r)}}throw new Error(this.errorMessage||r.getMessages().unionNoMatch(s))}safeParse(s){const t=[];for(let e=0;e<this.validators.length;e++){const r=this.validators[e],a=this.typeCheckers[e];if(a&&!a(s))continue;const n=this.simpleModes[e];if(void 0!==n)return{success:!0,data:this.parseSimpleValue(n,e,s)};try{return{success:!0,data:r.parse(s)}}catch(e){const r=e instanceof Error?e.message:String(e);t.push(r)}}return{success:!1,error:e.ensureVldError(this.errorMessage||r.getMessages().unionNoMatch(t))}}}exports.VldUnion=VldUnion;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-
|
|
1
|
+
"use strict";var e=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-C0mA6tfa.cjs");class VldUnknown extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.UNKNOWN)}static create(){return new VldUnknown}get isSimple(){return!0}parse(e){return e}safeParse(e){return{success:!0,data:e}}}exports.VldUnknown=VldUnknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-
|
|
1
|
+
"use strict";var e=require("./base.cjs"),r=require("../locales/runtime.cjs"),s=require("../chunks/errors-core-C0mA6tfa.cjs");require("../registry.cjs"),require("../locales/en.cjs");class VldVoid extends e.VldBase{constructor(){super(e.VLD_VALIDATOR_TYPES.VOID)}static create(){return new VldVoid}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error(r.getMessages().expectedUndefined)}safeParse(e){return void 0===e?{success:!0,data:void 0}:{success:!1,error:new s.VldError([{code:"invalid_type",path:[],message:r.getMessages().expectedUndefined}])}}}exports.VldVoid=VldVoid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./base.cjs"),r=require("../chunks/errors-core-C0mA6tfa.cjs");require("../registry.cjs");class VldOptionalV2 extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.OPTIONAL),this.__def=Object.freeze({type:"optional",inner:r})}static create(e){return new VldOptionalV2(e)}parse(e){if(void 0!==e)return this.__def.inner.parse(e)}safeParse(e){return void 0===e?{success:!0,data:void 0}:this.__def.inner.safeParse(e)}unwrap(){return this.__def.inner}}class VldNullableV2 extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.NULLABLE),this.__def=Object.freeze({type:"nullable",inner:r})}static create(e){return new VldNullableV2(e)}parse(e){return null===e?null:this.__def.inner.parse(e)}safeParse(e){return null===e?{success:!0,data:null}:this.__def.inner.safeParse(e)}unwrap(){return this.__def.inner}}class VldNullishV2 extends e.VldBase{constructor(r){super(e.VLD_VALIDATOR_TYPES.NULLISH),this.__def=Object.freeze({type:"nullish",inner:r})}static create(e){return new VldNullishV2(e)}parse(e){return null==e?e:this.__def.inner.parse(e)}safeParse(e){return null==e?{success:!0,data:e}:this.__def.inner.safeParse(e)}unwrap(){return this.__def.inner}}class VldRefineV2 extends e.VldBase{constructor(r,s,t="Refinement check failed",n){super(e.VLD_VALIDATOR_TYPES.REFINE),this.__def=Object.freeze({type:"refine",inner:r,predicate:s,message:t,path:n})}static create(e,r,s="Refinement check failed"){return new VldRefineV2(e,r,s)}parse(e){const s=this.__def.inner.parse(e),t=this.__def.predicate(s);if(t instanceof Promise)throw new Error("Use parseAsync for async refinements");if(!t)throw new r.VldError([{code:"custom",path:this.__def.path?[...this.__def.path]:[],message:this.__def.message}]);return s}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}async parseAsync(e){const s=await this.__def.inner.parseAsync(e);if(!await this.__def.predicate(s))throw new r.VldError([{code:"custom",path:[],message:this.__def.message}]);return s}async safeParseAsync(r){try{return{success:!0,data:await this.parseAsync(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}unwrap(){return this.__def.inner}}class VldTransformV2 extends e.VldBase{constructor(r,s){super(e.VLD_VALIDATOR_TYPES.TRANSFORM),this.__def=Object.freeze({type:"transform",inner:r,transformer:s})}static create(e,r){return new VldTransformV2(e,r)}parse(e){const r=this.__def.inner.parse(e);try{const e=this.__def.transformer(r);if(e instanceof Promise)throw new Error("Use parseAsync for async transforms");return e}catch(e){throw new Error(`Transform failed: ${e.message}`)}}safeParse(r){try{return{success:!0,data:this.parse(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}async parseAsync(e){const r=await this.__def.inner.parseAsync(e);return this.__def.transformer(r)}async safeParseAsync(r){try{return{success:!0,data:await this.parseAsync(r)}}catch(r){return{success:!1,error:e.ensureVldError(r)}}}unwrap(){return this.__def.inner}}exports.VldNullableV2=VldNullableV2,exports.VldNullishV2=VldNullishV2,exports.VldOptionalV2=VldOptionalV2,exports.VldRefineV2=VldRefineV2,exports.VldTransformV2=VldTransformV2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-
|
|
1
|
+
"use strict";var r=require("./base.cjs");require("../registry.cjs"),require("../chunks/errors-core-C0mA6tfa.cjs");class VldXor extends r.VldBase{constructor(s){super(r.VLD_VALIDATOR_TYPES.XOR),this._options=s}static create(r){return new VldXor(r)}parse(r){const s=this.safeParse(r);if(!s.success)throw s.error;return s.data}safeParse(s){let e=0,t=null;for(const r of this._options){const o=r.safeParse(s);if(o.success&&(e++,t=o,e>1))break}return 0===e?{success:!1,error:r.ensureVldError("No schema matched in XOR union")}:e>1?{success:!1,error:r.ensureVldError(`Input matches ${e} schemas in XOR union, but exactly one is required`)}:t}getOptions(){return this._options}}exports.VldXor=VldXor;
|
package/dist/errors-core.d.ts
CHANGED
|
@@ -49,7 +49,10 @@ export interface VldErrorJSON {
|
|
|
49
49
|
}
|
|
50
50
|
export declare class VldError extends Error {
|
|
51
51
|
readonly issues: VldIssue[];
|
|
52
|
+
private _stack;
|
|
52
53
|
constructor(issues: VldIssue[], customMessage?: string);
|
|
54
|
+
/** Force-capture the stack trace on demand. */
|
|
55
|
+
captureStack(): void;
|
|
53
56
|
get firstError(): VldIssue | undefined;
|
|
54
57
|
get errors(): VldIssue[];
|
|
55
58
|
get isEmpty(): boolean;
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{vldTheme as e}from"./pigment.js";export{V as VldError}from"./chunks/errors-core-
|
|
1
|
+
import{vldTheme as e}from"./pigment.js";export{V as VldError}from"./chunks/errors-core-BU14-Dk8.js";function r(e){const r={errors:[]};for(const t of e.issues){let e=r;const s=t.path;for(let r=0;r<s.length;r++){const o=s[r],n=r===s.length-1;if("string"==typeof o)e.properties||(e.properties={}),e.properties[o]||(e.properties[o]={errors:[]}),n?e.properties[o].errors.push(t.message):e=e.properties[o];else if("number"==typeof o){for(e.items||(e.items=[]);e.items.length<=o;)e.items.push(void 0);e.items[o]||(e.items[o]={errors:[]}),n?e.items[o].errors.push(t.message):e=e.items[o]}}0===s.length&&r.errors.push(t.message)}return r}function t(r,t={}){const{colored:s=!0,theme:o=e,includeCode:n=!1,includeDetails:i=!1}=t,c=[];for(const e of r.issues){let r=`${s?o.symbol("✖"):"✖"} ${s?o.error(e.message):e.message}`;if(n){r+=` ${s?o.muted(`[${e.code}]`):`[${e.code}]`}`}if(e.path.length>0){const t=e.path.map((e,r)=>{if("string"==typeof e){const t=0===r?e:`.${e}`;return s?o.path(t):t}{const r=`[${e}]`;return s?o.path(r):r}}).join("");r+=`\n ${s?o.muted("→ at "):"→ at "}${t}`}if(i){if(e.expected){r+=`\n ${s?o.muted("expected: ")+o.success(e.expected):`expected: ${e.expected}`}`}if(e.received){r+=`\n ${s?o.muted("received: ")+o.warning(e.received):`received: ${e.received}`}`}}c.push(r)}return c.join("\n")}function s(e,r={}){return t(e,{...r,colored:!0})}function o(e,r={}){return t(e,{...r,colored:!1})}function n(e){const r=[],t={};for(const s of e.issues)if(0===s.path.length)r.push(s.message);else{const e=s.path[0].toString();t[e]||(t[e]=[]),t[e].push(s.message)}return{formErrors:r,fieldErrors:t}}function i(e,r,t,s){return{code:e,path:[...r],message:t,...s}}function c(e){return null===e?"null":void 0===e?"undefined":Array.isArray(e)?"array":e instanceof Date?"date":typeof e}export{i as createIssue,n as flattenError,c as getValueType,t as prettifyError,s as prettifyErrorColored,o as prettifyErrorPlain,r as treeifyError};
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,15 @@ import type { Infer, Input, Output } from './validators/index.js';
|
|
|
18
18
|
import { registry } from './registry.js';
|
|
19
19
|
import { VldError, type VldIssue } from './errors-core.js';
|
|
20
20
|
import { VldString } from './validators/string.js';
|
|
21
|
+
import { VldStringV2, VldCoerceStringV2 } from './validators/string-v2.js';
|
|
22
|
+
import { VldNumberV2, VldCoerceNumberV2 } from './validators/number-v2.js';
|
|
23
|
+
import { VldDateV2 } from './validators/date-v2.js';
|
|
24
|
+
import { VldBigIntV2 } from './validators/bigint-v2.js';
|
|
25
|
+
import { VldArrayV2 } from './validators/array-v2.js';
|
|
26
|
+
import { VldUnionV2 } from './validators/union-v2.js';
|
|
27
|
+
import { VldRefineV2, VldTransformV2, VldOptionalV2, VldNullableV2, VldNullishV2 } from './validators/wrapper-v2.js';
|
|
28
|
+
import { VldLiteralV2, VldBooleanV2, VldEnumV2, VldRecordV2, VldAnyV2, VldUnknownV2, VldVoidV2, VldNeverV2, VldNullV2, VldUndefinedV2, VldSymbolV2, VldFunctionV2 } from './validators/leaf-v2.js';
|
|
29
|
+
import { VldTupleV2, VldSetV2, VldMapV2, VldIntersectionV2 } from './validators/composite-v2.js';
|
|
21
30
|
import { VldNumber } from './validators/number.js';
|
|
22
31
|
import { VldBoolean } from './validators/boolean.js';
|
|
23
32
|
import { VldDate } from './validators/date.js';
|
|
@@ -238,7 +247,11 @@ export declare function output<T extends AnySchema>(schema: T): T;
|
|
|
238
247
|
*/
|
|
239
248
|
export declare const v: {
|
|
240
249
|
string: () => VldString;
|
|
250
|
+
stringLegacy: () => VldString;
|
|
251
|
+
stringV2: () => VldStringV2;
|
|
241
252
|
number: () => VldNumber;
|
|
253
|
+
numberLegacy: () => VldNumber;
|
|
254
|
+
numberV2: () => VldNumberV2;
|
|
242
255
|
int: () => VldNumber;
|
|
243
256
|
int32: () => VldNumber;
|
|
244
257
|
uint32: () => VldNumber;
|
|
@@ -247,8 +260,13 @@ export declare const v: {
|
|
|
247
260
|
float32: () => VldNumber;
|
|
248
261
|
float64: () => VldNumber;
|
|
249
262
|
boolean: () => VldBoolean;
|
|
263
|
+
booleanV2: () => VldBooleanV2;
|
|
250
264
|
date: () => VldDate;
|
|
265
|
+
dateLegacy: () => VldDate;
|
|
266
|
+
dateV2: () => VldDateV2;
|
|
251
267
|
bigint: () => VldBigInt;
|
|
268
|
+
bigintLegacy: () => VldBigInt;
|
|
269
|
+
bigintV2: () => VldBigIntV2;
|
|
252
270
|
symbol: () => VldSymbol;
|
|
253
271
|
stringbool: (options?: {
|
|
254
272
|
truthy?: readonly string[];
|
|
@@ -256,17 +274,24 @@ export declare const v: {
|
|
|
256
274
|
caseSensitive?: boolean;
|
|
257
275
|
}) => VldStringBool;
|
|
258
276
|
array: <T>(item: VldBase<unknown, T>) => VldArray<T>;
|
|
277
|
+
arrayV2: <T>(item: VldBase<unknown, T>) => VldArrayV2<T>;
|
|
278
|
+
tuple: typeof tupleFactory;
|
|
279
|
+
tupleV2: <T extends readonly VldBase<any, any>[]>(...items: T) => VldTupleV2<[...T]>;
|
|
280
|
+
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
281
|
+
setV2: <T>(item: VldBase<unknown, T>) => VldSetV2<T>;
|
|
282
|
+
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
283
|
+
mapV2: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMapV2<K, V>;
|
|
284
|
+
record: typeof recordFactory;
|
|
285
|
+
recordV2: <T>(value: VldBase<unknown, T>) => VldRecordV2<T>;
|
|
259
286
|
object: typeof objectFactory;
|
|
260
287
|
strictObject: typeof strictObjectFactory;
|
|
261
288
|
looseObject: typeof looseObjectFactory;
|
|
262
|
-
tuple: typeof tupleFactory;
|
|
263
|
-
record: typeof recordFactory;
|
|
264
289
|
partialRecord: typeof partialRecordFactory;
|
|
265
290
|
looseRecord: typeof looseRecordFactory;
|
|
266
|
-
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
267
|
-
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
268
291
|
union: typeof unionFactory;
|
|
292
|
+
unionV2: <T extends readonly VldBase<any, any>[]>(...validators: T) => VldUnionV2<[...T]>;
|
|
269
293
|
intersection: <A, B>(first: VldBase<unknown, A>, second: VldBase<unknown, B>) => VldIntersection<A, B>;
|
|
294
|
+
intersectionV2: <A, B>(left: VldBase<any, A>, right: VldBase<any, B>) => VldIntersectionV2<A, B>;
|
|
270
295
|
discriminatedUnion: typeof discriminatedUnionFactory;
|
|
271
296
|
xor: typeof xorFactory;
|
|
272
297
|
keyof: <T extends Record<string, any>>(schema: VldObject<T>) => VldEnum<[string, ...string[]]>;
|
|
@@ -274,7 +299,9 @@ export declare const v: {
|
|
|
274
299
|
input: typeof input;
|
|
275
300
|
output: typeof output;
|
|
276
301
|
literal: typeof literalFactory;
|
|
302
|
+
literalV2: <T extends string | number | boolean | null | undefined>(value: T) => VldLiteralV2<T>;
|
|
277
303
|
enum: typeof enumFactoryCompat;
|
|
304
|
+
enumV2: <T extends readonly (string | number)[]>(values: T) => VldEnumV2<T>;
|
|
278
305
|
nativeEnum: <T extends NativeEnumLike>(enumObject: T) => VldEnum<any>;
|
|
279
306
|
any: () => VldAny;
|
|
280
307
|
unknown: () => VldUnknown;
|
|
@@ -306,20 +333,26 @@ export declare const v: {
|
|
|
306
333
|
};
|
|
307
334
|
ZodFirstPartyTypeKind: {};
|
|
308
335
|
optional: <T>(validator: VldBase<unknown, T>) => VldOptional<unknown, T>;
|
|
336
|
+
optionalV2: <T>(validator: VldBase<unknown, T>) => VldOptionalV2<unknown, T>;
|
|
309
337
|
nullable: <T>(validator: VldBase<unknown, T>) => VldNullable<unknown, T>;
|
|
338
|
+
nullableV2: <T>(validator: VldBase<unknown, T>) => VldNullableV2<unknown, T>;
|
|
310
339
|
nullish: <T>(validator: VldBase<unknown, T>) => VldNullish<unknown, T>;
|
|
340
|
+
nullishV2: <T>(validator: VldBase<unknown, T>) => VldNullishV2<unknown, T>;
|
|
311
341
|
exactOptional: <T>(validator: VldBase<unknown, T>) => VldExactOptional<unknown, T>;
|
|
312
342
|
nonoptional: <T>(validator: VldBase<unknown, T | undefined>, message?: RefinementMessage) => VldRefine<unknown, T | undefined, Exclude<T, undefined>>;
|
|
313
343
|
catch: <T>(validator: VldBase<unknown, T>, fallbackValue: T) => VldCatch<unknown, T>;
|
|
314
344
|
prefault: <TInput, TOutput>(validator: VldBase<TInput, TOutput>, defaultValue: TInput | (() => TInput)) => VldPrefault<TInput, TOutput>;
|
|
315
345
|
readonly: <T>(validator: VldBase<unknown, T>) => VldReadonly<unknown, T>;
|
|
316
346
|
pipe: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
347
|
+
pipeline: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
317
348
|
clone: <T extends VldBase<any, any>>(schema: T) => T;
|
|
318
349
|
describe: <TInput, TOutput>(schemaOrDescription: VldBase<TInput, TOutput> | string, description?: string) => VldMeta<unknown, unknown>;
|
|
319
350
|
meta: <TInput, TOutput>(schemaOrMetadata: VldBase<TInput, TOutput> | Partial<SchemaMetadata>, metadata?: Partial<SchemaMetadata>) => VldMeta<unknown, unknown>;
|
|
320
351
|
transform: <TInput = unknown, TOutput = TInput>(schemaOrTransformer: VldBase<unknown, TInput> | ((value: TInput, ctx?: SuperRefineContext) => TOutput | Promise<TOutput>), transformer?: (value: TInput) => TOutput | Promise<TOutput>) => VldTransform<unknown, TInput, TOutput> | VldBase<TInput, Awaited<TOutput>>;
|
|
352
|
+
transformV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TBase | Promise<TBase>) => VldTransformV2<TInput, TBase, TBase>;
|
|
321
353
|
overwrite: <T>(transformer: (value: T) => T) => VldBase<T, Awaited<T>>;
|
|
322
354
|
refine: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
355
|
+
refineV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string) => VldRefineV2<TInput, TBase, TBase>;
|
|
323
356
|
check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
324
357
|
superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
|
|
325
358
|
property: typeof propertyCheck;
|
|
@@ -399,13 +432,19 @@ export declare const v: {
|
|
|
399
432
|
custom: typeof customFn;
|
|
400
433
|
file: () => VldFile;
|
|
401
434
|
function: () => VldFunction;
|
|
435
|
+
useV2: boolean;
|
|
436
|
+
setV2Mode: (enabled: boolean) => void;
|
|
402
437
|
preprocess: <TInput, TOutput>(preprocessor: (input: unknown) => unknown, schema: VldBase<TInput, TOutput>) => VldPreprocess<TInput, TOutput>;
|
|
403
438
|
coerce: {
|
|
404
439
|
string: () => VldCoerceString;
|
|
440
|
+
stringLegacy: () => VldCoerceString;
|
|
405
441
|
number: () => VldCoerceNumber;
|
|
442
|
+
numberLegacy: () => VldCoerceNumber;
|
|
406
443
|
boolean: () => VldCoerceBoolean;
|
|
407
444
|
date: () => VldCoerceDate;
|
|
408
445
|
bigint: () => VldCoerceBigInt;
|
|
446
|
+
stringV2: () => VldCoerceStringV2;
|
|
447
|
+
numberV2: () => VldCoerceNumberV2;
|
|
409
448
|
};
|
|
410
449
|
email: (options?: {
|
|
411
450
|
pattern?: RegExp;
|
|
@@ -619,6 +658,57 @@ export declare const v: {
|
|
|
619
658
|
$output: symbol;
|
|
620
659
|
$input: symbol;
|
|
621
660
|
};
|
|
661
|
+
/**
|
|
662
|
+
* v3.0: vV2 — drop-in factory that uses V2 validators everywhere.
|
|
663
|
+
* Recommended for new code and migrations from Zod 4.5.
|
|
664
|
+
*
|
|
665
|
+
* import { vV2 as v } from '@oxog/vld';
|
|
666
|
+
* const schema = v.object({ email: v.string().email() });
|
|
667
|
+
*
|
|
668
|
+
* Identical API to `v` but every factory returns the V2 implementation,
|
|
669
|
+
* giving 2-6x faster parse and 1.6-10x smaller memory on hot paths.
|
|
670
|
+
*/
|
|
671
|
+
export declare const vV2: {
|
|
672
|
+
string: () => VldStringV2;
|
|
673
|
+
number: () => VldNumberV2;
|
|
674
|
+
boolean: () => VldBooleanV2;
|
|
675
|
+
date: () => VldDateV2;
|
|
676
|
+
bigint: () => VldBigIntV2;
|
|
677
|
+
int: () => VldNumberV2;
|
|
678
|
+
int32: () => VldNumberV2;
|
|
679
|
+
uint32: () => VldNumberV2;
|
|
680
|
+
uint64: () => VldNumberV2;
|
|
681
|
+
int64: () => VldNumberV2;
|
|
682
|
+
float32: () => VldNumberV2;
|
|
683
|
+
float64: () => VldNumberV2;
|
|
684
|
+
array: <T>(item: VldBase<unknown, T>) => VldArrayV2<T>;
|
|
685
|
+
tuple: <T extends readonly VldBase<any, any>[]>(...items: T) => VldTupleV2<[...T]>;
|
|
686
|
+
set: <T>(item: VldBase<unknown, T>) => VldSetV2<T>;
|
|
687
|
+
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMapV2<K, V>;
|
|
688
|
+
record: <T>(value: VldBase<unknown, T>) => VldRecordV2<T>;
|
|
689
|
+
union: <T extends readonly VldBase<any, any>[]>(...validators: T) => VldUnionV2<[...T]>;
|
|
690
|
+
intersection: <A, B>(left: VldBase<any, A>, right: VldBase<any, B>) => VldIntersectionV2<A, B>;
|
|
691
|
+
literal: <T extends string | number | boolean | null | undefined>(value: T) => VldLiteralV2<T>;
|
|
692
|
+
enum: <T extends readonly (string | number)[]>(values: T) => VldEnumV2<T>;
|
|
693
|
+
optional: <T>(validator: VldBase<unknown, T>) => VldOptionalV2<unknown, T>;
|
|
694
|
+
nullable: <T>(validator: VldBase<unknown, T>) => VldNullableV2<unknown, T>;
|
|
695
|
+
nullish: <T>(validator: VldBase<unknown, T>) => VldNullishV2<unknown, T>;
|
|
696
|
+
object: typeof objectFactory;
|
|
697
|
+
any: () => VldAnyV2;
|
|
698
|
+
unknown: () => VldUnknownV2;
|
|
699
|
+
void: () => VldVoidV2;
|
|
700
|
+
never: () => VldNeverV2;
|
|
701
|
+
null: () => VldNullV2;
|
|
702
|
+
undefined: () => VldUndefinedV2;
|
|
703
|
+
symbol: () => VldSymbolV2;
|
|
704
|
+
function: () => VldFunctionV2;
|
|
705
|
+
coerce: {
|
|
706
|
+
string: () => VldCoerceStringV2;
|
|
707
|
+
number: () => VldCoerceNumberV2;
|
|
708
|
+
};
|
|
709
|
+
transformV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TBase | Promise<TBase>) => VldTransformV2<TInput, TBase, TBase>;
|
|
710
|
+
refineV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string) => VldRefineV2<TInput, TBase, TBase>;
|
|
711
|
+
};
|
|
622
712
|
export declare namespace v {
|
|
623
713
|
type infer<T extends VldBase<any, any>> = Infer<T>;
|
|
624
714
|
type input<T extends VldBase<any, any>> = Input<T>;
|
|
@@ -691,7 +781,11 @@ export type { SafeParseSuccess, SafeParseError, SafeParseReturnType, CustomError
|
|
|
691
781
|
*/
|
|
692
782
|
export declare const z: {
|
|
693
783
|
string: () => VldString;
|
|
784
|
+
stringLegacy: () => VldString;
|
|
785
|
+
stringV2: () => VldStringV2;
|
|
694
786
|
number: () => VldNumber;
|
|
787
|
+
numberLegacy: () => VldNumber;
|
|
788
|
+
numberV2: () => VldNumberV2;
|
|
695
789
|
int: () => VldNumber;
|
|
696
790
|
int32: () => VldNumber;
|
|
697
791
|
uint32: () => VldNumber;
|
|
@@ -700,8 +794,13 @@ export declare const z: {
|
|
|
700
794
|
float32: () => VldNumber;
|
|
701
795
|
float64: () => VldNumber;
|
|
702
796
|
boolean: () => VldBoolean;
|
|
797
|
+
booleanV2: () => VldBooleanV2;
|
|
703
798
|
date: () => VldDate;
|
|
799
|
+
dateLegacy: () => VldDate;
|
|
800
|
+
dateV2: () => VldDateV2;
|
|
704
801
|
bigint: () => VldBigInt;
|
|
802
|
+
bigintLegacy: () => VldBigInt;
|
|
803
|
+
bigintV2: () => VldBigIntV2;
|
|
705
804
|
symbol: () => VldSymbol;
|
|
706
805
|
stringbool: (options?: {
|
|
707
806
|
truthy?: readonly string[];
|
|
@@ -709,17 +808,24 @@ export declare const z: {
|
|
|
709
808
|
caseSensitive?: boolean;
|
|
710
809
|
}) => VldStringBool;
|
|
711
810
|
array: <T>(item: VldBase<unknown, T>) => VldArray<T>;
|
|
811
|
+
arrayV2: <T>(item: VldBase<unknown, T>) => VldArrayV2<T>;
|
|
812
|
+
tuple: typeof tupleFactory;
|
|
813
|
+
tupleV2: <T extends readonly VldBase<any, any>[]>(...items: T) => VldTupleV2<[...T]>;
|
|
814
|
+
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
815
|
+
setV2: <T>(item: VldBase<unknown, T>) => VldSetV2<T>;
|
|
816
|
+
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
817
|
+
mapV2: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMapV2<K, V>;
|
|
818
|
+
record: typeof recordFactory;
|
|
819
|
+
recordV2: <T>(value: VldBase<unknown, T>) => VldRecordV2<T>;
|
|
712
820
|
object: typeof objectFactory;
|
|
713
821
|
strictObject: typeof strictObjectFactory;
|
|
714
822
|
looseObject: typeof looseObjectFactory;
|
|
715
|
-
tuple: typeof tupleFactory;
|
|
716
|
-
record: typeof recordFactory;
|
|
717
823
|
partialRecord: typeof partialRecordFactory;
|
|
718
824
|
looseRecord: typeof looseRecordFactory;
|
|
719
|
-
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
720
|
-
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
721
825
|
union: typeof unionFactory;
|
|
826
|
+
unionV2: <T extends readonly VldBase<any, any>[]>(...validators: T) => VldUnionV2<[...T]>;
|
|
722
827
|
intersection: <A, B>(first: VldBase<unknown, A>, second: VldBase<unknown, B>) => VldIntersection<A, B>;
|
|
828
|
+
intersectionV2: <A, B>(left: VldBase<any, A>, right: VldBase<any, B>) => VldIntersectionV2<A, B>;
|
|
723
829
|
discriminatedUnion: typeof discriminatedUnionFactory;
|
|
724
830
|
xor: typeof xorFactory;
|
|
725
831
|
keyof: <T extends Record<string, any>>(schema: VldObject<T>) => VldEnum<[string, ...string[]]>;
|
|
@@ -727,7 +833,9 @@ export declare const z: {
|
|
|
727
833
|
input: typeof input;
|
|
728
834
|
output: typeof output;
|
|
729
835
|
literal: typeof literalFactory;
|
|
836
|
+
literalV2: <T extends string | number | boolean | null | undefined>(value: T) => VldLiteralV2<T>;
|
|
730
837
|
enum: typeof enumFactoryCompat;
|
|
838
|
+
enumV2: <T extends readonly (string | number)[]>(values: T) => VldEnumV2<T>;
|
|
731
839
|
nativeEnum: <T extends NativeEnumLike>(enumObject: T) => VldEnum<any>;
|
|
732
840
|
any: () => VldAny;
|
|
733
841
|
unknown: () => VldUnknown;
|
|
@@ -759,20 +867,26 @@ export declare const z: {
|
|
|
759
867
|
};
|
|
760
868
|
ZodFirstPartyTypeKind: {};
|
|
761
869
|
optional: <T>(validator: VldBase<unknown, T>) => VldOptional<unknown, T>;
|
|
870
|
+
optionalV2: <T>(validator: VldBase<unknown, T>) => VldOptionalV2<unknown, T>;
|
|
762
871
|
nullable: <T>(validator: VldBase<unknown, T>) => VldNullable<unknown, T>;
|
|
872
|
+
nullableV2: <T>(validator: VldBase<unknown, T>) => VldNullableV2<unknown, T>;
|
|
763
873
|
nullish: <T>(validator: VldBase<unknown, T>) => VldNullish<unknown, T>;
|
|
874
|
+
nullishV2: <T>(validator: VldBase<unknown, T>) => VldNullishV2<unknown, T>;
|
|
764
875
|
exactOptional: <T>(validator: VldBase<unknown, T>) => VldExactOptional<unknown, T>;
|
|
765
876
|
nonoptional: <T>(validator: VldBase<unknown, T | undefined>, message?: RefinementMessage) => VldRefine<unknown, T | undefined, Exclude<T, undefined>>;
|
|
766
877
|
catch: <T>(validator: VldBase<unknown, T>, fallbackValue: T) => VldCatch<unknown, T>;
|
|
767
878
|
prefault: <TInput, TOutput>(validator: VldBase<TInput, TOutput>, defaultValue: TInput | (() => TInput)) => VldPrefault<TInput, TOutput>;
|
|
768
879
|
readonly: <T>(validator: VldBase<unknown, T>) => VldReadonly<unknown, T>;
|
|
769
880
|
pipe: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
881
|
+
pipeline: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
770
882
|
clone: <T extends VldBase<any, any>>(schema: T) => T;
|
|
771
883
|
describe: <TInput, TOutput>(schemaOrDescription: VldBase<TInput, TOutput> | string, description?: string) => VldMeta<unknown, unknown>;
|
|
772
884
|
meta: <TInput, TOutput>(schemaOrMetadata: VldBase<TInput, TOutput> | Partial<SchemaMetadata>, metadata?: Partial<SchemaMetadata>) => VldMeta<unknown, unknown>;
|
|
773
885
|
transform: <TInput = unknown, TOutput = TInput>(schemaOrTransformer: VldBase<unknown, TInput> | ((value: TInput, ctx?: SuperRefineContext) => TOutput | Promise<TOutput>), transformer?: (value: TInput) => TOutput | Promise<TOutput>) => VldTransform<unknown, TInput, TOutput> | VldBase<TInput, Awaited<TOutput>>;
|
|
886
|
+
transformV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TBase | Promise<TBase>) => VldTransformV2<TInput, TBase, TBase>;
|
|
774
887
|
overwrite: <T>(transformer: (value: T) => T) => VldBase<T, Awaited<T>>;
|
|
775
888
|
refine: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
889
|
+
refineV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string) => VldRefineV2<TInput, TBase, TBase>;
|
|
776
890
|
check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
777
891
|
superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
|
|
778
892
|
property: typeof propertyCheck;
|
|
@@ -852,13 +966,19 @@ export declare const z: {
|
|
|
852
966
|
custom: typeof customFn;
|
|
853
967
|
file: () => VldFile;
|
|
854
968
|
function: () => VldFunction;
|
|
969
|
+
useV2: boolean;
|
|
970
|
+
setV2Mode: (enabled: boolean) => void;
|
|
855
971
|
preprocess: <TInput, TOutput>(preprocessor: (input: unknown) => unknown, schema: VldBase<TInput, TOutput>) => VldPreprocess<TInput, TOutput>;
|
|
856
972
|
coerce: {
|
|
857
973
|
string: () => VldCoerceString;
|
|
974
|
+
stringLegacy: () => VldCoerceString;
|
|
858
975
|
number: () => VldCoerceNumber;
|
|
976
|
+
numberLegacy: () => VldCoerceNumber;
|
|
859
977
|
boolean: () => VldCoerceBoolean;
|
|
860
978
|
date: () => VldCoerceDate;
|
|
861
979
|
bigint: () => VldCoerceBigInt;
|
|
980
|
+
stringV2: () => VldCoerceStringV2;
|
|
981
|
+
numberV2: () => VldCoerceNumberV2;
|
|
862
982
|
};
|
|
863
983
|
email: (options?: {
|
|
864
984
|
pattern?: RegExp;
|
|
@@ -1072,6 +1192,8 @@ export declare const z: {
|
|
|
1072
1192
|
$output: symbol;
|
|
1073
1193
|
$input: symbol;
|
|
1074
1194
|
};
|
|
1195
|
+
export { toZodError, toZodSafeResult, ZodLikeError } from './zod-error.js';
|
|
1196
|
+
export type { ZodLikeIssue } from './zod-error.js';
|
|
1075
1197
|
/**
|
|
1076
1198
|
* Zod-compatible root-level factory aliases.
|
|
1077
1199
|
*
|
|
@@ -1085,10 +1207,14 @@ export declare const string: () => VldString, number: () => VldNumber, int: () =
|
|
|
1085
1207
|
caseSensitive?: boolean;
|
|
1086
1208
|
}) => VldStringBool, array: <T>(item: VldBase<unknown, T>) => VldArray<T>, object: typeof objectFactory, strictObject: typeof strictObjectFactory, looseObject: typeof looseObjectFactory, tuple: typeof tupleFactory, record: typeof recordFactory, partialRecord: typeof partialRecordFactory, looseRecord: typeof looseRecordFactory, set: <T>(item: VldBase<unknown, T>) => VldSet<T>, union: typeof unionFactory, intersection: <A, B>(first: VldBase<unknown, A>, second: VldBase<unknown, B>) => VldIntersection<A, B>, discriminatedUnion: typeof discriminatedUnionFactory, xor: typeof xorFactory, keyof: <T extends Record<string, any>>(schema: VldObject<T>) => VldEnum<[string, ...string[]]>, literal: typeof literalFactory, nativeEnum: <T extends NativeEnumLike>(enumObject: T) => VldEnum<any>, any: () => VldAny, unknown: () => VldUnknown, nan: () => VldNan, optional: <T>(validator: VldBase<unknown, T>) => VldOptional<unknown, T>, nullable: <T>(validator: VldBase<unknown, T>) => VldNullable<unknown, T>, nullish: <T>(validator: VldBase<unknown, T>) => VldNullish<unknown, T>, exactOptional: <T>(validator: VldBase<unknown, T>) => VldExactOptional<unknown, T>, nonoptional: <T>(validator: VldBase<unknown, T | undefined>, message?: RefinementMessage) => VldRefine<unknown, T | undefined, Exclude<T, undefined>>, readonly: <T>(validator: VldBase<unknown, T>) => VldReadonly<unknown, T>, pipe: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>, clone: <T extends VldBase<any, any>>(schema: T) => T, describe: <TInput, TOutput>(schemaOrDescription: VldBase<TInput, TOutput> | string, description?: string) => VldMeta<unknown, unknown>, meta: <TInput, TOutput>(schemaOrMetadata: VldBase<TInput, TOutput> | Partial<SchemaMetadata>, metadata?: Partial<SchemaMetadata>) => VldMeta<unknown, unknown>, transform: <TInput = unknown, TOutput = TInput>(schemaOrTransformer: VldBase<unknown, TInput> | ((value: TInput, ctx?: SuperRefineContext) => TOutput | Promise<TOutput>), transformer?: (value: TInput) => TOutput | Promise<TOutput>) => VldTransform<unknown, TInput, TOutput> | VldBase<TInput, Awaited<TOutput>>, overwrite: <T>(transformer: (value: T) => T) => VldBase<T, Awaited<T>>, refine: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>, check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>, superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>, property: typeof propertyCheck, config: typeof configure, setErrorMap: typeof setGlobalErrorMap, getErrorMap: typeof getGlobalErrorMap, locales: typeof localeNamespace, lazy: <T>(schemaGetter: () => VldBase<unknown, T>) => VldLazy<unknown, T>, json: <T = unknown>(schema?: VldBase<unknown, T>) => VldJson<T>, custom: typeof customFn, file: () => VldFile, preprocess: <TInput, TOutput>(preprocessor: (input: unknown) => unknown, schema: VldBase<TInput, TOutput>) => VldPreprocess<TInput, TOutput>, coerce: {
|
|
1087
1209
|
string: () => VldCoerceString;
|
|
1210
|
+
stringLegacy: () => VldCoerceString;
|
|
1088
1211
|
number: () => VldCoerceNumber;
|
|
1212
|
+
numberLegacy: () => VldCoerceNumber;
|
|
1089
1213
|
boolean: () => VldCoerceBoolean;
|
|
1090
1214
|
date: () => VldCoerceDate;
|
|
1091
1215
|
bigint: () => VldCoerceBigInt;
|
|
1216
|
+
stringV2: () => VldCoerceStringV2;
|
|
1217
|
+
numberV2: () => VldCoerceNumberV2;
|
|
1092
1218
|
}, email: (options?: {
|
|
1093
1219
|
pattern?: RegExp;
|
|
1094
1220
|
}) => stringFormats.VldStringFormat, url: (options?: stringFormats.URLFormatOptions) => stringFormats.VldStringFormat, uuid: (options?: {
|
|
@@ -1133,7 +1259,11 @@ declare const undefinedFactory: () => VldUndefined;
|
|
|
1133
1259
|
declare const voidFactory: () => VldVoid;
|
|
1134
1260
|
declare const defaultFactory: {
|
|
1135
1261
|
string: () => VldString;
|
|
1262
|
+
stringLegacy: () => VldString;
|
|
1263
|
+
stringV2: () => VldStringV2;
|
|
1136
1264
|
number: () => VldNumber;
|
|
1265
|
+
numberLegacy: () => VldNumber;
|
|
1266
|
+
numberV2: () => VldNumberV2;
|
|
1137
1267
|
int: () => VldNumber;
|
|
1138
1268
|
int32: () => VldNumber;
|
|
1139
1269
|
uint32: () => VldNumber;
|
|
@@ -1142,8 +1272,13 @@ declare const defaultFactory: {
|
|
|
1142
1272
|
float32: () => VldNumber;
|
|
1143
1273
|
float64: () => VldNumber;
|
|
1144
1274
|
boolean: () => VldBoolean;
|
|
1275
|
+
booleanV2: () => VldBooleanV2;
|
|
1145
1276
|
date: () => VldDate;
|
|
1277
|
+
dateLegacy: () => VldDate;
|
|
1278
|
+
dateV2: () => VldDateV2;
|
|
1146
1279
|
bigint: () => VldBigInt;
|
|
1280
|
+
bigintLegacy: () => VldBigInt;
|
|
1281
|
+
bigintV2: () => VldBigIntV2;
|
|
1147
1282
|
symbol: () => VldSymbol;
|
|
1148
1283
|
stringbool: (options?: {
|
|
1149
1284
|
truthy?: readonly string[];
|
|
@@ -1151,17 +1286,24 @@ declare const defaultFactory: {
|
|
|
1151
1286
|
caseSensitive?: boolean;
|
|
1152
1287
|
}) => VldStringBool;
|
|
1153
1288
|
array: <T>(item: VldBase<unknown, T>) => VldArray<T>;
|
|
1289
|
+
arrayV2: <T>(item: VldBase<unknown, T>) => VldArrayV2<T>;
|
|
1290
|
+
tuple: typeof tupleFactory;
|
|
1291
|
+
tupleV2: <T extends readonly VldBase<any, any>[]>(...items: T) => VldTupleV2<[...T]>;
|
|
1292
|
+
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
1293
|
+
setV2: <T>(item: VldBase<unknown, T>) => VldSetV2<T>;
|
|
1294
|
+
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
1295
|
+
mapV2: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMapV2<K, V>;
|
|
1296
|
+
record: typeof recordFactory;
|
|
1297
|
+
recordV2: <T>(value: VldBase<unknown, T>) => VldRecordV2<T>;
|
|
1154
1298
|
object: typeof objectFactory;
|
|
1155
1299
|
strictObject: typeof strictObjectFactory;
|
|
1156
1300
|
looseObject: typeof looseObjectFactory;
|
|
1157
|
-
tuple: typeof tupleFactory;
|
|
1158
|
-
record: typeof recordFactory;
|
|
1159
1301
|
partialRecord: typeof partialRecordFactory;
|
|
1160
1302
|
looseRecord: typeof looseRecordFactory;
|
|
1161
|
-
set: <T>(item: VldBase<unknown, T>) => VldSet<T>;
|
|
1162
|
-
map: <K, V>(key: VldBase<unknown, K>, value: VldBase<unknown, V>) => VldMap<K, V>;
|
|
1163
1303
|
union: typeof unionFactory;
|
|
1304
|
+
unionV2: <T extends readonly VldBase<any, any>[]>(...validators: T) => VldUnionV2<[...T]>;
|
|
1164
1305
|
intersection: <A, B>(first: VldBase<unknown, A>, second: VldBase<unknown, B>) => VldIntersection<A, B>;
|
|
1306
|
+
intersectionV2: <A, B>(left: VldBase<any, A>, right: VldBase<any, B>) => VldIntersectionV2<A, B>;
|
|
1165
1307
|
discriminatedUnion: typeof discriminatedUnionFactory;
|
|
1166
1308
|
xor: typeof xorFactory;
|
|
1167
1309
|
keyof: <T extends Record<string, any>>(schema: VldObject<T>) => VldEnum<[string, ...string[]]>;
|
|
@@ -1169,7 +1311,9 @@ declare const defaultFactory: {
|
|
|
1169
1311
|
input: typeof input;
|
|
1170
1312
|
output: typeof output;
|
|
1171
1313
|
literal: typeof literalFactory;
|
|
1314
|
+
literalV2: <T extends string | number | boolean | null | undefined>(value: T) => VldLiteralV2<T>;
|
|
1172
1315
|
enum: typeof enumFactoryCompat;
|
|
1316
|
+
enumV2: <T extends readonly (string | number)[]>(values: T) => VldEnumV2<T>;
|
|
1173
1317
|
nativeEnum: <T extends NativeEnumLike>(enumObject: T) => VldEnum<any>;
|
|
1174
1318
|
any: () => VldAny;
|
|
1175
1319
|
unknown: () => VldUnknown;
|
|
@@ -1201,20 +1345,26 @@ declare const defaultFactory: {
|
|
|
1201
1345
|
};
|
|
1202
1346
|
ZodFirstPartyTypeKind: {};
|
|
1203
1347
|
optional: <T>(validator: VldBase<unknown, T>) => VldOptional<unknown, T>;
|
|
1348
|
+
optionalV2: <T>(validator: VldBase<unknown, T>) => VldOptionalV2<unknown, T>;
|
|
1204
1349
|
nullable: <T>(validator: VldBase<unknown, T>) => VldNullable<unknown, T>;
|
|
1350
|
+
nullableV2: <T>(validator: VldBase<unknown, T>) => VldNullableV2<unknown, T>;
|
|
1205
1351
|
nullish: <T>(validator: VldBase<unknown, T>) => VldNullish<unknown, T>;
|
|
1352
|
+
nullishV2: <T>(validator: VldBase<unknown, T>) => VldNullishV2<unknown, T>;
|
|
1206
1353
|
exactOptional: <T>(validator: VldBase<unknown, T>) => VldExactOptional<unknown, T>;
|
|
1207
1354
|
nonoptional: <T>(validator: VldBase<unknown, T | undefined>, message?: RefinementMessage) => VldRefine<unknown, T | undefined, Exclude<T, undefined>>;
|
|
1208
1355
|
catch: <T>(validator: VldBase<unknown, T>, fallbackValue: T) => VldCatch<unknown, T>;
|
|
1209
1356
|
prefault: <TInput, TOutput>(validator: VldBase<TInput, TOutput>, defaultValue: TInput | (() => TInput)) => VldPrefault<TInput, TOutput>;
|
|
1210
1357
|
readonly: <T>(validator: VldBase<unknown, T>) => VldReadonly<unknown, T>;
|
|
1211
1358
|
pipe: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
1359
|
+
pipeline: <TInput, TIntermediate, TOutput>(first: VldBase<TInput, TIntermediate>, second: VldBase<any, TOutput>) => VldPipe<TInput, TIntermediate, TOutput>;
|
|
1212
1360
|
clone: <T extends VldBase<any, any>>(schema: T) => T;
|
|
1213
1361
|
describe: <TInput, TOutput>(schemaOrDescription: VldBase<TInput, TOutput> | string, description?: string) => VldMeta<unknown, unknown>;
|
|
1214
1362
|
meta: <TInput, TOutput>(schemaOrMetadata: VldBase<TInput, TOutput> | Partial<SchemaMetadata>, metadata?: Partial<SchemaMetadata>) => VldMeta<unknown, unknown>;
|
|
1215
1363
|
transform: <TInput = unknown, TOutput = TInput>(schemaOrTransformer: VldBase<unknown, TInput> | ((value: TInput, ctx?: SuperRefineContext) => TOutput | Promise<TOutput>), transformer?: (value: TInput) => TOutput | Promise<TOutput>) => VldTransform<unknown, TInput, TOutput> | VldBase<TInput, Awaited<TOutput>>;
|
|
1364
|
+
transformV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TBase | Promise<TBase>) => VldTransformV2<TInput, TBase, TBase>;
|
|
1216
1365
|
overwrite: <T>(transformer: (value: T) => T) => VldBase<T, Awaited<T>>;
|
|
1217
1366
|
refine: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
1367
|
+
refineV2: <TInput, TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string) => VldRefineV2<TInput, TBase, TBase>;
|
|
1218
1368
|
check: <T = unknown>(schemaOrPredicate: VldBase<unknown, T> | ((value: T) => boolean | Promise<boolean>), predicateOrMessage?: ((value: T) => boolean | Promise<boolean>) | RefinementMessage, message?: RefinementMessage) => VldBase<unknown, T>;
|
|
1219
1369
|
superRefine: <T = unknown>(schemaOrRefinement: VldBase<unknown, T> | ((value: T, ctx: SuperRefineContext) => void | Promise<void>), refinement?: (value: T, ctx: SuperRefineContext) => void | Promise<void>) => VldBase<unknown, T>;
|
|
1220
1370
|
property: typeof propertyCheck;
|
|
@@ -1294,13 +1444,19 @@ declare const defaultFactory: {
|
|
|
1294
1444
|
custom: typeof customFn;
|
|
1295
1445
|
file: () => VldFile;
|
|
1296
1446
|
function: () => VldFunction;
|
|
1447
|
+
useV2: boolean;
|
|
1448
|
+
setV2Mode: (enabled: boolean) => void;
|
|
1297
1449
|
preprocess: <TInput, TOutput>(preprocessor: (input: unknown) => unknown, schema: VldBase<TInput, TOutput>) => VldPreprocess<TInput, TOutput>;
|
|
1298
1450
|
coerce: {
|
|
1299
1451
|
string: () => VldCoerceString;
|
|
1452
|
+
stringLegacy: () => VldCoerceString;
|
|
1300
1453
|
number: () => VldCoerceNumber;
|
|
1454
|
+
numberLegacy: () => VldCoerceNumber;
|
|
1301
1455
|
boolean: () => VldCoerceBoolean;
|
|
1302
1456
|
date: () => VldCoerceDate;
|
|
1303
1457
|
bigint: () => VldCoerceBigInt;
|
|
1458
|
+
stringV2: () => VldCoerceStringV2;
|
|
1459
|
+
numberV2: () => VldCoerceNumberV2;
|
|
1304
1460
|
};
|
|
1305
1461
|
email: (options?: {
|
|
1306
1462
|
pattern?: RegExp;
|