unischema 1.0.1 → 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.
Files changed (70) hide show
  1. package/README.md +780 -228
  2. package/dist/adapters/backend/index.d.mts +2 -1
  3. package/dist/adapters/backend/index.d.ts +2 -1
  4. package/dist/adapters/backend/index.js +17 -441
  5. package/dist/adapters/backend/index.mjs +9 -433
  6. package/dist/adapters/frontend/index.d.mts +2 -1
  7. package/dist/adapters/frontend/index.d.ts +2 -1
  8. package/dist/adapters/frontend/index.js +10 -421
  9. package/dist/adapters/frontend/index.mjs +8 -419
  10. package/dist/chunk-5A4ITJVD.mjs +124 -0
  11. package/dist/chunk-66RFUBVU.js +131 -0
  12. package/dist/chunk-75YSYC4K.mjs +85 -0
  13. package/dist/chunk-76BBWQDH.js +90 -0
  14. package/dist/chunk-7XES4A3M.mjs +237 -0
  15. package/dist/chunk-BVRXGZLS.js +17 -0
  16. package/dist/chunk-COMVAVFU.mjs +335 -0
  17. package/dist/chunk-DT2TQZU7.js +796 -0
  18. package/dist/chunk-FPCCH55A.js +103 -0
  19. package/dist/chunk-IUXRLMET.js +206 -0
  20. package/dist/chunk-JEW6U6CB.js +353 -0
  21. package/dist/chunk-KZCV5IW4.mjs +97 -0
  22. package/dist/chunk-KZZ7NVU3.mjs +41 -0
  23. package/dist/chunk-MFEBMQAU.mjs +779 -0
  24. package/dist/chunk-OIYG5D2I.js +50 -0
  25. package/dist/chunk-RW6HDA5H.mjs +194 -0
  26. package/dist/chunk-TTK77YBI.mjs +15 -0
  27. package/dist/chunk-TXT36BCE.js +248 -0
  28. package/dist/index-C17xs-fU.d.mts +140 -0
  29. package/dist/index-C17xs-fU.d.ts +140 -0
  30. package/dist/index.d.mts +26 -7
  31. package/dist/index.d.ts +26 -7
  32. package/dist/index.js +769 -499
  33. package/dist/index.mjs +695 -487
  34. package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
  35. package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -79
  36. package/dist/validators/array.d.mts +15 -0
  37. package/dist/validators/array.d.ts +15 -0
  38. package/dist/validators/array.js +31 -0
  39. package/dist/validators/array.mjs +2 -0
  40. package/dist/validators/common.d.mts +13 -0
  41. package/dist/validators/common.d.ts +13 -0
  42. package/dist/validators/common.js +27 -0
  43. package/dist/validators/common.mjs +2 -0
  44. package/dist/validators/date.d.mts +23 -0
  45. package/dist/validators/date.d.ts +23 -0
  46. package/dist/validators/date.js +47 -0
  47. package/dist/validators/date.mjs +2 -0
  48. package/dist/validators/index.d.mts +46 -0
  49. package/dist/validators/index.d.ts +46 -0
  50. package/dist/validators/index.js +256 -0
  51. package/dist/validators/index.mjs +7 -0
  52. package/dist/validators/number.d.mts +25 -0
  53. package/dist/validators/number.d.ts +25 -0
  54. package/dist/validators/number.js +51 -0
  55. package/dist/validators/number.mjs +2 -0
  56. package/dist/validators/object.d.mts +11 -0
  57. package/dist/validators/object.d.ts +11 -0
  58. package/dist/validators/object.js +23 -0
  59. package/dist/validators/object.mjs +2 -0
  60. package/dist/validators/string.d.mts +37 -0
  61. package/dist/validators/string.d.ts +37 -0
  62. package/dist/validators/string.js +75 -0
  63. package/dist/validators/string.mjs +2 -0
  64. package/package.json +82 -5
  65. package/dist/adapters/backend/index.js.map +0 -1
  66. package/dist/adapters/backend/index.mjs.map +0 -1
  67. package/dist/adapters/frontend/index.js.map +0 -1
  68. package/dist/adapters/frontend/index.mjs.map +0 -1
  69. package/dist/index.js.map +0 -1
  70. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ // src/validators/utils.ts
