@ram_28/kf-ai-sdk 1.0.5 → 1.0.8

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 (38) hide show
  1. package/dist/api/index.d.ts +1 -1
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/components/hooks/useFilter/index.d.ts +3 -4
  4. package/dist/components/hooks/useFilter/index.d.ts.map +1 -1
  5. package/dist/components/hooks/useFilter/types.d.ts +84 -127
  6. package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
  7. package/dist/components/hooks/useFilter/useFilter.d.ts +1 -1
  8. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  9. package/dist/components/hooks/useKanban/index.d.ts +1 -1
  10. package/dist/components/hooks/useKanban/index.d.ts.map +1 -1
  11. package/dist/components/hooks/useKanban/types.d.ts +6 -49
  12. package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
  13. package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
  14. package/dist/components/hooks/useTable/types.d.ts +5 -35
  15. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  16. package/dist/components/hooks/useTable/useTable.d.ts +0 -5
  17. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  18. package/dist/index.cjs +13 -13
  19. package/dist/index.mjs +2395 -2865
  20. package/dist/types/common.d.ts +35 -26
  21. package/dist/types/common.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/sdk/api/index.ts +7 -3
  24. package/sdk/components/hooks/useFilter/index.ts +19 -31
  25. package/sdk/components/hooks/useFilter/types.ts +157 -138
  26. package/sdk/components/hooks/useFilter/useFilter.ts +259 -414
  27. package/sdk/components/hooks/useKanban/index.ts +0 -1
  28. package/sdk/components/hooks/useKanban/types.ts +8 -71
  29. package/sdk/components/hooks/useKanban/useKanban.ts +14 -77
  30. package/sdk/components/hooks/useTable/types.ts +7 -63
  31. package/sdk/components/hooks/useTable/useTable.ts +13 -122
  32. package/sdk/types/common.ts +42 -26
  33. package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +0 -33
  34. package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +0 -1
  35. package/dist/components/hooks/useFilter/validation.utils.d.ts +0 -38
  36. package/dist/components/hooks/useFilter/validation.utils.d.ts.map +0 -1
  37. package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +0 -298
  38. package/sdk/components/hooks/useFilter/validation.utils.ts +0 -401
@@ -18,44 +18,11 @@ interface SortingState<T> {
18
18
  direction: "asc" | "desc" | null;
19
19
  }
20
20
 
21
- interface FilteringState {
22
- global: string;
23
- }
24
-
25
21
  interface PaginationState {
26
22
  pageNo: number; // 1-indexed page number
27
23
  pageSize: number;
28
24
  }
29
25
 
30
- // ============================================================
31
- // FIELD TYPE DETECTION
32
- // ============================================================
33
-
34
- /**
35
- * Detect field type for auto-formatting
36
- * This will be enhanced with actual type introspection in the future
37
- * Currently unused but kept for future auto-formatting implementation
38
- */
39
- // function _detectFieldType<T>(fieldId: keyof T): string {
40
- // const fieldName = String(fieldId);
41
- //
42
- // // Basic pattern matching - will be replaced with actual type introspection
43
- // if (fieldName.includes('price') || fieldName.includes('cost') || fieldName.includes('amount')) {
44
- // return 'currency';
45
- // }
46
- // if (fieldName.includes('date') || fieldName.includes('At') || fieldName === 'created' || fieldName === 'updated') {
47
- // return 'datetime';
48
- // }
49
- // if (fieldName.includes('stock') || fieldName.includes('quantity') || fieldName.includes('count')) {
50
- // return 'number';
51
- // }
52
- // if (fieldName.includes('status') || fieldName.includes('type') || fieldName.includes('category')) {
53
- // return 'string';
54
- // }
55
- //
56
- // return 'string'; // default
57
- // }
58
-
59
26
  // ============================================================
60
27
  // MAIN HOOK
61
28
  // ============================================================
@@ -76,12 +43,8 @@ export function useTable<T = any>(
76
43
  direction: options.initialState?.sorting?.direction || null,
77
44
  });
78
45
 
