@ram_28/kf-ai-sdk 1.0.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/LICENSE +21 -0
- package/README.md +840 -0
- package/dist/api/client.d.ts +78 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/datetime.d.ts +21 -0
- package/dist/api/datetime.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/metadata.d.ts +75 -0
- package/dist/api/metadata.d.ts.map +1 -0
- package/dist/components/hooks/index.d.ts +8 -0
- package/dist/components/hooks/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/index.d.ts +5 -0
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +33 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/types.d.ts +137 -0
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts +3 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts +38 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/apiClient.d.ts +71 -0
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/index.d.ts +6 -0
- package/dist/components/hooks/useForm/index.d.ts.map +1 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +88 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts +29 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/types.d.ts +412 -0
- package/dist/components/hooks/useForm/types.d.ts.map +1 -0
- package/dist/components/hooks/useForm/useForm.d.ts +3 -0
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts +99 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/context.d.ts +4 -0
- package/dist/components/hooks/useKanban/context.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts +27 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/index.d.ts +6 -0
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/types.d.ts +438 -0
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts +3 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts +62 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts.map +1 -0
- package/dist/components/hooks/useTable/index.d.ts +3 -0
- package/dist/components/hooks/useTable/index.d.ts.map +1 -0
- package/dist/components/hooks/useTable/types.d.ts +107 -0
- package/dist/components/hooks/useTable/types.d.ts.map +1 -0
- package/dist/components/hooks/useTable/useTable.d.ts +8 -0
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/kanban/Kanban.d.ts +12 -0
- package/dist/components/ui/kanban/Kanban.d.ts.map +1 -0
- package/dist/components/ui/kanban/index.d.ts +2 -0
- package/dist/components/ui/kanban/index.d.ts.map +1 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +6522 -0
- package/dist/types/base-fields.d.ts +182 -0
- package/dist/types/base-fields.d.ts.map +1 -0
- package/dist/types/common.d.ts +238 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/cn.d.ts +7 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +52 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +98 -0
- package/sdk/api/client.ts +447 -0
- package/sdk/api/datetime.ts +33 -0
- package/sdk/api/index.ts +61 -0
- package/sdk/api/metadata.ts +148 -0
- package/sdk/components/hooks/index.ts +34 -0
- package/sdk/components/hooks/useFilter/index.ts +37 -0
- package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +298 -0
- package/sdk/components/hooks/useFilter/types.ts +158 -0
- package/sdk/components/hooks/useFilter/useFilter.llm.txt +497 -0
- package/sdk/components/hooks/useFilter/useFilter.ts +494 -0
- package/sdk/components/hooks/useFilter/validation.utils.ts +401 -0
- package/sdk/components/hooks/useForm/apiClient.ts +441 -0
- package/sdk/components/hooks/useForm/expressionValidator.utils.ts +444 -0
- package/sdk/components/hooks/useForm/index.ts +64 -0
- package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +482 -0
- package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +424 -0
- package/sdk/components/hooks/useForm/schemaParser.utils.ts +519 -0
- package/sdk/components/hooks/useForm/types.ts +630 -0
- package/sdk/components/hooks/useForm/useForm.llm.txt +340 -0
- package/sdk/components/hooks/useForm/useForm.ts +821 -0
- package/sdk/components/hooks/useKanban/apiClient.ts +494 -0
- package/sdk/components/hooks/useKanban/context.ts +14 -0
- package/sdk/components/hooks/useKanban/dragDropManager.ts +529 -0
- package/sdk/components/hooks/useKanban/index.ts +63 -0
- package/sdk/components/hooks/useKanban/types.ts +606 -0
- package/sdk/components/hooks/useKanban/useKanban.llm.txt +482 -0
- package/sdk/components/hooks/useKanban/useKanban.ts +725 -0
- package/sdk/components/hooks/useKanban/useKanbanSimple.ts +389 -0
- package/sdk/components/hooks/useTable/index.ts +5 -0
- package/sdk/components/hooks/useTable/types.ts +154 -0
- package/sdk/components/hooks/useTable/useTable.llm.txt +344 -0
- package/sdk/components/hooks/useTable/useTable.ts +413 -0
- package/sdk/components/index.ts +15 -0
- package/sdk/components/ui/index.ts +2 -0
- package/sdk/components/ui/kanban/Kanban.tsx +134 -0
- package/sdk/components/ui/kanban/index.ts +11 -0
- package/sdk/index.ts +13 -0
- package/sdk/types/base-fields.ts +221 -0
- package/sdk/types/common.ts +306 -0
- package/sdk/types/index.ts +5 -0
- package/sdk/utils/cn.ts +10 -0
- package/sdk/utils/formatting.ts +212 -0
- package/sdk/utils/index.ts +5 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import type { FilterOperator } from "../../../types/common";
|
|
2
|
+
import type { FieldDefinition, ValidationResult } from "../useFilter";
|
|
3
|
+
|
|
4
|
+
// ============================================================
|
|
5
|
+
// FIELD TYPE VALIDATION HELPERS
|
|
6
|
+
// ============================================================
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validate number values based on operator
|
|
10
|
+
*/
|
|
11
|
+
export const validateNumberValue = (value: any, operator: FilterOperator): ValidationResult => {
|
|
12
|
+
const errors: string[] = [];
|
|
13
|
+
|
|
14
|
+
switch (operator) {
|
|
15
|
+
case 'Between':
|
|
16
|
+
case 'NotBetween':
|
|
17
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
18
|
+
errors.push('Between operators require exactly two numeric values');
|
|
19
|
+
} else {
|
|
20
|
+
const [min, max] = value;
|
|
21
|
+
if (typeof min !== 'number' || typeof max !== 'number') {
|
|
22
|
+
errors.push('Between values must be numbers');
|
|
23
|
+
} else if (min >= max) {
|
|
24
|
+
errors.push('First value must be less than second value');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
case 'IN':
|
|
29
|
+
case 'NIN':
|
|
30
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
31
|
+
errors.push('IN/NIN operators require a non-empty array of numbers');
|
|
32
|
+
} else if (!value.every((v: any) => typeof v === 'number')) {
|
|
33
|
+
errors.push('All values in array must be numbers');
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case 'Empty':
|
|
37
|
+
case 'NotEmpty':
|
|
38
|
+
// No validation needed for these operators
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
|
42
|
+
errors.push('Value must be a valid number');
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
isValid: errors.length === 0,
|
|
49
|
+
errors
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Validate date values based on operator
|
|
55
|
+
*/
|
|
56
|
+
export const validateDateValue = (value: any, operator: FilterOperator): ValidationResult => {
|
|
57
|
+
const errors: string[] = [];
|
|
58
|
+
|
|
59
|
+
const isValidDate = (date: any): boolean => {
|
|
60
|
+
return date instanceof Date && !isNaN(date.getTime());
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const parseDate = (val: any): Date | null => {
|
|
64
|
+
if (val instanceof Date) return val;
|
|
65
|
+
if (typeof val === 'string' || typeof val === 'number') {
|
|
66
|
+
const parsed = new Date(val);
|
|
67
|
+
return isValidDate(parsed) ? parsed : null;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
switch (operator) {
|
|
73
|
+
case 'Between':
|
|
74
|
+
case 'NotBetween':
|
|
75
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
76
|
+
errors.push('Between operators require exactly two date values');
|
|
77
|
+
} else {
|
|
78
|
+
const [start, end] = value.map(parseDate);
|
|
79
|
+
if (!start || !end) {
|
|
80
|
+
errors.push('Between values must be valid dates');
|
|
81
|
+
} else if (start >= end) {
|
|
82
|
+
errors.push('Start date must be before end date');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'IN':
|
|
87
|
+
case 'NIN':
|
|
88
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
89
|
+
errors.push('IN/NIN operators require a non-empty array of dates');
|
|
90
|
+
} else if (!value.every((v: any) => parseDate(v))) {
|
|
91
|
+
errors.push('All values in array must be valid dates');
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case 'Empty':
|
|
95
|
+
case 'NotEmpty':
|
|
96
|
+
// No validation needed for these operators
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
if (!parseDate(value)) {
|
|
100
|
+
errors.push('Value must be a valid date');
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
isValid: errors.length === 0,
|
|
107
|
+
errors
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Validate currency values based on operator
|
|
113
|
+
*/
|
|
114
|
+
export const validateCurrencyValue = (value: any, operator: FilterOperator): ValidationResult => {
|
|
115
|
+
const errors: string[] = [];
|
|
116
|
+
|
|
117
|
+
const isValidCurrencyObject = (val: any): boolean => {
|
|
118
|
+
return val &&
|
|
119
|
+
typeof val === 'object' &&
|
|
120
|
+
typeof val.value === 'number' &&
|
|
121
|
+
typeof val.currency === 'string' &&
|
|
122
|
+
val.currency.length === 3; // Standard currency codes are 3 letters
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const isValidCurrencyString = (val: any): boolean => {
|
|
126
|
+
return typeof val === 'string' && /^\d+(\.\d{2})?\s[A-Z]{3}$/.test(val);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const isValidCurrency = (val: any): boolean => {
|
|
130
|
+
return isValidCurrencyObject(val) || isValidCurrencyString(val) || typeof val === 'number';
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
switch (operator) {
|
|
134
|
+
case 'Between':
|
|
135
|
+
case 'NotBetween':
|
|
136
|
+
if (!Array.isArray(value) || value.length !== 2) {
|
|
137
|
+
errors.push('Between operators require exactly two currency values');
|
|
138
|
+
} else if (!value.every(isValidCurrency)) {
|
|
139
|
+
errors.push('Between values must be valid currency amounts');
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case 'IN':
|
|
143
|
+
case 'NIN':
|
|
144
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
145
|
+
errors.push('IN/NIN operators require a non-empty array of currency values');
|
|
146
|
+
} else if (!value.every(isValidCurrency)) {
|
|
147
|
+
errors.push('All values in array must be valid currency amounts');
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case 'Empty':
|
|
151
|
+
case 'NotEmpty':
|
|
152
|
+
// No validation needed for these operators
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
if (!isValidCurrency(value)) {
|
|
156
|
+
errors.push('Value must be a valid currency amount');
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
isValid: errors.length === 0,
|
|
163
|
+
errors
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Validate string values based on operator
|
|
169
|
+
*/
|
|
170
|
+
export const validateStringValue = (value: any, operator: FilterOperator): ValidationResult => {
|
|
171
|
+
const errors: string[] = [];
|
|
172
|
+
|
|
173
|
+
switch (operator) {
|
|
174
|
+
case 'Between':
|
|
175
|
+
case 'NotBetween':
|
|
176
|
+
errors.push('Between operators are not supported for string fields');
|
|
177
|
+
break;
|
|
178
|
+
case 'GT':
|
|
179
|
+
case 'GTE':
|
|
180
|
+
case 'LT':
|
|
181
|
+
case 'LTE':
|
|
182
|
+
errors.push('Comparison operators are not supported for string fields');
|
|
183
|
+
break;
|
|
184
|
+
case 'IN':
|
|
185
|
+
case 'NIN':
|
|
186
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
187
|
+
errors.push('IN/NIN operators require a non-empty array of strings');
|
|
188
|
+
} else if (!value.every((v: any) => typeof v === 'string')) {
|
|
189
|
+
errors.push('All values in array must be strings');
|
|
190
|
+
}
|
|
191
|
+
break;
|
|
192
|
+
case 'MinLength':
|
|
193
|
+
if (typeof value !== 'number' || value < 0) {
|
|
194
|
+
errors.push('MinLength value must be a non-negative number');
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case 'MaxLength':
|
|
198
|
+
if (typeof value !== 'number' || value < 0) {
|
|
199
|
+
errors.push('MaxLength value must be a non-negative number');
|
|
200
|
+
}
|
|
201
|
+
break;
|
|
202
|
+
case 'Empty':
|
|
203
|
+
case 'NotEmpty':
|
|
204
|
+
// No validation needed for these operators
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
if (typeof value !== 'string') {
|
|
208
|
+
errors.push('Value must be a string');
|
|
209
|
+
}
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
isValid: errors.length === 0,
|
|
215
|
+
errors
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Validate boolean values based on operator
|
|
221
|
+
*/
|
|
222
|
+
export const validateBooleanValue = (value: any, operator: FilterOperator): ValidationResult => {
|
|
223
|
+
const errors: string[] = [];
|
|
224
|
+
|
|
225
|
+
const supportedOperators: FilterOperator[] = ['EQ', 'NE', 'IN', 'NIN', 'Empty', 'NotEmpty'];
|
|
226
|
+
|
|
227
|
+
if (!supportedOperators.includes(operator)) {
|
|
228
|
+
errors.push(`Operator ${operator} is not supported for boolean fields`);
|
|
229
|
+
return { isValid: false, errors };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
switch (operator) {
|
|
233
|
+
case 'IN':
|
|
234
|
+
case 'NIN':
|
|
235
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
236
|
+
errors.push('IN/NIN operators require a non-empty array of boolean values');
|
|
237
|
+
} else if (!value.every((v: any) => typeof v === 'boolean')) {
|
|
238
|
+
errors.push('All values in array must be boolean');
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case 'Empty':
|
|
242
|
+
case 'NotEmpty':
|
|
243
|
+
// No validation needed for these operators
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
if (typeof value !== 'boolean') {
|
|
247
|
+
errors.push('Value must be a boolean (true or false)');
|
|
248
|
+
}
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
isValid: errors.length === 0,
|
|
254
|
+
errors
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Validate select field values based on operator and available options
|
|
260
|
+
*/
|
|
261
|
+
export const validateSelectValue = (
|
|
262
|
+
value: any,
|
|
263
|
+
operator: FilterOperator,
|
|
264
|
+
selectOptions?: Array<{ label: string; value: any }>
|
|
265
|
+
): ValidationResult => {
|
|
266
|
+
const errors: string[] = [];
|
|
267
|
+
|
|
268
|
+
if (!selectOptions || selectOptions.length === 0) {
|
|
269
|
+
errors.push('No select options defined for this field');
|
|
270
|
+
return { isValid: false, errors };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const validValues = selectOptions.map(option => option.value);
|
|
274
|
+
const isValidOption = (val: any) => validValues.includes(val);
|
|
275
|
+
|
|
276
|
+
switch (operator) {
|
|
277
|
+
case 'Between':
|
|
278
|
+
case 'NotBetween':
|
|
279
|
+
case 'GT':
|
|
280
|
+
case 'GTE':
|
|
281
|
+
case 'LT':
|
|
282
|
+
case 'LTE':
|
|
283
|
+
errors.push(`Operator ${operator} is not supported for select fields`);
|
|
284
|
+
break;
|
|
285
|
+
case 'IN':
|
|
286
|
+
case 'NIN':
|
|
287
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
288
|
+
errors.push('IN/NIN operators require a non-empty array of values');
|
|
289
|
+
} else if (!value.every(isValidOption)) {
|
|
290
|
+
errors.push('All values must be from the available options');
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
case 'Empty':
|
|
294
|
+
case 'NotEmpty':
|
|
295
|
+
// No validation needed for these operators
|
|
296
|
+
break;
|
|
297
|
+
default:
|
|
298
|
+
if (!isValidOption(value)) {
|
|
299
|
+
errors.push('Value must be one of the available options');
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
isValid: errors.length === 0,
|
|
306
|
+
errors
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// ============================================================
|
|
311
|
+
// FIELD DEFINITION HELPERS
|
|
312
|
+
// ============================================================
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Get default field definition based on field type
|
|
316
|
+
*/
|
|
317
|
+
export const getDefaultFieldDefinition = (fieldType: FieldDefinition['type']): FieldDefinition => {
|
|
318
|
+
switch (fieldType) {
|
|
319
|
+
case 'string':
|
|
320
|
+
return {
|
|
321
|
+
type: 'string',
|
|
322
|
+
allowedOperators: ['EQ', 'NE', 'Contains', 'NotContains', 'IN', 'NIN', 'Empty', 'NotEmpty', 'MinLength', 'MaxLength'],
|
|
323
|
+
validateValue: validateStringValue
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
case 'number':
|
|
327
|
+
return {
|
|
328
|
+
type: 'number',
|
|
329
|
+
allowedOperators: ['EQ', 'NE', 'GT', 'GTE', 'LT', 'LTE', 'Between', 'NotBetween', 'IN', 'NIN', 'Empty', 'NotEmpty'],
|
|
330
|
+
validateValue: validateNumberValue
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
case 'date':
|
|
334
|
+
return {
|
|
335
|
+
type: 'date',
|
|
336
|
+
allowedOperators: ['EQ', 'NE', 'GT', 'GTE', 'LT', 'LTE', 'Between', 'NotBetween', 'IN', 'NIN', 'Empty', 'NotEmpty'],
|
|
337
|
+
validateValue: validateDateValue
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
case 'boolean':
|
|
341
|
+
return {
|
|
342
|
+
type: 'boolean',
|
|
343
|
+
allowedOperators: ['EQ', 'NE', 'IN', 'NIN', 'Empty', 'NotEmpty'],
|
|
344
|
+
validateValue: validateBooleanValue
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
case 'currency':
|
|
348
|
+
return {
|
|
349
|
+
type: 'currency',
|
|
350
|
+
allowedOperators: ['EQ', 'NE', 'GT', 'GTE', 'LT', 'LTE', 'Between', 'NotBetween', 'IN', 'NIN', 'Empty', 'NotEmpty'],
|
|
351
|
+
validateValue: validateCurrencyValue
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
case 'select':
|
|
355
|
+
const selectFieldDef: FieldDefinition = {
|
|
356
|
+
type: 'select',
|
|
357
|
+
allowedOperators: ['EQ', 'NE', 'IN', 'NIN', 'Empty', 'NotEmpty'],
|
|
358
|
+
selectOptions: []
|
|
359
|
+
};
|
|
360
|
+
selectFieldDef.validateValue = (value: any, operator: FilterOperator) =>
|
|
361
|
+
validateSelectValue(value, operator, selectFieldDef.selectOptions);
|
|
362
|
+
return selectFieldDef;
|
|
363
|
+
|
|
364
|
+
default:
|
|
365
|
+
// Default to string type
|
|
366
|
+
return getDefaultFieldDefinition('string');
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Create field definitions from sample data
|
|
372
|
+
*/
|
|
373
|
+
export const createFieldDefinitionsFromSample = <T>(sampleData: T): Record<keyof T, FieldDefinition> => {
|
|
374
|
+
const fieldDefinitions = {} as Record<keyof T, FieldDefinition>;
|
|
375
|
+
|
|
376
|
+
if (!sampleData || typeof sampleData !== 'object') {
|
|
377
|
+
return fieldDefinitions;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
Object.keys(sampleData).forEach(key => {
|
|
381
|
+
const value = (sampleData as any)[key];
|
|
382
|
+
const fieldKey = key as keyof T;
|
|
383
|
+
|
|
384
|
+
if (typeof value === 'string') {
|
|
385
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('string');
|
|
386
|
+
} else if (typeof value === 'number') {
|
|
387
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('number');
|
|
388
|
+
} else if (typeof value === 'boolean') {
|
|
389
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('boolean');
|
|
390
|
+
} else if (value instanceof Date) {
|
|
391
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('date');
|
|
392
|
+
} else if (value && typeof value === 'object' && 'value' in value && 'currency' in value) {
|
|
393
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('currency');
|
|
394
|
+
} else {
|
|
395
|
+
// Default to string for complex types
|
|
396
|
+
fieldDefinitions[fieldKey] = getDefaultFieldDefinition('string');
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
return fieldDefinitions;
|
|
401
|
+
};
|