amplifyquery 1.0.11 → 1.0.13
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 +2 -2
- package/dist/singleton.js +33 -2
- package/dist/types.d.ts +1 -0
- 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);
|
package/dist/singleton.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.getModelIds = void 0;
|
|
|
13
13
|
exports.createSingletonService = createSingletonService;
|
|
14
14
|
const client_1 = require("./client");
|
|
15
15
|
const auth_1 = require("aws-amplify/auth");
|
|
16
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
16
17
|
/**
|
|
17
18
|
* Function to create an extension service for singleton models
|
|
18
19
|
* @param baseService Base service
|
|
@@ -32,7 +33,7 @@ function createSingletonService(baseService, getModelId) {
|
|
|
32
33
|
return baseService.get(modelId, options);
|
|
33
34
|
}
|
|
34
35
|
catch (error) {
|
|
35
|
-
console.error(`${modelName} singleton instance lookup error:`, error);
|
|
36
|
+
// console.error(`${modelName} singleton instance lookup error:`, error);
|
|
36
37
|
// Safely call getStore
|
|
37
38
|
try {
|
|
38
39
|
(_c = (_b = (_a = baseService
|
|
@@ -122,7 +123,37 @@ function createSingletonService(baseService, getModelId) {
|
|
|
122
123
|
console.error(`${modelName} singleton instance final Upsert error:`, error);
|
|
123
124
|
return null;
|
|
124
125
|
}
|
|
125
|
-
})
|
|
126
|
+
}),
|
|
127
|
+
// React hook to manage the current singleton item
|
|
128
|
+
useCurrentHook: () => {
|
|
129
|
+
// Resolve current singleton ID with React Query (object-style API)
|
|
130
|
+
const { data: currentId } = (0, react_query_1.useQuery)({
|
|
131
|
+
queryKey: [modelName, "currentId"],
|
|
132
|
+
queryFn: () => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
var _a, _b, _c;
|
|
134
|
+
try {
|
|
135
|
+
const id = yield getModelId();
|
|
136
|
+
return id || null;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// Safely call getStore to surface errors if available
|
|
140
|
+
try {
|
|
141
|
+
(_c = (_b = (_a = baseService
|
|
142
|
+
.getStore) === null || _a === void 0 ? void 0 : _a.call(baseService)) === null || _b === void 0 ? void 0 : _b.setError) === null || _c === void 0 ? void 0 : _c.call(_b, error instanceof Error ? error : new Error(String(error)));
|
|
143
|
+
}
|
|
144
|
+
catch (_storeError) {
|
|
145
|
+
// Ignore store errors
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}),
|
|
150
|
+
staleTime: 1000 * 60,
|
|
151
|
+
refetchOnWindowFocus: false,
|
|
152
|
+
});
|
|
153
|
+
// Delegate to base service's single item hook once ID is known
|
|
154
|
+
const resolvedId = currentId !== null && currentId !== void 0 ? currentId : "";
|
|
155
|
+
return baseService.useItemHook(resolvedId);
|
|
156
|
+
} });
|
|
126
157
|
return singletonService;
|
|
127
158
|
}
|
|
128
159
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ export interface SingletonAmplifyService<T> extends AmplifyDataService<T> {
|
|
|
106
106
|
}) => Promise<T | null>;
|
|
107
107
|
updateCurrent: (data: Partial<T>) => Promise<T | null>;
|
|
108
108
|
upsertCurrent: (data: Partial<T>) => Promise<T | null>;
|
|
109
|
+
useCurrentHook: () => ItemHook<T>;
|
|
109
110
|
}
|
|
110
111
|
export interface BaseModel {
|
|
111
112
|
id: string;
|