@flavoai/fastfold
Version:
Zero-boilerplate backend for React apps with auto-generated CRUD and declarative security
151 lines • 6.13 kB
TypeScript
import { QueryClient } from '@tanstack/react-query';
import { QueryParams } from '../types';
interface FastfoldClientConfig {
baseUrl: string;
headers?: Record<string, string>;
}
/**
* Configure the Fastfold client
*/
export declare function configureFastfold(config: Partial<FastfoldClientConfig>): void;
/**
* Set authentication token for all requests
*/
export declare function setAuthToken(token: string): void;
/**
* Clear authentication token
*/
export declare function clearAuthToken(): void;
/**
* Generate consistent query keys for React Query
*/
export declare const queryKeys: {
all: (tableName: string) => readonly [string];
lists: (tableName: string) => readonly [string, "list"];
list: (tableName: string, params: QueryParams) => readonly [string, "list", QueryParams];
details: (tableName: string) => readonly [string, "detail"];
detail: (tableName: string, id: string | number) => readonly [string, "detail", string | number];
};
interface UseQueryOptions {
enabled?: boolean;
staleTime?: number;
cacheTime?: number;
refetchOnWindowFocus?: boolean;
refetchInterval?: number;
}
/**
* 📋 QUERY HOOK - Fetch multiple records with React Query
*
* @param tableName The table to query
* @param params Query parameters (where, orderBy, limit, with, etc.)
* @param options React Query options
*
* @example
* const { data: posts, isLoading, error } = useQuery('posts', {
* where: { published: true },
* with: { author: true }
* });
*/
export declare function useFastfoldQuery<T = any>(tableName: string, params?: QueryParams, options?: UseQueryOptions): import("@tanstack/react-query").UseQueryResult<T[], Error>;
/**
* 🎯 QUERY ONE HOOK - Fetch single record by ID with React Query
*
* @param tableName The table to query
* @param id The record ID
* @param params Additional query parameters (with, etc.)
* @param options React Query options
*
* @example
* const { data: post } = useQueryOne('posts', '123', {
* with: { author: true, comments: true }
* });
*/
export declare function useFastfoldQueryOne<T = any>(tableName: string, id: string | number, params?: Omit<QueryParams, 'where' | 'limit' | 'offset'>, options?: UseQueryOptions): import("@tanstack/react-query").UseQueryResult<import("@tanstack/react-query").NoInfer<T>, Error>;
interface UseMutationOptions<TData = any, TVariables = any> {
onSuccess?: (data: TData, variables: TVariables) => void;
onError?: (error: Error, variables: TVariables) => void;
onSettled?: (data: TData | undefined, error: Error | null, variables: TVariables) => void;
invalidateQueries?: boolean;
updateCache?: (data: TData, variables: TVariables, queryClient: QueryClient) => void;
}
/**
* ✏️ CREATE HOOK - Create new records with automatic cache invalidation
*
* @param tableName The table to create records in
* @param options Mutation options
*
* @example
* const createPost = useCreate('posts', {
* onSuccess: (newPost) => console.log('Created:', newPost)
* });
*
* await createPost.mutateAsync({ title: 'Hello', content: 'World' });
*/
export declare function useFastfoldCreate<TData = any, TVariables = any>(tableName: string, options?: UseMutationOptions<TData, TVariables>): import("@tanstack/react-query").UseMutationResult<TData, Error, TVariables, unknown>;
/**
* 🔄 UPDATE HOOK - Update existing records with automatic cache invalidation
*
* @param tableName The table to update records in
* @param options Mutation options
*
* @example
* const updatePost = useUpdate('posts', {
* onSuccess: (updatedPost) => console.log('Updated:', updatedPost)
* });
*
* await updatePost.mutateAsync({ id: '123', data: { title: 'New Title' } });
*/
export declare function useFastfoldUpdate<TData = any, TVariables extends {
id: string | number;
data: any;
} = any>(tableName: string, options?: UseMutationOptions<TData, TVariables>): import("@tanstack/react-query").UseMutationResult<TData, Error, TVariables, unknown>;
/**
* 🗑️ DELETE HOOK - Delete records with automatic cache invalidation
*
* @param tableName The table to delete records from
* @param options Mutation options
*
* @example
* const deletePost = useDelete('posts', {
* onSuccess: () => console.log('Deleted successfully')
* });
*
* await deletePost.mutateAsync('123');
*/
export declare function useFastfoldDelete<TData = any, TVariables extends string | number = string | number>(tableName: string, options?: UseMutationOptions<TData, TVariables>): import("@tanstack/react-query").UseMutationResult<TData, Error, TVariables, unknown>;
export declare const useQuery: typeof useFastfoldQuery;
export declare const useQueryOne: typeof useFastfoldQueryOne;
export declare const useCreate: typeof useFastfoldCreate;
export declare const useUpdate: typeof useFastfoldUpdate;
export declare const useDelete: typeof useFastfoldDelete;
/**
* 🔄 INVALIDATE CACHE - Manually invalidate queries
*
* @example
* const invalidate = useInvalidateCache();
* invalidate.table('posts'); // Invalidate all posts queries
* invalidate.record('posts', '123'); // Invalidate specific post
*/
export declare function useInvalidateCache(): {
table: (tableName: string) => void;
lists: (tableName: string) => void;
record: (tableName: string, id: string | number) => void;
all: () => void;
};
/**
* 📝 UPDATE CACHE - Manually update cached data
*
* @example
* const updateCache = useUpdateCache();
* updateCache.record('posts', '123', updatedPost);
* updateCache.addToList('posts', {}, newPost);
*/
export declare function useUpdateCache(): {
record: <T>(tableName: string, id: string | number, data: T) => void;
addToList: <T>(tableName: string, params: QueryParams, newItem: T) => void;
removeFromList: (tableName: string, params: QueryParams, id: string | number) => void;
updateInList: <T>(tableName: string, params: QueryParams, id: string | number, data: T) => void;
};
export { FastfoldProvider, createFastfoldQueryClient } from './provider';
export * from '../types';
//# sourceMappingURL=react-query.d.ts.map