unischema 1.1.0 → 1.2.0
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/README.md +151 -2
- package/dist/adapters/backend/index.d.mts +2 -2
- package/dist/adapters/backend/index.d.ts +2 -2
- package/dist/adapters/backend/index.js +11 -11
- package/dist/adapters/backend/index.mjs +8 -8
- package/dist/adapters/frontend/index.d.mts +2 -2
- package/dist/adapters/frontend/index.d.ts +2 -2
- package/dist/adapters/frontend/index.js +10 -10
- package/dist/adapters/frontend/index.mjs +8 -8
- package/dist/{chunk-XGTUU27F.mjs → chunk-5A4ITJVD.mjs} +1 -1
- package/dist/{chunk-ASKTY6EG.js → chunk-66RFUBVU.js} +20 -20
- package/dist/{chunk-KHHJD6QK.mjs → chunk-75YSYC4K.mjs} +1 -1
- package/dist/{chunk-BNIB23NQ.js → chunk-76BBWQDH.js} +13 -13
- package/dist/{chunk-ELL7U7IC.mjs → chunk-7XES4A3M.mjs} +1 -1
- package/dist/{chunk-FRBZHN4K.mjs → chunk-COMVAVFU.mjs} +1 -1
- package/dist/chunk-DT2TQZU7.js +796 -0
- package/dist/{chunk-2JYFKT3R.js → chunk-FPCCH55A.js} +14 -14
- package/dist/{chunk-3FANCMEF.js → chunk-IUXRLMET.js} +34 -34
- package/dist/{chunk-CQYXR2LZ.js → chunk-JEW6U6CB.js} +65 -65
- package/dist/{chunk-XC4DKEXP.mjs → chunk-KZCV5IW4.mjs} +1 -1
- package/dist/{chunk-FKDWSZIV.mjs → chunk-KZZ7NVU3.mjs} +4 -2
- package/dist/{chunk-3TS35CVJ.mjs → chunk-MFEBMQAU.mjs} +341 -40
- package/dist/{chunk-NUW55QTO.js → chunk-OIYG5D2I.js} +4 -2
- package/dist/{chunk-VWP24NYS.mjs → chunk-RW6HDA5H.mjs} +1 -1
- package/dist/{chunk-FZ7K2PC7.js → chunk-TXT36BCE.js} +35 -35
- package/dist/index-C17xs-fU.d.mts +140 -0
- package/dist/index-C17xs-fU.d.ts +140 -0
- package/dist/index.d.mts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +262 -25
- package/dist/index.mjs +228 -14
- package/dist/{schema-DYU1zGVm.d.mts → schema-DYE8Wz8X.d.mts} +84 -2
- package/dist/{schema-CpAjXgEF.d.ts → schema-Dtp-joeT.d.ts} +84 -2
- package/dist/validators/array.d.mts +1 -1
- package/dist/validators/array.d.ts +1 -1
- package/dist/validators/array.js +8 -8
- package/dist/validators/array.mjs +2 -2
- package/dist/validators/common.d.mts +1 -1
- package/dist/validators/common.d.ts +1 -1
- package/dist/validators/common.js +7 -7
- package/dist/validators/common.mjs +2 -2
- package/dist/validators/date.d.mts +1 -1
- package/dist/validators/date.d.ts +1 -1
- package/dist/validators/date.js +12 -12
- package/dist/validators/date.mjs +2 -2
- package/dist/validators/index.d.mts +2 -2
- package/dist/validators/index.d.ts +2 -2
- package/dist/validators/index.js +68 -68
- package/dist/validators/index.mjs +7 -7
- package/dist/validators/number.d.mts +1 -1
- package/dist/validators/number.d.ts +1 -1
- package/dist/validators/number.js +13 -13
- package/dist/validators/number.mjs +2 -2
- package/dist/validators/object.d.mts +1 -1
- package/dist/validators/object.d.ts +1 -1
- package/dist/validators/object.js +6 -6
- package/dist/validators/object.mjs +2 -2
- package/dist/validators/string.d.mts +1 -1
- package/dist/validators/string.d.ts +1 -1
- package/dist/validators/string.js +19 -19
- package/dist/validators/string.mjs +2 -2
- package/package.json +47 -5
- package/dist/chunk-BJLVOIAP.js +0 -491
- package/dist/index-BQR7OrY7.d.mts +0 -80
- package/dist/index-BQR7OrY7.d.ts +0 -80
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
|
|
4
4
|
|
|
5
5
|
// src/validators/date/today.ts
|
|
6
6
|
var todayValidator = (value, params, context) => {
|
|
7
|
-
if (
|
|
7
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
8
8
|
const soft = params?.soft;
|
|
9
9
|
const message = params?.message;
|
|
10
|
-
const date =
|
|
10
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
11
11
|
if (!date) return null;
|
|
12
12
|
const today = /* @__PURE__ */ new Date();
|
|
13
13
|
today.setHours(0, 0, 0, 0);
|
|
14
14
|
date.setHours(0, 0, 0, 0);
|
|
15
15
|
if (date.getTime() !== today.getTime()) {
|
|
16
|
-
return
|
|
16
|
+
return chunkOIYG5D2I_js.createError(
|
|
17
17
|
context,
|
|
18
18
|
"INVALID_TODAY",
|
|
19
19
|
message || "Date must be today",
|
|
@@ -25,17 +25,17 @@ var todayValidator = (value, params, context) => {
|
|
|
25
25
|
|
|
26
26
|
// src/validators/date/yesterday.ts
|
|
27
27
|
var yesterdayValidator = (value, params, context) => {
|
|
28
|
-
if (
|
|
28
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
29
29
|
const soft = params?.soft;
|
|
30
30
|
const message = params?.message;
|
|
31
|
-
const date =
|
|
31
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
32
32
|
if (!date) return null;
|
|
33
33
|
const yesterday = /* @__PURE__ */ new Date();
|
|
34
34
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
35
35
|
yesterday.setHours(0, 0, 0, 0);
|
|
36
36
|
date.setHours(0, 0, 0, 0);
|
|
37
37
|
if (date.getTime() !== yesterday.getTime()) {
|
|
38
|
-
return
|
|
38
|
+
return chunkOIYG5D2I_js.createError(
|
|
39
39
|
context,
|
|
40
40
|
"INVALID_YESTERDAY",
|
|
41
41
|
message || "Date must be yesterday",
|
|
@@ -47,17 +47,17 @@ var yesterdayValidator = (value, params, context) => {
|
|
|
47
47
|
|
|
48
48
|
// src/validators/date/tomorrow.ts
|
|
49
49
|
var tomorrowValidator = (value, params, context) => {
|
|
50
|
-
if (
|
|
50
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
51
51
|
const soft = params?.soft;
|
|
52
52
|
const message = params?.message;
|
|
53
|
-
const date =
|
|
53
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
54
54
|
if (!date) return null;
|
|
55
55
|
const tomorrow = /* @__PURE__ */ new Date();
|
|
56
56
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
57
57
|
tomorrow.setHours(0, 0, 0, 0);
|
|
58
58
|
date.setHours(0, 0, 0, 0);
|
|
59
59
|
if (date.getTime() !== tomorrow.getTime()) {
|
|
60
|
-
return
|
|
60
|
+
return chunkOIYG5D2I_js.createError(
|
|
61
61
|
context,
|
|
62
62
|
"INVALID_TOMORROW",
|
|
63
63
|
message || "Date must be tomorrow",
|
|
@@ -69,10 +69,10 @@ var tomorrowValidator = (value, params, context) => {
|
|
|
69
69
|
|
|
70
70
|
// src/validators/date/thisWeek.ts
|
|
71
71
|
var thisWeekValidator = (value, params, context) => {
|
|
72
|
-
if (
|
|
72
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
73
73
|
const soft = params?.soft;
|
|
74
74
|
const message = params?.message;
|
|
75
|
-
const date =
|
|
75
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
76
76
|
if (!date) return null;
|
|
77
77
|
const now = /* @__PURE__ */ new Date();
|
|
78
78
|
const startOfWeek = new Date(now);
|
|
@@ -82,7 +82,7 @@ var thisWeekValidator = (value, params, context) => {
|
|
|
82
82
|
endOfWeek.setDate(startOfWeek.getDate() + 6);
|
|
83
83
|
endOfWeek.setHours(23, 59, 59, 999);
|
|
84
84
|
if (date < startOfWeek || date > endOfWeek) {
|
|
85
|
-
return
|
|
85
|
+
return chunkOIYG5D2I_js.createError(
|
|
86
86
|
context,
|
|
87
87
|
"INVALID_THIS_WEEK",
|
|
88
88
|
message || "Date must be within this week",
|
|
@@ -94,16 +94,16 @@ var thisWeekValidator = (value, params, context) => {
|
|
|
94
94
|
|
|
95
95
|
// src/validators/date/thisMonth.ts
|
|
96
96
|
var thisMonthValidator = (value, params, context) => {
|
|
97
|
-
if (
|
|
97
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
98
98
|
const soft = params?.soft;
|
|
99
99
|
const message = params?.message;
|
|
100
|
-
const date =
|
|
100
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
101
101
|
if (!date) return null;
|
|
102
102
|
const now = /* @__PURE__ */ new Date();
|
|
103
103
|
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
104
104
|
const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
105
105
|
if (date < startOfMonth || date > endOfMonth) {
|
|
106
|
-
return
|
|
106
|
+
return chunkOIYG5D2I_js.createError(
|
|
107
107
|
context,
|
|
108
108
|
"INVALID_THIS_MONTH",
|
|
109
109
|
message || "Date must be within this month",
|
|
@@ -115,16 +115,16 @@ var thisMonthValidator = (value, params, context) => {
|
|
|
115
115
|
|
|
116
116
|
// src/validators/date/thisYear.ts
|
|
117
117
|
var thisYearValidator = (value, params, context) => {
|
|
118
|
-
if (
|
|
118
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
119
119
|
const soft = params?.soft;
|
|
120
120
|
const message = params?.message;
|
|
121
|
-
const date =
|
|
121
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
122
122
|
if (!date) return null;
|
|
123
123
|
const now = /* @__PURE__ */ new Date();
|
|
124
124
|
const startOfYear = new Date(now.getFullYear(), 0, 1);
|
|
125
125
|
const endOfYear = new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
|
|
126
126
|
if (date < startOfYear || date > endOfYear) {
|
|
127
|
-
return
|
|
127
|
+
return chunkOIYG5D2I_js.createError(
|
|
128
128
|
context,
|
|
129
129
|
"INVALID_THIS_YEAR",
|
|
130
130
|
message || "Date must be within this year",
|
|
@@ -136,14 +136,14 @@ var thisYearValidator = (value, params, context) => {
|
|
|
136
136
|
|
|
137
137
|
// src/validators/date/weekday.ts
|
|
138
138
|
var weekdayValidator = (value, params, context) => {
|
|
139
|
-
if (
|
|
139
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
140
140
|
const soft = params?.soft;
|
|
141
141
|
const message = params?.message;
|
|
142
|
-
const date =
|
|
142
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
143
143
|
if (!date) return null;
|
|
144
144
|
const day = date.getDay();
|
|
145
145
|
if (day === 0 || day === 6) {
|
|
146
|
-
return
|
|
146
|
+
return chunkOIYG5D2I_js.createError(
|
|
147
147
|
context,
|
|
148
148
|
"INVALID_WEEKDAY",
|
|
149
149
|
message || "Date must be a weekday",
|
|
@@ -155,14 +155,14 @@ var weekdayValidator = (value, params, context) => {
|
|
|
155
155
|
|
|
156
156
|
// src/validators/date/weekend.ts
|
|
157
157
|
var weekendValidator = (value, params, context) => {
|
|
158
|
-
if (
|
|
158
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
159
159
|
const soft = params?.soft;
|
|
160
160
|
const message = params?.message;
|
|
161
|
-
const date =
|
|
161
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
162
162
|
if (!date) return null;
|
|
163
163
|
const day = date.getDay();
|
|
164
164
|
if (day !== 0 && day !== 6) {
|
|
165
|
-
return
|
|
165
|
+
return chunkOIYG5D2I_js.createError(
|
|
166
166
|
context,
|
|
167
167
|
"INVALID_WEEKEND",
|
|
168
168
|
message || "Date must be a weekend",
|
|
@@ -174,12 +174,12 @@ var weekendValidator = (value, params, context) => {
|
|
|
174
174
|
|
|
175
175
|
// src/validators/date/age.ts
|
|
176
176
|
var ageValidator = (value, params, context) => {
|
|
177
|
-
if (
|
|
177
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
178
178
|
const min = params?.min;
|
|
179
179
|
const max = params?.max;
|
|
180
180
|
const soft = params?.soft;
|
|
181
181
|
const message = params?.message;
|
|
182
|
-
const birthDate =
|
|
182
|
+
const birthDate = chunkOIYG5D2I_js.parseDate(value);
|
|
183
183
|
if (!birthDate) return null;
|
|
184
184
|
const today = /* @__PURE__ */ new Date();
|
|
185
185
|
let age = today.getFullYear() - birthDate.getFullYear();
|
|
@@ -188,7 +188,7 @@ var ageValidator = (value, params, context) => {
|
|
|
188
188
|
age--;
|
|
189
189
|
}
|
|
190
190
|
if (min !== void 0 && age < min) {
|
|
191
|
-
return
|
|
191
|
+
return chunkOIYG5D2I_js.createError(
|
|
192
192
|
context,
|
|
193
193
|
"INVALID_AGE_MIN",
|
|
194
194
|
message || `Age must be at least ${min}`,
|
|
@@ -196,7 +196,7 @@ var ageValidator = (value, params, context) => {
|
|
|
196
196
|
);
|
|
197
197
|
}
|
|
198
198
|
if (max !== void 0 && age > max) {
|
|
199
|
-
return
|
|
199
|
+
return chunkOIYG5D2I_js.createError(
|
|
200
200
|
context,
|
|
201
201
|
"INVALID_AGE_MAX",
|
|
202
202
|
message || `Age must be at most ${max}`,
|
|
@@ -208,17 +208,17 @@ var ageValidator = (value, params, context) => {
|
|
|
208
208
|
|
|
209
209
|
// src/validators/date/between.ts
|
|
210
210
|
var betweenValidator = (value, params, context) => {
|
|
211
|
-
if (
|
|
211
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
212
212
|
const start = params?.start;
|
|
213
213
|
const end = params?.end;
|
|
214
214
|
const soft = params?.soft;
|
|
215
215
|
const message = params?.message;
|
|
216
|
-
const date =
|
|
216
|
+
const date = chunkOIYG5D2I_js.parseDate(value);
|
|
217
217
|
if (!date) return null;
|
|
218
|
-
const startDate =
|
|
219
|
-
const endDate =
|
|
218
|
+
const startDate = chunkOIYG5D2I_js.parseDate(start);
|
|
219
|
+
const endDate = chunkOIYG5D2I_js.parseDate(end);
|
|
220
220
|
if (startDate && date < startDate) {
|
|
221
|
-
return
|
|
221
|
+
return chunkOIYG5D2I_js.createError(
|
|
222
222
|
context,
|
|
223
223
|
"INVALID_DATE_BEFORE",
|
|
224
224
|
message || `Date must be after ${startDate.toLocaleDateString()}`,
|
|
@@ -226,7 +226,7 @@ var betweenValidator = (value, params, context) => {
|
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
if (endDate && date > endDate) {
|
|
229
|
-
return
|
|
229
|
+
return chunkOIYG5D2I_js.createError(
|
|
230
230
|
context,
|
|
231
231
|
"INVALID_DATE_AFTER",
|
|
232
232
|
message || `Date must be before ${endDate.toLocaleDateString()}`,
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the FormSchema validation engine
|
|
3
|
+
*/
|
|
4
|
+
type ValidationSeverity = 'hard' | 'soft';
|
|
5
|
+
interface ValidationError {
|
|
6
|
+
/** Field path (e.g., "email" or "address.city") */
|
|
7
|
+
field: string;
|
|
8
|
+
/** Path as array (e.g., ["address", "city"]) */
|
|
9
|
+
path?: string[];
|
|
10
|
+
/** Error code for programmatic handling */
|
|
11
|
+
code: string;
|
|
12
|
+
/** Human-readable error message */
|
|
13
|
+
message: string;
|
|
14
|
+
/** Severity level - hard errors block submission, soft are warnings */
|
|
15
|
+
severity: ValidationSeverity;
|
|
16
|
+
/** Value that was received (for context) */
|
|
17
|
+
received?: unknown;
|
|
18
|
+
/** Expected value or constraints (for context) */
|
|
19
|
+
expected?: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface ValidationResult {
|
|
22
|
+
/** True if no hard errors exist */
|
|
23
|
+
valid: boolean;
|
|
24
|
+
/** Errors that block form submission */
|
|
25
|
+
hardErrors: ValidationError[];
|
|
26
|
+
/** Warnings that don't block submission */
|
|
27
|
+
softErrors: ValidationError[];
|
|
28
|
+
/** Errors aggregated by field path */
|
|
29
|
+
errorsByField?: Record<string, ValidationError[]>;
|
|
30
|
+
}
|
|
31
|
+
/** Validation options */
|
|
32
|
+
interface ValidationOptions {
|
|
33
|
+
/** Custom error message formatter */
|
|
34
|
+
errorMap?: (error: ValidationError) => ValidationError | {
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
/** Stop validation on first error */
|
|
38
|
+
abortEarly?: boolean;
|
|
39
|
+
/** Aggregate errors by field */
|
|
40
|
+
aggregateByField?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
|
|
43
|
+
interface ValidationRule {
|
|
44
|
+
/** Rule type identifier */
|
|
45
|
+
type: string;
|
|
46
|
+
/** Rule parameters */
|
|
47
|
+
params?: Record<string, unknown>;
|
|
48
|
+
/** Custom error message */
|
|
49
|
+
message?: string;
|
|
50
|
+
/** Is this a soft validation (warning only)? */
|
|
51
|
+
soft?: boolean;
|
|
52
|
+
/** Is this an async validation? */
|
|
53
|
+
async?: boolean;
|
|
54
|
+
/** Debounce delay in ms for async validators */
|
|
55
|
+
debounce?: number;
|
|
56
|
+
/** Timeout in ms for async validators */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
59
|
+
interface FieldDefinition<T = unknown> {
|
|
60
|
+
/** The base type of this field */
|
|
61
|
+
type: FieldType;
|
|
62
|
+
/** Validation rules to apply */
|
|
63
|
+
rules: ValidationRule[];
|
|
64
|
+
/** Is this field required? */
|
|
65
|
+
required: boolean;
|
|
66
|
+
/** Default value */
|
|
67
|
+
defaultValue?: T;
|
|
68
|
+
/** For nested schemas */
|
|
69
|
+
schema?: SchemaDefinition;
|
|
70
|
+
/** For array items */
|
|
71
|
+
items?: FieldDefinition;
|
|
72
|
+
/** Field metadata */
|
|
73
|
+
meta?: Record<string, unknown>;
|
|
74
|
+
/** Transform functions to apply to value */
|
|
75
|
+
transforms?: Array<(value: unknown) => unknown>;
|
|
76
|
+
/** Preprocess function to apply before validation */
|
|
77
|
+
preprocess?: (value: unknown) => unknown;
|
|
78
|
+
/** Allow null values */
|
|
79
|
+
nullable?: boolean;
|
|
80
|
+
/** Allow null or undefined values */
|
|
81
|
+
nullish?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface SchemaDefinition {
|
|
84
|
+
/** Field definitions keyed by field name */
|
|
85
|
+
fields: Record<string, FieldDefinition>;
|
|
86
|
+
/** Schema metadata */
|
|
87
|
+
meta?: Record<string, unknown>;
|
|
88
|
+
/** Allow unknown keys to pass through */
|
|
89
|
+
passthrough?: boolean;
|
|
90
|
+
/** Strict mode - reject unknown keys */
|
|
91
|
+
strict?: boolean;
|
|
92
|
+
/** Catchall field definition for unknown keys */
|
|
93
|
+
catchall?: FieldDefinition;
|
|
94
|
+
}
|
|
95
|
+
interface ValidatorContext {
|
|
96
|
+
/** Current field path */
|
|
97
|
+
path: string;
|
|
98
|
+
/** Full data object being validated */
|
|
99
|
+
root: unknown;
|
|
100
|
+
/** Parent object containing this field */
|
|
101
|
+
parent?: unknown;
|
|
102
|
+
}
|
|
103
|
+
type ValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => ValidationError | null;
|
|
104
|
+
type AsyncValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => Promise<ValidationError | null>;
|
|
105
|
+
/** Async refine function type - returns boolean or validation result object */
|
|
106
|
+
type AsyncRefineFn<T = unknown> = (value: T) => Promise<boolean | {
|
|
107
|
+
valid: boolean;
|
|
108
|
+
message?: string;
|
|
109
|
+
}>;
|
|
110
|
+
/** Options for async validation */
|
|
111
|
+
interface AsyncValidationOptions {
|
|
112
|
+
/** Custom error message */
|
|
113
|
+
message?: string;
|
|
114
|
+
/** Debounce delay in ms */
|
|
115
|
+
debounce?: number;
|
|
116
|
+
/** Timeout in ms (default: 5000) */
|
|
117
|
+
timeout?: number;
|
|
118
|
+
/** Is this a soft validation (warning only)? */
|
|
119
|
+
soft?: boolean;
|
|
120
|
+
/** Cache results (useful for expensive checks) */
|
|
121
|
+
cache?: boolean;
|
|
122
|
+
/** Cache TTL in seconds (default: 3600) */
|
|
123
|
+
cacheTTL?: number;
|
|
124
|
+
}
|
|
125
|
+
interface EnterpriseValidationResponse {
|
|
126
|
+
status: 'success' | 'validation_error';
|
|
127
|
+
data?: unknown;
|
|
128
|
+
errors: ValidationError[];
|
|
129
|
+
msg: string;
|
|
130
|
+
validation: {
|
|
131
|
+
hard_validations: ValidationError[];
|
|
132
|
+
soft_validations: ValidationError[];
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert ValidationResult to enterprise-compatible response format
|
|
137
|
+
*/
|
|
138
|
+
declare function toEnterpriseResponse(result: ValidationResult, data?: unknown): EnterpriseValidationResponse;
|
|
139
|
+
|
|
140
|
+
export { type AsyncRefineFn as A, type EnterpriseValidationResponse as E, type FieldDefinition as F, type SchemaDefinition as S, type ValidatorContext as V, type ValidationError as a, type ValidationResult as b, type ValidationRule as c, type AsyncValidationOptions as d, type ValidationOptions as e, type ValidatorFn as f, type ValidationSeverity as g, type FieldType as h, type AsyncValidatorFn as i, toEnterpriseResponse as t };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the FormSchema validation engine
|
|
3
|
+
*/
|
|
4
|
+
type ValidationSeverity = 'hard' | 'soft';
|
|
5
|
+
interface ValidationError {
|
|
6
|
+
/** Field path (e.g., "email" or "address.city") */
|
|
7
|
+
field: string;
|
|
8
|
+
/** Path as array (e.g., ["address", "city"]) */
|
|
9
|
+
path?: string[];
|
|
10
|
+
/** Error code for programmatic handling */
|
|
11
|
+
code: string;
|
|
12
|
+
/** Human-readable error message */
|
|
13
|
+
message: string;
|
|
14
|
+
/** Severity level - hard errors block submission, soft are warnings */
|
|
15
|
+
severity: ValidationSeverity;
|
|
16
|
+
/** Value that was received (for context) */
|
|
17
|
+
received?: unknown;
|
|
18
|
+
/** Expected value or constraints (for context) */
|
|
19
|
+
expected?: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface ValidationResult {
|
|
22
|
+
/** True if no hard errors exist */
|
|
23
|
+
valid: boolean;
|
|
24
|
+
/** Errors that block form submission */
|
|
25
|
+
hardErrors: ValidationError[];
|
|
26
|
+
/** Warnings that don't block submission */
|
|
27
|
+
softErrors: ValidationError[];
|
|
28
|
+
/** Errors aggregated by field path */
|
|
29
|
+
errorsByField?: Record<string, ValidationError[]>;
|
|
30
|
+
}
|
|
31
|
+
/** Validation options */
|
|
32
|
+
interface ValidationOptions {
|
|
33
|
+
/** Custom error message formatter */
|
|
34
|
+
errorMap?: (error: ValidationError) => ValidationError | {
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
/** Stop validation on first error */
|
|
38
|
+
abortEarly?: boolean;
|
|
39
|
+
/** Aggregate errors by field */
|
|
40
|
+
aggregateByField?: boolean;
|
|
41
|
+
}
|
|
42
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
|
|
43
|
+
interface ValidationRule {
|
|
44
|
+
/** Rule type identifier */
|
|
45
|
+
type: string;
|
|
46
|
+
/** Rule parameters */
|
|
47
|
+
params?: Record<string, unknown>;
|
|
48
|
+
/** Custom error message */
|
|
49
|
+
message?: string;
|
|
50
|
+
/** Is this a soft validation (warning only)? */
|
|
51
|
+
soft?: boolean;
|
|
52
|
+
/** Is this an async validation? */
|
|
53
|
+
async?: boolean;
|
|
54
|
+
/** Debounce delay in ms for async validators */
|
|
55
|
+
debounce?: number;
|
|
56
|
+
/** Timeout in ms for async validators */
|
|
57
|
+
timeout?: number;
|
|
58
|
+
}
|
|
59
|
+
interface FieldDefinition<T = unknown> {
|
|
60
|
+
/** The base type of this field */
|
|
61
|
+
type: FieldType;
|
|
62
|
+
/** Validation rules to apply */
|
|
63
|
+
rules: ValidationRule[];
|
|
64
|
+
/** Is this field required? */
|
|
65
|
+
required: boolean;
|
|
66
|
+
/** Default value */
|
|
67
|
+
defaultValue?: T;
|
|
68
|
+
/** For nested schemas */
|
|
69
|
+
schema?: SchemaDefinition;
|
|
70
|
+
/** For array items */
|
|
71
|
+
items?: FieldDefinition;
|
|
72
|
+
/** Field metadata */
|
|
73
|
+
meta?: Record<string, unknown>;
|
|
74
|
+
/** Transform functions to apply to value */
|
|
75
|
+
transforms?: Array<(value: unknown) => unknown>;
|
|
76
|
+
/** Preprocess function to apply before validation */
|
|
77
|
+
preprocess?: (value: unknown) => unknown;
|
|
78
|
+
/** Allow null values */
|
|
79
|
+
nullable?: boolean;
|
|
80
|
+
/** Allow null or undefined values */
|
|
81
|
+
nullish?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface SchemaDefinition {
|
|
84
|
+
/** Field definitions keyed by field name */
|
|
85
|
+
fields: Record<string, FieldDefinition>;
|
|
86
|
+
/** Schema metadata */
|
|
87
|
+
meta?: Record<string, unknown>;
|
|
88
|
+
/** Allow unknown keys to pass through */
|
|
89
|
+
passthrough?: boolean;
|
|
90
|
+
/** Strict mode - reject unknown keys */
|
|
91
|
+
strict?: boolean;
|
|
92
|
+
/** Catchall field definition for unknown keys */
|
|
93
|
+
catchall?: FieldDefinition;
|
|
94
|
+
}
|
|
95
|
+
interface ValidatorContext {
|
|
96
|
+
/** Current field path */
|
|
97
|
+
path: string;
|
|
98
|
+
/** Full data object being validated */
|
|
99
|
+
root: unknown;
|
|
100
|
+
/** Parent object containing this field */
|
|
101
|
+
parent?: unknown;
|
|
102
|
+
}
|
|
103
|
+
type ValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => ValidationError | null;
|
|
104
|
+
type AsyncValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => Promise<ValidationError | null>;
|
|
105
|
+
/** Async refine function type - returns boolean or validation result object */
|
|
106
|
+
type AsyncRefineFn<T = unknown> = (value: T) => Promise<boolean | {
|
|
107
|
+
valid: boolean;
|
|
108
|
+
message?: string;
|
|
109
|
+
}>;
|
|
110
|
+
/** Options for async validation */
|
|
111
|
+
interface AsyncValidationOptions {
|
|
112
|
+
/** Custom error message */
|
|
113
|
+
message?: string;
|
|
114
|
+
/** Debounce delay in ms */
|
|
115
|
+
debounce?: number;
|
|
116
|
+
/** Timeout in ms (default: 5000) */
|
|
117
|
+
timeout?: number;
|
|
118
|
+
/** Is this a soft validation (warning only)? */
|
|
119
|
+
soft?: boolean;
|
|
120
|
+
/** Cache results (useful for expensive checks) */
|
|
121
|
+
cache?: boolean;
|
|
122
|
+
/** Cache TTL in seconds (default: 3600) */
|
|
123
|
+
cacheTTL?: number;
|
|
124
|
+
}
|
|
125
|
+
interface EnterpriseValidationResponse {
|
|
126
|
+
status: 'success' | 'validation_error';
|
|
127
|
+
data?: unknown;
|
|
128
|
+
errors: ValidationError[];
|
|
129
|
+
msg: string;
|
|
130
|
+
validation: {
|
|
131
|
+
hard_validations: ValidationError[];
|
|
132
|
+
soft_validations: ValidationError[];
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Convert ValidationResult to enterprise-compatible response format
|
|
137
|
+
*/
|
|
138
|
+
declare function toEnterpriseResponse(result: ValidationResult, data?: unknown): EnterpriseValidationResponse;
|
|
139
|
+
|
|
140
|
+
export { type AsyncRefineFn as A, type EnterpriseValidationResponse as E, type FieldDefinition as F, type SchemaDefinition as S, type ValidatorContext as V, type ValidationError as a, type ValidationResult as b, type ValidationRule as c, type AsyncValidationOptions as d, type ValidationOptions as e, type ValidatorFn as f, type ValidationSeverity as g, type FieldType as h, type AsyncValidatorFn as i, toEnterpriseResponse as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition, b as ValidationResult,
|
|
2
|
-
export { E as EnterpriseValidationResponse,
|
|
3
|
-
export { A as ArrayFieldBuilder, B as BaseFieldBuilder,
|
|
1
|
+
import { S as SchemaDefinition, e as ValidationOptions, b as ValidationResult, f as ValidatorFn } from './index-C17xs-fU.mjs';
|
|
2
|
+
export { A as AsyncRefineFn, d as AsyncValidationOptions, i as AsyncValidatorFn, E as EnterpriseValidationResponse, F as FieldDefinition, h as FieldType, a as ValidationError, c as ValidationRule, g as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-C17xs-fU.mjs';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, l as BooleanFieldBuilder, n as DateFieldBuilder, D as DeepPartial, E as EnumFieldBuilder, I as InferInput, j as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, k as StringFieldBuilder, f as catchall, i as coerce, d as deepPartial, e as extend, h as field, m as merge, o as omit, g as optional, a as partial, b as passthrough, p as pick, r as required, s as schema, c as strict } from './schema-DYE8Wz8X.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Core validation engine - runs unchanged in browser and Node.js
|
|
@@ -9,19 +9,19 @@ export { A as ArrayFieldBuilder, B as BaseFieldBuilder, d as BooleanFieldBuilder
|
|
|
9
9
|
/**
|
|
10
10
|
* Validate data against a schema
|
|
11
11
|
*/
|
|
12
|
-
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): ValidationResult;
|
|
12
|
+
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown, options?: ValidationOptions): ValidationResult;
|
|
13
13
|
/**
|
|
14
14
|
* Main validation function
|
|
15
15
|
*/
|
|
16
|
-
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): ValidationResult;
|
|
16
|
+
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): ValidationResult;
|
|
17
17
|
/**
|
|
18
18
|
* Check if data is valid (no hard errors)
|
|
19
19
|
*/
|
|
20
|
-
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown
|
|
20
|
+
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown>, options?: ValidationOptions): boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Validate and throw if invalid
|
|
23
23
|
*/
|
|
24
|
-
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): T;
|
|
24
|
+
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): T;
|
|
25
25
|
/**
|
|
26
26
|
* Merge multiple validation results
|
|
27
27
|
*/
|
|
@@ -35,6 +35,24 @@ declare function validResult(): ValidationResult;
|
|
|
35
35
|
*/
|
|
36
36
|
declare function errorResult(field: string, code: string, message: string, soft?: boolean): ValidationResult;
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Async validation engine for handling asynchronous validators
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
declare function validateSchemaAsync(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): Promise<ValidationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Main async validation function
|
|
45
|
+
*/
|
|
46
|
+
declare function validateAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<ValidationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if data is valid async (no hard errors)
|
|
49
|
+
*/
|
|
50
|
+
declare function isValidAsync(schema: SchemaDefinition, data: Record<string, unknown>): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate async and throw if invalid
|
|
53
|
+
*/
|
|
54
|
+
declare function assertValidAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<T>;
|
|
55
|
+
|
|
38
56
|
/**
|
|
39
57
|
* Built-in validators for common validation rules
|
|
40
58
|
*/
|
|
@@ -54,4 +72,4 @@ declare function getValidator(name: string): ValidatorFn | undefined;
|
|
|
54
72
|
*/
|
|
55
73
|
declare function getTypeValidator(type: string): ValidatorFn | undefined;
|
|
56
74
|
|
|
57
|
-
export { SchemaDefinition, ValidationResult, ValidatorFn, assertValid, errorResult, getTypeValidator, getValidator, isValid, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateSchema };
|
|
75
|
+
export { SchemaDefinition, ValidationOptions, ValidationResult, ValidatorFn, assertValid, assertValidAsync, errorResult, getTypeValidator, getValidator, isValid, isValidAsync, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateAsync, validateSchema, validateSchemaAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition, b as ValidationResult,
|
|
2
|
-
export { E as EnterpriseValidationResponse,
|
|
3
|
-
export { A as ArrayFieldBuilder, B as BaseFieldBuilder,
|
|
1
|
+
import { S as SchemaDefinition, e as ValidationOptions, b as ValidationResult, f as ValidatorFn } from './index-C17xs-fU.js';
|
|
2
|
+
export { A as AsyncRefineFn, d as AsyncValidationOptions, i as AsyncValidatorFn, E as EnterpriseValidationResponse, F as FieldDefinition, h as FieldType, a as ValidationError, c as ValidationRule, g as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-C17xs-fU.js';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, l as BooleanFieldBuilder, n as DateFieldBuilder, D as DeepPartial, E as EnumFieldBuilder, I as InferInput, j as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, k as StringFieldBuilder, f as catchall, i as coerce, d as deepPartial, e as extend, h as field, m as merge, o as omit, g as optional, a as partial, b as passthrough, p as pick, r as required, s as schema, c as strict } from './schema-Dtp-joeT.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Core validation engine - runs unchanged in browser and Node.js
|
|
@@ -9,19 +9,19 @@ export { A as ArrayFieldBuilder, B as BaseFieldBuilder, d as BooleanFieldBuilder
|
|
|
9
9
|
/**
|
|
10
10
|
* Validate data against a schema
|
|
11
11
|
*/
|
|
12
|
-
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): ValidationResult;
|
|
12
|
+
declare function validateSchema(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown, options?: ValidationOptions): ValidationResult;
|
|
13
13
|
/**
|
|
14
14
|
* Main validation function
|
|
15
15
|
*/
|
|
16
|
-
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): ValidationResult;
|
|
16
|
+
declare function validate<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): ValidationResult;
|
|
17
17
|
/**
|
|
18
18
|
* Check if data is valid (no hard errors)
|
|
19
19
|
*/
|
|
20
|
-
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown
|
|
20
|
+
declare function isValid(schema: SchemaDefinition, data: Record<string, unknown>, options?: ValidationOptions): boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Validate and throw if invalid
|
|
23
23
|
*/
|
|
24
|
-
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): T;
|
|
24
|
+
declare function assertValid<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T, options?: ValidationOptions): T;
|
|
25
25
|
/**
|
|
26
26
|
* Merge multiple validation results
|
|
27
27
|
*/
|
|
@@ -35,6 +35,24 @@ declare function validResult(): ValidationResult;
|
|
|
35
35
|
*/
|
|
36
36
|
declare function errorResult(field: string, code: string, message: string, soft?: boolean): ValidationResult;
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Async validation engine for handling asynchronous validators
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
declare function validateSchemaAsync(schema: SchemaDefinition, data: Record<string, unknown>, basePath?: string, root?: unknown): Promise<ValidationResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Main async validation function
|
|
45
|
+
*/
|
|
46
|
+
declare function validateAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<ValidationResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Check if data is valid async (no hard errors)
|
|
49
|
+
*/
|
|
50
|
+
declare function isValidAsync(schema: SchemaDefinition, data: Record<string, unknown>): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Validate async and throw if invalid
|
|
53
|
+
*/
|
|
54
|
+
declare function assertValidAsync<T extends Record<string, unknown>>(schema: SchemaDefinition, data: T): Promise<T>;
|
|
55
|
+
|
|
38
56
|
/**
|
|
39
57
|
* Built-in validators for common validation rules
|
|
40
58
|
*/
|
|
@@ -54,4 +72,4 @@ declare function getValidator(name: string): ValidatorFn | undefined;
|
|
|
54
72
|
*/
|
|
55
73
|
declare function getTypeValidator(type: string): ValidatorFn | undefined;
|
|
56
74
|
|
|
57
|
-
export { SchemaDefinition, ValidationResult, ValidatorFn, assertValid, errorResult, getTypeValidator, getValidator, isValid, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateSchema };
|
|
75
|
+
export { SchemaDefinition, ValidationOptions, ValidationResult, ValidatorFn, assertValid, assertValidAsync, errorResult, getTypeValidator, getValidator, isValid, isValidAsync, mergeResults, registerValidator, ruleValidators, typeValidators, validResult, validate, validateAsync, validateSchema, validateSchemaAsync };
|