@classic-homes/offline-svelte 0.2.0 → 0.3.2
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/useDraftSync.svelte.js +28 -11
- package/package.json +6 -6
|
@@ -122,7 +122,9 @@ export function useDraftSync(options) {
|
|
|
122
122
|
* Sync all drafts
|
|
123
123
|
*/
|
|
124
124
|
async function syncAll() {
|
|
125
|
-
|
|
125
|
+
// Local reference: dispose() clears syncService while this awaits
|
|
126
|
+
const service = syncService;
|
|
127
|
+
if (!service) {
|
|
126
128
|
return {
|
|
127
129
|
success: false,
|
|
128
130
|
uploaded: 0,
|
|
@@ -137,14 +139,19 @@ export function useDraftSync(options) {
|
|
|
137
139
|
}
|
|
138
140
|
isSyncing = true;
|
|
139
141
|
error = null;
|
|
142
|
+
// Disposed meanwhile: the outcome belongs to a service (and possibly an
|
|
143
|
+
// account) this state no longer shows
|
|
144
|
+
const isCurrent = () => !disposed && syncService === service;
|
|
140
145
|
try {
|
|
141
|
-
const result = await
|
|
142
|
-
|
|
146
|
+
const result = await service.syncAll();
|
|
147
|
+
if (isCurrent())
|
|
148
|
+
pendingCount = service.pendingCount;
|
|
143
149
|
return result;
|
|
144
150
|
}
|
|
145
151
|
catch (err) {
|
|
146
152
|
const errorMsg = err instanceof Error ? err.message : 'Sync failed';
|
|
147
|
-
|
|
153
|
+
if (isCurrent())
|
|
154
|
+
error = errorMsg;
|
|
148
155
|
return {
|
|
149
156
|
success: false,
|
|
150
157
|
uploaded: 0,
|
|
@@ -187,8 +194,10 @@ export function useDraftSync(options) {
|
|
|
187
194
|
if (!syncService) {
|
|
188
195
|
throw new Error('Sync service not initialized');
|
|
189
196
|
}
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
const service = syncService;
|
|
198
|
+
await service.forcePush(draftId);
|
|
199
|
+
if (syncService === service)
|
|
200
|
+
conflicts = service.getConflicts();
|
|
192
201
|
}
|
|
193
202
|
/**
|
|
194
203
|
* Force pull a draft
|
|
@@ -197,8 +206,10 @@ export function useDraftSync(options) {
|
|
|
197
206
|
if (!syncService) {
|
|
198
207
|
throw new Error('Sync service not initialized');
|
|
199
208
|
}
|
|
200
|
-
|
|
201
|
-
|
|
209
|
+
const service = syncService;
|
|
210
|
+
await service.forcePull(draftId);
|
|
211
|
+
if (syncService === service)
|
|
212
|
+
conflicts = service.getConflicts();
|
|
202
213
|
}
|
|
203
214
|
/**
|
|
204
215
|
* Resolve a conflict
|
|
@@ -207,8 +218,10 @@ export function useDraftSync(options) {
|
|
|
207
218
|
if (!syncService) {
|
|
208
219
|
throw new Error('Sync service not initialized');
|
|
209
220
|
}
|
|
210
|
-
|
|
211
|
-
|
|
221
|
+
const service = syncService;
|
|
222
|
+
await service.resolveConflict(draftId, resolution);
|
|
223
|
+
if (syncService === service)
|
|
224
|
+
conflicts = service.getConflicts();
|
|
212
225
|
}
|
|
213
226
|
/**
|
|
214
227
|
* Start auto-sync
|
|
@@ -228,8 +241,12 @@ export function useDraftSync(options) {
|
|
|
228
241
|
* Dispose the sync service
|
|
229
242
|
*/
|
|
230
243
|
function dispose() {
|
|
231
|
-
|
|
244
|
+
// The service stops its in-flight sync and drops these callbacks; the
|
|
245
|
+
// returned promise (lock released) is not needed here
|
|
246
|
+
void syncService?.dispose();
|
|
232
247
|
syncService = null;
|
|
248
|
+
isSyncing = false;
|
|
249
|
+
isAutoSyncActive = false;
|
|
233
250
|
}
|
|
234
251
|
// Initialize on mount, clean up on destroy. untrack: initialization writes
|
|
235
252
|
// state this effect must not subscribe to.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@classic-homes/offline-svelte",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Svelte bindings for offline persistence and caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"svelte": "^5.
|
|
63
|
+
"svelte": "^5.59.1",
|
|
64
64
|
"zod": "^3.23.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@sveltejs/package": "^2.3.0",
|
|
71
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
71
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.2",
|
|
72
72
|
"@testing-library/svelte": "^5.0.0",
|
|
73
73
|
"@vitest/coverage-v8": "^4.1.10",
|
|
74
|
-
"fake-indexeddb": "^6.
|
|
74
|
+
"fake-indexeddb": "^6.2.8",
|
|
75
75
|
"jsdom": "^25.0.0",
|
|
76
|
-
"svelte": "^5.
|
|
77
|
-
"svelte-check": "^4.
|
|
76
|
+
"svelte": "^5.59.1",
|
|
77
|
+
"svelte-check": "^4.7.8",
|
|
78
78
|
"typescript": "^5.3.0",
|
|
79
79
|
"vitest": "^4.1.10",
|
|
80
80
|
"zod": "^3.23.0"
|