@umituz/react-native-design-system 4.23.80 → 4.23.81
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 +1 -1
- package/src/atoms/AtomicInput.tsx +11 -48
- package/src/atoms/AtomicPicker.tsx +19 -94
- package/src/atoms/EmptyState.tsx +1 -1
- package/src/atoms/icon/AtomicIcon.tsx +0 -1
- package/src/atoms/icon/iconStore.ts +0 -2
- package/src/atoms/picker/components/PickerModal.tsx +40 -121
- package/src/device/infrastructure/services/PersistentDeviceIdService.ts +0 -4
- package/src/device/presentation/hooks/useDeviceInfo.ts +55 -149
- package/src/haptics/infrastructure/services/HapticService.ts +0 -1
- package/src/image/index.ts +2 -1
- package/src/image/presentation/hooks/useImageBatch.ts +2 -1
- package/src/infinite-scroll/presentation/components/infinite-scroll-list.tsx +1 -1
- package/src/infinite-scroll/presentation/hooks/pagination.helper.ts +0 -5
- package/src/infinite-scroll/presentation/hooks/useInfiniteScroll.ts +4 -54
- package/src/init/createAppInitializer.ts +0 -1
- package/src/init/env/createEnvConfig.ts +0 -1
- package/src/init/useAppInitialization.ts +0 -1
- package/src/layouts/ScreenHeader/ScreenHeader.tsx +1 -1
- package/src/media/infrastructure/services/CardMediaOptimizerService.ts +0 -1
- package/src/media/infrastructure/services/CardMediaUploadService.ts +0 -1
- package/src/media/presentation/hooks/useCardMediaGeneration.ts +1 -1
- package/src/media/presentation/hooks/useCardMediaUpload.ts +1 -1
- package/src/media/presentation/hooks/useCardMediaValidation.ts +1 -1
- package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +1 -1
- package/src/media/presentation/hooks/useMedia.ts +0 -1
- package/src/media/presentation/hooks/useMediaGeneration.ts +1 -1
- package/src/media/presentation/hooks/useMediaUpload.ts +1 -1
- package/src/media/presentation/hooks/useMediaValidation.ts +1 -1
- package/src/media/presentation/hooks/useMultimediaFlashcard.ts +1 -1
- package/src/molecules/BaseModal.tsx +1 -3
- package/src/molecules/ConfirmationModalContent.tsx +1 -1
- package/src/molecules/ConfirmationModalMain.tsx +1 -1
- package/src/molecules/bottom-sheet/components/BottomSheetModal.tsx +0 -3
- package/src/molecules/bottom-sheet/components/filter/FilterBottomSheet.tsx +100 -179
- package/src/molecules/calendar/infrastructure/stores/useCalendarEvents.ts +0 -1
- package/src/molecules/confirmation-modal/useConfirmationModal.ts +1 -1
- package/src/molecules/countdown/components/Countdown.tsx +1 -1
- package/src/molecules/navigation/StackNavigator.tsx +0 -1
- package/src/molecules/navigation/TabsNavigator.tsx +0 -1
- package/src/molecules/navigation/utils/AppNavigation.ts +0 -8
- package/src/molecules/splash/components/SplashScreen.tsx +0 -4
- package/src/offline/infrastructure/events/NetworkEvents.ts +0 -1
- package/src/offline/infrastructure/utils/healthCheck.ts +0 -5
- package/src/offline/presentation/hooks/useOffline.ts +0 -1
- package/src/offline/presentation/hooks/useOfflineWithMutations.ts +0 -2
- package/src/onboarding/index.ts +0 -1
- package/src/onboarding/infrastructure/hooks/useOnboardingNavigation.ts +0 -1
- package/src/onboarding/infrastructure/storage/actions/storageHelpers.ts +0 -2
- package/src/onboarding/presentation/hooks/useOnboardingScreenHandlers.ts +0 -2
- package/src/onboarding/presentation/hooks/useOnboardingScreenState.ts +0 -1
- package/src/onboarding/presentation/screens/OnboardingScreen.tsx +0 -3
- package/src/organisms/FormContainer.tsx +1 -1
- package/src/services/api/ApiClient.ts +42 -135
- package/src/storage/cache/domain/Cache.ts +0 -2
- package/src/storage/cache/infrastructure/TTLCache.ts +0 -3
- package/src/storage/domain/utils/devUtils.ts +0 -3
- package/src/storage/infrastructure/adapters/StorageService.ts +0 -3
- package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +0 -1
- package/src/tanstack/domain/config/QueryClientAccessor.ts +0 -1
- package/src/tanstack/domain/repositories/BaseRepository.ts +4 -4
- package/src/tanstack/domain/repositories/IBaseRepository.ts +3 -5
- package/src/tanstack/domain/repositories/RepositoryFactory.ts +0 -2
- package/src/tanstack/domain/repositories/mixins/repositoryInvalidationMethods.ts +10 -11
- package/src/tanstack/domain/repositories/mixins/repositoryQueryMethods.ts +11 -11
- package/src/tanstack/domain/utils/ErrorHelpers.ts +0 -1
- package/src/tanstack/infrastructure/config/PersisterConfig.ts +0 -7
- package/src/tanstack/infrastructure/config/QueryClientConfig.ts +0 -1
- package/src/tanstack/infrastructure/monitoring/DevMonitorLogger.ts +0 -6
- package/src/tanstack/presentation/hooks/useInvalidateQueries.ts +0 -4
- package/src/tanstack/presentation/hooks/useOptimisticUpdate.ts +0 -2
- package/src/tanstack/presentation/hooks/usePrefetch.ts +18 -119
- package/src/theme/core/CustomColors.ts +4 -122
- package/src/theme/infrastructure/storage/ThemeStorage.ts +0 -1
- package/src/typography/presentation/utils/textColorUtils.ts +36 -163
- package/src/tanstack/presentation/hooks/utils/prefetchLogger.ts +0 -27
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
ApiClientConfig,
|
|
8
8
|
ApiRequestConfig,
|
|
9
9
|
ApiResponse,
|
|
10
|
+
HttpMethod,
|
|
10
11
|
} from './types/ApiTypes';
|
|
11
12
|
import {
|
|
12
13
|
buildURL,
|
|
@@ -20,6 +21,20 @@ import {
|
|
|
20
21
|
fetchWithTimeout,
|
|
21
22
|
} from './utils/responseHandler';
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Applies interceptors to a value
|
|
26
|
+
*/
|
|
27
|
+
async function applyInterceptors<T>(
|
|
28
|
+
value: T,
|
|
29
|
+
interceptors: Array<(value: T) => T | Promise<T>> | undefined
|
|
30
|
+
): Promise<T> {
|
|
31
|
+
let result = value;
|
|
32
|
+
for (const interceptor of interceptors || []) {
|
|
33
|
+
result = await interceptor(result);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
export class ApiClient {
|
|
24
39
|
private config: ApiClientConfig;
|
|
25
40
|
|
|
@@ -32,19 +47,11 @@ export class ApiClient {
|
|
|
32
47
|
|
|
33
48
|
/**
|
|
34
49
|
* Makes an HTTP request
|
|
35
|
-
*
|
|
36
|
-
* @param requestConfig - Request configuration
|
|
37
|
-
* @returns API response
|
|
38
50
|
*/
|
|
39
51
|
async request<T>(requestConfig: ApiRequestConfig): Promise<ApiResponse<T>> {
|
|
40
52
|
try {
|
|
41
|
-
|
|
42
|
-
let config = requestConfig;
|
|
43
|
-
for (const interceptor of this.config.requestInterceptors || []) {
|
|
44
|
-
config = await interceptor(config);
|
|
45
|
-
}
|
|
53
|
+
const config = await applyInterceptors(requestConfig, this.config.requestInterceptors);
|
|
46
54
|
|
|
47
|
-
// Build request
|
|
48
55
|
const fullURL = config.url.startsWith('http')
|
|
49
56
|
? config.url
|
|
50
57
|
: buildURL(this.config.baseURL, config.url, config.params);
|
|
@@ -54,176 +61,74 @@ export class ApiClient {
|
|
|
54
61
|
headers: { ...this.config.headers, ...config.headers },
|
|
55
62
|
});
|
|
56
63
|
|
|
57
|
-
// Make request with timeout
|
|
58
64
|
const response = await fetchWithTimeout(
|
|
59
65
|
fullURL,
|
|
60
66
|
fetchOptions,
|
|
61
67
|
config.timeout || this.config.timeout || 30000
|
|
62
68
|
);
|
|
63
69
|
|
|
64
|
-
// Check for HTTP errors
|
|
65
70
|
if (!isSuccessfulResponse(response)) {
|
|
66
71
|
const error = await handleHttpError(response);
|
|
67
|
-
|
|
68
|
-
// Apply error interceptors
|
|
69
|
-
let finalError = error;
|
|
70
|
-
for (const interceptor of this.config.errorInterceptors || []) {
|
|
71
|
-
finalError = await interceptor(finalError);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw finalError;
|
|
72
|
+
throw await applyInterceptors(error, this.config.errorInterceptors);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
// Parse response
|
|
78
75
|
let parsedResponse = await parseResponse<T>(response);
|
|
79
|
-
|
|
80
|
-
// Apply response interceptors
|
|
81
|
-
for (const interceptor of this.config.responseInterceptors || []) {
|
|
82
|
-
parsedResponse = await interceptor(parsedResponse);
|
|
83
|
-
}
|
|
76
|
+
parsedResponse = await applyInterceptors(parsedResponse, this.config.responseInterceptors);
|
|
84
77
|
|
|
85
78
|
return parsedResponse;
|
|
86
79
|
} catch (error) {
|
|
87
|
-
// Handle network errors
|
|
88
80
|
const apiError = handleNetworkError(error);
|
|
89
|
-
|
|
90
|
-
// Apply error interceptors
|
|
91
|
-
let finalError = apiError;
|
|
92
|
-
for (const interceptor of this.config.errorInterceptors || []) {
|
|
93
|
-
finalError = await interceptor(finalError);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
throw finalError;
|
|
81
|
+
throw await applyInterceptors(apiError, this.config.errorInterceptors);
|
|
97
82
|
}
|
|
98
83
|
}
|
|
99
84
|
|
|
100
85
|
/**
|
|
101
|
-
* Makes a
|
|
102
|
-
*
|
|
103
|
-
* @param url - Request URL
|
|
104
|
-
* @param params - Query parameters
|
|
105
|
-
* @param config - Additional config
|
|
106
|
-
* @returns API response
|
|
86
|
+
* Makes an HTTP request with a specific method
|
|
107
87
|
*/
|
|
108
|
-
|
|
88
|
+
private requestWithMethod<T>(
|
|
89
|
+
method: HttpMethod,
|
|
109
90
|
url: string,
|
|
110
|
-
|
|
91
|
+
bodyOrParams?: any,
|
|
111
92
|
config?: Partial<ApiRequestConfig>
|
|
112
93
|
): Promise<ApiResponse<T>> {
|
|
113
|
-
|
|
94
|
+
const requestData: ApiRequestConfig = {
|
|
114
95
|
url,
|
|
115
|
-
method
|
|
116
|
-
params,
|
|
96
|
+
method,
|
|
97
|
+
...(method === 'GET' || method === 'DELETE' ? { params: bodyOrParams } : { body: bodyOrParams }),
|
|
117
98
|
...config,
|
|
118
|
-
}
|
|
99
|
+
};
|
|
100
|
+
return this.request<T>(requestData);
|
|
119
101
|
}
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*
|
|
124
|
-
* @param url - Request URL
|
|
125
|
-
* @param body - Request body
|
|
126
|
-
* @param config - Additional config
|
|
127
|
-
* @returns API response
|
|
128
|
-
*/
|
|
129
|
-
async post<T>(
|
|
130
|
-
url: string,
|
|
131
|
-
body?: any,
|
|
132
|
-
config?: Partial<ApiRequestConfig>
|
|
133
|
-
): Promise<ApiResponse<T>> {
|
|
134
|
-
return this.request<T>({
|
|
135
|
-
url,
|
|
136
|
-
method: 'POST',
|
|
137
|
-
body,
|
|
138
|
-
...config,
|
|
139
|
-
});
|
|
103
|
+
get<T>(url: string, params?: Record<string, string | number | boolean | undefined>, config?: Partial<ApiRequestConfig>): Promise<ApiResponse<T>> {
|
|
104
|
+
return this.requestWithMethod<T>('GET', url, params, config);
|
|
140
105
|
}
|
|
141
106
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
145
|
-
* @param url - Request URL
|
|
146
|
-
* @param body - Request body
|
|
147
|
-
* @param config - Additional config
|
|
148
|
-
* @returns API response
|
|
149
|
-
*/
|
|
150
|
-
async put<T>(
|
|
151
|
-
url: string,
|
|
152
|
-
body?: any,
|
|
153
|
-
config?: Partial<ApiRequestConfig>
|
|
154
|
-
): Promise<ApiResponse<T>> {
|
|
155
|
-
return this.request<T>({
|
|
156
|
-
url,
|
|
157
|
-
method: 'PUT',
|
|
158
|
-
body,
|
|
159
|
-
...config,
|
|
160
|
-
});
|
|
107
|
+
post<T>(url: string, body?: any, config?: Partial<ApiRequestConfig>): Promise<ApiResponse<T>> {
|
|
108
|
+
return this.requestWithMethod<T>('POST', url, body, config);
|
|
161
109
|
}
|
|
162
110
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
*
|
|
166
|
-
* @param url - Request URL
|
|
167
|
-
* @param body - Request body
|
|
168
|
-
* @param config - Additional config
|
|
169
|
-
* @returns API response
|
|
170
|
-
*/
|
|
171
|
-
async patch<T>(
|
|
172
|
-
url: string,
|
|
173
|
-
body?: any,
|
|
174
|
-
config?: Partial<ApiRequestConfig>
|
|
175
|
-
): Promise<ApiResponse<T>> {
|
|
176
|
-
return this.request<T>({
|
|
177
|
-
url,
|
|
178
|
-
method: 'PATCH',
|
|
179
|
-
body,
|
|
180
|
-
...config,
|
|
181
|
-
});
|
|
111
|
+
put<T>(url: string, body?: any, config?: Partial<ApiRequestConfig>): Promise<ApiResponse<T>> {
|
|
112
|
+
return this.requestWithMethod<T>('PUT', url, body, config);
|
|
182
113
|
}
|
|
183
114
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*/
|
|
191
|
-
async delete<T>(
|
|
192
|
-
url: string,
|
|
193
|
-
config?: Partial<ApiRequestConfig>
|
|
194
|
-
): Promise<ApiResponse<T>> {
|
|
195
|
-
return this.request<T>({
|
|
196
|
-
url,
|
|
197
|
-
method: 'DELETE',
|
|
198
|
-
...config,
|
|
199
|
-
});
|
|
115
|
+
patch<T>(url: string, body?: any, config?: Partial<ApiRequestConfig>): Promise<ApiResponse<T>> {
|
|
116
|
+
return this.requestWithMethod<T>('PATCH', url, body, config);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
delete<T>(url: string, config?: Partial<ApiRequestConfig>): Promise<ApiResponse<T>> {
|
|
120
|
+
return this.requestWithMethod<T>('DELETE', url, undefined, config);
|
|
200
121
|
}
|
|
201
122
|
|
|
202
|
-
/**
|
|
203
|
-
* Updates base configuration
|
|
204
|
-
*
|
|
205
|
-
* @param updates - Configuration updates
|
|
206
|
-
*/
|
|
207
123
|
updateConfig(updates: Partial<ApiClientConfig>): void {
|
|
208
124
|
this.config = { ...this.config, ...updates };
|
|
209
125
|
}
|
|
210
126
|
|
|
211
|
-
/**
|
|
212
|
-
* Gets current configuration
|
|
213
|
-
*
|
|
214
|
-
* @returns Current configuration
|
|
215
|
-
*/
|
|
216
127
|
getConfig(): ApiClientConfig {
|
|
217
128
|
return { ...this.config };
|
|
218
129
|
}
|
|
219
130
|
}
|
|
220
131
|
|
|
221
|
-
/**
|
|
222
|
-
* Creates a singleton API client instance
|
|
223
|
-
*
|
|
224
|
-
* @param config - API client configuration
|
|
225
|
-
* @returns API client instance
|
|
226
|
-
*/
|
|
227
132
|
let apiClientInstance: ApiClient | null = null;
|
|
228
133
|
|
|
229
134
|
export function createApiClient(config: ApiClientConfig): ApiClient {
|
|
@@ -240,3 +145,5 @@ export function getApiClient(): ApiClient | null {
|
|
|
240
145
|
export function resetApiClient(): void {
|
|
241
146
|
apiClientInstance = null;
|
|
242
147
|
}
|
|
148
|
+
|
|
149
|
+
|
|
@@ -47,7 +47,6 @@ export class Cache<T = unknown> {
|
|
|
47
47
|
this.statsTracker.updateSize(this.store.size);
|
|
48
48
|
|
|
49
49
|
if (__DEV__) {
|
|
50
|
-
console.log(`Cache: Set key "${key}" with TTL ${entry.ttl}ms`);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -135,7 +134,6 @@ export class Cache<T = unknown> {
|
|
|
135
134
|
this.statsTracker.updateSize(this.store.size);
|
|
136
135
|
|
|
137
136
|
if (__DEV__) {
|
|
138
|
-
console.log(`Cache: Evicted key "${keyToEvict}" using ${strategy} strategy`);
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
if (entry) {
|
|
@@ -48,7 +48,6 @@ export class TTLCache<T = unknown> extends Cache<T> {
|
|
|
48
48
|
this.statsTracker.recordExpiration();
|
|
49
49
|
|
|
50
50
|
if (__DEV__) {
|
|
51
|
-
console.log(`TTLCache: Cleaned up ${cleanedCount} expired entries`);
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
@@ -69,7 +68,6 @@ export class TTLCache<T = unknown> extends Cache<T> {
|
|
|
69
68
|
override set(key: string, value: T, ttl?: number): void {
|
|
70
69
|
if (this.isDestroyed) {
|
|
71
70
|
if (__DEV__) {
|
|
72
|
-
console.warn('TTLCache: Attempted to set value on destroyed cache');
|
|
73
71
|
}
|
|
74
72
|
return;
|
|
75
73
|
}
|
|
@@ -79,7 +77,6 @@ export class TTLCache<T = unknown> extends Cache<T> {
|
|
|
79
77
|
override get(key: string): T | undefined {
|
|
80
78
|
if (this.isDestroyed) {
|
|
81
79
|
if (__DEV__) {
|
|
82
|
-
console.warn('TTLCache: Attempted to get value from destroyed cache');
|
|
83
80
|
}
|
|
84
81
|
return undefined;
|
|
85
82
|
}
|
|
@@ -14,7 +14,6 @@ export const isDev = (): boolean => {
|
|
|
14
14
|
*/
|
|
15
15
|
export const devWarn = (message: string, ...args: unknown[]): void => {
|
|
16
16
|
if (__DEV__) {
|
|
17
|
-
console.warn(message, ...args);
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
19
|
|
|
@@ -23,7 +22,6 @@ export const devWarn = (message: string, ...args: unknown[]): void => {
|
|
|
23
22
|
*/
|
|
24
23
|
export const devError = (message: string, ...args: unknown[]): void => {
|
|
25
24
|
if (__DEV__) {
|
|
26
|
-
console.error(message, ...args);
|
|
27
25
|
}
|
|
28
26
|
};
|
|
29
27
|
|
|
@@ -32,6 +30,5 @@ export const devError = (message: string, ...args: unknown[]): void => {
|
|
|
32
30
|
*/
|
|
33
31
|
export const devLog = (message: string, ...args: unknown[]): void => {
|
|
34
32
|
if (__DEV__) {
|
|
35
|
-
console.log(message, ...args);
|
|
36
33
|
}
|
|
37
34
|
};
|
|
@@ -22,7 +22,6 @@ export const storageService: StateStorage = {
|
|
|
22
22
|
devWarn(errorMessage, error);
|
|
23
23
|
// Also log in production for debugging
|
|
24
24
|
if (!__DEV__) {
|
|
25
|
-
console.error(errorMessage, error);
|
|
26
25
|
}
|
|
27
26
|
return null;
|
|
28
27
|
}
|
|
@@ -36,7 +35,6 @@ export const storageService: StateStorage = {
|
|
|
36
35
|
devWarn(errorMessage, error);
|
|
37
36
|
// Also log in production for debugging
|
|
38
37
|
if (!__DEV__) {
|
|
39
|
-
console.error(errorMessage, error);
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
},
|
|
@@ -49,7 +47,6 @@ export const storageService: StateStorage = {
|
|
|
49
47
|
devWarn(errorMessage, error);
|
|
50
48
|
// Also log in production for debugging
|
|
51
49
|
if (!__DEV__) {
|
|
52
|
-
console.error(errorMessage, error);
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
52
|
},
|
|
@@ -21,7 +21,6 @@ export function setGlobalQueryClient(client: QueryClient): void {
|
|
|
21
21
|
if (globalQueryClient && globalQueryClient !== client) {
|
|
22
22
|
if (__DEV__) {
|
|
23
23
|
|
|
24
|
-
console.warn(
|
|
25
24
|
'[TanStack] QueryClient instance changed. Ensure you are not creating multiple instances.',
|
|
26
25
|
);
|
|
27
26
|
}
|
|
@@ -60,8 +60,8 @@ export abstract class BaseRepository<
|
|
|
60
60
|
TCreateVariables = unknown,
|
|
61
61
|
TUpdateVariables = Partial<TData>,
|
|
62
62
|
> {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
public readonly resource: string;
|
|
64
|
+
public readonly options: RepositoryOptions;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Query key factory for this repository
|
|
@@ -77,14 +77,14 @@ export abstract class BaseRepository<
|
|
|
77
77
|
/**
|
|
78
78
|
* Get query client instance
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
public getClient(): QueryClient {
|
|
81
81
|
return getGlobalQueryClient();
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
85
|
* Get cache options for queries
|
|
86
86
|
*/
|
|
87
|
-
|
|
87
|
+
public getCacheOptions(): { staleTime: number; gcTime: number } {
|
|
88
88
|
return getCacheOptions(this.options);
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { QueryClient } from '@tanstack/react-query';
|
|
7
|
-
import type { QueryKeyFactory } from '../utils/QueryKeyFactory';
|
|
8
7
|
import type {
|
|
9
8
|
CreateParams,
|
|
10
9
|
UpdateParams,
|
|
11
10
|
ListParams,
|
|
12
|
-
RepositoryOptions,
|
|
13
11
|
} from './RepositoryTypes';
|
|
14
12
|
|
|
15
13
|
export interface IBaseRepository<TData, TCreateVariables, TUpdateVariables> {
|
|
@@ -20,15 +18,15 @@ export interface IBaseRepository<TData, TCreateVariables, TUpdateVariables> {
|
|
|
20
18
|
readonly resource: string;
|
|
21
19
|
|
|
22
20
|
/** Query key factory */
|
|
23
|
-
readonly keys: QueryKeyFactory
|
|
21
|
+
readonly keys: ReturnType<typeof import('../utils/QueryKeyFactory').createQueryKeyFactory>;
|
|
24
22
|
|
|
25
23
|
/** Cache options */
|
|
26
|
-
getCacheOptions():
|
|
24
|
+
getCacheOptions(): { staleTime: number; gcTime: number };
|
|
27
25
|
|
|
28
26
|
/** Abstract methods to be implemented by subclasses */
|
|
29
27
|
fetchAll(params?: ListParams): Promise<TData[]>;
|
|
30
28
|
fetchById(id: string | number): Promise<TData>;
|
|
31
29
|
create(data: CreateParams<TCreateVariables>): Promise<TData>;
|
|
32
|
-
update(
|
|
30
|
+
update(params: UpdateParams<TUpdateVariables>): Promise<TData>;
|
|
33
31
|
remove(id: string | number): Promise<void>;
|
|
34
32
|
}
|
|
@@ -44,7 +44,6 @@ class RepositoryFactoryClass {
|
|
|
44
44
|
if (this.repositories.has(key)) {
|
|
45
45
|
if (__DEV__) {
|
|
46
46
|
|
|
47
|
-
console.warn(
|
|
48
47
|
`[RepositoryFactory] Repository "${key}" is already registered. Overwriting.`,
|
|
49
48
|
);
|
|
50
49
|
}
|
|
@@ -83,7 +82,6 @@ class RepositoryFactoryClass {
|
|
|
83
82
|
unregister(key: string): boolean {
|
|
84
83
|
if (__DEV__ && !this.repositories.has(key)) {
|
|
85
84
|
|
|
86
|
-
console.warn(`[RepositoryFactory] Repository "${key}" is not registered.`);
|
|
87
85
|
}
|
|
88
86
|
return this.repositories.delete(key);
|
|
89
87
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Cache invalidation methods for repository operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
7
6
|
import type { IBaseRepository } from '../IBaseRepository';
|
|
8
7
|
import { matchesResource } from '../helpers/repositoryHelpers';
|
|
9
8
|
|
|
@@ -15,8 +14,8 @@ import { matchesResource } from '../helpers/repositoryHelpers';
|
|
|
15
14
|
export function invalidateAll<TData>(
|
|
16
15
|
repository: IBaseRepository<TData, unknown, unknown>
|
|
17
16
|
): Promise<void> {
|
|
18
|
-
const client =
|
|
19
|
-
const resource =
|
|
17
|
+
const client = repository.getClient();
|
|
18
|
+
const resource = repository.resource;
|
|
20
19
|
|
|
21
20
|
return client.invalidateQueries({
|
|
22
21
|
predicate: (query: { queryKey: readonly unknown[] }) => {
|
|
@@ -33,7 +32,7 @@ export function invalidateAll<TData>(
|
|
|
33
32
|
export function invalidateLists<TData>(
|
|
34
33
|
repository: IBaseRepository<TData, unknown, unknown>
|
|
35
34
|
): Promise<void> {
|
|
36
|
-
const client =
|
|
35
|
+
const client = repository.getClient();
|
|
37
36
|
return client.invalidateQueries({
|
|
38
37
|
queryKey: repository.keys.lists(),
|
|
39
38
|
});
|
|
@@ -49,7 +48,7 @@ export function invalidateDetail<TData>(
|
|
|
49
48
|
repository: IBaseRepository<TData, unknown, unknown>,
|
|
50
49
|
id: string | number
|
|
51
50
|
): Promise<void> {
|
|
52
|
-
const client =
|
|
51
|
+
const client = repository.getClient();
|
|
53
52
|
return client.invalidateQueries({
|
|
54
53
|
queryKey: repository.keys.detail(id),
|
|
55
54
|
});
|
|
@@ -63,11 +62,11 @@ export function invalidateDetail<TData>(
|
|
|
63
62
|
* @param data - Data to set
|
|
64
63
|
*/
|
|
65
64
|
export function setData<TData>(
|
|
66
|
-
repository:
|
|
65
|
+
repository: IBaseRepository<TData, unknown, unknown>,
|
|
67
66
|
id: string | number,
|
|
68
67
|
data: TData
|
|
69
68
|
): void {
|
|
70
|
-
const client =
|
|
69
|
+
const client = repository.getClient();
|
|
71
70
|
client.setQueryData(repository.keys.detail(id), data);
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -79,10 +78,10 @@ export function setData<TData>(
|
|
|
79
78
|
* @returns Cached data or undefined
|
|
80
79
|
*/
|
|
81
80
|
export function getData<TData>(
|
|
82
|
-
repository:
|
|
81
|
+
repository: IBaseRepository<TData, unknown, unknown>,
|
|
83
82
|
id: string | number
|
|
84
83
|
): TData | undefined {
|
|
85
|
-
const client =
|
|
84
|
+
const client = repository.getClient();
|
|
86
85
|
return client.getQueryData<TData>(repository.keys.detail(id));
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -93,9 +92,9 @@ export function getData<TData>(
|
|
|
93
92
|
* @param id - Item ID
|
|
94
93
|
*/
|
|
95
94
|
export function clearData<TData>(
|
|
96
|
-
repository:
|
|
95
|
+
repository: IBaseRepository<TData, unknown, unknown>,
|
|
97
96
|
id: string | number
|
|
98
97
|
): void {
|
|
99
|
-
const client =
|
|
98
|
+
const client = repository.getClient();
|
|
100
99
|
client.setQueryData(repository.keys.detail(id), undefined);
|
|
101
100
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Query methods for repository operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type { QueryKey } from '@tanstack/react-query';
|
|
7
7
|
import type { ListParams } from '../RepositoryTypes';
|
|
8
8
|
import type { IBaseRepository } from '../IBaseRepository';
|
|
9
9
|
|
|
@@ -18,11 +18,11 @@ export async function queryAll<TData>(
|
|
|
18
18
|
repository: IBaseRepository<TData, unknown, unknown>,
|
|
19
19
|
params?: ListParams
|
|
20
20
|
): Promise<TData[]> {
|
|
21
|
-
const client =
|
|
21
|
+
const client = repository.getClient();
|
|
22
22
|
const queryKey = params
|
|
23
23
|
? repository.keys.list(params as Record<string, unknown>)
|
|
24
24
|
: repository.keys.lists();
|
|
25
|
-
const cacheOptions =
|
|
25
|
+
const cacheOptions = repository.getCacheOptions();
|
|
26
26
|
|
|
27
27
|
return client.fetchQuery({
|
|
28
28
|
queryKey: queryKey as QueryKey,
|
|
@@ -42,9 +42,9 @@ export async function queryById<TData>(
|
|
|
42
42
|
repository: IBaseRepository<TData, unknown, unknown>,
|
|
43
43
|
id: string | number
|
|
44
44
|
): Promise<TData | undefined> {
|
|
45
|
-
const client =
|
|
45
|
+
const client = repository.getClient();
|
|
46
46
|
const queryKey = repository.keys.detail(id);
|
|
47
|
-
const cacheOptions =
|
|
47
|
+
const cacheOptions = repository.getCacheOptions();
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
return client.fetchQuery({
|
|
@@ -64,14 +64,14 @@ export async function queryById<TData>(
|
|
|
64
64
|
* @param params - Optional list parameters
|
|
65
65
|
*/
|
|
66
66
|
export async function prefetchAll<TData>(
|
|
67
|
-
repository:
|
|
67
|
+
repository: IBaseRepository<TData, unknown, unknown>,
|
|
68
68
|
params?: ListParams
|
|
69
69
|
): Promise<void> {
|
|
70
|
-
const client =
|
|
70
|
+
const client = repository.getClient();
|
|
71
71
|
const queryKey = params
|
|
72
72
|
? repository.keys.list(params as Record<string, unknown>)
|
|
73
73
|
: repository.keys.lists();
|
|
74
|
-
const cacheOptions =
|
|
74
|
+
const cacheOptions = repository.getCacheOptions();
|
|
75
75
|
|
|
76
76
|
await client.prefetchQuery({
|
|
77
77
|
queryKey: queryKey as QueryKey,
|
|
@@ -87,12 +87,12 @@ export async function prefetchAll<TData>(
|
|
|
87
87
|
* @param id - Item ID
|
|
88
88
|
*/
|
|
89
89
|
export async function prefetchById<TData>(
|
|
90
|
-
repository:
|
|
90
|
+
repository: IBaseRepository<TData, unknown, unknown>,
|
|
91
91
|
id: string | number
|
|
92
92
|
): Promise<void> {
|
|
93
|
-
const client =
|
|
93
|
+
const client = repository.getClient();
|
|
94
94
|
const queryKey = repository.keys.detail(id);
|
|
95
|
-
const cacheOptions =
|
|
95
|
+
const cacheOptions = repository.getCacheOptions();
|
|
96
96
|
|
|
97
97
|
await client.prefetchQuery({
|
|
98
98
|
queryKey: queryKey as QueryKey,
|
|
@@ -83,7 +83,6 @@ export function createPersister(options: PersisterFactoryOptions = {}): Persiste
|
|
|
83
83
|
if (parsed.version !== busterVersion) {
|
|
84
84
|
if (__DEV__) {
|
|
85
85
|
|
|
86
|
-
console.log(
|
|
87
86
|
`[TanStack Query] Cache version mismatch. Expected: ${busterVersion}, Got: ${parsed.version}`,
|
|
88
87
|
);
|
|
89
88
|
}
|
|
@@ -95,7 +94,6 @@ export function createPersister(options: PersisterFactoryOptions = {}): Persiste
|
|
|
95
94
|
if (age > maxAge) {
|
|
96
95
|
if (__DEV__) {
|
|
97
96
|
|
|
98
|
-
console.log(`[TanStack Query] Cache expired. Age: ${age}ms, Max: ${maxAge}ms`);
|
|
99
97
|
}
|
|
100
98
|
return undefined;
|
|
101
99
|
}
|
|
@@ -104,7 +102,6 @@ export function createPersister(options: PersisterFactoryOptions = {}): Persiste
|
|
|
104
102
|
} catch (error) {
|
|
105
103
|
if (__DEV__) {
|
|
106
104
|
|
|
107
|
-
console.error('[TanStack Query] Failed to deserialize cache:', error);
|
|
108
105
|
}
|
|
109
106
|
return undefined;
|
|
110
107
|
}
|
|
@@ -126,12 +123,10 @@ export async function clearPersistedCache(keyPrefix: string = 'tanstack-query'):
|
|
|
126
123
|
await storageService.removeItem(`${keyPrefix}-cache`);
|
|
127
124
|
if (__DEV__) {
|
|
128
125
|
|
|
129
|
-
console.log(`[TanStack Query] Cleared persisted cache: ${keyPrefix}`);
|
|
130
126
|
}
|
|
131
127
|
} catch (error) {
|
|
132
128
|
if (__DEV__) {
|
|
133
129
|
|
|
134
|
-
console.error('[TanStack Query] Failed to clear persisted cache:', error);
|
|
135
130
|
}
|
|
136
131
|
}
|
|
137
132
|
}
|
|
@@ -143,7 +138,6 @@ export async function clearPersistedCache(keyPrefix: string = 'tanstack-query'):
|
|
|
143
138
|
* @example
|
|
144
139
|
* ```typescript
|
|
145
140
|
* const size = await getPersistedCacheSize('myapp');
|
|
146
|
-
* console.log(`Cache size: ${size} bytes`);
|
|
147
141
|
* ```
|
|
148
142
|
*/
|
|
149
143
|
export async function getPersistedCacheSize(
|
|
@@ -155,7 +149,6 @@ export async function getPersistedCacheSize(
|
|
|
155
149
|
} catch (error) {
|
|
156
150
|
if (__DEV__) {
|
|
157
151
|
|
|
158
|
-
console.error('[TanStack Query] Failed to get cache size:', error);
|
|
159
152
|
}
|
|
160
153
|
return 0;
|
|
161
154
|
}
|