79
- const [filtering, setFiltering] = useState<FilteringState>({
80
- global: options.initialState?.globalFilter || "",
81
- });
82
-
83
46
  const [pagination, setPagination] = useState<PaginationState>({
84
- pageNo: options.initialState?.pagination?.pageNo || 1, // Start at page 1
47
+ pageNo: options.initialState?.pagination?.pageNo || 1,
85
48
  pageSize: options.initialState?.pagination?.pageSize || 10,
86
49
  });
87
50
 
@@ -89,24 +52,9 @@ export function useTable<T = any>(
89
52
  // FILTER HOOK INTEGRATION
90
53
  // ============================================================
91
54
 
92
- const filterHook = useFilter<T>({
55
+ const filter = useFilter({
93
56
  initialConditions: options.initialState?.filters,
94
- initialLogicalOperator: options.initialState?.filterOperator || "And",
95
- fieldDefinitions: options.fieldDefinitions,
96
- validateOnChange: true,
97
- onValidationError: options.onFilterError,
98
- onConditionAdd: () => {
99
- // Reset to first page when adding filters
100
- setPagination((prev) => ({ ...prev, pageNo: 1 }));
101
- },
102
- onConditionUpdate: () => {
103
- // Reset to first page when updating filters
104
- setPagination((prev) => ({ ...prev, pageNo: 1 }));
105
- },
106
- onConditionRemove: () => {
107
- // Reset to first page when removing filters
108
- setPagination((prev) => ({ ...prev, pageNo: 1 }));
109
- },
57
+ initialOperator: options.initialState?.filterOperator || "And",
110
58
  });
111
59
 
112
60
  // ============================================================
@@ -123,12 +71,12 @@ export function useTable<T = any>(
123
71
  }
124
72
 
125
73
  // Add filter conditions (affects count)
126
- if (filterHook.filterPayload) {
127
- opts.Filter = filterHook.filterPayload;
74
+ if (filter.payload) {
75
+ opts.Filter = filter.payload;
128
76
  }
129
77
 
130
78
  return opts;
131
- }, [search.query, filterHook.filterPayload]);
79
+ }, [search.query, filter.payload]);
132
80
 
133
81
  // Options for list query - includes all options
