@flavoai/fastfold
Version:
Zero-boilerplate backend for React apps with auto-generated CRUD and declarative security
72 lines • 2.88 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
// Optional devtools import
let ReactQueryDevtools = null;
try {
ReactQueryDevtools = require('@tanstack/react-query-devtools').ReactQueryDevtools;
}
catch (e) {
// Devtools not installed, that's okay
}
// ============================================================================
// FASTFOLD QUERY CLIENT
// ============================================================================
/**
* Create a pre-configured QueryClient optimized for Fastfold
*/
export function createFastfoldQueryClient(options = {}) {
return new QueryClient({
defaultOptions: {
queries: {
staleTime: options.staleTime ?? 5 * 60 * 1000, // 5 minutes
gcTime: options.gcTime ?? 10 * 60 * 1000, // 10 minutes
refetchOnWindowFocus: options.refetchOnWindowFocus ?? false,
retry: options.retry ?? 3,
retryDelay: options.retryDelay ?? ((attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000)),
},
mutations: {
retry: options.retry ?? 1,
retryDelay: options.retryDelay ?? 1000,
},
},
});
}
/**
* 🚀 FASTFOLD PROVIDER - Wrap your app with this to enable Fastfold hooks
*
* @example
* function App() {
* return (
* <FastfoldProvider>
* <YourApp />
* </FastfoldProvider>
* );
* }
*
* @example With custom configuration and devtools
* const queryClient = createFastfoldQueryClient({
* staleTime: 10 * 60 * 1000, // 10 minutes
* refetchOnWindowFocus: true
* });
*
* function App() {
* return (
* <FastfoldProvider
* queryClient={queryClient}
* showDevtools={true} // Opt-in to show devtools
* >
* <YourApp />
* </FastfoldProvider>
* );
* }
*/
export function FastfoldProvider({ children, queryClient, showDevtools = false, // Disabled by default
devtoolsOptions = {} }) {
const client = queryClient || createFastfoldQueryClient();
return (_jsxs(QueryClientProvider, { client: client, children: [children, showDevtools && ReactQueryDevtools && (_jsx(ReactQueryDevtools, { initialIsOpen: devtoolsOptions.initialIsOpen ?? false, position: devtoolsOptions.position ?? 'bottom-right' })), showDevtools && !ReactQueryDevtools && (console.warn('FastfoldProvider: showDevtools=true but @tanstack/react-query-devtools is not installed. Install it with: npm install @tanstack/react-query-devtools'))] }));
}
// ============================================================================
// HOOKS FOR QUERY CLIENT ACCESS
// ============================================================================
export { useQueryClient } from '@tanstack/react-query';
//# sourceMappingURL=provider.js.map