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.
- package/dist/service.js +22 -5
- 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
|
-
// λ°°μ΄μ΄ μΊμλμ΄ μμΌλ©΄ μΊμλ₯Ό
|
|
1257
|
-
|
|
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:
|
|
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
|