@oxog/vld 1.4.0 → 2.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 +449 -333
- package/README.md +1171 -1130
- package/dist/chunks/bigint-ZKkWLdmi.js +1628 -0
- package/dist/chunks/bigint-ZKkWLdmi.js.map +1 -0
- package/dist/{coercion/string.js → chunks/date-7Iz2BGsL.js} +271 -5
- package/dist/chunks/date-7Iz2BGsL.js.map +1 -0
- package/dist/chunks/index-BoV-4S1F.js +894 -0
- package/dist/chunks/index-BoV-4S1F.js.map +1 -0
- package/dist/chunks/index-eWXdjyyy.js +426 -0
- package/dist/chunks/index-eWXdjyyy.js.map +1 -0
- package/dist/chunks/json-nIhyRPOU.js +1934 -0
- package/dist/chunks/json-nIhyRPOU.js.map +1 -0
- package/dist/{validators/unknown.js → chunks/unknown-CjSRcELI.js} +6 -3
- package/dist/chunks/unknown-CjSRcELI.js.map +1 -0
- package/dist/cjs/errors.cjs +387 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/index.cjs +9815 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/locales/index.cjs +2877 -0
- package/dist/cjs/locales/index.cjs.map +1 -0
- package/dist/cjs/locales/lazy.cjs +3169 -0
- package/dist/cjs/locales/lazy.cjs.map +1 -0
- package/dist/cjs/mini.cjs +7161 -0
- package/dist/cjs/mini.cjs.map +1 -0
- package/dist/cli/bin.d.ts +8 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/commands/benchmark.d.ts +11 -0
- package/dist/cli/commands/benchmark.d.ts.map +1 -0
- package/dist/cli/commands/validate.d.ts +11 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/index.d.ts +59 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/codecs/index.d.ts.map +1 -1
- package/dist/codecs/index.js +4 -256
- package/dist/codecs/index.js.map +1 -1
- package/dist/coercion/boolean.d.ts.map +1 -1
- package/dist/coercion/index.d.ts +11 -0
- package/dist/coercion/index.d.ts.map +1 -0
- package/dist/coercion/{bigint.js → index.js} +7 -4
- package/dist/coercion/index.js.map +1 -0
- package/dist/compat/emitter.d.ts +73 -0
- package/dist/compat/emitter.d.ts.map +1 -0
- package/dist/compat/emitter.js +181 -0
- package/dist/compat/emitter.js.map +1 -0
- package/dist/compat/index.d.ts +15 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/result.d.ts +128 -0
- package/dist/compat/result.d.ts.map +1 -0
- package/dist/compat/result.js +171 -0
- package/dist/compat/result.js.map +1 -0
- package/dist/errors.d.ts +58 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +106 -15
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +140 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -103
- package/dist/index.js.map +1 -1
- package/dist/kernel.d.ts +29 -0
- package/dist/kernel.d.ts.map +1 -0
- package/dist/kernel.js +405 -0
- package/dist/kernel.js.map +1 -0
- package/dist/locales/af.js +4 -2
- package/dist/locales/af.js.map +1 -1
- package/dist/locales/ar.js +4 -2
- package/dist/locales/ar.js.map +1 -1
- package/dist/locales/bn.js +4 -2
- package/dist/locales/bn.js.map +1 -1
- package/dist/locales/da.js +4 -2
- package/dist/locales/da.js.map +1 -1
- package/dist/locales/de.js +4 -2
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +4 -2
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es-MX.js +4 -2
- package/dist/locales/es-MX.js.map +1 -1
- package/dist/locales/es.js +4 -2
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fi.js +4 -2
- package/dist/locales/fi.js.map +1 -1
- package/dist/locales/fr.js +4 -2
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/hi.js +4 -2
- package/dist/locales/hi.js.map +1 -1
- package/dist/locales/id.js +4 -2
- package/dist/locales/id.js.map +1 -1
- package/dist/locales/index.js +3 -91
- package/dist/locales/index.js.map +1 -1
- package/dist/locales/it.js +4 -2
- package/dist/locales/it.js.map +1 -1
- package/dist/locales/ja.js +4 -2
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +4 -2
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/lazy.d.ts +111 -0
- package/dist/locales/lazy.d.ts.map +1 -0
- package/dist/locales/lazy.js +220 -0
- package/dist/locales/lazy.js.map +1 -0
- package/dist/locales/nl.js +4 -2
- package/dist/locales/nl.js.map +1 -1
- package/dist/locales/no.js +4 -2
- package/dist/locales/no.js.map +1 -1
- package/dist/locales/pl.js +4 -2
- package/dist/locales/pl.js.map +1 -1
- package/dist/locales/pt-BR.js +4 -2
- package/dist/locales/pt-BR.js.map +1 -1
- package/dist/locales/pt.js +4 -2
- package/dist/locales/pt.js.map +1 -1
- package/dist/locales/ru.js +4 -2
- package/dist/locales/ru.js.map +1 -1
- package/dist/locales/sv.js +4 -2
- package/dist/locales/sv.js.map +1 -1
- package/dist/locales/sw.js +4 -2
- package/dist/locales/sw.js.map +1 -1
- package/dist/locales/th.js +4 -2
- package/dist/locales/th.js.map +1 -1
- package/dist/locales/tr.js +4 -2
- package/dist/locales/tr.js.map +1 -1
- package/dist/locales/vi.js +4 -2
- package/dist/locales/vi.js.map +1 -1
- package/dist/locales/zh.js +4 -2
- package/dist/locales/zh.js.map +1 -1
- package/dist/logger.d.ts +94 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/mini.d.ts +182 -0
- package/dist/mini.d.ts.map +1 -0
- package/dist/mini.js +132 -0
- package/dist/mini.js.map +1 -0
- package/dist/pigment.d.ts +124 -0
- package/dist/pigment.d.ts.map +1 -0
- package/dist/pigment.js +178 -0
- package/dist/pigment.js.map +1 -0
- package/dist/plugins/index.d.ts +8 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/types.d.ts +186 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/utils/codec-utils.d.ts.map +1 -1
- package/dist/utils/ip-validation.d.ts.map +1 -1
- package/dist/validators/base.d.ts +3 -0
- package/dist/validators/base.d.ts.map +1 -1
- package/dist/validators/index.js +5 -45
- package/dist/validators/index.js.map +1 -1
- package/dist/validators/object.d.ts.map +1 -1
- package/dist/validators/template-literal.d.ts.map +1 -1
- package/package.json +153 -79
- package/dist/coercion/bigint.js.map +0 -1
- package/dist/coercion/boolean.js +0 -67
- package/dist/coercion/boolean.js.map +0 -1
- package/dist/coercion/date.js +0 -52
- package/dist/coercion/date.js.map +0 -1
- package/dist/coercion/number.js +0 -160
- package/dist/coercion/number.js.map +0 -1
- package/dist/coercion/string.js.map +0 -1
- package/dist/locales/backup-en.js +0 -105
- package/dist/locales/backup-en.js.map +0 -1
- package/dist/locales/types.js +0 -2
- package/dist/locales/types.js.map +0 -1
- package/dist/utils/codec-utils.js +0 -223
- package/dist/utils/codec-utils.js.map +0 -1
- package/dist/utils/deep-merge.js +0 -76
- package/dist/utils/deep-merge.js.map +0 -1
- package/dist/utils/ip-validation.js +0 -78
- package/dist/utils/ip-validation.js.map +0 -1
- package/dist/utils/security.js +0 -61
- package/dist/utils/security.js.map +0 -1
- package/dist/validators/any.js +0 -25
- package/dist/validators/any.js.map +0 -1
- package/dist/validators/array.js +0 -190
- package/dist/validators/array.js.map +0 -1
- package/dist/validators/base.js +0 -491
- package/dist/validators/base.js.map +0 -1
- package/dist/validators/base64.js +0 -65
- package/dist/validators/base64.js.map +0 -1
- package/dist/validators/bigint.js +0 -142
- package/dist/validators/bigint.js.map +0 -1
- package/dist/validators/boolean.js +0 -114
- package/dist/validators/boolean.js.map +0 -1
- package/dist/validators/codec.js +0 -182
- package/dist/validators/codec.js.map +0 -1
- package/dist/validators/custom.js +0 -50
- package/dist/validators/custom.js.map +0 -1
- package/dist/validators/date.js +0 -227
- package/dist/validators/date.js.map +0 -1
- package/dist/validators/discriminated-union.js +0 -98
- package/dist/validators/discriminated-union.js.map +0 -1
- package/dist/validators/enum.js +0 -82
- package/dist/validators/enum.js.map +0 -1
- package/dist/validators/file.js +0 -114
- package/dist/validators/file.js.map +0 -1
- package/dist/validators/function.js +0 -45
- package/dist/validators/function.js.map +0 -1
- package/dist/validators/hex.js +0 -62
- package/dist/validators/hex.js.map +0 -1
- package/dist/validators/intersection.js +0 -64
- package/dist/validators/intersection.js.map +0 -1
- package/dist/validators/json.js +0 -64
- package/dist/validators/json.js.map +0 -1
- package/dist/validators/lazy.js +0 -42
- package/dist/validators/lazy.js.map +0 -1
- package/dist/validators/literal.js +0 -45
- package/dist/validators/literal.js.map +0 -1
- package/dist/validators/map.js +0 -54
- package/dist/validators/map.js.map +0 -1
- package/dist/validators/nan.js +0 -32
- package/dist/validators/nan.js.map +0 -1
- package/dist/validators/never.js +0 -29
- package/dist/validators/never.js.map +0 -1
- package/dist/validators/null.js +0 -31
- package/dist/validators/null.js.map +0 -1
- package/dist/validators/number.js +0 -225
- package/dist/validators/number.js.map +0 -1
- package/dist/validators/object.js +0 -458
- package/dist/validators/object.js.map +0 -1
- package/dist/validators/record.js +0 -128
- package/dist/validators/record.js.map +0 -1
- package/dist/validators/set.js +0 -51
- package/dist/validators/set.js.map +0 -1
- package/dist/validators/string-bool.js +0 -127
- package/dist/validators/string-bool.js.map +0 -1
- package/dist/validators/string-formats.js +0 -120
- package/dist/validators/string-formats.js.map +0 -1
- package/dist/validators/string.js +0 -253
- package/dist/validators/string.js.map +0 -1
- package/dist/validators/symbol.js +0 -42
- package/dist/validators/symbol.js.map +0 -1
- package/dist/validators/template-literal.js +0 -101
- package/dist/validators/template-literal.js.map +0 -1
- package/dist/validators/tuple.js +0 -55
- package/dist/validators/tuple.js.map +0 -1
- package/dist/validators/uint8array.js +0 -98
- package/dist/validators/uint8array.js.map +0 -1
- package/dist/validators/undefined.js +0 -31
- package/dist/validators/undefined.js.map +0 -1
- package/dist/validators/union.js +0 -126
- package/dist/validators/union.js.map +0 -1
- package/dist/validators/unknown.js.map +0 -1
- package/dist/validators/void.js +0 -35
- package/dist/validators/void.js.map +0 -1
- package/dist/validators/xor.js +0 -64
- package/dist/validators/xor.js.map +0 -1
package/dist/errors.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { vldTheme } from './pigment.js';
|
|
2
|
+
|
|
1
3
|
// VLD Error System - Advanced error formatting and utilities
|
|
2
|
-
|
|
4
|
+
class VldError extends Error {
|
|
3
5
|
constructor(issues) {
|
|
4
|
-
const message = issues.length === 1
|
|
5
|
-
? issues[0].message
|
|
6
|
-
: `${issues.length} validation errors`;
|
|
6
|
+
const message = issues.length === 1 ? issues[0].message : `${issues.length} validation errors`;
|
|
7
7
|
super(message);
|
|
8
8
|
this.name = 'VldError';
|
|
9
9
|
this.issues = issues;
|
|
@@ -16,13 +16,60 @@ export class VldError extends Error {
|
|
|
16
16
|
return this.issues[0];
|
|
17
17
|
}
|
|
18
18
|
get formattedErrors() {
|
|
19
|
-
return this.issues.map(issue => issue.message);
|
|
19
|
+
return this.issues.map((issue) => issue.message);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Convert error to JSON representation
|
|
23
|
+
* Compatible with @oxog/types OxogError
|
|
24
|
+
*/
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
name: this.name,
|
|
28
|
+
message: this.message,
|
|
29
|
+
code: 'VLD_VALIDATION_ERROR',
|
|
30
|
+
issues: this.issues.map((issue) => ({
|
|
31
|
+
code: issue.code,
|
|
32
|
+
path: issue.path,
|
|
33
|
+
message: issue.message,
|
|
34
|
+
expected: issue.expected,
|
|
35
|
+
received: issue.received,
|
|
36
|
+
keys: issue.keys,
|
|
37
|
+
minimum: issue.minimum,
|
|
38
|
+
maximum: issue.maximum,
|
|
39
|
+
exact: issue.exact,
|
|
40
|
+
inclusive: issue.inclusive
|
|
41
|
+
}))
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create VldError from JSON representation
|
|
46
|
+
*/
|
|
47
|
+
static fromJSON(json) {
|
|
48
|
+
const issues = json.issues.map((issue) => ({
|
|
49
|
+
code: issue.code,
|
|
50
|
+
path: issue.path,
|
|
51
|
+
message: issue.message,
|
|
52
|
+
expected: issue.expected,
|
|
53
|
+
received: issue.received,
|
|
54
|
+
keys: issue.keys,
|
|
55
|
+
minimum: issue.minimum,
|
|
56
|
+
maximum: issue.maximum,
|
|
57
|
+
exact: issue.exact,
|
|
58
|
+
inclusive: issue.inclusive
|
|
59
|
+
}));
|
|
60
|
+
return new VldError(issues);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Check if a value is a VldError
|
|
64
|
+
*/
|
|
65
|
+
static isVldError(value) {
|
|
66
|
+
return value instanceof VldError;
|
|
20
67
|
}
|
|
21
68
|
}
|
|
22
69
|
/**
|
|
23
70
|
* Convert VldError to a nested tree structure
|
|
24
71
|
*/
|
|
25
|
-
|
|
72
|
+
function treeifyError(error) {
|
|
26
73
|
const tree = { errors: [] };
|
|
27
74
|
for (const issue of error.issues) {
|
|
28
75
|
let currentNode = tree;
|
|
@@ -75,31 +122,73 @@ export function treeifyError(error) {
|
|
|
75
122
|
/**
|
|
76
123
|
* Convert VldError to human-readable string
|
|
77
124
|
*/
|
|
78
|
-
|
|
125
|
+
function prettifyError(error, options = {}) {
|
|
126
|
+
const { colored = true, theme = vldTheme, includeCode = false, includeDetails = false } = options;
|
|
79
127
|
const lines = [];
|
|
80
128
|
for (const issue of error.issues) {
|
|
81
|
-
|
|
129
|
+
// Symbol and message
|
|
130
|
+
const symbol = colored ? theme.symbol('✖') : '✖';
|
|
131
|
+
const message = colored ? theme.error(issue.message) : issue.message;
|
|
132
|
+
let line = `${symbol} ${message}`;
|
|
133
|
+
// Error code
|
|
134
|
+
if (includeCode) {
|
|
135
|
+
const code = colored ? theme.muted(`[${issue.code}]`) : `[${issue.code}]`;
|
|
136
|
+
line += ` ${code}`;
|
|
137
|
+
}
|
|
138
|
+
// Path
|
|
82
139
|
if (issue.path.length > 0) {
|
|
83
140
|
const pathStr = issue.path
|
|
84
141
|
.map((segment, index) => {
|
|
85
142
|
if (typeof segment === 'string') {
|
|
86
|
-
|
|
143
|
+
const str = index === 0 ? segment : `.${segment}`;
|
|
144
|
+
return colored ? theme.path(str) : str;
|
|
87
145
|
}
|
|
88
146
|
else {
|
|
89
|
-
|
|
147
|
+
const str = `[${segment}]`;
|
|
148
|
+
return colored ? theme.path(str) : str;
|
|
90
149
|
}
|
|
91
150
|
})
|
|
92
151
|
.join('');
|
|
93
|
-
|
|
152
|
+
const arrow = colored ? theme.muted('→ at ') : '→ at ';
|
|
153
|
+
line += `\n ${arrow}${pathStr}`;
|
|
154
|
+
}
|
|
155
|
+
// Details
|
|
156
|
+
if (includeDetails) {
|
|
157
|
+
if (issue.expected) {
|
|
158
|
+
const expected = colored
|
|
159
|
+
? theme.muted('expected: ') + theme.success(issue.expected)
|
|
160
|
+
: `expected: ${issue.expected}`;
|
|
161
|
+
line += `\n ${expected}`;
|
|
162
|
+
}
|
|
163
|
+
if (issue.received) {
|
|
164
|
+
const received = colored
|
|
165
|
+
? theme.muted('received: ') + theme.warning(issue.received)
|
|
166
|
+
: `received: ${issue.received}`;
|
|
167
|
+
line += `\n ${received}`;
|
|
168
|
+
}
|
|
94
169
|
}
|
|
95
170
|
lines.push(line);
|
|
96
171
|
}
|
|
97
172
|
return lines.join('\n');
|
|
98
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Convert VldError to human-readable string with full colors
|
|
176
|
+
* Shorthand for prettifyError with colored: true
|
|
177
|
+
*/
|
|
178
|
+
function prettifyErrorColored(error, options = {}) {
|
|
179
|
+
return prettifyError(error, { ...options, colored: true });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Convert VldError to plain text string (no colors)
|
|
183
|
+
* Shorthand for prettifyError with colored: false
|
|
184
|
+
*/
|
|
185
|
+
function prettifyErrorPlain(error, options = {}) {
|
|
186
|
+
return prettifyError(error, { ...options, colored: false });
|
|
187
|
+
}
|
|
99
188
|
/**
|
|
100
189
|
* Flatten VldError for simple form validation
|
|
101
190
|
*/
|
|
102
|
-
|
|
191
|
+
function flattenError(error) {
|
|
103
192
|
const formErrors = [];
|
|
104
193
|
const fieldErrors = {};
|
|
105
194
|
for (const issue of error.issues) {
|
|
@@ -119,7 +208,7 @@ export function flattenError(error) {
|
|
|
119
208
|
/**
|
|
120
209
|
* Create a validation issue
|
|
121
210
|
*/
|
|
122
|
-
|
|
211
|
+
function createIssue(code, path, message, extra) {
|
|
123
212
|
return {
|
|
124
213
|
code,
|
|
125
214
|
path: [...path],
|
|
@@ -130,7 +219,7 @@ export function createIssue(code, path, message, extra) {
|
|
|
130
219
|
/**
|
|
131
220
|
* Helper to determine the type of a value for error messages
|
|
132
221
|
*/
|
|
133
|
-
|
|
222
|
+
function getValueType(value) {
|
|
134
223
|
if (value === null)
|
|
135
224
|
return 'null';
|
|
136
225
|
if (value === undefined)
|
|
@@ -141,4 +230,6 @@ export function getValueType(value) {
|
|
|
141
230
|
return 'date';
|
|
142
231
|
return typeof value;
|
|
143
232
|
}
|
|
144
|
-
|
|
233
|
+
|
|
234
|
+
export { VldError, createIssue, flattenError, getValueType, prettifyError, prettifyErrorColored, prettifyErrorPlain, treeifyError };
|
|
235
|
+
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAwC7D,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGjC,YAAY,MAAkB;QAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC;YACjC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO;YACnB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,oBAAoB,CAAC;QAEzC,KAAK,CAAC,OAAO,CAAC,C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QAAQ,EAAE,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;YAC9B,CAAC;YACD,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,IAAkB,EAClB,IAAyB,EACzB,OAAe,EACf,KAAyB;IAEzB,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACf,OAAO;QACP,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC;IAC5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,KAAK,YAAY,IAAI;QAAE,OAAO,MAAM,CAAC;IACzC,OAAO,OAAO,KAAK,CAAC;AACtB,CAAC","sourcesContent":["// VLD Error System - Advanced error formatting and utilities\n\nexport type VldErrorCode = \n | 'invalid_type'\n | 'invalid_string'\n | 'string_too_small'\n | 'string_too_big'\n | 'invalid_email'\n | 'invalid_url'\n | 'invalid_uuid'\n | 'invalid_regex'\n | 'invalid_number'\n | 'too_small'\n | 'too_big'\n | 'not_integer'\n | 'not_finite'\n | 'not_safe'\n | 'invalid_boolean'\n | 'invalid_date'\n | 'invalid_array'\n | 'invalid_object'\n | 'unrecognized_keys'\n | 'invalid_union'\n | 'invalid_literal'\n | 'invalid_enum'\n | 'custom';\n\nexport interface VldIssue {\n code: VldErrorCode;\n path: (string | number)[];\n message: string;\n expected?: string;\n received?: string;\n keys?: string[];\n minimum?: number;\n maximum?: number;\n exact?: number;\n inclusive?: boolean;\n}\n\nexport class VldError extends Error {\n public readonly issues: VldIssue[];\n\n constructor(issues: VldIssue[]) {\n const message = issues.length === 1 \n ? issues[0].message\n : `${issues.length} validation errors`;\n \n super(message);\n this.name = 'VldError';\n this.issues = issues;\n \n // Maintain proper stack trace\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VldError);\n }\n }\n\n get firstError(): VldIssue | undefined {\n return this.issues[0];\n }\n\n get formattedErrors(): string[] {\n return this.issues.map(issue => issue.message);\n }\n}\n\n// Error tree structure for nested validation\nexport interface VldErrorTree {\n errors: string[];\n properties?: Record<string, VldErrorTree>;\n items?: (VldErrorTree | undefined)[];\n}\n\n// Flattened error structure for simple forms\nexport interface VldFlattenedError {\n formErrors: string[];\n fieldErrors: Record<string, string[]>;\n}\n\n/**\n * Convert VldError to a nested tree structure\n */\nexport function treeifyError(error: VldError): VldErrorTree {\n const tree: VldErrorTree = { errors: [] };\n\n for (const issue of error.issues) {\n let currentNode = tree;\n const path = issue.path;\n\n // Navigate to the correct position in the tree\n for (let i = 0; i < path.length; i++) {\n const segment = path[i];\n const isLast = i === path.length - 1;\n\n if (typeof segment === 'string') {\n // Object property\n if (!currentNode.properties) {\n currentNode.properties = {};\n }\n \n if (!currentNode.properties[segment]) {\n currentNode.properties[segment] = { errors: [] };\n }\n \n if (isLast) {\n currentNode.properties[segment].errors.push(issue.message);\n } else {\n currentNode = currentNode.properties[segment];\n }\n } else if (typeof segment === 'number') {\n // Array index\n if (!currentNode.items) {\n currentNode.items = [];\n }\n \n while (currentNode.items.length <= segment) {\n currentNode.items.push(undefined);\n }\n \n if (!currentNode.items[segment]) {\n currentNode.items[segment] = { errors: [] };\n }\n \n if (isLast) {\n currentNode.items[segment]!.errors.push(issue.message);\n } else {\n currentNode = currentNode.items[segment]!;\n }\n }\n }\n\n // If path is empty, add to root errors\n if (path.length === 0) {\n tree.errors.push(issue.message);\n }\n }\n\n return tree;\n}\n\n/**\n * Convert VldError to human-readable string\n */\nexport function prettifyError(error: VldError): string {\n const lines: string[] = [];\n\n for (const issue of error.issues) {\n let line = `✖ ${issue.message}`;\n \n if (issue.path.length > 0) {\n const pathStr = issue.path\n .map((segment, index) => {\n if (typeof segment === 'string') {\n return index === 0 ? segment : `.${segment}`;\n } else {\n return `[${segment}]`;\n }\n })\n .join('');\n \n line += `\\n → at ${pathStr}`;\n }\n \n lines.push(line);\n }\n\n return lines.join('\\n');\n}\n\n/**\n * Flatten VldError for simple form validation\n */\nexport function flattenError(error: VldError): VldFlattenedError {\n const formErrors: string[] = [];\n const fieldErrors: Record<string, string[]> = {};\n\n for (const issue of error.issues) {\n if (issue.path.length === 0) {\n formErrors.push(issue.message);\n } else {\n const fieldName = issue.path[0].toString();\n if (!fieldErrors[fieldName]) {\n fieldErrors[fieldName] = [];\n }\n fieldErrors[fieldName].push(issue.message);\n }\n }\n\n return { formErrors, fieldErrors };\n}\n\n/**\n * Create a validation issue\n */\nexport function createIssue(\n code: VldErrorCode,\n path: (string | number)[],\n message: string,\n extra?: Partial<VldIssue>\n): VldIssue {\n return {\n code,\n path: [...path],\n message,\n ...extra\n };\n}\n\n/**\n * Helper to determine the type of a value for error messages\n */\nexport function getValueType(value: unknown): string {\n if (value === null) return 'null';\n if (value === undefined) return 'undefined';\n if (Array.isArray(value)) return 'array';\n if (value instanceof Date) return 'date';\n return typeof value;\n}"]}
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../src/errors.ts"],"sourcesContent":["// VLD Error System - Advanced error formatting and utilities\r\n\r\nimport { type Theme, vldTheme } from './pigment';\r\n\r\nexport type VldErrorCode =\r\n | 'invalid_type'\r\n | 'invalid_string'\r\n | 'string_too_small'\r\n | 'string_too_big'\r\n | 'invalid_email'\r\n | 'invalid_url'\r\n | 'invalid_uuid'\r\n | 'invalid_regex'\r\n | 'invalid_number'\r\n | 'too_small'\r\n | 'too_big'\r\n | 'not_integer'\r\n | 'not_finite'\r\n | 'not_safe'\r\n | 'invalid_boolean'\r\n | 'invalid_date'\r\n | 'invalid_array'\r\n | 'invalid_object'\r\n | 'unrecognized_keys'\r\n | 'invalid_union'\r\n | 'invalid_literal'\r\n | 'invalid_enum'\r\n | 'custom';\r\n\r\nexport interface VldIssue {\r\n code: VldErrorCode;\r\n path: (string | number)[];\r\n message: string;\r\n expected?: string;\r\n received?: string;\r\n keys?: string[];\r\n minimum?: number;\r\n maximum?: number;\r\n exact?: number;\r\n inclusive?: boolean;\r\n}\r\n\r\nexport class VldError extends Error {\r\n public readonly issues: VldIssue[];\r\n\r\n constructor(issues: VldIssue[]) {\r\n const message =\r\n issues.length === 1 ? issues[0].message : `${issues.length} validation errors`;\r\n\r\n super(message);\r\n this.name = 'VldError';\r\n this.issues = issues;\r\n\r\n // Maintain proper stack trace\r\n if (Error.captureStackTrace) {\r\n Error.captureStackTrace(this, VldError);\r\n }\r\n }\r\n\r\n get firstError(): VldIssue | undefined {\r\n return this.issues[0];\r\n }\r\n\r\n get formattedErrors(): string[] {\r\n return this.issues.map((issue) => issue.message);\r\n }\r\n\r\n /**\r\n * Convert error to JSON representation\r\n * Compatible with @oxog/types OxogError\r\n */\r\n toJSON(): VldErrorJSON {\r\n return {\r\n name: this.name,\r\n message: this.message,\r\n code: 'VLD_VALIDATION_ERROR',\r\n issues: this.issues.map((issue) => ({\r\n code: issue.code,\r\n path: issue.path,\r\n message: issue.message,\r\n expected: issue.expected,\r\n received: issue.received,\r\n keys: issue.keys,\r\n minimum: issue.minimum,\r\n maximum: issue.maximum,\r\n exact: issue.exact,\r\n inclusive: issue.inclusive\r\n }))\r\n };\r\n }\r\n\r\n /**\r\n * Create VldError from JSON representation\r\n */\r\n static fromJSON(json: VldErrorJSON): VldError {\r\n const issues: VldIssue[] = json.issues.map((issue) => ({\r\n code: issue.code as VldErrorCode,\r\n path: issue.path,\r\n message: issue.message,\r\n expected: issue.expected,\r\n received: issue.received,\r\n keys: issue.keys,\r\n minimum: issue.minimum,\r\n maximum: issue.maximum,\r\n exact: issue.exact,\r\n inclusive: issue.inclusive\r\n }));\r\n return new VldError(issues);\r\n }\r\n\r\n /**\r\n * Check if a value is a VldError\r\n */\r\n static isVldError(value: unknown): value is VldError {\r\n return value instanceof VldError;\r\n }\r\n}\r\n\r\n/**\r\n * JSON representation of VldError\r\n */\r\nexport interface VldErrorJSON {\r\n name: string;\r\n message: string;\r\n code: string;\r\n issues: Array<{\r\n code: string;\r\n path: (string | number)[];\r\n message: string;\r\n expected?: string;\r\n received?: string;\r\n keys?: string[];\r\n minimum?: number;\r\n maximum?: number;\r\n exact?: number;\r\n inclusive?: boolean;\r\n }>;\r\n}\r\n\r\n// Error tree structure for nested validation\r\nexport interface VldErrorTree {\r\n errors: string[];\r\n properties?: Record<string, VldErrorTree>;\r\n items?: (VldErrorTree | undefined)[];\r\n}\r\n\r\n// Flattened error structure for simple forms\r\nexport interface VldFlattenedError {\r\n formErrors: string[];\r\n fieldErrors: Record<string, string[]>;\r\n}\r\n\r\n/**\r\n * Convert VldError to a nested tree structure\r\n */\r\nexport function treeifyError(error: VldError): VldErrorTree {\r\n const tree: VldErrorTree = { errors: [] };\r\n\r\n for (const issue of error.issues) {\r\n let currentNode = tree;\r\n const path = issue.path;\r\n\r\n // Navigate to the correct position in the tree\r\n for (let i = 0; i < path.length; i++) {\r\n const segment = path[i];\r\n const isLast = i === path.length - 1;\r\n\r\n if (typeof segment === 'string') {\r\n // Object property\r\n if (!currentNode.properties) {\r\n currentNode.properties = {};\r\n }\r\n \r\n if (!currentNode.properties[segment]) {\r\n currentNode.properties[segment] = { errors: [] };\r\n }\r\n \r\n if (isLast) {\r\n currentNode.properties[segment].errors.push(issue.message);\r\n } else {\r\n currentNode = currentNode.properties[segment];\r\n }\r\n } else if (typeof segment === 'number') {\r\n // Array index\r\n if (!currentNode.items) {\r\n currentNode.items = [];\r\n }\r\n \r\n while (currentNode.items.length <= segment) {\r\n currentNode.items.push(undefined);\r\n }\r\n \r\n if (!currentNode.items[segment]) {\r\n currentNode.items[segment] = { errors: [] };\r\n }\r\n \r\n if (isLast) {\r\n currentNode.items[segment]!.errors.push(issue.message);\r\n } else {\r\n currentNode = currentNode.items[segment]!;\r\n }\r\n }\r\n }\r\n\r\n // If path is empty, add to root errors\r\n if (path.length === 0) {\r\n tree.errors.push(issue.message);\r\n }\r\n }\r\n\r\n return tree;\r\n}\r\n\r\n/**\r\n * Prettify error options\r\n */\r\nexport interface PrettifyOptions {\r\n /** Enable colored output */\r\n colored?: boolean;\r\n /** Custom theme for colors */\r\n theme?: Theme;\r\n /** Include error code in output */\r\n includeCode?: boolean;\r\n /** Include expected/received values */\r\n includeDetails?: boolean;\r\n}\r\n\r\n/**\r\n * Convert VldError to human-readable string\r\n */\r\nexport function prettifyError(error: VldError, options: PrettifyOptions = {}): string {\r\n const { colored = true, theme = vldTheme, includeCode = false, includeDetails = false } =\r\n options;\r\n\r\n const lines: string[] = [];\r\n\r\n for (const issue of error.issues) {\r\n // Symbol and message\r\n const symbol = colored ? theme.symbol('✖') : '✖';\r\n const message = colored ? theme.error(issue.message) : issue.message;\r\n let line = `${symbol} ${message}`;\r\n\r\n // Error code\r\n if (includeCode) {\r\n const code = colored ? theme.muted(`[${issue.code}]`) : `[${issue.code}]`;\r\n line += ` ${code}`;\r\n }\r\n\r\n // Path\r\n if (issue.path.length > 0) {\r\n const pathStr = issue.path\r\n .map((segment, index) => {\r\n if (typeof segment === 'string') {\r\n const str = index === 0 ? segment : `.${segment}`;\r\n return colored ? theme.path(str) : str;\r\n } else {\r\n const str = `[${segment}]`;\r\n return colored ? theme.path(str) : str;\r\n }\r\n })\r\n .join('');\r\n\r\n const arrow = colored ? theme.muted('→ at ') : '→ at ';\r\n line += `\\n ${arrow}${pathStr}`;\r\n }\r\n\r\n // Details\r\n if (includeDetails) {\r\n if (issue.expected) {\r\n const expected = colored\r\n ? theme.muted('expected: ') + theme.success(issue.expected)\r\n : `expected: ${issue.expected}`;\r\n line += `\\n ${expected}`;\r\n }\r\n if (issue.received) {\r\n const received = colored\r\n ? theme.muted('received: ') + theme.warning(issue.received)\r\n : `received: ${issue.received}`;\r\n line += `\\n ${received}`;\r\n }\r\n }\r\n\r\n lines.push(line);\r\n }\r\n\r\n return lines.join('\\n');\r\n}\r\n\r\n/**\r\n * Convert VldError to human-readable string with full colors\r\n * Shorthand for prettifyError with colored: true\r\n */\r\nexport function prettifyErrorColored(error: VldError, options: Omit<PrettifyOptions, 'colored'> = {}): string {\r\n return prettifyError(error, { ...options, colored: true });\r\n}\r\n\r\n/**\r\n * Convert VldError to plain text string (no colors)\r\n * Shorthand for prettifyError with colored: false\r\n */\r\nexport function prettifyErrorPlain(error: VldError, options: Omit<PrettifyOptions, 'colored'> = {}): string {\r\n return prettifyError(error, { ...options, colored: false });\r\n}\r\n\r\n/**\r\n * Flatten VldError for simple form validation\r\n */\r\nexport function flattenError(error: VldError): VldFlattenedError {\r\n const formErrors: string[] = [];\r\n const fieldErrors: Record<string, string[]> = {};\r\n\r\n for (const issue of error.issues) {\r\n if (issue.path.length === 0) {\r\n formErrors.push(issue.message);\r\n } else {\r\n const fieldName = issue.path[0].toString();\r\n if (!fieldErrors[fieldName]) {\r\n fieldErrors[fieldName] = [];\r\n }\r\n fieldErrors[fieldName].push(issue.message);\r\n }\r\n }\r\n\r\n return { formErrors, fieldErrors };\r\n}\r\n\r\n/**\r\n * Create a validation issue\r\n */\r\nexport function createIssue(\r\n code: VldErrorCode,\r\n path: (string | number)[],\r\n message: string,\r\n extra?: Partial<VldIssue>\r\n): VldIssue {\r\n return {\r\n code,\r\n path: [...path],\r\n message,\r\n ...extra\r\n };\r\n}\r\n\r\n/**\r\n * Helper to determine the type of a value for error messages\r\n */\r\nexport function getValueType(value: unknown): string {\r\n if (value === null) return 'null';\r\n if (value === undefined) return 'undefined';\r\n if (Array.isArray(value)) return 'array';\r\n if (value instanceof Date) return 'date';\r\n return typeof value;\r\n}"],"names":[],"mappings":";;AAAA;AA0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AAK,KAAK,SAAS;AAAE,QAAA,OAAO,WAAW;AAC3C,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;AAAE,QAAA,OAAO,OAAO;IACxC,IAAI,KAAK,YAAY,IAAI;AAAE,QAAA,OAAO,MAAM;IACxC,OAAO,OAAO,KAAK;AACrB;;;;"}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VLD Event System
|
|
3
|
+
*
|
|
4
|
+
* This module defines all VLD-specific events for validation lifecycle,
|
|
5
|
+
* plugin management, and debugging.
|
|
6
|
+
*/
|
|
7
|
+
import type { EventMap } from './compat/emitter';
|
|
8
|
+
import type { VldError } from './errors';
|
|
9
|
+
import type { VldBase } from './validators/base';
|
|
10
|
+
/**
|
|
11
|
+
* VLD Event definitions
|
|
12
|
+
*/
|
|
13
|
+
export interface VldEvents extends EventMap {
|
|
14
|
+
/** Emitted when parsing starts */
|
|
15
|
+
'vld:parse:start': {
|
|
16
|
+
value: unknown;
|
|
17
|
+
schema: VldBase<unknown, unknown>;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
};
|
|
20
|
+
/** Emitted when parsing succeeds */
|
|
21
|
+
'vld:parse:success': {
|
|
22
|
+
data: unknown;
|
|
23
|
+
schema: VldBase<unknown, unknown>;
|
|
24
|
+
duration: number;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
};
|
|
27
|
+
/** Emitted when parsing fails */
|
|
28
|
+
'vld:parse:error': {
|
|
29
|
+
error: VldError;
|
|
30
|
+
schema: VldBase<unknown, unknown>;
|
|
31
|
+
duration: number;
|
|
32
|
+
timestamp: number;
|
|
33
|
+
};
|
|
34
|
+
/** Emitted for each field validation in objects */
|
|
35
|
+
'vld:validate:field': {
|
|
36
|
+
key: string;
|
|
37
|
+
value: unknown;
|
|
38
|
+
valid: boolean;
|
|
39
|
+
path: (string | number)[];
|
|
40
|
+
timestamp: number;
|
|
41
|
+
};
|
|
42
|
+
/** Emitted when a transform is applied */
|
|
43
|
+
'vld:validate:transform': {
|
|
44
|
+
before: unknown;
|
|
45
|
+
after: unknown;
|
|
46
|
+
schemaName: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
};
|
|
49
|
+
/** Emitted when a refinement is checked */
|
|
50
|
+
'vld:validate:refine': {
|
|
51
|
+
value: unknown;
|
|
52
|
+
passed: boolean;
|
|
53
|
+
message?: string;
|
|
54
|
+
timestamp: number;
|
|
55
|
+
};
|
|
56
|
+
/** Emitted when a plugin is registered */
|
|
57
|
+
'vld:plugin:registered': {
|
|
58
|
+
name: string;
|
|
59
|
+
version: string;
|
|
60
|
+
timestamp: number;
|
|
61
|
+
};
|
|
62
|
+
/** Emitted when a plugin encounters an error */
|
|
63
|
+
'vld:plugin:error': {
|
|
64
|
+
name: string;
|
|
65
|
+
error: Error;
|
|
66
|
+
timestamp: number;
|
|
67
|
+
};
|
|
68
|
+
/** Emitted when a custom validator is registered */
|
|
69
|
+
'vld:validator:registered': {
|
|
70
|
+
name: string;
|
|
71
|
+
timestamp: number;
|
|
72
|
+
};
|
|
73
|
+
/** Emitted when a custom codec is registered */
|
|
74
|
+
'vld:codec:registered': {
|
|
75
|
+
name: string;
|
|
76
|
+
timestamp: number;
|
|
77
|
+
};
|
|
78
|
+
/** Emitted when locale is changed */
|
|
79
|
+
'vld:locale:changed': {
|
|
80
|
+
from: string;
|
|
81
|
+
to: string;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
};
|
|
84
|
+
/** Emitted for debug logging */
|
|
85
|
+
'vld:debug': {
|
|
86
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
87
|
+
message: string;
|
|
88
|
+
data?: unknown;
|
|
89
|
+
timestamp: number;
|
|
90
|
+
};
|
|
91
|
+
/** Emitted for performance metrics */
|
|
92
|
+
'vld:metrics': {
|
|
93
|
+
operation: string;
|
|
94
|
+
duration: number;
|
|
95
|
+
success: boolean;
|
|
96
|
+
metadata?: Record<string, unknown>;
|
|
97
|
+
timestamp: number;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Event payload types for type-safe event handling
|
|
102
|
+
*/
|
|
103
|
+
export type VldEventPayload<K extends keyof VldEvents> = VldEvents[K];
|
|
104
|
+
/**
|
|
105
|
+
* Parse start event payload
|
|
106
|
+
*/
|
|
107
|
+
export type ParseStartEvent = VldEvents['vld:parse:start'];
|
|
108
|
+
/**
|
|
109
|
+
* Parse success event payload
|
|
110
|
+
*/
|
|
111
|
+
export type ParseSuccessEvent = VldEvents['vld:parse:success'];
|
|
112
|
+
/**
|
|
113
|
+
* Parse error event payload
|
|
114
|
+
*/
|
|
115
|
+
export type ParseErrorEvent = VldEvents['vld:parse:error'];
|
|
116
|
+
/**
|
|
117
|
+
* Field validation event payload
|
|
118
|
+
*/
|
|
119
|
+
export type FieldValidationEvent = VldEvents['vld:validate:field'];
|
|
120
|
+
/**
|
|
121
|
+
* Transform event payload
|
|
122
|
+
*/
|
|
123
|
+
export type TransformEvent = VldEvents['vld:validate:transform'];
|
|
124
|
+
/**
|
|
125
|
+
* Plugin registered event payload
|
|
126
|
+
*/
|
|
127
|
+
export type PluginRegisteredEvent = VldEvents['vld:plugin:registered'];
|
|
128
|
+
/**
|
|
129
|
+
* Locale changed event payload
|
|
130
|
+
*/
|
|
131
|
+
export type LocaleChangedEvent = VldEvents['vld:locale:changed'];
|
|
132
|
+
/**
|
|
133
|
+
* Debug event payload
|
|
134
|
+
*/
|
|
135
|
+
export type DebugEvent = VldEvents['vld:debug'];
|
|
136
|
+
/**
|
|
137
|
+
* Metrics event payload
|
|
138
|
+
*/
|
|
139
|
+
export type MetricsEvent = VldEvents['vld:metrics'];
|
|
140
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAA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CAAC,CAAC,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC,wBAAwB,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* - Secure deepMerge (no prototype pollution)
|
|
8
8
|
* - TypeScript strict mode support
|
|
9
9
|
* - Better performance through pooling and memoization
|
|
10
|
+
* - Plugin system for extensibility
|
|
11
|
+
* - Event system for validation lifecycle hooks
|
|
12
|
+
* - Result pattern for functional error handling
|
|
13
|
+
* - Colored console output for better debugging
|
|
14
|
+
* - Debug logging system
|
|
10
15
|
*/
|
|
11
16
|
import { VldBase } from './validators/base';
|
|
12
17
|
import { VldString } from './validators/string';
|
|
@@ -56,7 +61,7 @@ export type { Infer, Input, Output } from './validators';
|
|
|
56
61
|
export { VldBase } from './validators/base';
|
|
57
62
|
export { VldIntersection } from './validators/intersection';
|
|
58
63
|
export { setLocale, getLocale, getMessages, type Locale } from './locales';
|
|
59
|
-
export { VldError, VldIssue, VldErrorCode, VldErrorTree, VldFlattenedError, treeifyError, prettifyError, flattenError } from './errors';
|
|
64
|
+
export { VldError, VldIssue, VldErrorCode, VldErrorTree, VldFlattenedError, VldErrorJSON, treeifyError, prettifyError, prettifyErrorColored, prettifyErrorPlain, flattenError, type PrettifyOptions } from './errors';
|
|
60
65
|
export { base64ToUint8Array, uint8ArrayToBase64, uint8ArrayToBase64Url, hexToUint8Array, uint8ArrayToHex, stringToUint8Array, uint8ArrayToString } from './utils/codec-utils';
|
|
61
66
|
export type { CodecTransform } from './validators/codec';
|
|
62
67
|
export { stringToNumber, stringToInt, stringToBigInt, numberToBigInt, stringToBoolean, isoDatetimeToDate, epochSecondsToDate, epochMillisToDate, jsonCodec, stringToURL, stringToHttpURL, uriComponent, base64ToBytes, base64UrlToBytes, base64urlToBytes, hexToBytes, hexLowerToBytes, utf8ToBytes, bytesToUtf8, base64Json, jwtPayload } from './codecs';
|
|
@@ -682,5 +687,12 @@ export declare const v: {
|
|
|
682
687
|
encode: (value: TOutput) => TInput | Promise<TInput>;
|
|
683
688
|
}) => VldCodec<TInput, TOutput>;
|
|
684
689
|
};
|
|
690
|
+
export type { Result, VldResult } from './compat/result';
|
|
691
|
+
export { Ok, Err, success, failure, isOk, isErr, isResult, unwrap, unwrapOr, map, mapErr, flatMap, match, tryCatch, tryCatchAsync, all, fromNullable, ResultUtils } from './compat/result';
|
|
692
|
+
export { type EventMap, type EventHandler, type ListenerOptions, type Emitter, createEmitter, createEventBus, withEmitter } from './compat/emitter';
|
|
693
|
+
export type { VldEvents, VldEventPayload, ParseStartEvent, ParseSuccessEvent, ParseErrorEvent, FieldValidationEvent, TransformEvent, PluginRegisteredEvent, LocaleChangedEvent, DebugEvent, MetricsEvent } from './events';
|
|
694
|
+
export { createVldKernel, getVldKernel, resetVldKernel, usePlugin, definePlugin, type VldContext, type VldPlugin, type VldKernelInstance, type VldKernelOptions, type ValidatorFactory, type TransformFactory, type CodecFactory, type HookContext, type PluginBuilder, type PluginMeta, type PluginHooks } from './kernel';
|
|
695
|
+
export { createLogger, initLogger, getLogger, setLogLevel, enableDebug, disableLogging, createNoOpLogger, type Logger, type LoggerOptions, type LogLevel, type LogEntry, type LogHandler } from './logger';
|
|
696
|
+
export { pigment, supportsColor, bold, dim, italic, underline, red, green, yellow, blue, magenta, cyan, white, gray, grey, strip, vldTheme, createTheme, type Theme } from './pigment';
|
|
685
697
|
export default v;
|
|
686
698
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,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