amplifyquery 1.0.10 β†’ 1.0.12

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.
Files changed (2) hide show
  1. package/dist/service.js +22 -5
  2. package/package.json +1 -1
package/dist/service.js CHANGED
@@ -231,7 +231,7 @@ function createAmplifyService(modelName, defaultAuthMode) {
231
231
  cleanedData[key] = value;
232
232
  }
233
233
  });
234
- const newItem = Object.assign(Object.assign({}, cleanedData), { id: (0, expo_crypto_1.randomUUID)() });
234
+ const newItem = Object.assign(Object.assign({}, cleanedData), { id: cleanedData.id || (0, expo_crypto_1.randomUUID)() });
235
235
  // Extract relation fields (e.g., dailyId, userId)
236
236
  const relationFields = new Map();
237
237
  for (const [key, value] of Object.entries(newItem)) {
@@ -351,7 +351,7 @@ function createAmplifyService(modelName, defaultAuthMode) {
351
351
  cleanedData[key] = value;
352
352
  }
353
353
  });
354
- return Object.assign(Object.assign({}, cleanedData), { id: (0, expo_crypto_1.randomUUID)() });
354
+ return Object.assign(Object.assign({}, cleanedData), { id: cleanedData.id || (0, expo_crypto_1.randomUUID)() });
355
355
  })
356
356
  .filter(Boolean);
357
357
  const relatedQueryKeys = findRelatedQueryKeys(modelName, query_1.queryClient);
@@ -1253,8 +1253,13 @@ function createAmplifyService(modelName, defaultAuthMode) {
1253
1253
  console.warn(`🍬 ${modelName} useItemHook: Cache contains array instead of single item. Finding matching item.`);
1254
1254
  const matchingItem = rawCachedData.find((item) => (item === null || item === void 0 ? void 0 : item.id) === id);
1255
1255
  cachedData = matchingItem || undefined;
1256
- // 배열이 μΊμ‹œλ˜μ–΄ 있으면 μΊμ‹œλ₯Ό μ œκ±°ν•˜μ—¬ get λ©”μ„œλ“œκ°€ λ‹€μ‹œ ν˜ΈμΆœλ˜λ„λ‘ 함
1257
- hookQueryClient.removeQueries({ queryKey: singleItemQueryKey });
1256
+ // 배열이 μΊμ‹œλ˜μ–΄ 있으면 쑰용히 μΊμ‹œλ₯Ό 제거 (λ¬΄ν•œ 루프 λ°©μ§€)
1257
+ setTimeout(() => {
1258
+ hookQueryClient.removeQueries({
1259
+ queryKey: singleItemQueryKey,
1260
+ exact: true,
1261
+ });
1262
+ }, 0);
1258
1263
  }
1259
1264
  else if (rawCachedData && (rawCachedData === null || rawCachedData === void 0 ? void 0 : rawCachedData.id) === id) {
1260
1265
  cachedData = rawCachedData;
@@ -1269,7 +1274,8 @@ function createAmplifyService(modelName, defaultAuthMode) {
1269
1274
  queryFn: () => service.get(id),
1270
1275
  initialData: cachedData, // Use cached data as initial value if available
1271
1276
  staleTime: 1000 * 60, // Keep data "fresh" for 1 minute
1272
- refetchOnMount: "always", // Always attempt to refetch on mount
1277
+ refetchOnMount: cachedData ? false : true, // Only refetch if no cached data
1278
+ refetchOnWindowFocus: false, // Disable window focus refetch to prevent loops
1273
1279
  enabled: !!id, // Only enable query when id exists
1274
1280
  });
1275
1281
  // useMutation hooks call service methods,
@@ -1314,6 +1320,17 @@ function createAmplifyService(modelName, defaultAuthMode) {
1314
1320
  }), [deleteMutation]);
1315
1321
  // Change loading state to false when isLoading is true and cached data exists
1316
1322
  const effectiveLoading = isLoading && !cachedData;
1323
+ // μΊμ‹œ 정리λ₯Ό μœ„ν•œ 효과 μ΅œμ ν™” (ν•œ 번만 μ‹€ν–‰)
1324
+ const shouldCleanCache = Array.isArray(rawCachedData);
1325
+ if (shouldCleanCache && !isLoading) {
1326
+ // λ‘œλ”©μ΄ μ™„λ£Œλœ ν›„μ—λ§Œ μΊμ‹œ 정리 μ‹€ν–‰
1327
+ setTimeout(() => {
1328
+ const currentCache = hookQueryClient.getQueryData(singleItemQueryKey);
1329
+ if (Array.isArray(currentCache)) {
1330
+ hookQueryClient.setQueryData(singleItemQueryKey, item);
1331
+ }
1332
+ }, 100);
1333
+ }
1317
1334
  return {
1318
1335
  item: item || null,
1319
1336
  isLoading: effectiveLoading, // Not loading if cached data exists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amplifyquery",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Amplify+Query",
5
5
  "keywords": [
6
6
  "Amplify",