4
+ function createError(context, code, message, soft = false, received, expected) {
5
+ return {
6
+ field: context.path,
7
+ code,
8
+ message,
9
+ severity: soft ? "soft" : "hard",
10
+ received,
11
+ expected
12
+ };
13
+ }
14
+ function isEmpty(value) {
15
+ return value === void 0 || value === null || value === "";
16
+ }
17
+ function isString(value) {
18
+ return typeof value === "string";
19
+ }
20
+ function isNumber(value) {
21
+ return typeof value === "number" && !isNaN(value);
22
+ }
23
+ function isDate(value) {
24
+ return value instanceof Date && !isNaN(value.getTime());
25
+ }
26
+ function parseDate(value) {
27
+ if (value instanceof Date) {
28
+ return isNaN(value.getTime()) ? null : value;
29
+ }
30
+ if (typeof value === "string") {
31
+ const parsed = new Date(value);
32
+ return isNaN(parsed.getTime()) ? null : parsed;
33
+ }
34
+ return null;
35
+ }
36
+ function isArray(value) {
37
+ return Array.isArray(value);
38
+ }
39
+ function isObject(value) {
40
+ return typeof value === "object" && value !== null && !Array.isArray(value);
41
+ }
42
+
43
+ exports.createError = createError;
44
+ exports.isArray = isArray;
45
+ exports.isDate = isDate;
46
+ exports.isEmpty = isEmpty;
47
+ exports.isNumber = isNumber;
48
+ exports.isObject = isObject;
49
+ exports.isString = isString;
50
+ exports.parseDate = parseDate;
@@ -0,0 +1,194 @@
1
+ import { isEmpty, isNumber, createError } from './chunk-KZZ7NVU3.mjs';
2
+
3
+ // src/validators/number/port.ts
4
+ var portValidator = (value, params, context) => {
5
+ if (isEmpty(value)) return null;
6
+ const soft = params?.soft;
7
+ const message = params?.message;
8
+ if (!isNumber(value)) return null;
9
+ if (!Number.isInteger(value) || value < 0 || value > 65535) {
10
+ return createError(
11
+ context,
12
+ "INVALID_PORT",
13
+ message || "Must be a valid port number (0-65535)",
14
+ soft
15
+ );
16
+ }
17
+ return null;
18
+ };
19
+
20
+ // src/validators/number/latitude.ts
21
+ var latitudeValidator = (value, params, context) => {
22
+ if (isEmpty(value)) return null;
23
+ const soft = params?.soft;
24
+ const message = params?.message;
25
+ if (!isNumber(value)) return null;
26
+ if (value < -90 || value > 90) {
27
+ return createError(
28
+ context,
29
+ "INVALID_LATITUDE",
30
+ message || "Latitude must be between -90 and 90",
31
+ soft
32
+ );
33
+ }
34
+ return null;
35
+ };
36
+
37
+ // src/validators/number/longitude.ts
38
+ var longitudeValidator = (value, params, context) => {
39
+ if (isEmpty(value)) return null;
40
+ const soft = params?.soft;
41
+ const message = params?.message;
42
+ if (!isNumber(value)) return null;
43
+ if (value < -180 || value > 180) {
44
+ return createError(
45
+ context,
46
+ "INVALID_LONGITUDE",
47
+ message || "Longitude must be between -180 and 180",
48
+ soft
49
+ );
50
+ }
51
+ return null;
52
+ };
53
+
54
+ // src/validators/number/percentage.ts
55
+ var percentageValidator = (value, params, context) => {
56
+ if (isEmpty(value)) return null;
57
+ const soft = params?.soft;
58
+ const message = params?.message;
59
+ if (!isNumber(value)) return null;
60
+ if (value < 0 || value > 100) {
61
+ return createError(
62
+ context,
63
+ "INVALID_PERCENTAGE",
64
+ message || "Percentage must be between 0 and 100",
65
+ soft
66
+ );
67
+ }
68
+ return null;
69
+ };
70
+
71
+ // src/validators/number/between.ts
72
+ var betweenValidator = (value, params, context) => {
73
+ if (isEmpty(value)) return null;
74
+ const min = params?.min;
75
+ const max = params?.max;
76
+ const soft = params?.soft;
77
+ const message = params?.message;
78
+ if (!isNumber(value)) return null;
79
+ if (value < min || value > max) {
80
+ return createError(
81
+ context,
82
+ "INVALID_BETWEEN",
83
+ message || `Must be between ${min} and ${max}`,
84
+ soft
85
+ );
86
+ }
87
+ return null;
88
+ };
89
+
90
+ // src/validators/number/divisibleBy.ts
91
+ var divisibleByValidator = (value, params, context) => {
92
+ if (isEmpty(value)) return null;
93
+ const divisor = params?.divisor;
94
+ const soft = params?.soft;
95
+ const message = params?.message;
96
+ if (!isNumber(value)) return null;
97
+ if (value % divisor !== 0) {
98
+ return createError(
99
+ context,
100
+ "INVALID_DIVISIBLE_BY",
101
+ message || `Must be divisible by ${divisor}`,
102
+ soft
103
+ );
104
+ }
105
+ return null;
106
+ };
107
+
108
+ // src/validators/number/multipleOf.ts
109
+ var multipleOfValidator = (value, params, context) => {
110
+ if (isEmpty(value)) return null;
111
+ const multiple = params?.multiple;
112
+ const soft = params?.soft;
113
+ const message = params?.message;
114
+ if (!isNumber(value)) return null;
115
+ if (value % multiple !== 0) {
116
+ return createError(
117
+ context,
118
+ "INVALID_MULTIPLE_OF",
119
+ message || `Must be a multiple of ${multiple}`,
120
+ soft
121
+ );
122
+ }
123
+ return null;
124
+ };
125
+
126
+ // src/validators/number/even.ts
127
+ var evenValidator = (value, params, context) => {
128
+ if (isEmpty(value)) return null;
129
+ const soft = params?.soft;
130
+ const message = params?.message;
131
+ if (!isNumber(value)) return null;
132
+ if (value % 2 !== 0) {
133
+ return createError(
134
+ context,
135
+ "INVALID_EVEN",
136
+ message || "Must be an even number",
137
+ soft
138
+ );
139
+ }
140
+ return null;
141
+ };
142
+
143
+ // src/validators/number/odd.ts
144
+ var oddValidator = (value, params, context) => {
145
+ if (isEmpty(value)) return null;
146
+ const soft = params?.soft;
147
+ const message = params?.message;
148
+ if (!isNumber(value)) return null;
149
+ if (value % 2 === 0) {
150
+ return createError(
151
+ context,
152
+ "INVALID_ODD",
153
+ message || "Must be an odd number",
154
+ soft
155
+ );
156
+ }
157
+ return null;
158
+ };
159
+
160
+ // src/validators/number/safe.ts
161
+ var safeValidator = (value, params, context) => {
162
+ if (isEmpty(value)) return null;
163
+ const soft = params?.soft;
164
+ const message = params?.message;
165
+ if (!isNumber(value)) return null;
166
+ if (!Number.isSafeInteger(value)) {
167
+ return createError(
168
+ context,
169
+ "INVALID_SAFE_INTEGER",
170
+ message || "Must be a safe integer",
171
+ soft
172
+ );
173
+ }
174
+ return null;
175
+ };
176
+
177
+ // src/validators/number/finite.ts
178
+ var finiteValidator = (value, params, context) => {
179
+ if (isEmpty(value)) return null;
180
+ const soft = params?.soft;
181
+ const message = params?.message;
182
+ if (!isNumber(value)) return null;
183
+ if (!Number.isFinite(value)) {
184
+ return createError(
185
+ context,
186
+ "INVALID_FINITE",
187
+ message || "Must be a finite number",
188
+ soft
189
+ );
190
+ }
191
+ return null;
192
+ };
193
+
194
+ export { betweenValidator, divisibleByValidator, evenValidator, finiteValidator, latitudeValidator, longitudeValidator, multipleOfValidator, oddValidator, percentageValidator, portValidator, safeValidator };
@@ -0,0 +1,15 @@
1
+ // src/types/index.ts
2
+ function toEnterpriseResponse(result, data) {
3
+ return {
4
+ status: result.valid ? "success" : "validation_error",
5
+ data: result.valid ? data : void 0,
6
+ errors: [...result.hardErrors, ...result.softErrors],
7
+ msg: result.valid ? "Validation successful" : "Validation failed",
8
+ validation: {
9
+ hard_validations: result.hardErrors,
10
+ soft_validations: result.softErrors
11
+ }
12
+ };
13
+ }
14
+
15
+ export { toEnterpriseResponse };
@@ -0,0 +1,248 @@
1
+ 'use strict';
2
+
3
+ var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
4
+
5
+ // src/validators/date/today.ts
6
+ var todayValidator = (value, params, context) => {
7
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
8
+ const soft = params?.soft;
9
+ const message = params?.message;
10
+ const date = chunkOIYG5D2I_js.parseDate(value);
11
+ if (!date) return null;
12
+ const today = /* @__PURE__ */ new Date();
13
+ today.setHours(0, 0, 0, 0);
14
+ date.setHours(0, 0, 0, 0);
15
+ if (date.getTime() !== today.getTime()) {
16
+ return chunkOIYG5D2I_js.createError(
17
+ context,
18
+ "INVALID_TODAY",
19
+ message || "Date must be today",
20
+ soft
21
+ );
22
+ }
23
+ return null;
24
+ };
25
+
26
+ // src/validators/date/yesterday.ts
27
+ var yesterdayValidator = (value, params, context) => {
28
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
29
+ const soft = params?.soft;
30
+ const message = params?.message;
31
+ const date = chunkOIYG5D2I_js.parseDate(value);
32
+ if (!date) return null;
33
+ const yesterday = /* @__PURE__ */ new Date();
34
+ yesterday.setDate(yesterday.getDate() - 1);
35
+ yesterday.setHours(0, 0, 0, 0);
36
+ date.setHours(0, 0, 0, 0);
37
+ if (date.getTime() !== yesterday.getTime()) {
38
+ return chunkOIYG5D2I_js.createError(
39
+ context,
40
+ "INVALID_YESTERDAY",
41
+ message || "Date must be yesterday",
42
+ soft
43
+ );
44
+ }
45
+ return null;
46
+ };
47
+
48
+ // src/validators/date/tomorrow.ts
49
+ var tomorrowValidator = (value, params, context) => {
50
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
51
+ const soft = params?.soft;
52
+ const message = params?.message;
53
+ const date = chunkOIYG5D2I_js.parseDate(value);
54
+ if (!date) return null;
55
+ const tomorrow = /* @__PURE__ */ new Date();
56
+ tomorrow.setDate(tomorrow.getDate() + 1);
57
+ tomorrow.setHours(0, 0, 0, 0);
58
+ date.setHours(0, 0, 0, 0);
59
+ if (date.getTime() !== tomorrow.getTime()) {
60
+ return chunkOIYG5D2I_js.createError(
61
+ context,
62
+ "INVALID_TOMORROW",
63
+ message || "Date must be tomorrow",
64
+ soft
65
+ );
66
+ }
67
+ return null;
68
+ };
69
+
70
+ // src/validators/date/thisWeek.ts
71
+ var thisWeekValidator = (value, params, context) => {
72
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
73
+ const soft = params?.soft;
74
+ const message = params?.message;
75
+ const date = chunkOIYG5D2I_js.parseDate(value);
76
+ if (!date) return null;
77
+ const now = /* @__PURE__ */ new Date();
78
+ const startOfWeek = new Date(now);
79
+ startOfWeek.setDate(now.getDate() - now.getDay());
80
+ startOfWeek.setHours(0, 0, 0, 0);
81
+ const endOfWeek = new Date(startOfWeek);
82
+ endOfWeek.setDate(startOfWeek.getDate() + 6);
83
+ endOfWeek.setHours(23, 59, 59, 999);
84
+ if (date < startOfWeek || date > endOfWeek) {
85
+ return chunkOIYG5D2I_js.createError(
86
+ context,
87
+ "INVALID_THIS_WEEK",
88
+ message || "Date must be within this week",
89
+ soft
90
+ );
91
+ }
92
+ return null;
93
+ };
94
+
95
+ // src/validators/date/thisMonth.ts
96
+ var thisMonthValidator = (value, params, context) => {
97
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
98
+ const soft = params?.soft;
99
+ const message = params?.message;
100
+ const date = chunkOIYG5D2I_js.parseDate(value);
101
+ if (!date) return null;
102
+ const now = /* @__PURE__ */ new Date();
103
+ const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
104
+ const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
105
+ if (date < startOfMonth || date > endOfMonth) {
106
+ return chunkOIYG5D2I_js.createError(
107
+ context,
108
+ "INVALID_THIS_MONTH",
109
+ message || "Date must be within this month",
110
+ soft
111
+ );
112
+ }
113
+ return null;
114
+ };
115
+
116
+ // src/validators/date/thisYear.ts
117
+ var thisYearValidator = (value, params, context) => {
118
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
119
+ const soft = params?.soft;
120
+ const message = params?.message;
121
+ const date = chunkOIYG5D2I_js.parseDate(value);
122
+ if (!date) return null;
123
+ const now = /* @__PURE__ */ new Date();
124
+ const startOfYear = new Date(now.getFullYear(), 0, 1);
125
+ const endOfYear = new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
126
+ if (date < startOfYear || date > endOfYear) {
127
+ return chunkOIYG5D2I_js.createError(
128
+ context,
129
+ "INVALID_THIS_YEAR",
130
+ message || "Date must be within this year",
131
+ soft
132
+ );
133
+ }
134
+ return null;
135
+ };
136
+
137
+ // src/validators/date/weekday.ts
138
+ var weekdayValidator = (value, params, context) => {
139
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
140
+ const soft = params?.soft;
141
+ const message = params?.message;
142
+ const date = chunkOIYG5D2I_js.parseDate(value);
143
+ if (!date) return null;
144
+ const day = date.getDay();
145
+ if (day === 0 || day === 6) {
146
+ return chunkOIYG5D2I_js.createError(
147
+ context,
148
+ "INVALID_WEEKDAY",
149
+ message || "Date must be a weekday",
150
+ soft
151
+ );
152
+ }
153
+ return null;
154
+ };
155
+
156
+ // src/validators/date/weekend.ts
157
+ var weekendValidator = (value, params, context) => {
158
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
159
+ const soft = params?.soft;
160
+ const message = params?.message;
161
+ const date = chunkOIYG5D2I_js.parseDate(value);
162
+ if (!date) return null;
163
+ const day = date.getDay();
164
+ if (day !== 0 && day !== 6) {
165
+ return chunkOIYG5D2I_js.createError(
166
+ context,
167
+ "INVALID_WEEKEND",
168
+ message || "Date must be a weekend",
169
+ soft
170
+ );
171
+ }
172
+ return null;
173
+ };
174
+
175
+ // src/validators/date/age.ts
176
+ var ageValidator = (value, params, context) => {
177
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
178
+ const min = params?.min;
179
+ const max = params?.max;
180
+ const soft = params?.soft;
181
+ const message = params?.message;
182
+ const birthDate = chunkOIYG5D2I_js.parseDate(value);
183
+ if (!birthDate) return null;
184
+ const today = /* @__PURE__ */ new Date();
185
+ let age = today.getFullYear() - birthDate.getFullYear();
186
+ const monthDiff = today.getMonth() - birthDate.getMonth();
187
+ if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
188
+ age--;
189
+ }
190
+ if (min !== void 0 && age < min) {
191
+ return chunkOIYG5D2I_js.createError(
192
+ context,
193
+ "INVALID_AGE_MIN",
194
+ message || `Age must be at least ${min}`,
195
+ soft
196
+ );
197
+ }
198
+ if (max !== void 0 && age > max) {
199
+ return chunkOIYG5D2I_js.createError(
200
+ context,
201
+ "INVALID_AGE_MAX",
202
+ message || `Age must be at most ${max}`,
203
+ soft
204
+ );
205
+ }
206
+ return null;
207
+ };
208
+
209
+ // src/validators/date/between.ts
210
+ var betweenValidator = (value, params, context) => {
211
+ if (chunkOIYG5D2I_js.isEmpty(value)) return null;
212
+ const start = params?.start;
213
+ const end = params?.end;
214
+ const soft = params?.soft;
215
+ const message = params?.message;
216
+ const date = chunkOIYG5D2I_js.parseDate(value);
217
+ if (!date) return null;
218
+ const startDate = chunkOIYG5D2I_js.parseDate(start);
219
+ const endDate = chunkOIYG5D2I_js.parseDate(end);
220
+ if (startDate && date < startDate) {
221
+ return chunkOIYG5D2I_js.createError(
222
+ context,
223
+ "INVALID_DATE_BEFORE",
224
+ message || `Date must be after ${startDate.toLocaleDateString()}`,
225
+ soft
226
+ );
227
+ }
228
+ if (endDate && date > endDate) {
229
+ return chunkOIYG5D2I_js.createError(
230
+ context,
231
+ "INVALID_DATE_AFTER",
232
+ message || `Date must be before ${endDate.toLocaleDateString()}`,
233
+ soft
234
+ );
235
+ }
236
+ return null;
237
+ };
238
+
239
+ exports.ageValidator = ageValidator;
240
+ exports.betweenValidator = betweenValidator;
241
+ exports.thisMonthValidator = thisMonthValidator;
242
+ exports.thisWeekValidator = thisWeekValidator;
243
+ exports.thisYearValidator = thisYearValidator;
244
+ exports.todayValidator = todayValidator;
245
+ exports.tomorrowValidator = tomorrowValidator;
246
+ exports.weekdayValidator = weekdayValidator;
247
+ exports.weekendValidator = weekendValidator;
248
+ exports.yesterdayValidator = yesterdayValidator;
@@ -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 };