unischema 1.0.0 → 1.1.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 +634 -230
- package/dist/adapters/backend/index.d.mts +2 -1
- package/dist/adapters/backend/index.d.ts +2 -1
- package/dist/adapters/backend/index.js +17 -423
- package/dist/adapters/backend/index.mjs +9 -415
- package/dist/adapters/frontend/index.d.mts +2 -1
- package/dist/adapters/frontend/index.d.ts +2 -1
- package/dist/adapters/frontend/index.js +10 -403
- package/dist/adapters/frontend/index.mjs +8 -401
- package/dist/chunk-2JYFKT3R.js +103 -0
- package/dist/chunk-3FANCMEF.js +206 -0
- package/dist/chunk-3TS35CVJ.mjs +478 -0
- package/dist/chunk-ASKTY6EG.js +131 -0
- package/dist/chunk-BJLVOIAP.js +491 -0
- package/dist/chunk-BNIB23NQ.js +90 -0
- package/dist/chunk-BVRXGZLS.js +17 -0
- package/dist/chunk-CQYXR2LZ.js +353 -0
- package/dist/chunk-ELL7U7IC.mjs +237 -0
- package/dist/chunk-FKDWSZIV.mjs +39 -0
- package/dist/chunk-FRBZHN4K.mjs +335 -0
- package/dist/chunk-FZ7K2PC7.js +248 -0
- package/dist/chunk-KHHJD6QK.mjs +85 -0
- package/dist/chunk-NUW55QTO.js +48 -0
- package/dist/chunk-TTK77YBI.mjs +15 -0
- package/dist/chunk-VWP24NYS.mjs +194 -0
- package/dist/chunk-XC4DKEXP.mjs +97 -0
- package/dist/chunk-XGTUU27F.mjs +124 -0
- package/dist/index-BQR7OrY7.d.mts +80 -0
- package/dist/index-BQR7OrY7.d.ts +80 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +537 -476
- package/dist/index.mjs +486 -464
- package/dist/{schema-BwQtngae.d.mts → schema-CpAjXgEF.d.ts} +186 -79
- package/dist/{schema-BwQtngae.d.ts → schema-DYU1zGVm.d.mts} +186 -79
- package/dist/validators/array.d.mts +15 -0
- package/dist/validators/array.d.ts +15 -0
- package/dist/validators/array.js +31 -0
- package/dist/validators/array.mjs +2 -0
- package/dist/validators/common.d.mts +13 -0
- package/dist/validators/common.d.ts +13 -0
- package/dist/validators/common.js +27 -0
- package/dist/validators/common.mjs +2 -0
- package/dist/validators/date.d.mts +23 -0
- package/dist/validators/date.d.ts +23 -0
- package/dist/validators/date.js +47 -0
- package/dist/validators/date.mjs +2 -0
- package/dist/validators/index.d.mts +46 -0
- package/dist/validators/index.d.ts +46 -0
- package/dist/validators/index.js +256 -0
- package/dist/validators/index.mjs +7 -0
- package/dist/validators/number.d.mts +25 -0
- package/dist/validators/number.d.ts +25 -0
- package/dist/validators/number.js +51 -0
- package/dist/validators/number.mjs +2 -0
- package/dist/validators/object.d.mts +11 -0
- package/dist/validators/object.d.ts +11 -0
- package/dist/validators/object.js +23 -0
- package/dist/validators/object.mjs +2 -0
- package/dist/validators/string.d.mts +37 -0
- package/dist/validators/string.d.ts +37 -0
- package/dist/validators/string.js +75 -0
- package/dist/validators/string.mjs +2 -0
- package/package.json +36 -1
- package/dist/adapters/backend/index.js.map +0 -1
- package/dist/adapters/backend/index.mjs.map +0 -1
- package/dist/adapters/frontend/index.js.map +0 -1
- package/dist/adapters/frontend/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -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,194 @@
|
|
|
1
|
+
import { isEmpty, isNumber, createError } from './chunk-FKDWSZIV.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,97 @@
|
|
|
1
|
+
import { isEmpty, createError, isNumber } from './chunk-FKDWSZIV.mjs';
|
|
2
|
+
|
|
3
|
+
// src/validators/common/notMatches.ts
|
|
4
|
+
var notMatchesValidator = (value, params, context) => {
|
|
5
|
+
if (isEmpty(value)) return null;
|
|
6
|
+
const fieldName = params?.field;
|
|
7
|
+
const soft = params?.soft;
|
|
8
|
+
const message = params?.message;
|
|
9
|
+
if (!fieldName) return null;
|
|
10
|
+
const root = context.root;
|
|
11
|
+
const otherValue = root?.[fieldName];
|
|
12
|
+
if (value === otherValue) {
|
|
13
|
+
return createError(
|
|
14
|
+
context,
|
|
15
|
+
"INVALID_NOT_MATCHES",
|
|
16
|
+
message || `Must not match ${fieldName}`,
|
|
17
|
+
soft
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/validators/common/greaterThan.ts
|
|
24
|
+
var greaterThanValidator = (value, params, context) => {
|
|
25
|
+
if (isEmpty(value)) return null;
|
|
26
|
+
const fieldName = params?.field;
|
|
27
|
+
const soft = params?.soft;
|
|
28
|
+
const message = params?.message;
|
|
29
|
+
if (!isNumber(value) || !fieldName) return null;
|
|
30
|
+
const root = context.root;
|
|
31
|
+
const otherValue = root?.[fieldName];
|
|
32
|
+
if (isNumber(otherValue) && value <= otherValue) {
|
|
33
|
+
return createError(
|
|
34
|
+
context,
|
|
35
|
+
"INVALID_GREATER_THAN",
|
|
36
|
+
message || `Must be greater than ${fieldName}`,
|
|
37
|
+
soft
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/validators/common/lessThan.ts
|
|
44
|
+
var lessThanValidator = (value, params, context) => {
|
|
45
|
+
if (isEmpty(value)) return null;
|
|
46
|
+
const fieldName = params?.field;
|
|
47
|
+
const soft = params?.soft;
|
|
48
|
+
const message = params?.message;
|
|
49
|
+
if (!isNumber(value) || !fieldName) return null;
|
|
50
|
+
const root = context.root;
|
|
51
|
+
const otherValue = root?.[fieldName];
|
|
52
|
+
if (isNumber(otherValue) && value >= otherValue) {
|
|
53
|
+
return createError(
|
|
54
|
+
context,
|
|
55
|
+
"INVALID_LESS_THAN",
|
|
56
|
+
message || `Must be less than ${fieldName}`,
|
|
57
|
+
soft
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/validators/common/when.ts
|
|
64
|
+
var whenValidator = (value, params, context) => {
|
|
65
|
+
const fieldName = params?.field;
|
|
66
|
+
const is = params?.is;
|
|
67
|
+
const then = params?.then;
|
|
68
|
+
if (!fieldName || !then) return null;
|
|
69
|
+
const root = context.root;
|
|
70
|
+
const otherValue = root?.[fieldName];
|
|
71
|
+
if (otherValue === is) {
|
|
72
|
+
return then(value, params, context);
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/validators/common/dependsOn.ts
|
|
78
|
+
var dependsOnValidator = (value, params, context) => {
|
|
79
|
+
if (isEmpty(value)) return null;
|
|
80
|
+
const fieldName = params?.field;
|
|
81
|
+
const soft = params?.soft;
|
|
82
|
+
const message = params?.message;
|
|
83
|
+
if (!fieldName) return null;
|
|
84
|
+
const root = context.root;
|
|
85
|
+
const otherValue = root?.[fieldName];
|
|
86
|
+
if (isEmpty(otherValue)) {
|
|
87
|
+
return createError(
|
|
88
|
+
context,
|
|
89
|
+
"INVALID_DEPENDS_ON",
|
|
90
|
+
message || `This field requires ${fieldName} to be set`,
|
|
91
|
+
soft
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { dependsOnValidator, greaterThanValidator, lessThanValidator, notMatchesValidator, whenValidator };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isEmpty, isArray, createError } from './chunk-FKDWSZIV.mjs';
|
|
2
|
+
|
|
3
|
+
// src/validators/array/includes.ts
|
|
4
|
+
var includesValidator = (value, params, context) => {
|
|
5
|
+
if (isEmpty(value)) return null;
|
|
6
|
+
const item = params?.item;
|
|
7
|
+
const soft = params?.soft;
|
|
8
|
+
const message = params?.message;
|
|
9
|
+
if (!isArray(value)) return null;
|
|
10
|
+
if (!value.includes(item)) {
|
|
11
|
+
return createError(
|
|
12
|
+
context,
|
|
13
|
+
"INVALID_INCLUDES",
|
|
14
|
+
message || `Array must include ${JSON.stringify(item)}`,
|
|
15
|
+
soft
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/validators/array/excludes.ts
|
|
22
|
+
var excludesValidator = (value, params, context) => {
|
|
23
|
+
if (isEmpty(value)) return null;
|
|
24
|
+
const item = params?.item;
|
|
25
|
+
const soft = params?.soft;
|
|
26
|
+
const message = params?.message;
|
|
27
|
+
if (!isArray(value)) return null;
|
|
28
|
+
if (value.includes(item)) {
|
|
29
|
+
return createError(
|
|
30
|
+
context,
|
|
31
|
+
"INVALID_EXCLUDES",
|
|
32
|
+
message || `Array must not include ${JSON.stringify(item)}`,
|
|
33
|
+
soft
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/validators/array/empty.ts
|
|
40
|
+
var emptyValidator = (value, params, context) => {
|
|
41
|
+
if (isEmpty(value)) return null;
|
|
42
|
+
const soft = params?.soft;
|
|
43
|
+
const message = params?.message;
|
|
44
|
+
if (!isArray(value)) return null;
|
|
45
|
+
if (value.length > 0) {
|
|
46
|
+
return createError(
|
|
47
|
+
context,
|
|
48
|
+
"INVALID_EMPTY",
|
|
49
|
+
message || "Array must be empty",
|
|
50
|
+
soft
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/validators/array/notEmpty.ts
|
|
57
|
+
var notEmptyValidator = (value, params, context) => {
|
|
58
|
+
if (isEmpty(value)) return null;
|
|
59
|
+
const soft = params?.soft;
|
|
60
|
+
const message = params?.message;
|
|
61
|
+
if (!isArray(value)) return null;
|
|
62
|
+
if (value.length === 0) {
|
|
63
|
+
return createError(
|
|
64
|
+
context,
|
|
65
|
+
"INVALID_NOT_EMPTY",
|
|
66
|
+
message || "Array must not be empty",
|
|
67
|
+
soft
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/validators/array/sorted.ts
|
|
74
|
+
var sortedValidator = (value, params, context) => {
|
|
75
|
+
if (isEmpty(value)) return null;
|
|
76
|
+
const order = params?.order || "asc";
|
|
77
|
+
const soft = params?.soft;
|
|
78
|
+
const message = params?.message;
|
|
79
|
+
if (!isArray(value)) return null;
|
|
80
|
+
for (let i = 1; i < value.length; i++) {
|
|
81
|
+
const prev = value[i - 1];
|
|
82
|
+
const curr = value[i];
|
|
83
|
+
if (order === "asc") {
|
|
84
|
+
if (prev > curr) {
|
|
85
|
+
return createError(
|
|
86
|
+
context,
|
|
87
|
+
"INVALID_SORTED",
|
|
88
|
+
message || "Array must be sorted in ascending order",
|
|
89
|
+
soft
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (prev < curr) {
|
|
94
|
+
return createError(
|
|
95
|
+
context,
|
|
96
|
+
"INVALID_SORTED",
|
|
97
|
+
message || "Array must be sorted in descending order",
|
|
98
|
+
soft
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/validators/array/compact.ts
|
|
107
|
+
var compactValidator = (value, params, context) => {
|
|
108
|
+
if (isEmpty(value)) return null;
|
|
109
|
+
const soft = params?.soft;
|
|
110
|
+
const message = params?.message;
|
|
111
|
+
if (!isArray(value)) return null;
|
|
112
|
+
const hasFalsy = value.some((item) => !item);
|
|
113
|
+
if (hasFalsy) {
|
|
114
|
+
return createError(
|
|
115
|
+
context,
|
|
116
|
+
"INVALID_COMPACT",
|
|
117
|
+
message || "Array must not contain falsy values",
|
|
118
|
+
soft
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export { compactValidator, emptyValidator, excludesValidator, includesValidator, notEmptyValidator, sortedValidator };
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
/** Error code for programmatic handling */
|
|
9
|
+
code: string;
|
|
10
|
+
/** Human-readable error message */
|
|
11
|
+
message: string;
|
|
12
|
+
/** Severity level - hard errors block submission, soft are warnings */
|
|
13
|
+
severity: ValidationSeverity;
|
|
14
|
+
}
|
|
15
|
+
interface ValidationResult {
|
|
16
|
+
/** True if no hard errors exist */
|
|
17
|
+
valid: boolean;
|
|
18
|
+
/** Errors that block form submission */
|
|
19
|
+
hardErrors: ValidationError[];
|
|
20
|
+
/** Warnings that don't block submission */
|
|
21
|
+
softErrors: ValidationError[];
|
|
22
|
+
}
|
|
23
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
|
|
24
|
+
interface ValidationRule {
|
|
25
|
+
/** Rule type identifier */
|
|
26
|
+
type: string;
|
|
27
|
+
/** Rule parameters */
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
/** Custom error message */
|
|
30
|
+
message?: string;
|
|
31
|
+
/** Is this a soft validation (warning only)? */
|
|
32
|
+
soft?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface FieldDefinition<T = unknown> {
|
|
35
|
+
/** The base type of this field */
|
|
36
|
+
type: FieldType;
|
|
37
|
+
/** Validation rules to apply */
|
|
38
|
+
rules: ValidationRule[];
|
|
39
|
+
/** Is this field required? */
|
|
40
|
+
required: boolean;
|
|
41
|
+
/** Default value */
|
|
42
|
+
defaultValue?: T;
|
|
43
|
+
/** For nested schemas */
|
|
44
|
+
schema?: SchemaDefinition;
|
|
45
|
+
/** For array items */
|
|
46
|
+
items?: FieldDefinition;
|
|
47
|
+
/** Field metadata */
|
|
48
|
+
meta?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface SchemaDefinition {
|
|
51
|
+
/** Field definitions keyed by field name */
|
|
52
|
+
fields: Record<string, FieldDefinition>;
|
|
53
|
+
/** Schema metadata */
|
|
54
|
+
meta?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
interface ValidatorContext {
|
|
57
|
+
/** Current field path */
|
|
58
|
+
path: string;
|
|
59
|
+
/** Full data object being validated */
|
|
60
|
+
root: unknown;
|
|
61
|
+
/** Parent object containing this field */
|
|
62
|
+
parent?: unknown;
|
|
63
|
+
}
|
|
64
|
+
type ValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => ValidationError | null;
|
|
65
|
+
interface EnterpriseValidationResponse {
|
|
66
|
+
status: 'success' | 'validation_error';
|
|
67
|
+
data?: unknown;
|
|
68
|
+
errors: ValidationError[];
|
|
69
|
+
msg: string;
|
|
70
|
+
validation: {
|
|
71
|
+
hard_validations: ValidationError[];
|
|
72
|
+
soft_validations: ValidationError[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert ValidationResult to enterprise-compatible response format
|
|
77
|
+
*/
|
|
78
|
+
declare function toEnterpriseResponse(result: ValidationResult, data?: unknown): EnterpriseValidationResponse;
|
|
79
|
+
|
|
80
|
+
export { type EnterpriseValidationResponse as E, type FieldType as F, type SchemaDefinition as S, type ValidatorContext as V, type ValidationError as a, type ValidationResult as b, type ValidatorFn as c, type ValidationSeverity as d, type ValidationRule as e, type FieldDefinition as f, toEnterpriseResponse as t };
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
/** Error code for programmatic handling */
|
|
9
|
+
code: string;
|
|
10
|
+
/** Human-readable error message */
|
|
11
|
+
message: string;
|
|
12
|
+
/** Severity level - hard errors block submission, soft are warnings */
|
|
13
|
+
severity: ValidationSeverity;
|
|
14
|
+
}
|
|
15
|
+
interface ValidationResult {
|
|
16
|
+
/** True if no hard errors exist */
|
|
17
|
+
valid: boolean;
|
|
18
|
+
/** Errors that block form submission */
|
|
19
|
+
hardErrors: ValidationError[];
|
|
20
|
+
/** Warnings that don't block submission */
|
|
21
|
+
softErrors: ValidationError[];
|
|
22
|
+
}
|
|
23
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object';
|
|
24
|
+
interface ValidationRule {
|
|
25
|
+
/** Rule type identifier */
|
|
26
|
+
type: string;
|
|
27
|
+
/** Rule parameters */
|
|
28
|
+
params?: Record<string, unknown>;
|
|
29
|
+
/** Custom error message */
|
|
30
|
+
message?: string;
|
|
31
|
+
/** Is this a soft validation (warning only)? */
|
|
32
|
+
soft?: boolean;
|
|
33
|
+
}
|
|
34
|
+
interface FieldDefinition<T = unknown> {
|
|
35
|
+
/** The base type of this field */
|
|
36
|
+
type: FieldType;
|
|
37
|
+
/** Validation rules to apply */
|
|
38
|
+
rules: ValidationRule[];
|
|
39
|
+
/** Is this field required? */
|
|
40
|
+
required: boolean;
|
|
41
|
+
/** Default value */
|
|
42
|
+
defaultValue?: T;
|
|
43
|
+
/** For nested schemas */
|
|
44
|
+
schema?: SchemaDefinition;
|
|
45
|
+
/** For array items */
|
|
46
|
+
items?: FieldDefinition;
|
|
47
|
+
/** Field metadata */
|
|
48
|
+
meta?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
interface SchemaDefinition {
|
|
51
|
+
/** Field definitions keyed by field name */
|
|
52
|
+
fields: Record<string, FieldDefinition>;
|
|
53
|
+
/** Schema metadata */
|
|
54
|
+
meta?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
interface ValidatorContext {
|
|
57
|
+
/** Current field path */
|
|
58
|
+
path: string;
|
|
59
|
+
/** Full data object being validated */
|
|
60
|
+
root: unknown;
|
|
61
|
+
/** Parent object containing this field */
|
|
62
|
+
parent?: unknown;
|
|
63
|
+
}
|
|
64
|
+
type ValidatorFn = (value: unknown, params: Record<string, unknown> | undefined, context: ValidatorContext) => ValidationError | null;
|
|
65
|
+
interface EnterpriseValidationResponse {
|
|
66
|
+
status: 'success' | 'validation_error';
|
|
67
|
+
data?: unknown;
|
|
68
|
+
errors: ValidationError[];
|
|
69
|
+
msg: string;
|
|
70
|
+
validation: {
|
|
71
|
+
hard_validations: ValidationError[];
|
|
72
|
+
soft_validations: ValidationError[];
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert ValidationResult to enterprise-compatible response format
|
|
77
|
+
*/
|
|
78
|
+
declare function toEnterpriseResponse(result: ValidationResult, data?: unknown): EnterpriseValidationResponse;
|
|
79
|
+
|
|
80
|
+
export { type EnterpriseValidationResponse as E, type FieldType as F, type SchemaDefinition as S, type ValidatorContext as V, type ValidationError as a, type ValidationResult as b, type ValidatorFn as c, type ValidationSeverity as d, type ValidationRule as e, type FieldDefinition as f, toEnterpriseResponse as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition,
|
|
2
|
-
export {
|
|
1
|
+
import { S as SchemaDefinition, b as ValidationResult, c as ValidatorFn } from './index-BQR7OrY7.mjs';
|
|
2
|
+
export { E as EnterpriseValidationResponse, f as FieldDefinition, F as FieldType, a as ValidationError, e as ValidationRule, d as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-BQR7OrY7.mjs';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, d as BooleanFieldBuilder, D as DateFieldBuilder, E as EnumFieldBuilder, I as InferInput, b as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, c as StringFieldBuilder, e as extend, f as field, m as merge, o as omit, a as partial, p as pick, s as schema } from './schema-DYU1zGVm.mjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Core validation engine - runs unchanged in browser and Node.js
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { S as SchemaDefinition,
|
|
2
|
-
export {
|
|
1
|
+
import { S as SchemaDefinition, b as ValidationResult, c as ValidatorFn } from './index-BQR7OrY7.js';
|
|
2
|
+
export { E as EnterpriseValidationResponse, f as FieldDefinition, F as FieldType, a as ValidationError, e as ValidationRule, d as ValidationSeverity, V as ValidatorContext, t as toEnterpriseResponse } from './index-BQR7OrY7.js';
|
|
3
|
+
export { A as ArrayFieldBuilder, B as BaseFieldBuilder, d as BooleanFieldBuilder, D as DateFieldBuilder, E as EnumFieldBuilder, I as InferInput, b as InferOutput, N as NumberFieldBuilder, O as ObjectFieldBuilder, S as SchemaBuilder, c as StringFieldBuilder, e as extend, f as field, m as merge, o as omit, a as partial, p as pick, s as schema } from './schema-CpAjXgEF.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Core validation engine - runs unchanged in browser and Node.js
|