@umituz/react-native-tanstack 1.0.0 → 1.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-tanstack",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "TanStack Query configuration and utilities for React Native apps - Pre-configured QueryClient with AsyncStorage persistence",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/index.ts CHANGED
@@ -72,6 +72,14 @@ export {
72
72
  type OptimisticUpdateConfig,
73
73
  } from './presentation/hooks/useOptimisticUpdate';
74
74
 
75
+ // Presentation - Utils
76
+ export {
77
+ createConditionalRetry,
78
+ createQuotaAwareRetry,
79
+ type RetryFunction,
80
+ type ErrorChecker,
81
+ } from './presentation/utils/RetryHelpers';
82
+
75
83
  // Re-export TanStack Query core for convenience
76
84
  export {
77
85
  useQuery,
@@ -59,6 +59,11 @@ export const CacheStrategies: Record<CacheStrategyType, CacheConfig> = {
59
59
  },
60
60
  };
61
61
 
62
+ /**
63
+ * Retry function type
64
+ */
65
+ export type RetryFunction = (failureCount: number, error: Error) => boolean;
66
+
62
67
  /**
63
68
  * QueryClient factory options
64
69
  */
@@ -77,9 +82,10 @@ export interface QueryClientFactoryOptions {
77
82
 
78
83
  /**
79
84
  * Default retry configuration
85
+ * Can be a boolean, number, or custom retry function
80
86
  * @default 3
81
87
  */
82
- defaultRetry?: boolean | number;
88
+ defaultRetry?: boolean | number | RetryFunction;
83
89
 
84
90
  /**
85
91
  * Enable development mode logging
@@ -109,7 +109,7 @@ export function TanstackProvider({
109
109
  persisterOptions,
110
110
  onPersistSuccess,
111
111
  onPersistError,
112
- }: TanstackProviderProps): JSX.Element {
112
+ }: TanstackProviderProps): React.ReactElement {
113
113
  // Create QueryClient if not provided
114
114
  const [queryClient] = React.useState(() => providedQueryClient ?? createQueryClient(queryClientOptions));
115
115
 
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Retry Helpers
3
+ * Presentation layer - Utility functions for retry logic
4
+ *
5
+ * General-purpose retry helpers for any React Native app
6
+ */
7
+
8
+ /**
9
+ * Retry function type for TanStack Query
10
+ */
11
+ export type RetryFunction = (failureCount: number, error: Error) => boolean;
12
+
13
+ /**
14
+ * Error checker function type
15
+ */
16
+ export type ErrorChecker = (error: unknown) => boolean;
17
+
18
+ /**
19
+ * Creates a retry function that stops retrying on specific errors
20
+ *
21
+ * @param shouldNotRetry - Function to check if error should NOT be retried
22
+ * @param maxRetries - Maximum number of retries (default: 1)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const isQuotaError = (error: unknown) => {
27
+ * return error instanceof Error && error.message.includes('quota');
28
+ * };
29
+ *
30
+ * const retryFn = createConditionalRetry(isQuotaError, 1);
31
+ * ```
32
+ */
33
+ export function createConditionalRetry(
34
+ shouldNotRetry: ErrorChecker,
35
+ maxRetries = 1,
36
+ ): RetryFunction {
37
+ return (failureCount: number, error: Error) => {
38
+ // Don't retry if error matches condition
39
+ if (shouldNotRetry(error)) {
40
+ return false;
41
+ }
42
+
43
+ // Retry up to maxRetries times
44
+ return failureCount < maxRetries;
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Creates a quota-aware retry function
50
+ * Stops retrying on quota errors, retries other errors
51
+ *
52
+ * @param isQuotaError - Function to check if error is quota-related
53
+ * @param maxRetries - Maximum number of retries (default: 1)
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * import { isQuotaError } from '@umituz/react-native-firestore';
58
+ *
59
+ * const retryFn = createQuotaAwareRetry(isQuotaError);
60
+ * ```
61
+ */
62
+ export function createQuotaAwareRetry(
63
+ isQuotaError: ErrorChecker,
64
+ maxRetries = 1,
65
+ ): RetryFunction {
66
+ return createConditionalRetry(isQuotaError, maxRetries);
67
+ }