@oxog/vld 2.4.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +68 -1
  2. package/README.md +113 -1
  3. package/dist/chunks/errors-core-BU14-Dk8.js +1 -0
  4. package/dist/cjs/chunks/errors-core-C0mA6tfa.cjs +1 -0
  5. package/dist/cjs/cli/bin.cjs +1 -1
  6. package/dist/cjs/codecs/index.cjs +1 -1
  7. package/dist/cjs/coercion/index.cjs +1 -1
  8. package/dist/cjs/compile.cjs +1 -1
  9. package/dist/cjs/errors.cjs +1 -1
  10. package/dist/cjs/index.cjs +1 -1
  11. package/dist/cjs/mini.cjs +1 -1
  12. package/dist/cjs/v3/index.cjs +1 -1
  13. package/dist/cjs/v4/core/index.cjs +1 -1
  14. package/dist/cjs/v4/index.cjs +1 -1
  15. package/dist/cjs/v4/mini/index.cjs +1 -1
  16. package/dist/cjs/v4-mini/index.cjs +1 -1
  17. package/dist/cjs/validators/any.cjs +1 -1
  18. package/dist/cjs/validators/array-v2.cjs +1 -0
  19. package/dist/cjs/validators/array.cjs +1 -1
  20. package/dist/cjs/validators/base.cjs +1 -1
  21. package/dist/cjs/validators/base64.cjs +1 -1
  22. package/dist/cjs/validators/bigint-v2.cjs +1 -0
  23. package/dist/cjs/validators/bigint.cjs +1 -1
  24. package/dist/cjs/validators/boolean.cjs +1 -1
  25. package/dist/cjs/validators/codec.cjs +1 -1
  26. package/dist/cjs/validators/composite-v2.cjs +1 -0
  27. package/dist/cjs/validators/custom.cjs +1 -1
  28. package/dist/cjs/validators/date-v2.cjs +1 -0
  29. package/dist/cjs/validators/date.cjs +1 -1
  30. package/dist/cjs/validators/discriminated-union.cjs +1 -1
  31. package/dist/cjs/validators/enum.cjs +1 -1
  32. package/dist/cjs/validators/file.cjs +1 -1
  33. package/dist/cjs/validators/function.cjs +1 -1
  34. package/dist/cjs/validators/hex.cjs +1 -1
  35. package/dist/cjs/validators/index.cjs +1 -1
  36. package/dist/cjs/validators/intersection.cjs +1 -1
  37. package/dist/cjs/validators/json.cjs +1 -1
  38. package/dist/cjs/validators/lazy.cjs +1 -1
  39. package/dist/cjs/validators/leaf-v2.cjs +1 -0
  40. package/dist/cjs/validators/literal.cjs +1 -1
  41. package/dist/cjs/validators/map.cjs +1 -1
  42. package/dist/cjs/validators/nan.cjs +1 -1
  43. package/dist/cjs/validators/never.cjs +1 -1
  44. package/dist/cjs/validators/null.cjs +1 -1
  45. package/dist/cjs/validators/number-v2.cjs +1 -0
  46. package/dist/cjs/validators/number.cjs +1 -1
  47. package/dist/cjs/validators/object-v2.cjs +1 -0
  48. package/dist/cjs/validators/object.cjs +1 -1
  49. package/dist/cjs/validators/promise.cjs +1 -1
  50. package/dist/cjs/validators/record.cjs +1 -1
  51. package/dist/cjs/validators/set.cjs +1 -1
  52. package/dist/cjs/validators/string-bool.cjs +1 -1
  53. package/dist/cjs/validators/string-formats.cjs +1 -1
  54. package/dist/cjs/validators/string-v2.cjs +1 -0
  55. package/dist/cjs/validators/string.cjs +1 -1
  56. package/dist/cjs/validators/symbol.cjs +1 -1
  57. package/dist/cjs/validators/template-literal.cjs +1 -1
  58. package/dist/cjs/validators/tuple.cjs +1 -1
  59. package/dist/cjs/validators/uint8array.cjs +1 -1
  60. package/dist/cjs/validators/undefined.cjs +1 -1
  61. package/dist/cjs/validators/union-v2.cjs +1 -0
  62. package/dist/cjs/validators/union.cjs +1 -1
  63. package/dist/cjs/validators/unknown.cjs +1 -1
  64. package/dist/cjs/validators/void.cjs +1 -1
  65. package/dist/cjs/validators/wrapper-v2.cjs +1 -0
  66. package/dist/cjs/validators/xor.cjs +1 -1
  67. package/dist/errors-core.d.ts +3 -0
  68. package/dist/errors.js +1 -1
  69. package/dist/index.d.ts +168 -12
  70. package/dist/index.js +1 -1
  71. package/dist/v3/index.js +1 -1
  72. package/dist/v4/core/index.js +1 -1
  73. package/dist/v4/index.js +1 -1
  74. package/dist/v4/mini/index.js +1 -1
  75. package/dist/v4-mini/index.js +1 -1
  76. package/dist/validators/array-v2.d.ts +113 -0
  77. package/dist/validators/array-v2.js +1 -0
  78. package/dist/validators/array.js +1 -1
  79. package/dist/validators/base.js +1 -1
  80. package/dist/validators/base64.js +1 -1
  81. package/dist/validators/bigint-v2.d.ts +105 -0
  82. package/dist/validators/bigint-v2.js +1 -0
  83. package/dist/validators/bigint.js +1 -1
  84. package/dist/validators/boolean.js +1 -1
  85. package/dist/validators/codec.js +1 -1
  86. package/dist/validators/composite-v2.d.ts +59 -0
  87. package/dist/validators/composite-v2.js +1 -0
  88. package/dist/validators/date-v2.d.ts +140 -0
  89. package/dist/validators/date-v2.js +1 -0
  90. package/dist/validators/date.js +1 -1
  91. package/dist/validators/enum.js +1 -1
  92. package/dist/validators/file.js +1 -1
  93. package/dist/validators/function.js +1 -1
  94. package/dist/validators/hex.js +1 -1
  95. package/dist/validators/intersection.js +1 -1
  96. package/dist/validators/leaf-v2.d.ts +138 -0
  97. package/dist/validators/leaf-v2.js +1 -0
  98. package/dist/validators/literal.js +1 -1
  99. package/dist/validators/map.js +1 -1
  100. package/dist/validators/nan.js +1 -1
  101. package/dist/validators/never.js +1 -1
  102. package/dist/validators/null.js +1 -1
  103. package/dist/validators/number-v2.d.ts +252 -0
  104. package/dist/validators/number-v2.js +1 -0
  105. package/dist/validators/number.js +1 -1
  106. package/dist/validators/object-v2.d.ts +40 -0
  107. package/dist/validators/object-v2.js +1 -0
  108. package/dist/validators/object.js +1 -1
  109. package/dist/validators/record.js +1 -1
  110. package/dist/validators/set.js +1 -1
  111. package/dist/validators/string-formats.js +1 -1
  112. package/dist/validators/string-v2.d.ts +274 -0
  113. package/dist/validators/string-v2.js +1 -0
  114. package/dist/validators/string.js +1 -1
  115. package/dist/validators/symbol.js +1 -1
  116. package/dist/validators/tuple.js +1 -1
  117. package/dist/validators/uint8array.js +1 -1
  118. package/dist/validators/undefined.js +1 -1
  119. package/dist/validators/union-v2.d.ts +28 -0
  120. package/dist/validators/union-v2.js +1 -0
  121. package/dist/validators/void.js +1 -1
  122. package/dist/validators/wrapper-v2.d.ts +74 -0
  123. package/dist/validators/wrapper-v2.js +1 -0
  124. package/dist/zod-error.d.ts +84 -0
  125. package/package.json +1 -1
  126. package/dist/chunks/errors-core-CerMg2rq.js +0 -1
  127. package/dist/cjs/chunks/errors-core-DrydF46s.cjs +0 -1