134
82
  const apiOptions = useMemo((): ListOptions => {
@@ -145,7 +93,7 @@ export function useTable<T = any>(
145
93
 
146
94
  // Add pagination
147
95
  if (options.enablePagination) {
148
- opts.Page = pagination.pageNo; // Already 1-indexed
96
+ opts.Page = pagination.pageNo;
149
97
  opts.PageSize = pagination.pageSize;
150
98
  }
151
99
 
@@ -182,7 +130,7 @@ export function useTable<T = any>(
182
130
  gcTime: 0,
183
131
  });
184
132
 
185
- // Count query for accurate total items (only depends on filters/search, not sorting/pagination)
133
+ // Count query for accurate total items
186
134
  const {
187
135
  data: countData,
188
136
  isLoading: isCountLoading,
@@ -223,14 +171,12 @@ export function useTable<T = any>(
223
171
  const toggleSort = useCallback((field: keyof T) => {
224
172
  setSorting((prev) => {
225
173
  if (prev.field === field) {
226
- // Same field - toggle direction or clear
227
174
  if (prev.direction === "asc") {
228
175
  return { field, direction: "desc" };
229
176
  } else if (prev.direction === "desc") {
230
177
  return { field: null, direction: null };
231
178
  }
232
179
  }
233
- // New field or no current sort
234
180
  return { field, direction: "asc" };
235
181
  });
236
182
  }, []);
@@ -252,7 +198,6 @@ export function useTable<T = any>(
252
198
 
253
199
  const setSearchQuery = useCallback((value: string) => {
254
200
  setSearch({ query: value });
255
- // Reset to first page when searching
256
201
  setPagination((prev) => ({ ...prev, pageNo: 1 }));
257
202
  }, []);
258
203
 
@@ -260,20 +205,6 @@ export function useTable<T = any>(
260
205
  setSearch({ query: "" });
261
206
  }, []);
262
207
 
263
- // ============================================================
264
- // FILTERING OPERATIONS
265
- // ============================================================
266
-
267
- const setGlobalFilter = useCallback((value: string) => {
268
- setFiltering((prev) => ({ ...prev, global: value }));
269
- // Reset to first page when filtering
270
- setPagination((prev) => ({ ...prev, pageNo: 1 }));
271
- }, []);
272
-
273
- const clearFilter = useCallback(() => {
274
- setFiltering({ global: "" });
275
- }, []);
276
-
277
208
  // ============================================================
278
209
  // PAGINATION OPERATIONS
279
210
  // ============================================================
@@ -295,7 +226,7 @@ export function useTable<T = any>(
295
226
 
296
227
  const goToPage = useCallback(
297
228
  (page: number) => {
298
- const pageNo = Math.max(1, Math.min(page, totalPages)); // Clamp between 1 and totalPages
229
+ const pageNo = Math.max(1, Math.min(page, totalPages));
299
230
  setPagination((prev) => ({ ...prev, pageNo }));
300
231
  },
301
232
  [totalPages]
@@ -305,7 +236,7 @@ export function useTable<T = any>(
305
236
  setPagination((prev) => ({
306
237
  ...prev,
307
238
  pageSize: size,
308
- pageNo: 1, // Reset to first page
239
+ pageNo: 1,
309
240
  }));
310
241
  }, []);
311
242
 
@@ -350,52 +281,12 @@ export function useTable<T = any>(
350
281
  set: setSort,
351
282
  },
352
283
 
353
- // Legacy Global Filtering (Flat Access)
354
- globalFilter: {
355
- value: filtering.global,
356
- setValue: setGlobalFilter,
357
- clear: clearFilter,
358
- },
359
-
360
- // Advanced Filtering (Filter Conditions)
361
- filter: {
362
- // State
363
- conditions: filterHook.conditions,
364
- logicalOperator: filterHook.logicalOperator,
365
- isValid: filterHook.isValid,
366
- validationErrors: filterHook.validationErrors,
367
- hasConditions: filterHook.hasConditions,
368
-
369
- // Condition Management
370
- addCondition: filterHook.addCondition,
371
- updateCondition: filterHook.updateCondition,
372
- removeCondition: filterHook.removeCondition,
373
- clearConditions: filterHook.clearConditions,
374
- getCondition: filterHook.getCondition,
375
-
376
- // Logical Operator
377
- setLogicalOperator: filterHook.setLogicalOperator,
378
-
379
- // Bulk Operations
380
- setConditions: filterHook.setConditions,
381
- replaceCondition: filterHook.replaceCondition,
382
-
383
- // Validation
384
- validateCondition: filterHook.validateCondition,
385
- validateAllConditions: filterHook.validateAllConditions,
386
-
387
- // State Management
388
- exportState: filterHook.exportState,
389
- importState: filterHook.importState,
390
- resetToInitial: filterHook.resetToInitial,
391
-
392
- // Utilities
393
- getConditionCount: filterHook.getConditionCount,
394
- },
284
+ // Filter (Simplified chainable API)
285
+ filter,
395
286
 
396
287
  // Pagination (Flat Access)
397
288
  pagination: {
398
- currentPage: pagination.pageNo, // Already 1-indexed
289
+ currentPage: pagination.pageNo,
399
290
  pageSize: pagination.pageSize,
400
291
  totalPages,
401
292
  totalItems,
@@ -15,18 +15,20 @@ export type SortOption = Record<string, SortDirection>;
15
15
  export type Sort = SortOption[];
16
16
 
17
17
  /**
18
- * Filter operators for individual conditions (leaf nodes)
18
+ * Condition operators for individual conditions (leaf nodes)
19
+ * Used in Condition.Operator
19
20
  */
20
- export type FilterOperator =
21
+ export type ConditionOperator =
21
22
  | "EQ" | "NE" | "GT" | "GTE" | "LT" | "LTE"
22
23
  | "Between" | "NotBetween" | "IN" | "NIN"
23
24
  | "Empty" | "NotEmpty" | "Contains" | "NotContains"
24
25
  | "MinLength" | "MaxLength";
25
26
 
26
27
  /**
27
- * Logical operators for combining filter conditions (tree nodes)
28
+ * Operators for combining conditions in a group (tree nodes)
29
+ * Used in ConditionGroup.Operator
28
30
  */
29
- export type LogicalOperator = "And" | "Or" | "Not";
31
+ export type ConditionGroupOperator = "And" | "Or" | "Not";
30
32
 
31
33
  /**
32
34
  * RHS value type for filter conditions
@@ -34,19 +36,13 @@ export type LogicalOperator = "And" | "Or" | "Not";
34
36
  export type FilterRHSType = "Constant" | "BOField" | "AppVariable";
35
37
 
36
38
  /**
37
- * Base interface for all filter nodes
39
+ * Leaf condition (actual field comparison)
38
40
  */
39
- interface FilterNodeBase {
40
- /** Operator type */
41
- Operator: FilterOperator | LogicalOperator;
42
- }
43
-
44
- /**
45
- * Leaf filter condition (actual field comparison)
46
- */
47
- export interface FilterCondition extends FilterNodeBase {
41
+ export interface Condition {
42
+ /** Optional ID for hook state management (omitted in API payload) */
43
+ id?: string;
48
44
  /** Condition operator */
49
- Operator: FilterOperator;
45
+ Operator: ConditionOperator;
50
46
  /** Left-hand side field name */
51
47
  LHSField: string;
52
48
  /** Right-hand side value */
@@ -56,25 +52,45 @@ export interface FilterCondition extends FilterNodeBase {
56
52
  }
57
53
 
58
54
  /**
59
- * Logical filter node (combines multiple conditions)
55
+ * Group combining conditions (recursive structure)
60
56
  */
61
- export interface FilterLogical extends FilterNodeBase {
62
- /** Logical operator */
63
- Operator: LogicalOperator;
64
- /** Nested conditions (can be FilterCondition or FilterLogical) */
65
- Condition: Array<FilterCondition | FilterLogical>;
57
+ export interface ConditionGroup {
58
+ /** Optional ID for hook state management (omitted in API payload) */
59
+ id?: string;
60
+ /** Group operator (And, Or, Not) */
61
+ Operator: ConditionGroupOperator;
62
+ /** Nested conditions (can be Condition or ConditionGroup) */
63
+ Condition: Array<Condition | ConditionGroup>;
66
64
  }
67
65
 
68
66
  /**
69
- * Filter structure matching API specification (root level)
70
- * This is a discriminated union - a filter is either a logical node or a condition
67
+ * Root filter type (alias for ConditionGroup)
68
+ */
69
+ export type Filter = ConditionGroup;
70
+
71
+ // ============================================================
72
+ // LEGACY TYPE ALIASES (for backwards compatibility)
73
+ // ============================================================
74
+
75
+ /**
76
+ * @deprecated Use `Condition` instead
77
+ */
78
+ export type FilterCondition = Condition;
79
+
80
+ /**
81
+ * @deprecated Use `ConditionGroup` instead
82
+ */
83
+ export type FilterLogical = ConditionGroup;
84
+
85
+ /**
86
+ * @deprecated Use `ConditionGroupOperator` instead
71
87
  */
72
- export type Filter = FilterLogical;
88
+ export type FilterOperator = ConditionGroupOperator;
73
89
 
74
90
  /**
75
- * Convenience type for any filter node (leaf or logical)
91
+ * @deprecated Use `Condition | ConditionGroup` instead
76
92
  */
77
- export type FilterNode = FilterCondition | FilterLogical;
93
+ export type FilterNode = Condition | ConditionGroup;
78
94
 
79
95
  /**
80
96
  * DateTime encoding format used by the API
@@ -1,33 +0,0 @@
1
- import type { Filter, LogicalOperator } from "../../../types/common";
2
- import type { FilterConditionWithId, FilterState } from "../useFilter";
3
- /**
4
- * Build SDK Filter payload from filter state
5
- * Returns undefined if no valid conditions exist
6
- * Supports both flat and nested filter structures
7
- */
8
- export declare const buildFilterPayload: (conditions: FilterConditionWithId[], logicalOperator: LogicalOperator) => Filter | undefined;
9
- /**
10
- * Build filter payload from complete filter state
11
- */
12
- export declare const buildFilterPayloadFromState: (state: FilterState) => Filter | undefined;
13
- /**
14
- * Validate that a filter payload is well-formed (supports nested filters)
15
- */
16
- export declare const validateFilterPayload: (filter: Filter | undefined) => boolean;
17
- /**
18
- * Deep clone a filter payload (supports nested filters)
19
- */
20
- export declare const cloneFilterPayload: (filter: Filter | undefined) => Filter | undefined;
21
- /**
22
- * Merge multiple filter payloads with a logical operator
23
- */
24
- export declare const mergeFilterPayloads: (filters: (Filter | undefined)[], operator: LogicalOperator) => Filter | undefined;
25
- /**
26
- * Convert filter payload to a human-readable string for debugging (supports nested filters)
27
- */
28
- export declare const filterPayloadToString: (filter: Filter | undefined) => string;
29
- /**
30
- * Check if two filter payloads are equivalent (supports nested filters)
31
- */
32
- export declare const areFilterPayloadsEqual: (filter1: Filter | undefined, filter2: Filter | undefined) => boolean;
33
- //# sourceMappingURL=payloadBuilder.utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payloadBuilder.utils.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useFilter/payloadBuilder.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkC,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACrG,OAAO,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqCvE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,qBAAqB,EAAE,EACnC,iBAAiB,eAAe,KAC/B,MAAM,GAAG,SAmBX,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GAAI,OAAO,WAAW,KAAG,MAAM,GAAG,SAEzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,OAwClE,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SASxE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,EAC/B,UAAU,eAAe,KACxB,MAAM,GAAG,SAoBX,CAAC;AA6BF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAYlE,CAAC;AAyCF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,SAAS,MAAM,GAAG,SAAS,EAC3B,SAAS,MAAM,GAAG,SAAS,KAC1B,OAyBF,CAAC"}
@@ -1,38 +0,0 @@
1
- import type { FilterOperator } from "../../../types/common";
2
- import type { FieldDefinition, ValidationResult } from "../useFilter";
3
- /**
4
- * Validate number values based on operator
5
- */
6
- export declare const validateNumberValue: (value: any, operator: FilterOperator) => ValidationResult;
7
- /**
8
- * Validate date values based on operator
9
- */
10
- export declare const validateDateValue: (value: any, operator: FilterOperator) => ValidationResult;
11
- /**
12
- * Validate currency values based on operator
13
- */
14
- export declare const validateCurrencyValue: (value: any, operator: FilterOperator) => ValidationResult;
15
- /**
16
- * Validate string values based on operator
17
- */
18
- export declare const validateStringValue: (value: any, operator: FilterOperator) => ValidationResult;
19
- /**
20
- * Validate boolean values based on operator
21
- */
22
- export declare const validateBooleanValue: (value: any, operator: FilterOperator) => ValidationResult;
23
- /**
24
- * Validate select field values based on operator and available options
25
- */
26
- export declare const validateSelectValue: (value: any, operator: FilterOperator, selectOptions?: Array<{
27
- label: string;
28
- value: any;
29
- }>) => ValidationResult;
30
- /**
31
- * Get default field definition based on field type
32
- */
33
- export declare const getDefaultFieldDefinition: (fieldType: FieldDefinition["type"]) => FieldDefinition;
34
- /**
35
- * Create field definitions from sample data
36
- */
37
- export declare const createFieldDefinitionsFromSample: <T>(sampleData: T) => Record<keyof T, FieldDefinition>;
38
- //# sourceMappingURL=validation.utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.utils.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useFilter/validation.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAMtE;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,GAAG,EAAE,UAAU,cAAc,KAAG,gBAwC1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,GAAG,EAAE,UAAU,cAAc,KAAG,gBAqDxE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,GAAG,EAAE,UAAU,cAAc,KAAG,gBAmD5E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,GAAG,EAAE,UAAU,cAAc,KAAG,gBA+C1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,GAAG,EAAE,UAAU,cAAc,KAAG,gBAkC3E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,GAAG,EACV,UAAU,cAAc,EACxB,gBAAgB,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE,CAAC,KACnD,gBA2CF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GAAI,WAAW,eAAe,CAAC,MAAM,CAAC,KAAG,eAmD9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,GAAI,CAAC,EAAE,YAAY,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,EAAE,eAAe,CA4BlG,CAAC"}