@jcbuisson/express-x-client 3.0.0 → 3.0.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/package.json +2 -2
- package/src/{index.mjs → client.mts} +25 -25
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcbuisson/express-x-client",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Client library for ExpressX framework",
|
|
6
|
-
"main": "src/
|
|
6
|
+
"main": "src/client.mts",
|
|
7
7
|
"test": "node --test",
|
|
8
8
|
"scripts": {
|
|
9
9
|
},
|
|
@@ -8,20 +8,6 @@ import { tryOnScopeDispose } from '@vueuse/core';
|
|
|
8
8
|
import { useSessionStorage } from '@vueuse/core'
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
////////////////////////// UTILITIES //////////////////////////
|
|
12
|
-
|
|
13
|
-
function generateUID(length) {
|
|
14
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
15
|
-
let uid = ''
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
const randomIndex = Math.floor(Math.random() * characters.length)
|
|
19
|
-
uid += characters.charAt(randomIndex)
|
|
20
|
-
}
|
|
21
|
-
return uid
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
11
|
////////////////////////// EXPRESSX //////////////////////////
|
|
26
12
|
|
|
27
13
|
export function createClient(socket, options={}) {
|
|
@@ -370,9 +356,9 @@ export function offlinePlugin(app) {
|
|
|
370
356
|
return removeSynchroDBWhere(where, db.whereList)
|
|
371
357
|
}
|
|
372
358
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
359
|
+
async function synchronizeAll() {
|
|
360
|
+
await synchronizeModelWhereList(modelName, db.values, db.metadata, app.disconnectedDate, db.whereList)
|
|
361
|
+
}
|
|
376
362
|
|
|
377
363
|
// Automatically clean up when the component using this composable unmounts
|
|
378
364
|
tryOnScopeDispose(async () => {
|
|
@@ -388,7 +374,7 @@ export function offlinePlugin(app) {
|
|
|
388
374
|
create, update, remove,
|
|
389
375
|
findByUID, findWhere,
|
|
390
376
|
getObservable,
|
|
391
|
-
|
|
377
|
+
synchronizeAll,
|
|
392
378
|
addSynchroWhere,
|
|
393
379
|
}
|
|
394
380
|
}
|
|
@@ -411,7 +397,7 @@ export function offlinePlugin(app) {
|
|
|
411
397
|
const mutex = new Mutex()
|
|
412
398
|
|
|
413
399
|
// ex: where = { uid: 'azer' }
|
|
414
|
-
async function synchronize(
|
|
400
|
+
async function synchronize(modelName, idbValues, idbMetadata, where, cutoffDate) {
|
|
415
401
|
await mutex.acquire()
|
|
416
402
|
console.log('synchronize', modelName, where)
|
|
417
403
|
|
|
@@ -566,12 +552,12 @@ export function offlinePlugin(app) {
|
|
|
566
552
|
}
|
|
567
553
|
}
|
|
568
554
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
555
|
+
async function synchronizeModelWhereList(modelName, idbValues, idbMetadata, cutoffDate, whereDb) {
|
|
556
|
+
const whereList = await getWhereList(whereDb)
|
|
557
|
+
for (const where of whereList) {
|
|
558
|
+
await synchronize(modelName, idbValues, idbMetadata, where, cutoffDate)
|
|
559
|
+
}
|
|
560
|
+
}
|
|
575
561
|
|
|
576
562
|
// Singleton map to reuse Dexie instances per database name
|
|
577
563
|
const dbInstances = new Map();
|
|
@@ -596,6 +582,20 @@ export function offlinePlugin(app) {
|
|
|
596
582
|
}
|
|
597
583
|
|
|
598
584
|
|
|
585
|
+
////////////////////////// UTILITIES //////////////////////////
|
|
586
|
+
|
|
587
|
+
function generateUID(length) {
|
|
588
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
589
|
+
let uid = ''
|
|
590
|
+
|
|
591
|
+
for (let i = 0; i < length; i++) {
|
|
592
|
+
const randomIndex = Math.floor(Math.random() * characters.length)
|
|
593
|
+
uid += characters.charAt(randomIndex)
|
|
594
|
+
}
|
|
595
|
+
return uid
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
|
|
599
599
|
function stringifyWithSortedKeys(obj, space = null) {
|
|
600
600
|
return JSON.stringify(obj, (key, value) => {
|
|
601
601
|
// If the value is a plain object (not an array, null, or other object type like Date)
|