@jcbuisson/express-x-client 3.1.9 → 3.1.11
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/package.json +1 -1
- package/src/client.mts +16 -6
package/package.json
CHANGED
package/src/client.mts
CHANGED
|
@@ -26,7 +26,11 @@ export function createClient(socket, options={}) {
|
|
|
26
26
|
socket.on("connect", async () => {
|
|
27
27
|
if (options.debug) console.log("socket connected", socket.id)
|
|
28
28
|
for (const func of connectListeners) {
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
await func(socket)
|
|
31
|
+
} catch(err) {
|
|
32
|
+
console.error('connect listener error', err)
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
35
|
})
|
|
32
36
|
|
|
@@ -369,8 +373,14 @@ export function offlinePlugin(app) {
|
|
|
369
373
|
app.connectedDate = new Date()
|
|
370
374
|
console.log('onConnect', app.connectedDate)
|
|
371
375
|
app.isConnected = true
|
|
372
|
-
|
|
373
|
-
|
|
376
|
+
const disconnectedDate = app.disconnectedDate
|
|
377
|
+
if (disconnectedDate) {
|
|
378
|
+
const results = await Promise.allSettled(modelSyncFunctions.map(sync => sync()))
|
|
379
|
+
const failures = results.filter(result => result.status === 'rejected')
|
|
380
|
+
if (failures.length > 0) {
|
|
381
|
+
console.error('err reconnect synchronizeAll', failures.map(result => result.reason))
|
|
382
|
+
return
|
|
383
|
+
}
|
|
374
384
|
}
|
|
375
385
|
app.disconnectedDate = null
|
|
376
386
|
})
|
|
@@ -441,10 +451,9 @@ export function offlinePlugin(app) {
|
|
|
441
451
|
// 3- update elements of cache with server's newer version
|
|
442
452
|
for (const [elt, serverMeta] of updateClient) {
|
|
443
453
|
const value = { ...elt }
|
|
444
|
-
delete value.uid
|
|
445
454
|
delete value.__deleted__
|
|
446
|
-
await idbValues.
|
|
447
|
-
await idbMetadata.
|
|
455
|
+
await idbValues.put(value)
|
|
456
|
+
await idbMetadata.put({ uid: elt.uid, ...serverMeta })
|
|
448
457
|
}
|
|
449
458
|
|
|
450
459
|
// 4- create elements of `addDatabase` with full data from cache
|
|
@@ -484,6 +493,7 @@ export function offlinePlugin(app) {
|
|
|
484
493
|
}
|
|
485
494
|
} catch(err) {
|
|
486
495
|
console.log('err synchronize', modelName, where, err)
|
|
496
|
+
throw err
|
|
487
497
|
} finally {
|
|
488
498
|
mutex.release()
|
|
489
499
|
}
|