amplifyquery 2.0.4 → 2.0.5
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/README.md +1 -4
- package/dist/config.d.ts +1 -2
- package/dist/config.js +1 -2
- package/dist/singleton.js +7 -9
- package/dist/types.d.ts +1 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -166,10 +166,7 @@ const {
|
|
|
166
166
|
isLoading: isSettingsLoading,
|
|
167
167
|
update: upsertSettings, // creates if missing
|
|
168
168
|
refresh: refreshSettings,
|
|
169
|
-
} = UserSettingsService.
|
|
170
|
-
|
|
171
|
-
// Legacy alias (deprecated)
|
|
172
|
-
// UserSettingsService.useCurrentHook()
|
|
169
|
+
} = UserSettingsService.useSingletonHook();
|
|
173
170
|
```
|
|
174
171
|
|
|
175
172
|
### 4. Data Fetching and Saving
|
package/dist/config.d.ts
CHANGED
|
@@ -42,8 +42,7 @@ export declare function resetConfig(): void;
|
|
|
42
42
|
/**
|
|
43
43
|
* Enable/disable singleton auto-create behavior for singleton hooks.
|
|
44
44
|
*
|
|
45
|
-
* - **New**: `
|
|
46
|
-
* - **Legacy**: `useCurrentHook()` (deprecated alias)
|
|
45
|
+
* - **New**: `useSingletonHook()` (recommended)
|
|
47
46
|
*/
|
|
48
47
|
export declare function setSingletonAutoCreate(config: {
|
|
49
48
|
enabled?: boolean;
|
package/dist/config.js
CHANGED
|
@@ -93,8 +93,7 @@ function resetConfig() {
|
|
|
93
93
|
/**
|
|
94
94
|
* Enable/disable singleton auto-create behavior for singleton hooks.
|
|
95
95
|
*
|
|
96
|
-
* - **New**: `
|
|
97
|
-
* - **Legacy**: `useCurrentHook()` (deprecated alias)
|
|
96
|
+
* - **New**: `useSingletonHook()` (recommended)
|
|
98
97
|
*/
|
|
99
98
|
function setSingletonAutoCreate(config) {
|
|
100
99
|
globalConfig.singletonAutoCreate = {
|
package/dist/singleton.js
CHANGED
|
@@ -102,7 +102,7 @@ function createSingletonService(baseService, getModelId) {
|
|
|
102
102
|
}
|
|
103
103
|
}),
|
|
104
104
|
// React hook to manage the current singleton item
|
|
105
|
-
|
|
105
|
+
useSingletonHook: (options) => {
|
|
106
106
|
const { data: currentId, isLoading: isIdLoading, error: idError, refetch: refetchId, } = (0, react_query_1.useQuery)({
|
|
107
107
|
queryKey: [modelName, "currentId"],
|
|
108
108
|
queryFn: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -118,7 +118,7 @@ function createSingletonService(baseService, getModelId) {
|
|
|
118
118
|
refetchOnWindowFocus: false,
|
|
119
119
|
});
|
|
120
120
|
const idForItemHook = currentId !== null && currentId !== void 0 ? currentId : "";
|
|
121
|
-
(0, config_2.debugLog)(`🍬 ${modelName}
|
|
121
|
+
(0, config_2.debugLog)(`🍬 ${modelName} useSingletonHook currentId`, {
|
|
122
122
|
currentId,
|
|
123
123
|
idForItemHook,
|
|
124
124
|
});
|
|
@@ -134,7 +134,7 @@ function createSingletonService(baseService, getModelId) {
|
|
|
134
134
|
const isLoading = isIdLoading || core.isLoading;
|
|
135
135
|
const error = idError || core.error || null;
|
|
136
136
|
(0, react_1.useEffect)(() => {
|
|
137
|
-
(0, config_2.debugLog)(`🍬 ${modelName}
|
|
137
|
+
(0, config_2.debugLog)(`🍬 ${modelName} useSingletonHook effect check`, {
|
|
138
138
|
currentId,
|
|
139
139
|
isLoading,
|
|
140
140
|
autoCreateEnabled,
|
|
@@ -158,18 +158,18 @@ function createSingletonService(baseService, getModelId) {
|
|
|
158
158
|
// Best-effort: create { id } if missing.
|
|
159
159
|
void (() => __awaiter(this, void 0, void 0, function* () {
|
|
160
160
|
try {
|
|
161
|
-
(0, config_2.debugWarn)(`🍬 ${modelName}
|
|
161
|
+
(0, config_2.debugWarn)(`🍬 ${modelName} useSingletonHook auto-create starting`, {
|
|
162
162
|
currentId,
|
|
163
163
|
});
|
|
164
164
|
yield singletonService.upsertCurrent({});
|
|
165
165
|
yield singletonService.getCurrent({ forceRefresh: true });
|
|
166
|
-
(0, config_2.debugLog)(`🍬 ${modelName}
|
|
166
|
+
(0, config_2.debugLog)(`🍬 ${modelName} useSingletonHook auto-create done`, {
|
|
167
167
|
currentId,
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
catch (e) {
|
|
171
171
|
attemptedAutoCreateForIdRef.current = null; // allow retry later
|
|
172
|
-
(0, config_2.debugWarn)(`🍬 ${modelName}
|
|
172
|
+
(0, config_2.debugWarn)(`🍬 ${modelName} useSingletonHook auto-create failed:`, e);
|
|
173
173
|
}
|
|
174
174
|
}))();
|
|
175
175
|
}, [currentId, isLoading, item, modelName, autoCreateEnabled, error]);
|
|
@@ -200,9 +200,7 @@ function createSingletonService(baseService, getModelId) {
|
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
return { item, isLoading, error, refresh, update, delete: remove };
|
|
203
|
-
}
|
|
204
|
-
// Backward-compatible alias
|
|
205
|
-
useCurrentHook: (options) => singletonService.useSigletoneHook(options) });
|
|
203
|
+
} });
|
|
206
204
|
return singletonService;
|
|
207
205
|
}
|
|
208
206
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -121,7 +121,7 @@ export interface SingletonAmplifyService<T> extends AmplifyDataService<T> {
|
|
|
121
121
|
}) => Promise<T | null>;
|
|
122
122
|
updateCurrent: (data: Partial<T>) => Promise<T | null>;
|
|
123
123
|
upsertCurrent: (data: Partial<T>) => Promise<T | null>;
|
|
124
|
-
|
|
124
|
+
useSingletonHook: (options?: {
|
|
125
125
|
/**
|
|
126
126
|
* When true (default), if the singleton item does not exist it will be created.
|
|
127
127
|
* You can set false to disable auto-create for this hook call.
|
|
@@ -132,16 +132,6 @@ export interface SingletonAmplifyService<T> extends AmplifyDataService<T> {
|
|
|
132
132
|
observeOptions?: Record<string, any>;
|
|
133
133
|
};
|
|
134
134
|
}) => ItemHook<T>;
|
|
135
|
-
/**
|
|
136
|
-
* @deprecated Use useSigletoneHook() instead.
|
|
137
|
-
*/
|
|
138
|
-
useCurrentHook: (options?: {
|
|
139
|
-
autoCreate?: boolean;
|
|
140
|
-
realtime?: {
|
|
141
|
-
enabled?: boolean;
|
|
142
|
-
observeOptions?: Record<string, any>;
|
|
143
|
-
};
|
|
144
|
-
}) => ItemHook<T>;
|
|
145
135
|
}
|
|
146
136
|
export interface BaseModel {
|
|
147
137
|
id: string;
|