@ram_28/kf-ai-sdk 1.0.14 → 1.0.15

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.
@@ -8,6 +8,17 @@ export declare const isConditionGroup: (item: ConditionType | ConditionGroupType
8
8
  * Type guard to check if an item is a leaf Condition (has LHSField)
9
9
  */
10
10
  export declare const isCondition: (item: ConditionType | ConditionGroupType) => item is ConditionType;
11
+ /**
12
+ * Builder interface for fluent condition group construction
13
+ */
14
+ export interface ConditionGroupBuilder {
15
+ /** The id of the created group */
16
+ readonly id: string;
17
+ /** Add a condition to this group */
18
+ addCondition(condition: Omit<ConditionType, "id">): ConditionGroupBuilder;
19
+ /** Add a nested condition group */
20
+ addConditionGroup(operator: ConditionGroupOperatorType): ConditionGroupBuilder;
21
+ }
11
22
  /**
12
23
  * Hook options (minimal configuration)
13
24
  */
@@ -30,53 +41,45 @@ export interface UseFilterReturnType {
30
41
  /** Whether any conditions exist */
31
42
  hasConditions: boolean;
32
43
  /**
33
- * Add a leaf condition at root level
34
- * @returns The id of the created condition
35
- */
36
- add: (condition: Omit<ConditionType, "id">) => string;
37
- /**
38
- * Add a condition group at root level
39
- * @returns The id of the created group
40
- */
41
- addGroup: (operator: ConditionGroupOperatorType) => string;
42
- /**
43
- * Add a leaf condition to a specific parent group
44
- * @param parentId - The id of the parent ConditionGroup
44
+ * Add a leaf condition at root level or to a specific parent group
45
+ * @param condition - The condition to add (without id)
46
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
45
47
  * @returns The id of the created condition
46
48
  */
47
- addTo: (parentId: string, condition: Omit<ConditionType, "id">) => string;
49
+ addCondition: (condition: Omit<ConditionType, "id">, parentId?: string) => string;
48
50
  /**
49
- * Add a condition group to a specific parent group
50
- * @param parentId - The id of the parent ConditionGroup
51
+ * Add a condition group at root level or to a specific parent group
52
+ * @param operator - The operator for the new group ("And" | "Or" | "Not")
53
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
51
54
  * @returns The id of the created group
52
55
  */
53
- addGroupTo: (parentId: string, operator: ConditionGroupOperatorType) => string;
56
+ addConditionGroup: (operator: ConditionGroupOperatorType, parentId?: string) => string;
54
57
  /**
55
58
  * Update a leaf condition by id
56
59
  * @param id - The id of the condition to update
57
60
  * @param updates - Partial updates to apply
58
61
  */
59
- update: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
62
+ updateCondition: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
60
63
  /**
61
64
  * Update a condition group's operator by id
62
65
  * @param id - The id of the group to update
63
66
  * @param operator - The new operator
64
67
  */
65
- updateOperator: (id: string, operator: ConditionGroupOperatorType) => void;
68
+ updateGroupOperator: (id: string, operator: ConditionGroupOperatorType) => void;
66
69
  /**
67
70
  * Remove a condition or group by id
68
71
  * @param id - The id of the item to remove
69
72
  */
70
- remove: (id: string) => void;
73
+ removeCondition: (id: string) => void;
71
74
  /**
72
75
  * Get a condition or group by id
73
76
  * @param id - The id to look up
74
77
  * @returns The item or undefined if not found
75
78
  */
76
- get: (id: string) => ConditionType | ConditionGroupType | undefined;
79
+ getCondition: (id: string) => ConditionType | ConditionGroupType | undefined;
77
80
  /** Clear all conditions */
78
- clear: () => void;
81
+ clearAllConditions: () => void;
79
82
  /** Set the root operator for combining conditions */
80
- setOperator: (op: ConditionGroupOperatorType) => void;
83
+ setRootOperator: (op: ConditionGroupOperatorType) => void;
81
84
  }
82
85
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useFilter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,0BAA0B,EAC1B,UAAU,EACV,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,0BAA0B,EAC1B,UAAU,EACV,iBAAiB,GAClB,CAAC;AAMF;;GAE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{"version":3,"file":"useFilter.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useFilter/useFilter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA6KzE,wBAAgB,SAAS,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CA2JjF"}
1
+ {"version":3,"file":"useFilter.d.ts","sourceRoot":"","sources":["../../../../sdk/components/hooks/useFilter/useFilter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA6KzE,wBAAgB,SAAS,CAAC,OAAO,GAAE,oBAAyB,GAAG,mBAAmB,CA+IjF"}
package/dist/filter.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./useFilter-D-bCDo6Z.cjs");exports.isCondition=i.isCondition;exports.isConditionGroup=i.isConditionGroup;exports.useFilter=i.useFilter;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./useFilter-Dofowpr_.cjs");exports.isCondition=i.isCondition;exports.isConditionGroup=i.isConditionGroup;exports.useFilter=i.useFilter;
package/dist/filter.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as s, a, u as n } from "./useFilter-CXFqEHyI.js";
1
+ import { i as s, a, u as n } from "./useFilter-Dv-mr9QW.js";
2
2
  export {
3
3
  s as isCondition,
4
4
  a as isConditionGroup,
package/dist/kanban.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),A=require("@tanstack/react-query"),F=require("./client-C15j4O5B.cjs"),St=require("./useFilter-D-bCDo6Z.cjs"),nt=50,st=5,it=5;function ot({onCardMove:s,onError:c,columns:l,announceMove:a}){const[i,S]=u.useState({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),O=u.useRef(null),w=u.useRef(null),K=u.useRef(null),_=u.useCallback(()=>{S({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),w.current&&(clearTimeout(w.current),w.current=null)},[]),D=u.useCallback(d=>l.find(o=>o._id===d)||null,[l]),X=u.useCallback(d=>{for(const o of l){const y=o.cards.find(m=>m._id===d);if(y)return{card:y,column:o}}return null},[l]),P=u.useCallback((d,o)=>{var y,m;try{const g=d.target,f=D(o.columnId);if(!f)throw new Error("Source column not found");(y=d.dataTransfer)==null||y.setData("text/plain",o._id),(m=d.dataTransfer)==null||m.setData("application/json",JSON.stringify(o));const k=g.cloneNode(!0);k.style.cssText=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),A=require("@tanstack/react-query"),F=require("./client-C15j4O5B.cjs"),St=require("./useFilter-Dofowpr_.cjs"),nt=50,st=5,it=5;function ot({onCardMove:s,onError:c,columns:l,announceMove:a}){const[i,S]=u.useState({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),O=u.useRef(null),w=u.useRef(null),K=u.useRef(null),_=u.useCallback(()=>{S({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),w.current&&(clearTimeout(w.current),w.current=null)},[]),D=u.useCallback(d=>l.find(o=>o._id===d)||null,[l]),X=u.useCallback(d=>{for(const o of l){const y=o.cards.find(m=>m._id===d);if(y)return{card:y,column:o}}return null},[l]),P=u.useCallback((d,o)=>{var y,m;try{const g=d.target,f=D(o.columnId);if(!f)throw new Error("Source column not found");(y=d.dataTransfer)==null||y.setData("text/plain",o._id),(m=d.dataTransfer)==null||m.setData("application/json",JSON.stringify(o));const k=g.cloneNode(!0);k.style.cssText=`
2
2
  position: fixed;
3
3
  top: -1000px;
4
4
  left: -1000px;
package/dist/kanban.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useState as G, useRef as k, useCallback as h, useEffect as rt, useMemo as ot, createContext as qt, useContext as Qt } from "react";
2
2
  import { useQueryClient as At, useQueries as Tt, keepPreviousData as kt, useQuery as Pt, useMutation as j } from "@tanstack/react-query";
3
3
  import { a as F } from "./client-CfvLiGfP.js";
4
- import { u as Et } from "./useFilter-CXFqEHyI.js";
4
+ import { u as Et } from "./useFilter-Dv-mr9QW.js";
5
5
  const ct = 50, dt = 5, ut = 5;
6
6
  function Ft({
7
7
  onCardMove: i,
package/dist/table.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),O=require("@tanstack/react-query"),Q=require("./client-C15j4O5B.cjs"),_=require("./useFilter-D-bCDo6Z.cjs");function $(t){var N,m,P,k,z,T,F,M,w,E;const[o,p]=a.useState({query:""}),[n,y]=a.useState({field:((m=(N=t.initialState)==null?void 0:N.sorting)==null?void 0:m.field)||null,direction:((k=(P=t.initialState)==null?void 0:P.sorting)==null?void 0:k.direction)||null}),[i,c]=a.useState({pageNo:((T=(z=t.initialState)==null?void 0:z.pagination)==null?void 0:T.pageNo)||1,pageSize:((M=(F=t.initialState)==null?void 0:F.pagination)==null?void 0:M.pageSize)||10}),s=_.useFilter({initialConditions:(w=t.initialState)==null?void 0:w.filters,initialOperator:((E=t.initialState)==null?void 0:E.filterOperator)||"And"}),l=a.useMemo(()=>{const e={};return o.query&&(e.Search=o.query),s.payload&&(e.Filter=s.payload),e},[o.query,s.payload]),b=a.useMemo(()=>{const e={...l};return n.field&&n.direction&&(e.Sort=[{[String(n.field)]:n.direction==="asc"?"ASC":"DESC"}]),t.enablePagination&&(e.Page=i.pageNo,e.PageSize=i.pageSize),e},[l,n,i,t.enablePagination]),{data:u,isLoading:L,isFetching:R,error:x,refetch:q}=O.useQuery({queryKey:["table",t.source,b],queryFn:async()=>{try{const e=await Q.api(t.source).list(b);return t.onSuccess&&t.onSuccess(e.Data),e}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),{data:g,isLoading:A,isFetching:D,error:G,refetch:C}=O.useQuery({queryKey:["table-count",t.source,l],queryFn:async()=>{try{return await Q.api(t.source).count(l)}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),K=a.useMemo(()=>(u==null?void 0:u.Data)||[],[u]),S=a.useMemo(()=>(g==null?void 0:g.Count)||0,[g]),d=a.useMemo(()=>Math.ceil(S/i.pageSize),[S,i.pageSize]),j=a.useCallback(e=>{y(r=>{if(r.field===e){if(r.direction==="asc")return{field:e,direction:"desc"};if(r.direction==="desc")return{field:null,direction:null}}return{field:e,direction:"asc"}})},[]),I=a.useCallback(()=>{y({field:null,direction:null})},[]),B=a.useCallback((e,r)=>{y({field:e,direction:r})},[]),H=a.useCallback(e=>{p({query:e}),c(r=>({...r,pageNo:1}))},[]),J=a.useCallback(()=>{p({query:""})},[]),f=i.pageNo<d,h=i.pageNo>1,U=a.useCallback(()=>{f&&c(e=>({...e,pageNo:e.pageNo+1}))},[f]),V=a.useCallback(()=>{h&&c(e=>({...e,pageNo:e.pageNo-1}))},[h]),W=a.useCallback(e=>{const r=Math.max(1,Math.min(e,d));c(Z=>({...Z,pageNo:r}))},[d]),X=a.useCallback(e=>{c(r=>({...r,pageSize:e,pageNo:1}))},[]),Y=a.useCallback(async()=>{const[e]=await Promise.all([q(),C()]);return e.data||{Data:[]}},[q,C]);return{rows:K,totalItems:S,isLoading:L||A,isFetching:R||D,error:x||G,search:{query:o.query,setQuery:H,clear:J},sort:{field:n.field,direction:n.direction,toggle:j,clear:I,set:B},filter:s,pagination:{currentPage:i.pageNo,pageSize:i.pageSize,totalPages:d,totalItems:S,canGoNext:f,canGoPrevious:h,goToNext:U,goToPrevious:V,goToPage:W,setPageSize:X},refetch:Y}}exports.useTable=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),O=require("@tanstack/react-query"),Q=require("./client-C15j4O5B.cjs"),_=require("./useFilter-Dofowpr_.cjs");function $(t){var N,m,P,k,z,T,F,M,w,E;const[o,p]=a.useState({query:""}),[n,y]=a.useState({field:((m=(N=t.initialState)==null?void 0:N.sorting)==null?void 0:m.field)||null,direction:((k=(P=t.initialState)==null?void 0:P.sorting)==null?void 0:k.direction)||null}),[i,c]=a.useState({pageNo:((T=(z=t.initialState)==null?void 0:z.pagination)==null?void 0:T.pageNo)||1,pageSize:((M=(F=t.initialState)==null?void 0:F.pagination)==null?void 0:M.pageSize)||10}),s=_.useFilter({initialConditions:(w=t.initialState)==null?void 0:w.filters,initialOperator:((E=t.initialState)==null?void 0:E.filterOperator)||"And"}),l=a.useMemo(()=>{const e={};return o.query&&(e.Search=o.query),s.payload&&(e.Filter=s.payload),e},[o.query,s.payload]),b=a.useMemo(()=>{const e={...l};return n.field&&n.direction&&(e.Sort=[{[String(n.field)]:n.direction==="asc"?"ASC":"DESC"}]),t.enablePagination&&(e.Page=i.pageNo,e.PageSize=i.pageSize),e},[l,n,i,t.enablePagination]),{data:u,isLoading:L,isFetching:R,error:x,refetch:q}=O.useQuery({queryKey:["table",t.source,b],queryFn:async()=>{try{const e=await Q.api(t.source).list(b);return t.onSuccess&&t.onSuccess(e.Data),e}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),{data:g,isLoading:A,isFetching:D,error:G,refetch:C}=O.useQuery({queryKey:["table-count",t.source,l],queryFn:async()=>{try{return await Q.api(t.source).count(l)}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),K=a.useMemo(()=>(u==null?void 0:u.Data)||[],[u]),S=a.useMemo(()=>(g==null?void 0:g.Count)||0,[g]),d=a.useMemo(()=>Math.ceil(S/i.pageSize),[S,i.pageSize]),j=a.useCallback(e=>{y(r=>{if(r.field===e){if(r.direction==="asc")return{field:e,direction:"desc"};if(r.direction==="desc")return{field:null,direction:null}}return{field:e,direction:"asc"}})},[]),I=a.useCallback(()=>{y({field:null,direction:null})},[]),B=a.useCallback((e,r)=>{y({field:e,direction:r})},[]),H=a.useCallback(e=>{p({query:e}),c(r=>({...r,pageNo:1}))},[]),J=a.useCallback(()=>{p({query:""})},[]),f=i.pageNo<d,h=i.pageNo>1,U=a.useCallback(()=>{f&&c(e=>({...e,pageNo:e.pageNo+1}))},[f]),V=a.useCallback(()=>{h&&c(e=>({...e,pageNo:e.pageNo-1}))},[h]),W=a.useCallback(e=>{const r=Math.max(1,Math.min(e,d));c(Z=>({...Z,pageNo:r}))},[d]),X=a.useCallback(e=>{c(r=>({...r,pageSize:e,pageNo:1}))},[]),Y=a.useCallback(async()=>{const[e]=await Promise.all([q(),C()]);return e.data||{Data:[]}},[q,C]);return{rows:K,totalItems:S,isLoading:L||A,isFetching:R||D,error:x||G,search:{query:o.query,setQuery:H,clear:J},sort:{field:n.field,direction:n.direction,toggle:j,clear:I,set:B},filter:s,pagination:{currentPage:i.pageNo,pageSize:i.pageSize,totalPages:d,totalItems:S,canGoNext:f,canGoPrevious:h,goToNext:U,goToPrevious:V,goToPage:W,setPageSize:X},refetch:Y}}exports.useTable=$;
package/dist/table.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useState as m, useMemo as c, useCallback as i } from "react";
2
2
  import { useQuery as A } from "@tanstack/react-query";
3
3
  import { a as D } from "./client-CfvLiGfP.js";
4
- import { u as v } from "./useFilter-CXFqEHyI.js";
4
+ import { u as v } from "./useFilter-Dv-mr9QW.js";
5
5
  function ae(t) {
6
6
  var F, T, C, b, w, E, x, L, M, O;
7
7
  const [s, N] = m({
@@ -0,0 +1 @@
1
+ "use strict";const u=require("react"),d=r=>"Condition"in r,R=r=>"LHSField"in r;let _=0;const l=()=>`filter_${Date.now()}_${++_}`,$=r=>r.id?r:{...r,id:l()},k=r=>r.map(o=>{const n=$(o);return d(n)?{...n,Condition:k(n.Condition)}:n}),O=r=>r.map(o=>{if(d(o)){const{id:b,...C}=o;return{...C,Condition:O(o.Condition)}}const{id:n,...t}=o;return t}),h=(r,o)=>{for(const n of r){if(n.id===o)return n;if(d(n)){const t=h(n.Condition,o);if(t)return t}}},f=(r,o,n)=>r.map(t=>t.id===o?n(t):d(t)?{...t,Condition:f(t.Condition,o,n)}:t),G=(r,o)=>r.filter(n=>n.id!==o).map(n=>d(n)?{...n,Condition:G(n.Condition,o)}:n),p=(r,o,n)=>r.map(t=>t.id===o&&d(t)?{...t,Condition:[...t.Condition,n]}:d(t)?{...t,Condition:p(t.Condition,o,n)}:t);function q(r={}){const[o,n]=u.useState(()=>k(r.initialConditions||[])),[t,b]=u.useState(r.initialOperator||"And"),C=u.useMemo(()=>{if(o.length!==0)return{Operator:t,Condition:O(o)}},[o,t]),g=o.length>0,v=u.useCallback((i,s)=>{const c=l(),e={...i,id:c};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),F=u.useCallback((i,s)=>{const c=l(),e={id:c,Operator:i,Condition:[]};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),I=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?e:{...e,...s}))},[]),S=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?{...e,Operator:s}:e))},[]),w=u.useCallback(i=>{n(s=>G(s,i))},[]),T=u.useCallback(i=>h(o,i),[o]),y=u.useCallback(()=>{n([])},[]),A=u.useCallback(i=>{b(i)},[]);return{operator:t,items:o,payload:C,hasConditions:g,addCondition:v,addConditionGroup:F,updateCondition:I,updateGroupOperator:S,removeCondition:w,getCondition:T,clearAllConditions:y,setRootOperator:A}}exports.isCondition=R;exports.isConditionGroup=d;exports.useFilter=q;
@@ -0,0 +1,117 @@
1
+ import { useState as h, useMemo as k, useCallback as c } from "react";
2
+ const u = (t) => "Condition" in t, H = (t) => "LHSField" in t;
3
+ let x = 0;
4
+ const f = () => `filter_${Date.now()}_${++x}`, B = (t) => t.id ? t : { ...t, id: f() }, g = (t) => t.map((o) => {
5
+ const n = B(o);
6
+ return u(n) ? {
7
+ ...n,
8
+ Condition: g(n.Condition)
9
+ } : n;
10
+ }), v = (t) => t.map((o) => {
11
+ if (u(o)) {
12
+ const { id: O, ...C } = o;
13
+ return {
14
+ ...C,
15
+ Condition: v(o.Condition)
16
+ };
17
+ }
18
+ const { id: n, ...r } = o;
19
+ return r;
20
+ }), G = (t, o) => {
21
+ for (const n of t) {
22
+ if (n.id === o)
23
+ return n;
24
+ if (u(n)) {
25
+ const r = G(n.Condition, o);
26
+ if (r) return r;
27
+ }
28
+ }
29
+ }, p = (t, o, n) => t.map((r) => r.id === o ? n(r) : u(r) ? {
30
+ ...r,
31
+ Condition: p(r.Condition, o, n)
32
+ } : r), I = (t, o) => t.filter((n) => n.id !== o).map((n) => u(n) ? {
33
+ ...n,
34
+ Condition: I(n.Condition, o)
35
+ } : n), l = (t, o, n) => t.map((r) => r.id === o && u(r) ? {
36
+ ...r,
37
+ Condition: [...r.Condition, n]
38
+ } : u(r) ? {
39
+ ...r,
40
+ Condition: l(r.Condition, o, n)
41
+ } : r);
42
+ function L(t = {}) {
43
+ const [o, n] = h(
44
+ () => g(t.initialConditions || [])
45
+ ), [r, O] = h(
46
+ t.initialOperator || "And"
47
+ ), C = k(() => {
48
+ if (o.length !== 0)
49
+ return {
50
+ Operator: r,
51
+ Condition: v(o)
52
+ };
53
+ }, [o, r]), w = o.length > 0, F = c(
54
+ (i, s) => {
55
+ const d = f(), e = { ...i, id: d };
56
+ return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
57
+ },
58
+ []
59
+ ), S = c(
60
+ (i, s) => {
61
+ const d = f(), e = {
62
+ id: d,
63
+ Operator: i,
64
+ Condition: []
65
+ };
66
+ return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
67
+ },
68
+ []
69
+ ), T = c(
70
+ (i, s) => {
71
+ n(
72
+ (d) => p(d, i, (e) => u(e) ? e : { ...e, ...s })
73
+ );
74
+ },
75
+ []
76
+ ), y = c(
77
+ (i, s) => {
78
+ n(
79
+ (d) => p(d, i, (e) => u(e) ? { ...e, Operator: s } : e)
80
+ );
81
+ },
82
+ []
83
+ ), A = c((i) => {
84
+ n((s) => I(s, i));
85
+ }, []), _ = c(
86
+ (i) => G(o, i),
87
+ [o]
88
+ ), $ = c(() => {
89
+ n([]);
90
+ }, []), b = c((i) => {
91
+ O(i);
92
+ }, []);
93
+ return {
94
+ // State
95
+ operator: r,
96
+ items: o,
97
+ payload: C,
98
+ hasConditions: w,
99
+ // Add operations
100
+ addCondition: F,
101
+ addConditionGroup: S,
102
+ // Update operations
103
+ updateCondition: T,
104
+ updateGroupOperator: y,
105
+ // Remove & access
106
+ removeCondition: A,
107
+ getCondition: _,
108
+ // Utility
109
+ clearAllConditions: $,
110
+ setRootOperator: b
111
+ };
112
+ }
113
+ export {
114
+ u as a,
115
+ H as i,
116
+ L as u
117
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ram_28/kf-ai-sdk",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
5
5
  "author": "Ramprasad",
6
6
  "license": "MIT",
@@ -41,6 +41,20 @@ export const isCondition = (
41
41
  // HOOK-SPECIFIC TYPE DEFINITIONS
42
42
  // ============================================================
43
43
 
44
+ /**
45
+ * Builder interface for fluent condition group construction
46
+ */
47
+ export interface ConditionGroupBuilder {
48
+ /** The id of the created group */
49
+ readonly id: string;
50
+
51
+ /** Add a condition to this group */
52
+ addCondition(condition: Omit<ConditionType, "id">): ConditionGroupBuilder;
53
+
54
+ /** Add a nested condition group */
55
+ addConditionGroup(operator: ConditionGroupOperatorType): ConditionGroupBuilder;
56
+ }
57
+
44
58
  /**
45
59
  * Hook options (minimal configuration)
46
60
  */
@@ -76,30 +90,20 @@ export interface UseFilterReturnType {
76
90
  // ============================================================
77
91
 
78
92
  /**
79
- * Add a leaf condition at root level
80
- * @returns The id of the created condition
81
- */
82
- add: (condition: Omit<ConditionType, "id">) => string;
83
-
84
- /**
85
- * Add a condition group at root level
86
- * @returns The id of the created group
87
- */
88
- addGroup: (operator: ConditionGroupOperatorType) => string;
89
-
90
- /**
91
- * Add a leaf condition to a specific parent group
92
- * @param parentId - The id of the parent ConditionGroup
93
+ * Add a leaf condition at root level or to a specific parent group
94
+ * @param condition - The condition to add (without id)
95
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
93
96
  * @returns The id of the created condition
94
97
  */
95
- addTo: (parentId: string, condition: Omit<ConditionType, "id">) => string;
98
+ addCondition: (condition: Omit<ConditionType, "id">, parentId?: string) => string;
96
99
 
97
100
  /**
98
- * Add a condition group to a specific parent group
99
- * @param parentId - The id of the parent ConditionGroup
101
+ * Add a condition group at root level or to a specific parent group
102
+ * @param operator - The operator for the new group ("And" | "Or" | "Not")
103
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
100
104
  * @returns The id of the created group
101
105
  */
102
- addGroupTo: (parentId: string, operator: ConditionGroupOperatorType) => string;
106
+ addConditionGroup: (operator: ConditionGroupOperatorType, parentId?: string) => string;
103
107
 
104
108
  // ============================================================
105
109
  // UPDATE OPERATIONS
@@ -110,14 +114,14 @@ export interface UseFilterReturnType {
110
114
  * @param id - The id of the condition to update
111
115
  * @param updates - Partial updates to apply
112
116
  */
113
- update: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
117
+ updateCondition: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
114
118
 
115
119
  /**
116
120
  * Update a condition group's operator by id
117
121
  * @param id - The id of the group to update
118
122
  * @param operator - The new operator
119
123
  */
120
- updateOperator: (id: string, operator: ConditionGroupOperatorType) => void;
124
+ updateGroupOperator: (id: string, operator: ConditionGroupOperatorType) => void;
121
125
 
122
126
  // ============================================================
123
127
  // REMOVE & ACCESS
@@ -127,22 +131,22 @@ export interface UseFilterReturnType {
127
131
  * Remove a condition or group by id
128
132
  * @param id - The id of the item to remove
129
133
  */
130
- remove: (id: string) => void;
134
+ removeCondition: (id: string) => void;
131
135
 
132
136
  /**
133
137
  * Get a condition or group by id
134
138
  * @param id - The id to look up
135
139
  * @returns The item or undefined if not found
136
140
  */
137
- get: (id: string) => ConditionType | ConditionGroupType | undefined;
141
+ getCondition: (id: string) => ConditionType | ConditionGroupType | undefined;
138
142
 
139
143
  // ============================================================
140
144
  // UTILITY
141
145
  // ============================================================
142
146
 
143
147
  /** Clear all conditions */
144
- clear: () => void;
148
+ clearAllConditions: () => void;
145
149
 
146
150
  /** Set the root operator for combining conditions */
147
- setOperator: (op: ConditionGroupOperatorType) => void;
151
+ setRootOperator: (op: ConditionGroupOperatorType) => void;
148
152
  }