@@ -13,20 +13,47 @@ import { useClient } from './context';
1313
1414/**
1515 * Query options for useQuery hook
16+ *
17+ * Supports both **canonical** (Spec protocol) and **legacy** field names.
18+ * Canonical names are preferred; legacy names are accepted for backward
19+ * compatibility and will be removed in a future major release.
20+ *
21+ * | Canonical | Legacy (deprecated) |
22+ * |-----------|---------------------|
23+ * | `where` | `filters` |
24+ * | `fields` | `select` |
25+ * | `orderBy` | `sort` |
26+ * | `limit` | `top` |
27+ * | `offset` | `skip` |
1628 */
1729export interface UseQueryOptions < T = any > {
1830 /** Query AST or simplified query options */
1931 query ?: Partial < QueryAST > ;
20- /** Simple field selection */
32+
33+ // ── Canonical (Spec protocol) field names ──────────────────────────
34+ /** Filter conditions (WHERE clause). */
35+ where ?: FilterCondition ;
36+ /** Fields to retrieve (SELECT clause). */
37+ fields ?: string [ ] ;
38+ /** Sort definition (ORDER BY clause). */
39+ orderBy ?: string | string [ ] ;
40+ /** Maximum number of records to return (LIMIT). */
41+ limit ?: number ;
42+ /** Number of records to skip (OFFSET). */
43+ offset ?: number ;
44+
45+ // ── Legacy field names (deprecated) ────────────────────────────────
46+ /** @deprecated Use `fields` instead. */
2147 select ?: string [ ] ;
22- /** Simple filters */
48+ /** @deprecated Use `where` instead. */
2349 filters ?: FilterCondition ;
24- /** Sort configuration */
50+ /** @deprecated Use `orderBy` instead. */
2551 sort ?: string | string [ ] ;
26- /** Limit results */
52+ /** @deprecated Use `limit` instead. */
2753 top ?: number ;
28- /** Skip results (for pagination) */
54+ /** @deprecated Use `offset` instead. */
2955 skip ?: number ;
56+
3057 /** Enable/disable automatic query execution */
3158 enabled ?: boolean ;
3259 /** Refetch interval in milliseconds */
@@ -60,9 +87,9 @@ export interface UseQueryResult<T = any> {
6087 * ```tsx
6188 * function TaskList() {
6289 * const { data, isLoading, error, refetch } = useQuery('todo_task', {
63- * select : ['id', 'subject', 'priority'],
64- * sort : ['-created_at'],
65- * top : 20
90+ * fields : ['id', 'subject', 'priority'],
91+ * orderBy : ['-created_at'],
92+ * limit : 20
6693 * });
6794 *
6895 * if (isLoading) return <div>Loading...</div>;
@@ -91,17 +118,23 @@ export function useQuery<T = any>(
91118
92119 const {
93120 query,
94- select,
95- filters,
96- sort,
97- top,
98- skip,
121+ // Canonical names take precedence over legacy names
122+ where, fields, orderBy, limit, offset,
123+ // Legacy names (deprecated fallbacks)
124+ select, filters, sort, top, skip,
99125 enabled = true ,
100126 refetchInterval,
101127 onSuccess,
102128 onError
103129 } = options ;
104130
131+ // Resolve canonical vs legacy: canonical wins when both are provided
132+ const resolvedFields = fields ?? select ;
133+ const resolvedWhere = where ?? filters ;
134+ const resolvedSort = orderBy ?? sort ;
135+ const resolvedLimit = limit ?? top ;
136+ const resolvedOffset = offset ?? skip ;
137+
105138 const fetchData = useCallback ( async ( isRefetch = false ) => {
106139 if ( ! enabled ) return ;
107140
@@ -119,13 +152,13 @@ export function useQuery<T = any>(
119152 // Use advanced query API
120153 result = await client . data . query < T > ( object , query ) ;
121154 } else {
122- // Use simplified find API
155+ // Use canonical QueryOptionsV2 for the find call
123156 result = await client . data . find < T > ( object , {
124- select ,
125- filters : filters as any ,
126- sort ,
127- top ,
128- skip
157+ where : resolvedWhere as any ,
158+ fields : resolvedFields ,
159+ orderBy : resolvedSort ,
160+ limit : resolvedLimit ,
161+ offset : resolvedOffset ,
129162 } ) ;
130163 }
131164
@@ -139,7 +172,7 @@ export function useQuery<T = any>(
139172 setIsLoading ( false ) ;
140173 setIsRefetching ( false ) ;
141174 }
142- } , [ client , object , query , select , filters , sort , top , skip , enabled , onSuccess , onError ] ) ;
175+ } , [ client , object , query , resolvedFields , resolvedWhere , resolvedSort , resolvedLimit , resolvedOffset , enabled , onSuccess , onError ] ) ;
143176
144177 // Initial fetch and dependency-based refetch
145178 useEffect ( ( ) => {
@@ -319,7 +352,7 @@ export function useMutation<TData = any, TVariables = any>(
319352/**
320353 * Pagination options for usePagination hook
321354 */
322- export interface UsePaginationOptions < T = any > extends Omit < UseQueryOptions < T > , 'top' | 'skip' > {
355+ export interface UsePaginationOptions < T = any > extends Omit < UseQueryOptions < T > , 'top' | 'skip' | 'limit' | 'offset' > {
323356 /** Page size */
324357 pageSize ?: number ;
325358 /** Initial page (1-based) */
@@ -365,7 +398,7 @@ export interface UsePaginationResult<T = any> extends UseQueryResult<T> {
365398 * hasPreviousPage
366399 * } = usePagination('todo_task', {
367400 * pageSize: 10,
368- * sort : ['-created_at']
401+ * orderBy : ['-created_at']
369402 * });
370403 *
371404 * return (
@@ -388,8 +421,8 @@ export function usePagination<T = any>(
388421
389422 const queryResult = useQuery < T > ( object , {
390423 ...queryOptions ,
391- top : pageSize ,
392- skip : ( page - 1 ) * pageSize
424+ limit : pageSize ,
425+ offset : ( page - 1 ) * pageSize
393426 } ) ;
394427
395428 const totalCount = queryResult . data ?. total || 0 ;
@@ -430,7 +463,7 @@ export function usePagination<T = any>(
430463/**
431464 * Infinite query options for useInfiniteQuery hook
432465 */
433- export interface UseInfiniteQueryOptions < T = any > extends Omit < UseQueryOptions < T > , 'skip' > {
466+ export interface UseInfiniteQueryOptions < T = any > extends Omit < UseQueryOptions < T > , 'skip' | 'offset' > {
434467 /** Page size for each fetch */
435468 pageSize ?: number ;
436469 /** Get next page parameter */
@@ -473,7 +506,7 @@ export interface UseInfiniteQueryResult<T = any> {
473506 * isFetchingNextPage
474507 * } = useInfiniteQuery('todo_task', {
475508 * pageSize: 20,
476- * sort : ['-created_at']
509+ * orderBy : ['-created_at']
477510 * });
478511 *
479512 * return (
@@ -498,14 +531,20 @@ export function useInfiniteQuery<T = any>(
498531 pageSize = 20 ,
499532 // getNextPageParam is reserved for future use
500533 query,
501- select,
502- filters,
503- sort,
534+ // Canonical names take precedence over legacy names
535+ where, fields, orderBy,
536+ // Legacy names (deprecated fallbacks)
537+ select, filters, sort,
504538 enabled = true ,
505539 onSuccess,
506540 onError
507541 } = options ;
508542
543+ // Resolve canonical vs legacy: canonical wins
544+ const resolvedFields = fields ?? select ;
545+ const resolvedWhere = where ?? filters ;
546+ const resolvedSort = orderBy ?? sort ;
547+
509548 const [ pages , setPages ] = useState < PaginatedResult < T > [ ] > ( [ ] ) ;
510549 const [ isLoading , setIsLoading ] = useState ( true ) ;
511550 const [ isFetchingNextPage , setIsFetchingNextPage ] = useState ( false ) ;
@@ -531,11 +570,11 @@ export function useInfiniteQuery<T = any>(
531570 } ) ;
532571 } else {
533572 result = await client . data . find < T > ( object , {
534- select ,
535- filters : filters as any ,
536- sort ,
537- top : pageSize ,
538- skip
573+ where : resolvedWhere as any ,
574+ fields : resolvedFields ,
575+ orderBy : resolvedSort ,
576+ limit : pageSize ,
577+ offset : skip ,
539578 } ) ;
540579 }
541580
@@ -559,7 +598,7 @@ export function useInfiniteQuery<T = any>(
559598 setIsLoading ( false ) ;
560599 setIsFetchingNextPage ( false ) ;
561600 }
562- } , [ client , object , query , select , filters , sort , pageSize , onSuccess , onError ] ) ;
601+ } , [ client , object , query , resolvedFields , resolvedWhere , resolvedSort , pageSize , onSuccess , onError ] ) ;
563602
564603 // Initial fetch
565604 useEffect ( ( ) => {
0 commit comments