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.
- package/README.md +780 -228
- 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 -441
- package/dist/adapters/backend/index.mjs +9 -433
- 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 -421
- package/dist/adapters/frontend/index.mjs +8 -419
- package/dist/chunk-5A4ITJVD.mjs +124 -0
- package/dist/chunk-66RFUBVU.js +131 -0
- package/dist/chunk-75YSYC4K.mjs +85 -0
- package/dist/chunk-76BBWQDH.js +90 -0
- package/dist/chunk-7XES4A3M.mjs +237 -0
- package/dist/chunk-BVRXGZLS.js +17 -0
- package/dist/chunk-COMVAVFU.mjs +335 -0
- package/dist/chunk-DT2TQZU7.js +796 -0
- package/dist/chunk-FPCCH55A.js +103 -0
- package/dist/chunk-IUXRLMET.js +206 -0
- package/dist/chunk-JEW6U6CB.js +353 -0
- package/dist/chunk-KZCV5IW4.mjs +97 -0
- package/dist/chunk-KZZ7NVU3.mjs +41 -0
- package/dist/chunk-MFEBMQAU.mjs +779 -0
- package/dist/chunk-OIYG5D2I.js +50 -0
- package/dist/chunk-RW6HDA5H.mjs +194 -0
- package/dist/chunk-TTK77YBI.mjs +15 -0
- package/dist/chunk-TXT36BCE.js +248 -0
- package/dist/index-C17xs-fU.d.mts +140 -0
- package/dist/index-C17xs-fU.d.ts +140 -0
- package/dist/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +769 -499
- package/dist/index.mjs +695 -487
- package/dist/{schema-D9DGC9E_.d.ts → schema-DYE8Wz8X.d.mts} +264 -79
- package/dist/{schema-D9DGC9E_.d.mts → schema-Dtp-joeT.d.ts} +264 -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 +82 -5
- 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,85 @@
|
|
|
1
|
+
import { isEmpty, isObject, createError } from './chunk-KZZ7NVU3.mjs';
|
|
2
|
+
|
|
3
|
+
// src/validators/object/keys.ts
|
|
4
|
+
var keysValidator = (value, params, context) => {
|
|
5
|
+
if (isEmpty(value)) return null;
|
|
6
|
+
const pattern = params?.pattern;
|
|
7
|
+
const soft = params?.soft;
|
|
8
|
+
const message = params?.message;
|
|
9
|
+
if (!isObject(value)) return null;
|
|
10
|
+
if (pattern) {
|
|
11
|
+
const keys = Object.keys(value);
|
|
12
|
+
const invalidKeys = keys.filter((key) => !pattern.test(key));
|
|
13
|
+
if (invalidKeys.length > 0) {
|
|
14
|
+
return createError(
|
|
15
|
+
context,
|
|
16
|
+
"INVALID_KEYS",
|
|
17
|
+
message || `Invalid keys: ${invalidKeys.join(", ")}`,
|
|
18
|
+
soft
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/validators/object/pick.ts
|
|
26
|
+
var pickValidator = (value, params, context) => {
|
|
27
|
+
if (isEmpty(value)) return null;
|
|
28
|
+
const allowedKeys = params?.keys;
|
|
29
|
+
const soft = params?.soft;
|
|
30
|
+
const message = params?.message;
|
|
31
|
+
if (!isObject(value) || !allowedKeys) return null;
|
|
32
|
+
const keys = Object.keys(value);
|
|
33
|
+
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
34
|
+
if (extraKeys.length > 0) {
|
|
35
|
+
return createError(
|
|
36
|
+
context,
|
|
37
|
+
"INVALID_PICK",
|
|
38
|
+
message || `Unexpected keys: ${extraKeys.join(", ")}`,
|
|
39
|
+
soft
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/validators/object/omit.ts
|
|
46
|
+
var omitValidator = (value, params, context) => {
|
|
47
|
+
if (isEmpty(value)) return null;
|
|
48
|
+
const forbiddenKeys = params?.keys;
|
|
49
|
+
const soft = params?.soft;
|
|
50
|
+
const message = params?.message;
|
|
51
|
+
if (!isObject(value) || !forbiddenKeys) return null;
|
|
52
|
+
const keys = Object.keys(value);
|
|
53
|
+
const foundForbidden = keys.filter((key) => forbiddenKeys.includes(key));
|
|
54
|
+
if (foundForbidden.length > 0) {
|
|
55
|
+
return createError(
|
|
56
|
+
context,
|
|
57
|
+
"INVALID_OMIT",
|
|
58
|
+
message || `Forbidden keys found: ${foundForbidden.join(", ")}`,
|
|
59
|
+
soft
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/validators/object/strict.ts
|
|
66
|
+
var strictValidator = (value, params, context) => {
|
|
67
|
+
if (isEmpty(value)) return null;
|
|
68
|
+
const allowedKeys = params?.allowedKeys;
|
|
69
|
+
const soft = params?.soft;
|
|
70
|
+
const message = params?.message;
|
|
71
|
+
if (!isObject(value) || !allowedKeys) return null;
|
|
72
|
+
const keys = Object.keys(value);
|
|
73
|
+
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
74
|
+
if (extraKeys.length > 0) {
|
|
75
|
+
return createError(
|
|
76
|
+
context,
|
|
77
|
+
"INVALID_STRICT",
|
|
78
|
+
message || `Unknown keys not allowed: ${extraKeys.join(", ")}`,
|
|
79
|
+
soft
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { keysValidator, omitValidator, pickValidator, strictValidator };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkOIYG5D2I_js = require('./chunk-OIYG5D2I.js');
|
|
4
|
+
|
|
5
|
+
// src/validators/object/keys.ts
|
|
6
|
+
var keysValidator = (value, params, context) => {
|
|
7
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
8
|
+
const pattern = params?.pattern;
|
|
9
|
+
const soft = params?.soft;
|
|
10
|
+
const message = params?.message;
|
|
11
|
+
if (!chunkOIYG5D2I_js.isObject(value)) return null;
|
|
12
|
+
if (pattern) {
|
|
13
|
+
const keys = Object.keys(value);
|
|
14
|
+
const invalidKeys = keys.filter((key) => !pattern.test(key));
|
|
15
|
+
if (invalidKeys.length > 0) {
|
|
16
|
+
return chunkOIYG5D2I_js.createError(
|
|
17
|
+
context,
|
|
18
|
+
"INVALID_KEYS",
|
|
19
|
+
message || `Invalid keys: ${invalidKeys.join(", ")}`,
|
|
20
|
+
soft
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/validators/object/pick.ts
|
|
28
|
+
var pickValidator = (value, params, context) => {
|
|
29
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
30
|
+
const allowedKeys = params?.keys;
|
|
31
|
+
const soft = params?.soft;
|
|
32
|
+
const message = params?.message;
|
|
33
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !allowedKeys) return null;
|
|
34
|
+
const keys = Object.keys(value);
|
|
35
|
+
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
36
|
+
if (extraKeys.length > 0) {
|
|
37
|
+
return chunkOIYG5D2I_js.createError(
|
|
38
|
+
context,
|
|
39
|
+
"INVALID_PICK",
|
|
40
|
+
message || `Unexpected keys: ${extraKeys.join(", ")}`,
|
|
41
|
+
soft
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/validators/object/omit.ts
|
|
48
|
+
var omitValidator = (value, params, context) => {
|
|
49
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
50
|
+
const forbiddenKeys = params?.keys;
|
|
51
|
+
const soft = params?.soft;
|
|
52
|
+
const message = params?.message;
|
|
53
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !forbiddenKeys) return null;
|
|
54
|
+
const keys = Object.keys(value);
|
|
55
|
+
const foundForbidden = keys.filter((key) => forbiddenKeys.includes(key));
|
|
56
|
+
if (foundForbidden.length > 0) {
|
|
57
|
+
return chunkOIYG5D2I_js.createError(
|
|
58
|
+
context,
|
|
59
|
+
"INVALID_OMIT",
|
|
60
|
+
message || `Forbidden keys found: ${foundForbidden.join(", ")}`,
|
|
61
|
+
soft
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/validators/object/strict.ts
|
|
68
|
+
var strictValidator = (value, params, context) => {
|
|
69
|
+
if (chunkOIYG5D2I_js.isEmpty(value)) return null;
|
|
70
|
+
const allowedKeys = params?.allowedKeys;
|
|
71
|
+
const soft = params?.soft;
|
|
72
|
+
const message = params?.message;
|
|
73
|
+
if (!chunkOIYG5D2I_js.isObject(value) || !allowedKeys) return null;
|
|
74
|
+
const keys = Object.keys(value);
|
|
75
|
+
const extraKeys = keys.filter((key) => !allowedKeys.includes(key));
|
|
76
|
+
if (extraKeys.length > 0) {
|
|
77
|
+
return chunkOIYG5D2I_js.createError(
|
|
78
|
+
context,
|
|
79
|
+
"INVALID_STRICT",
|
|
80
|
+
message || `Unknown keys not allowed: ${extraKeys.join(", ")}`,
|
|
81
|
+
soft
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
exports.keysValidator = keysValidator;
|
|
88
|
+
exports.omitValidator = omitValidator;
|
|
89
|
+
exports.pickValidator = pickValidator;
|
|
90
|
+
exports.strictValidator = strictValidator;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { isEmpty, parseDate, createError } from './chunk-KZZ7NVU3.mjs';
|
|
2
|
+
|
|
3
|
+
// src/validators/date/today.ts
|
|
4
|
+
var todayValidator = (value, params, context) => {
|
|
5
|
+
if (isEmpty(value)) return null;
|
|
6
|
+
const soft = params?.soft;
|
|
7
|
+
const message = params?.message;
|
|
8
|
+
const date = parseDate(value);
|
|
9
|
+
if (!date) return null;
|
|
10
|
+
const today = /* @__PURE__ */ new Date();
|
|
11
|
+
today.setHours(0, 0, 0, 0);
|
|
12
|
+
date.setHours(0, 0, 0, 0);
|
|
13
|
+
if (date.getTime() !== today.getTime()) {
|
|
14
|
+
return createError(
|
|
15
|
+
context,
|
|
16
|
+
"INVALID_TODAY",
|
|
17
|
+
message || "Date must be today",
|
|
18
|
+
soft
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/validators/date/yesterday.ts
|
|
25
|
+
var yesterdayValidator = (value, params, context) => {
|
|
26
|
+
if (isEmpty(value)) return null;
|
|
27
|
+
const soft = params?.soft;
|
|
28
|
+
const message = params?.message;
|
|
29
|
+
const date = parseDate(value);
|
|
30
|
+
if (!date) return null;
|
|
31
|
+
const yesterday = /* @__PURE__ */ new Date();
|
|
32
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
33
|
+
yesterday.setHours(0, 0, 0, 0);
|
|
34
|
+
date.setHours(0, 0, 0, 0);
|
|
35
|
+
if (date.getTime() !== yesterday.getTime()) {
|
|
36
|
+
return createError(
|
|
37
|
+
context,
|
|
38
|
+
"INVALID_YESTERDAY",
|
|
39
|
+
message || "Date must be yesterday",
|
|
40
|
+
soft
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/validators/date/tomorrow.ts
|
|
47
|
+
var tomorrowValidator = (value, params, context) => {
|
|
48
|
+
if (isEmpty(value)) return null;
|
|
49
|
+
const soft = params?.soft;
|
|
50
|
+
const message = params?.message;
|
|
51
|
+
const date = parseDate(value);
|
|
52
|
+
if (!date) return null;
|
|
53
|
+
const tomorrow = /* @__PURE__ */ new Date();
|
|
54
|
+
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
55
|
+
tomorrow.setHours(0, 0, 0, 0);
|
|
56
|
+
date.setHours(0, 0, 0, 0);
|
|
57
|
+
if (date.getTime() !== tomorrow.getTime()) {
|
|
58
|
+
return createError(
|
|
59
|
+
context,
|
|
60
|
+
"INVALID_TOMORROW",
|
|
61
|
+
message || "Date must be tomorrow",
|
|
62
|
+
soft
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/validators/date/thisWeek.ts
|
|
69
|
+
var thisWeekValidator = (value, params, context) => {
|
|
70
|
+
if (isEmpty(value)) return null;
|
|
71
|
+
const soft = params?.soft;
|
|
72
|
+
const message = params?.message;
|
|
73
|
+
const date = parseDate(value);
|
|
74
|
+
if (!date) return null;
|
|
75
|
+
const now = /* @__PURE__ */ new Date();
|
|
76
|
+
const startOfWeek = new Date(now);
|
|
77
|
+
startOfWeek.setDate(now.getDate() - now.getDay());
|
|
78
|
+
startOfWeek.setHours(0, 0, 0, 0);
|
|
79
|
+
const endOfWeek = new Date(startOfWeek);
|
|
80
|
+
endOfWeek.setDate(startOfWeek.getDate() + 6);
|
|
81
|
+
endOfWeek.setHours(23, 59, 59, 999);
|
|
82
|
+
if (date < startOfWeek || date > endOfWeek) {
|
|
83
|
+
return createError(
|
|
84
|
+
context,
|
|
85
|
+
"INVALID_THIS_WEEK",
|
|
86
|
+
message || "Date must be within this week",
|
|
87
|
+
soft
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/validators/date/thisMonth.ts
|
|
94
|
+
var thisMonthValidator = (value, params, context) => {
|
|
95
|
+
if (isEmpty(value)) return null;
|
|
96
|
+
const soft = params?.soft;
|
|
97
|
+
const message = params?.message;
|
|
98
|
+
const date = parseDate(value);
|
|
99
|
+
if (!date) return null;
|
|
100
|
+
const now = /* @__PURE__ */ new Date();
|
|
101
|
+
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
102
|
+
const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
103
|
+
if (date < startOfMonth || date > endOfMonth) {
|
|
104
|
+
return createError(
|
|
105
|
+
context,
|
|
106
|
+
"INVALID_THIS_MONTH",
|
|
107
|
+
message || "Date must be within this month",
|
|
108
|
+
soft
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/validators/date/thisYear.ts
|
|
115
|
+
var thisYearValidator = (value, params, context) => {
|
|
116
|
+
if (isEmpty(value)) return null;
|
|
117
|
+
const soft = params?.soft;
|
|
118
|
+
const message = params?.message;
|
|
119
|
+
const date = parseDate(value);
|
|
120
|
+
if (!date) return null;
|
|
121
|
+
const now = /* @__PURE__ */ new Date();
|
|
122
|
+
const startOfYear = new Date(now.getFullYear(), 0, 1);
|
|
123
|
+
const endOfYear = new Date(now.getFullYear(), 11, 31, 23, 59, 59, 999);
|
|
124
|
+
if (date < startOfYear || date > endOfYear) {
|
|
125
|
+
return createError(
|
|
126
|
+
context,
|
|
127
|
+
"INVALID_THIS_YEAR",
|
|
128
|
+
message || "Date must be within this year",
|
|
129
|
+
soft
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/validators/date/weekday.ts
|
|
136
|
+
var weekdayValidator = (value, params, context) => {
|
|
137
|
+
if (isEmpty(value)) return null;
|
|
138
|
+
const soft = params?.soft;
|
|
139
|
+
const message = params?.message;
|
|
140
|
+
const date = parseDate(value);
|
|
141
|
+
if (!date) return null;
|
|
142
|
+
const day = date.getDay();
|
|
143
|
+
if (day === 0 || day === 6) {
|
|
144
|
+
return createError(
|
|
145
|
+
context,
|
|
146
|
+
"INVALID_WEEKDAY",
|
|
147
|
+
message || "Date must be a weekday",
|
|
148
|
+
soft
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/validators/date/weekend.ts
|
|
155
|
+
var weekendValidator = (value, params, context) => {
|
|
156
|
+
if (isEmpty(value)) return null;
|
|
157
|
+
const soft = params?.soft;
|
|
158
|
+
const message = params?.message;
|
|
159
|
+
const date = parseDate(value);
|
|
160
|
+
if (!date) return null;
|
|
161
|
+
const day = date.getDay();
|
|
162
|
+
if (day !== 0 && day !== 6) {
|
|
163
|
+
return createError(
|
|
164
|
+
context,
|
|
165
|
+
"INVALID_WEEKEND",
|
|
166
|
+
message || "Date must be a weekend",
|
|
167
|
+
soft
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/validators/date/age.ts
|
|
174
|
+
var ageValidator = (value, params, context) => {
|
|
175
|
+
if (isEmpty(value)) return null;
|
|
176
|
+
const min = params?.min;
|
|
177
|
+
const max = params?.max;
|
|
178
|
+
const soft = params?.soft;
|
|
179
|
+
const message = params?.message;
|
|
180
|
+
const birthDate = parseDate(value);
|
|
181
|
+
if (!birthDate) return null;
|
|
182
|
+
const today = /* @__PURE__ */ new Date();
|
|
183
|
+
let age = today.getFullYear() - birthDate.getFullYear();
|
|
184
|
+
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
185
|
+
if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
|
|
186
|
+
age--;
|
|
187
|
+
}
|
|
188
|
+
if (min !== void 0 && age < min) {
|
|
189
|
+
return createError(
|
|
190
|
+
context,
|
|
191
|
+
"INVALID_AGE_MIN",
|
|
192
|
+
message || `Age must be at least ${min}`,
|
|
193
|
+
soft
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (max !== void 0 && age > max) {
|
|
197
|
+
return createError(
|
|
198
|
+
context,
|
|
199
|
+
"INVALID_AGE_MAX",
|
|
200
|
+
message || `Age must be at most ${max}`,
|
|
201
|
+
soft
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/validators/date/between.ts
|
|
208
|
+
var betweenValidator = (value, params, context) => {
|
|
209
|
+
if (isEmpty(value)) return null;
|
|
210
|
+
const start = params?.start;
|
|
211
|
+
const end = params?.end;
|
|
212
|
+
const soft = params?.soft;
|
|
213
|
+
const message = params?.message;
|
|
214
|
+
const date = parseDate(value);
|
|
215
|
+
if (!date) return null;
|
|
216
|
+
const startDate = parseDate(start);
|
|
217
|
+
const endDate = parseDate(end);
|
|
218
|
+
if (startDate && date < startDate) {
|
|
219
|
+
return createError(
|
|
220
|
+
context,
|
|
221
|
+
"INVALID_DATE_BEFORE",
|
|
222
|
+
message || `Date must be after ${startDate.toLocaleDateString()}`,
|
|
223
|
+
soft
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (endDate && date > endDate) {
|
|
227
|
+
return createError(
|
|
228
|
+
context,
|
|
229
|
+
"INVALID_DATE_AFTER",
|
|
230
|
+
message || `Date must be before ${endDate.toLocaleDateString()}`,
|
|
231
|
+
soft
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export { ageValidator, betweenValidator, thisMonthValidator, thisWeekValidator, thisYearValidator, todayValidator, tomorrowValidator, weekdayValidator, weekendValidator, yesterdayValidator };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/index.ts
|
|
4
|
+
function toEnterpriseResponse(result, data) {
|
|
5
|
+
return {
|
|
6
|
+
status: result.valid ? "success" : "validation_error",
|
|
7
|
+
data: result.valid ? data : void 0,
|
|
8
|
+
errors: [...result.hardErrors, ...result.softErrors],
|
|
9
|
+
msg: result.valid ? "Validation successful" : "Validation failed",
|
|
10
|
+
validation: {
|
|
11
|
+
hard_validations: result.hardErrors,
|
|
12
|
+
soft_validations: result.softErrors
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.toEnterpriseResponse = toEnterpriseResponse;
|