@@ -0,0 +1 @@
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{V as s}from"../chunks/errors-core-BU14-Dk8.js";import{getMessages as t}from"../locales/runtime.js";function n(e){if(!0===e.isSimple)switch(e.validatorType){case r.STRING:return"string";case r.NUMBER:return"number";case r.BOOLEAN:return"boolean";case r.BIGINT:return"bigint";case r.SYMBOL:return"symbol";case r.NULL:return"null";case r.UNDEFINED:case r.VOID:return"undefined";case r.LITERAL:return"literal";case r.ANY:case r.UNKNOWN:return"passthrough";default:return}}function a(e){switch(e.validatorType){case r.STRING:return e=>"string"==typeof e;case r.NUMBER:return e=>"number"==typeof e&&!isNaN(e);case r.BOOLEAN:return e=>"boolean"==typeof e;case r.BIGINT:return e=>"bigint"==typeof e;case r.SYMBOL:return e=>"symbol"==typeof e;case r.NAN:return e=>"number"==typeof e&&Number.isNaN(e);case r.ARRAY:return Array.isArray;case r.OBJECT:return e=>"object"==typeof e&&null!==e&&!Array.isArray(e);case r.NULL:return e=>null===e;case r.UNDEFINED:case r.VOID:return e=>void 0===e;case r.ENUM:return e=>"string"==typeof e||"number"==typeof e;case r.LITERAL:{const r=e.literal;return e=>e===r}case r.NEVER:return()=>!1;case r.ANY:case r.UNKNOWN:default:return()=>!0}}class VldUnionV2 extends e{constructor(e,s){super(r.UNION),this.__def=function(e,r){const s=e.map(a),t=e.map(n),c=e.map((e,r)=>"literal"===t[r]?e.literal:void 0);return{type:"union",validators:e,typeCheckers:s,simpleModes:t,simpleValues:c,errorMessage:r}}(e,s)}static create(...e){return new VldUnionV2(e)}get options(){return this.__def.validators}parse(e){const r=[],{validators:s,typeCheckers:n,simpleModes:a,simpleValues:c}=this.__def;for(let t=0;t<s.length;t++){const o=s[t],u=n[t];if(u&&!u(e))continue;const i=a[t];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[t]}try{return o.parse(e)}catch(e){r.push(e instanceof Error?e.message:String(e))}}throw new Error(this.__def.errorMessage||t().unionNoMatch(r))}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:e instanceof s?e:new s([{code:"custom",path:[],message:e.message}])}}}}export{VldUnionV2};
@@ -1 +1 @@
1
- import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as s}from"../locales/runtime.js";import{V as o}from"../chunks/errors-core-CerMg2rq.js";class VldVoid extends e{constructor(){super(r.VOID)}static create(){return new VldVoid}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error(s().expectedUndefined)}safeParse(e){return void 0===e?{success:!0,data:void 0}:{success:!1,error:new o([{code:"invalid_type",path:[],message:s().expectedUndefined}])}}}export{VldVoid};
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r}from"./base.js";import{getMessages as s}from"../locales/runtime.js";import{V as o}from"../chunks/errors-core-BU14-Dk8.js";class VldVoid extends e{constructor(){super(r.VOID)}static create(){return new VldVoid}get isSimple(){return!0}parse(e){if(void 0!==e)throw new Error(s().expectedUndefined)}safeParse(e){return void 0===e?{success:!0,data:void 0}:{success:!1,error:new o([{code:"invalid_type",path:[],message:s().expectedUndefined}])}}}export{VldVoid};
@@ -0,0 +1,74 @@
1
+ /**
2
+ * V2 wrappers: VldOptionalV2, VldNullableV2, VldNullishV2, VldRefineV2, VldTransformV2.
3
+ * All single-def pattern. Public API mirrors legacy wrappers 1:1.
4
+ */
5
+ import { VldBase, type ParseResult } from './base.js';
6
+ export interface VldOptionalDef<TInput, TOutput> {
7
+ readonly type: 'optional';
8
+ readonly inner: VldBase<TInput, TOutput>;
9
+ }
10
+ export declare class VldOptionalV2<TInput, TOutput> extends VldBase<TInput | undefined, TOutput | undefined> {
11
+ readonly __def: VldOptionalDef<TInput, TOutput>;
12
+ constructor(inner: VldBase<TInput, TOutput>);
13
+ static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldOptionalV2<TInput, TOutput>;
14
+ parse(value: unknown): TOutput | undefined;
15
+ safeParse(value: unknown): ParseResult<TOutput | undefined>;
16
+ unwrap(): VldBase<TInput, TOutput>;
17
+ }
18
+ export interface VldNullableDef<TInput, TOutput> {
19
+ readonly type: 'nullable';
20
+ readonly inner: VldBase<TInput, TOutput>;
21
+ }
22
+ export declare class VldNullableV2<TInput, TOutput> extends VldBase<TInput | null, TOutput | null> {
23
+ readonly __def: VldNullableDef<TInput, TOutput>;
24
+ constructor(inner: VldBase<TInput, TOutput>);
25
+ static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldNullableV2<TInput, TOutput>;
26
+ parse(value: unknown): TOutput | null;
27
+ safeParse(value: unknown): ParseResult<TOutput | null>;
28
+ unwrap(): VldBase<TInput, TOutput>;
29
+ }
30
+ export interface VldNullishDef<TInput, TOutput> {
31
+ readonly type: 'nullish';
32
+ readonly inner: VldBase<TInput, TOutput>;
33
+ }
34
+ export declare class VldNullishV2<TInput, TOutput> extends VldBase<TInput | null | undefined, TOutput | null | undefined> {
35
+ readonly __def: VldNullishDef<TInput, TOutput>;
36
+ constructor(inner: VldBase<TInput, TOutput>);
37
+ static create<TInput, TOutput>(baseValidator: VldBase<TInput, TOutput>): VldNullishV2<TInput, TOutput>;
38
+ parse(value: unknown): TOutput | null | undefined;
39
+ safeParse(value: unknown): ParseResult<TOutput | null | undefined>;
40
+ unwrap(): VldBase<TInput, TOutput>;
41
+ }
42
+ export interface VldRefineDef<TInput, TBase> {
43
+ readonly type: 'refine';
44
+ readonly inner: VldBase<TInput, TBase>;
45
+ readonly predicate: (value: TBase) => boolean | Promise<boolean>;
46
+ readonly message: string;
47
+ readonly path?: ReadonlyArray<string | number> | undefined;
48
+ }
49
+ export declare class VldRefineV2<TInput, TBase, TOutput extends TBase = TBase> extends VldBase<TInput, TOutput> {
50
+ readonly __def: VldRefineDef<TInput, TBase>;
51
+ constructor(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string, path?: ReadonlyArray<string | number>);
52
+ static create<TInput, TBase, TOutput extends TBase = TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => value is TOutput, message?: string): VldRefineV2<TInput, TBase, TOutput>;
53
+ static create<TInput, TBase, TOutput extends TBase = TBase>(inner: VldBase<TInput, TBase>, predicate: (value: TBase) => boolean | Promise<boolean>, message?: string): VldRefineV2<TInput, TBase, TOutput>;
54
+ parse(value: unknown): TOutput;
55
+ safeParse(value: unknown): ParseResult<TOutput>;
56
+ parseAsync(value: unknown): Promise<TOutput>;
57
+ safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
58
+ unwrap(): VldBase<TInput, TBase>;
59
+ }
60
+ export interface VldTransformDef<TInput, TBase, TOutput> {
61
+ readonly type: 'transform';
62
+ readonly inner: VldBase<TInput, TBase>;
63
+ readonly transformer: (value: TBase) => TOutput | Promise<TOutput>;
64
+ }
65
+ export declare class VldTransformV2<TInput, TBase, TOutput> extends VldBase<TInput, TOutput> {
66
+ readonly __def: VldTransformDef<TInput, TBase, TOutput>;
67
+ constructor(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TOutput | Promise<TOutput>);
68
+ static create<TInput, TBase, TOutput>(inner: VldBase<TInput, TBase>, transformer: (value: TBase) => TOutput | Promise<TOutput>): VldTransformV2<TInput, TBase, TOutput>;
69
+ parse(value: unknown): TOutput;
70
+ safeParse(value: unknown): ParseResult<TOutput>;
71
+ parseAsync(value: unknown): Promise<TOutput>;
72
+ safeParseAsync(value: unknown): Promise<ParseResult<TOutput>>;
73
+ unwrap(): VldBase<TInput, TBase>;
74
+ }
@@ -0,0 +1 @@
1
+ import{VldBase as e,VLD_VALIDATOR_TYPES as r,ensureVldError as s}from"./base.js";import{V as t}from"../chunks/errors-core-BU14-Dk8.js";class VldOptionalV2 extends e{constructor(e){super(r.OPTIONAL),this.__def=Object.freeze({type:"optional",inner:e})}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{constructor(e){super(r.NULLABLE),this.__def=Object.freeze({type:"nullable",inner:e})}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{constructor(e){super(r.NULLISH),this.__def=Object.freeze({type:"nullish",inner:e})}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{constructor(e,s,t="Refinement check failed",n){super(r.REFINE),this.__def=Object.freeze({type:"refine",inner:e,predicate:s,message:t,path:n})}static create(e,r,s="Refinement check failed"){return new VldRefineV2(e,r,s)}parse(e){const r=this.__def.inner.parse(e),s=this.__def.predicate(r);if(s instanceof Promise)throw new Error("Use parseAsync for async refinements");if(!s)throw new t([{code:"custom",path:this.__def.path?[...this.__def.path]:[],message:this.__def.message}]);return r}safeParse(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const r=await this.__def.inner.parseAsync(e);if(!await this.__def.predicate(r))throw new t([{code:"custom",path:[],message:this.__def.message}]);return r}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}unwrap(){return this.__def.inner}}class VldTransformV2 extends e{constructor(e,s){super(r.TRANSFORM),this.__def=Object.freeze({type:"transform",inner:e,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(e){try{return{success:!0,data:this.parse(e)}}catch(e){return{success:!1,error:s(e)}}}async parseAsync(e){const r=await this.__def.inner.parseAsync(e);return this.__def.transformer(r)}async safeParseAsync(e){try{return{success:!0,data:await this.parseAsync(e)}}catch(e){return{success:!1,error:s(e)}}}unwrap(){return this.__def.inner}}export{VldNullableV2,VldNullishV2,VldOptionalV2,VldRefineV2,VldTransformV2};
@@ -0,0 +1,84 @@
1
+ /**
2
+ * ZodError compatibility layer.
3
+ *
4
+ * Converts a VldError into a ZodError-shaped object so VLD can be a true
5
+ * drop-in replacement for Zod. The result has the same `issues` shape
6
+ * and `format()` / `flatten()` helpers that Zod users expect.
7
+ *
8
+ * @example
9
+ * const r = v.object({ a: v.string() }).safeParse({ a: 1 });
10
+ * if (!r.success) {
11
+ * const zErr = toZodError(r.error);
12
+ * console.log(zErr.issues[0].expected); // "string"
13
+ * console.log(zErr.format());
14
+ * }
15
+ */
16
+ export interface ZodLikeIssue {
17
+ /** The validator that failed: 'string', 'number', 'object', etc. */
18
+ origin?: string;
19
+ /** Discriminator code: 'invalid_type', 'too_small', 'invalid_format', etc. */
20
+ code: string;
21
+ /** Path to the failing field. */
22
+ path: (string | number)[];
23
+ /** Human-readable error message. */
24
+ message: string;
25
+ /** The expected value/type, when applicable. */
26
+ expected?: string | number | boolean | null;
27
+ /** The actual value/type that was received, when applicable. */
28
+ received?: unknown;
29
+ /** For numeric bounds. */
30
+ minimum?: number;
31
+ maximum?: number;
32
+ inclusive?: boolean;
33
+ /** For string length / array length bounds. */
34
+ format?: string;
35
+ pattern?: string;
36
+ /** Allow additional fields. */
37
+ [key: string]: unknown;
38
+ }
39
+ export declare class ZodLikeError extends Error {
40
+ /** Array of individual issue descriptors. */
41
+ readonly issues: ReadonlyArray<ZodLikeIssue>;
42
+ /** Top-level error code (VLD-specific; Zod doesn't have this). */
43
+ readonly code: string;
44
+ constructor(issues: ReadonlyArray<ZodLikeIssue>);
45
+ /**
46
+ * Zod-compatible `format()` method. Returns a nested error tree
47
+ * keyed by path. For backward compatibility with Zod, the default
48
+ * format() returns `_errors: string[]` and any nested fields.
49
+ */
50
+ format(): Record<string, any>;
51
+ /**
52
+ * Zod-compatible `flatten()` method. Returns `{ formErrors: string[],
53
+ * fieldErrors: Record<string, string[]> }`.
54
+ */
55
+ flatten(): {
56
+ formErrors: string[];
57
+ fieldErrors: Record<string, string[]>;
58
+ };
59
+ /** Zod-compatible `errors` getter (alias of `issues`). */
60
+ get errors(): ReadonlyArray<ZodLikeIssue>;
61
+ }
62
+ /**
63
+ * Convert a VldError to a ZodError-shaped error.
64
+ *
65
+ * The returned ZodLikeError has the same `issues` array shape, plus
66
+ * `format()` and `flatten()` helpers that Zod users expect.
67
+ */
68
+ export declare function toZodError(vldError: any): ZodLikeError;
69
+ /**
70
+ * Convenience: convert a safeParse result to a Zod-shaped result.
71
+ * If `result.success === false`, the `error` field will be a ZodLikeError
72
+ * instead of the raw VldError. Otherwise the result is unchanged.
73
+ */
74
+ export declare function toZodSafeResult<T>(result: {
75
+ success: boolean;
76
+ data?: T;
77
+ error?: any;
78
+ }): {
79
+ success: true;
80
+ data: T;
81
+ } | {
82
+ success: false;
83
+ error: ZodLikeError;
84
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxog/vld",
3
- "version": "2.4.0",
3
+ "version": "3.0.1",
4
4
  "description": "Ultra-fast TypeScript-first schema validation with zero dependencies, 27+ language support, plugin system, and CLI tools",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -1 +0,0 @@
1
- function e(e){return null===e?"null":void 0===e?"undefined":Array.isArray(e)?"array":"number"==typeof e?Number.isNaN(e)?"nan":e===1/0?"Infinity":e===-1/0?"-Infinity":"number":e instanceof Date?"date":e instanceof Map?"map":e instanceof Set?"set":typeof e}function s(e,s,r){return{code:"invalid_type",path:[],expected:e,received:s,message:r??`Invalid input: expected ${e}, received ${s}`}}function r(e){const s={code:e.code,path:e.path,message:e.message};return void 0!==e.expected&&(s.expected=e.expected),void 0!==e.received&&(s.received=e.received),void 0!==e.keys&&(s.keys=e.keys),void 0!==e.minimum&&(s.minimum=e.minimum),void 0!==e.maximum&&(s.maximum=e.maximum),void 0!==e.exact&&(s.exact=e.exact),void 0!==e.inclusive&&(s.inclusive=e.inclusive),void 0!==e.origin&&(s.origin=e.origin),void 0!==e.format&&(s.format=e.format),void 0!==e.values&&(s.values=e.values),void 0!==e.pattern&&(s.pattern=e.pattern),s}function i(e){const s={code:e.code,path:e.path,message:e.message};return void 0!==e.expected&&(s.expected=e.expected),void 0!==e.received&&(s.received=e.received),void 0!==e.keys&&(s.keys=e.keys),void 0!==e.minimum&&(s.minimum=e.minimum),void 0!==e.maximum&&(s.maximum=e.maximum),void 0!==e.exact&&(s.exact=e.exact),void 0!==e.inclusive&&(s.inclusive=e.inclusive),void 0!==e.origin&&(s.origin=e.origin),void 0!==e.format&&(s.format=e.format),void 0!==e.values&&(s.values=e.values),void 0!==e.pattern&&(s.pattern=e.pattern),s}class VldError extends Error{constructor(e,s){const r=e[0];super(void 0!==s?s:1===e.length&&void 0!==r?r.message:`${e.length} validation errors`),this.name="VldError",this.issues=e,Error.captureStackTrace&&Error.captureStackTrace(this,VldError)}get firstError(){return this.issues[0]}get errors(){return this.issues}get isEmpty(){return 0===this.issues.length}get formattedErrors(){return this.issues.map(e=>e.message)}addIssue(e){this.issues.push(e)}addIssues(e=[]){this.issues.push(...e)}format(){const e={_errors:[]};for(const s of this.issues)if(s.path&&0!==s.path.length){let r=e;for(const e of s.path)r[e]||(r[e]={_errors:[]}),r=r[e];r._errors.push(s.message)}else e._errors.push(s.message);return e}flatten(e){const s=e??(e=>e.message),r=[],i={};for(const e of this.issues)if(e.path&&0!==e.path.length){const r=String(e.path[0]);i[r]=i[r]??[],i[r].push(s(e))}else r.push(s(e));return{formErrors:r,fieldErrors:i}}toJSON(){return{name:this.name,message:this.message,code:"VLD_VALIDATION_ERROR",issues:this.issues.map(r)}}static fromJSON(e){const s=e.issues.map(i);return new VldError(s)}static isVldError(e){return e instanceof VldError}}export{VldError as V,s as c,e as g};
@@ -1 +0,0 @@
1
- "use strict";function e(e){const s={code:e.code,path:e.path,message:e.message};return void 0!==e.expected&&(s.expected=e.expected),void 0!==e.received&&(s.received=e.received),void 0!==e.keys&&(s.keys=e.keys),void 0!==e.minimum&&(s.minimum=e.minimum),void 0!==e.maximum&&(s.maximum=e.maximum),void 0!==e.exact&&(s.exact=e.exact),void 0!==e.inclusive&&(s.inclusive=e.inclusive),void 0!==e.origin&&(s.origin=e.origin),void 0!==e.format&&(s.format=e.format),void 0!==e.values&&(s.values=e.values),void 0!==e.pattern&&(s.pattern=e.pattern),s}function s(e){const s={code:e.code,path:e.path,message:e.message};return void 0!==e.expected&&(s.expected=e.expected),void 0!==e.received&&(s.received=e.received),void 0!==e.keys&&(s.keys=e.keys),void 0!==e.minimum&&(s.minimum=e.minimum),void 0!==e.maximum&&(s.maximum=e.maximum),void 0!==e.exact&&(s.exact=e.exact),void 0!==e.inclusive&&(s.inclusive=e.inclusive),void 0!==e.origin&&(s.origin=e.origin),void 0!==e.format&&(s.format=e.format),void 0!==e.values&&(s.values=e.values),void 0!==e.pattern&&(s.pattern=e.pattern),s}class VldError extends Error{constructor(e,s){const r=e[0];super(void 0!==s?s:1===e.length&&void 0!==r?r.message:`${e.length} validation errors`),this.name="VldError",this.issues=e,Error.captureStackTrace&&Error.captureStackTrace(this,VldError)}get firstError(){return this.issues[0]}get errors(){return this.issues}get isEmpty(){return 0===this.issues.length}get formattedErrors(){return this.issues.map(e=>e.message)}addIssue(e){this.issues.push(e)}addIssues(e=[]){this.issues.push(...e)}format(){const e={_errors:[]};for(const s of this.issues)if(s.path&&0!==s.path.length){let r=e;for(const e of s.path)r[e]||(r[e]={_errors:[]}),r=r[e];r._errors.push(s.message)}else e._errors.push(s.message);return e}flatten(e){const s=e??(e=>e.message),r=[],t={};for(const e of this.issues)if(e.path&&0!==e.path.length){const r=String(e.path[0]);t[r]=t[r]??[],t[r].push(s(e))}else r.push(s(e));return{formErrors:r,fieldErrors:t}}toJSON(){return{name:this.name,message:this.message,code:"VLD_VALIDATION_ERROR",issues:this.issues.map(e)}}static fromJSON(e){const r=e.issues.map(s);return new VldError(r)}static isVldError(e){return e instanceof VldError}}exports.VldError=VldError,exports.createInvalidTypeIssue=function(e,s,r){return{code:"invalid_type",path:[],expected:e,received:s,message:r??`Invalid input: expected ${e}, received ${s}`}},exports.getTypeName=function(e){return null===e?"null":void 0===e?"undefined":Array.isArray(e)?"array":"number"==typeof e?Number.isNaN(e)?"nan":e===1/0?"Infinity":e===-1/0?"-Infinity":"number":e instanceof Date?"date":e instanceof Map?"map":e instanceof Set?"set":typeof e};