@ram_28/kf-ai-sdk 1.0.21 → 1.0.23

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/docs/useFilter.md CHANGED
@@ -36,40 +36,87 @@ type ConditionGroupOperatorType = "And" | "Or" | "Not";
36
36
 
37
37
  // Single condition (generic for type-safe LHSField)
38
38
  interface ConditionType<T = any> {
39
+ // Auto-generated unique identifier
39
40
  id?: string;
41
+
42
+ // Comparison operator (EQ, GT, Contains, etc.)
40
43
  Operator: ConditionOperatorType;
41
- LHSField: keyof T | string; // Type-safe when T is provided
44
+
45
+ // Field name to compare
46
+ LHSField: keyof T | string;
47
+
48
+ // Value to compare against
42
49
  RHSValue: any;
50
+
51
+ // Value type (default: "Constant")
43
52
  RHSType?: "Constant" | "BOField" | "AppVariable";
44
53
  }
45
54
 
46
55
  // Condition group (can contain conditions or nested groups)
47
56
  interface ConditionGroupType<T = any> {
57
+ // Auto-generated unique identifier
48
58
  id?: string;
59
+
60
+ // Group operator (And, Or, Not)
49
61
  Operator: ConditionGroupOperatorType;
62
+
63
+ // Nested conditions or groups
50
64
  Condition: Array<ConditionType<T> | ConditionGroupType<T>>;
51
65
  }
52
66
 
53
67
  // Hook options (also used for initialState in useTable/useKanban)
54
68
  interface UseFilterOptionsType<T = any> {
69
+ // Initial conditions to populate the filter
55
70
  conditions?: Array<ConditionType<T> | ConditionGroupType<T>>;
71
+
72
+ // Root operator for combining conditions (default: "And")
56
73
  operator?: ConditionGroupOperatorType;
57
74
  }
58
75
 
59
76
  // Hook return type (generic for type-safe field names)
60
77
  interface UseFilterReturnType<T = any> {
78
+ // ============================================================
79
+ // STATE
80
+ // ============================================================
81
+
82
+ // Current root operator (And, Or, Not)
61
83
  operator: ConditionGroupOperatorType;
84
+
85
+ // All conditions and groups at root level
62
86
  items: Array<ConditionType<T> | ConditionGroupType<T>>;
87
+
88
+ // API-ready filter payload (undefined if no conditions)
63
89
  payload: FilterType<T> | undefined;
90
+
91
+ // True when at least one condition exists
64
92
  hasConditions: boolean;
65
93
 
94
+ // ============================================================
95
+ // METHODS
96
+ // ============================================================
97
+
98
+ // Add a condition, optionally to a parent group. Returns the new condition's ID
66
99
  addCondition: (condition: Omit<ConditionType<T>, "id">, parentId?: string) => string;
100
+
101
+ // Add a condition group, optionally to a parent group. Returns the new group's ID
67
102
  addConditionGroup: (operator: ConditionGroupOperatorType, parentId?: string) => string;
103
+
104
+ // Update a condition's properties (Operator, LHSField, RHSValue)
68
105
  updateCondition: (id: string, updates: Partial<Omit<ConditionType<T>, "id">>) => void;
106
+
107
+ // Change a group's operator (And, Or, Not)
69
108
  updateGroupOperator: (id: string, operator: ConditionGroupOperatorType) => void;
109
+
110
+ // Remove a condition or group by ID
70
111
  removeCondition: (id: string) => void;
112
+
113
+ // Get a condition or group by ID
71
114
  getCondition: (id: string) => ConditionType<T> | ConditionGroupType<T> | undefined;
115
+
116
+ // Remove all conditions and groups
72
117
  clearAllConditions: () => void;
118
+
119
+ // Change the root operator
73
120
  setRootOperator: (operator: ConditionGroupOperatorType) => void;
74
121
  }
75
122
  ```
@@ -126,18 +173,14 @@ Use the generic type parameter to get TypeScript validation on field names.
126
173
 
127
174
  ```tsx
128
175
  import { useFilter } from "@ram_28/kf-ai-sdk/filter";
176
+ import { Product, ProductType } from "../sources";
177
+ import { Roles } from "../sources/roles";
129
178
 
130
- interface Product {
131
- _id: string;
132
- Title: string;
133
- Price: number;
134
- Category: string;
135
- Stock: number;
136
- }
179
+ type BuyerProduct = ProductType<typeof Roles.Buyer>;
137
180
 
138
181
  function TypeSafeFilter() {
139
182
  // Pass the type parameter for type-safe LHSField
140
- const filter = useFilter<Product>();
183
+ const filter = useFilter<BuyerProduct>();
141
184
 
142
185
  const addCategoryFilter = () => {
143
186
  filter.addCondition({
@@ -150,7 +193,7 @@ function TypeSafeFilter() {
150
193
  const addInvalidFilter = () => {
151
194
  filter.addCondition({
152
195
  Operator: "EQ",
153
- LHSField: "InvalidField", // TypeScript error: not a key of Product
196
+ LHSField: "InvalidField", // TypeScript error: not a key of BuyerProduct
154
197
  RHSValue: "test",
155
198
  });
156
199
  };
@@ -173,16 +216,13 @@ function TypeSafeFilter() {
173
216
  ```tsx
174
217
  import { useFilter } from "@ram_28/kf-ai-sdk/filter";
175
218
  import type { UseFilterOptionsType } from "@ram_28/kf-ai-sdk/filter/types";
219
+ import { Product, ProductType } from "../sources";
220
+ import { Roles } from "../sources/roles";
176
221
 
177
- interface Product {
178
- _id: string;
179
- Title: string;
180
- Price: number;
181
- Category: string;
182
- }
222
+ type BuyerProduct = ProductType<typeof Roles.Buyer>;
183
223
 
184
224
  // Type-safe filter options
185
- const initialFilter: UseFilterOptionsType<Product> = {
225
+ const initialFilter: UseFilterOptionsType<BuyerProduct> = {
186
226
  conditions: [
187
227
  { Operator: "EQ", LHSField: "Category", RHSValue: "Electronics" },
188
228
  { Operator: "GT", LHSField: "Price", RHSValue: 100 },
@@ -191,7 +231,7 @@ const initialFilter: UseFilterOptionsType<Product> = {
191
231
  };
192
232
 
193
233
  // Use with useFilter
194
- const filter = useFilter<Product>(initialFilter);
234
+ const filter = useFilter<BuyerProduct>(initialFilter);
195
235
  ```
196
236
 
197
237
  ---