@cocreate/indexeddb 1.17.2 → 1.18.0
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/CHANGELOG.md +13 -0
- package/package.json +1 -1
- package/src/index.js +52 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [1.18.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.17.2...v1.18.0) (2023-11-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* set $filter.startingIndex ([18888cf](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/18888cf2cbfd8e8264a26f5274f2fb781c779308))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* cursor.advance(index) ([699d83f](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/699d83ffb4f5630fdbfa73b73b337fd0f08290a4))
|
|
12
|
+
* cursorUpdate ([5873caf](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/5873caf4d7fdc6da860e7c2ed01fb7d75f28143f))
|
|
13
|
+
|
|
1
14
|
## [1.17.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.17.1...v1.17.2) (2023-11-12)
|
|
2
15
|
|
|
3
16
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -555,14 +555,11 @@ async function processObject(data, newData, database, array, type) {
|
|
|
555
555
|
limit = data[type][i].$filter.limit
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
-
if (limit)
|
|
559
|
-
limit = (index || 0) + limit;
|
|
560
|
-
|
|
561
558
|
} else if (data.method == 'object.delete' || data.method == 'object.update' && !range && !upsert && !isFilter) {
|
|
562
559
|
continue
|
|
563
560
|
}
|
|
564
561
|
|
|
565
|
-
await openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators, reference);
|
|
562
|
+
await openCursor(objectStore, range, direction, data, newData, isFilter, index, limit, database, array, upsert, type, i, globalOperators, reference);
|
|
566
563
|
|
|
567
564
|
if (index)
|
|
568
565
|
newData = newData.slice(index)
|
|
@@ -581,11 +578,11 @@ async function processObject(data, newData, database, array, type) {
|
|
|
581
578
|
}
|
|
582
579
|
}
|
|
583
580
|
|
|
584
|
-
function openCursor(objectStore, range, direction, data, newData, isFilter, limit, database, array, upsert, type, i, globalOperators, reference) {
|
|
581
|
+
function openCursor(objectStore, range, direction, data, newData, isFilter, index, limit, database, array, upsert, type, i, globalOperators, reference) {
|
|
585
582
|
return new Promise(async (resolve, reject) => {
|
|
586
583
|
const request = objectStore.openCursor(range || null, direction);// next, prev
|
|
587
584
|
|
|
588
|
-
let hasUpdated, matchedLength = 0
|
|
585
|
+
let hasUpdated, matchedLength = 0, hasSkipped
|
|
589
586
|
request.onsuccess = async () => {
|
|
590
587
|
let cursor = request.result
|
|
591
588
|
|
|
@@ -622,47 +619,48 @@ function openCursor(objectStore, range, direction, data, newData, isFilter, limi
|
|
|
622
619
|
}
|
|
623
620
|
resolve();
|
|
624
621
|
} else if (cursor) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
622
|
+
if (index && !hasSkipped) {
|
|
623
|
+
cursor.advance(index);
|
|
624
|
+
hasSkipped = true;
|
|
625
|
+
} else {
|
|
626
|
+
let isMatch = true
|
|
627
|
+
if (isFilter)
|
|
628
|
+
isMatch = filter(objectStore, data, data[type][i], cursor.value)
|
|
629
|
+
|
|
630
|
+
if (isMatch !== false) {
|
|
631
|
+
let result = cursor.value
|
|
632
|
+
|
|
633
|
+
if (data.method == 'object.update') {
|
|
634
|
+
let update = createUpdate(cursor.value, data[type][i], globalOperators)
|
|
635
|
+
if (update)
|
|
636
|
+
result = await cursorUpdate(cursor, update)
|
|
637
|
+
// result = cursor.update(update)
|
|
638
|
+
hasUpdated = true
|
|
639
|
+
// set dotnotation for keys with $operators for items that end in [] to be used by socket.id
|
|
640
|
+
// TODO: if update.$<operator>.someKey[] requires the index of inerted item added to the field name. update.$<operator>.someKey[<index>]
|
|
641
|
+
// TODO: if $addToSet get field name and item if it does not exist.
|
|
642
|
+
// TODO: if $pull get field name and find if item exist and delete.
|
|
643
|
+
} else if (data.method == 'object.delete') {
|
|
644
|
+
result = cursor.value
|
|
645
|
+
cursor.delete()
|
|
646
|
+
}
|
|
631
647
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
} else if (data.method == 'object.delete') {
|
|
642
|
-
result = cursor.value
|
|
643
|
-
cursor.delete()
|
|
648
|
+
if (data[type][i]._id)
|
|
649
|
+
data[type][i] = { ...reference, ...result }
|
|
650
|
+
else {
|
|
651
|
+
let object = data[type].find(obj => obj._id && obj._id === result._id)
|
|
652
|
+
if (object)
|
|
653
|
+
object = { ...reference, ...object, ...result }
|
|
654
|
+
else
|
|
655
|
+
newData.push({ ...reference, ...result })
|
|
656
|
+
}
|
|
644
657
|
}
|
|
645
658
|
|
|
646
|
-
if (
|
|
647
|
-
|
|
648
|
-
else {
|
|
649
|
-
|
|
650
|
-
if (object)
|
|
651
|
-
object = { ...reference, ...object, ...result }
|
|
652
|
-
else
|
|
653
|
-
newData.push({ ...reference, ...result })
|
|
659
|
+
if (!limit || limit && (limit > newData.length + matchedLength)) {
|
|
660
|
+
cursor.continue();
|
|
661
|
+
} else {
|
|
662
|
+
resolve();
|
|
654
663
|
}
|
|
655
|
-
|
|
656
|
-
matchedLength++
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
if (!limit || limit && (limit > newData.length || limit > matchedLength)) {
|
|
660
|
-
cursor.continue();
|
|
661
|
-
} else if (cursor.close) {
|
|
662
|
-
cursor.close()
|
|
663
|
-
resolve();
|
|
664
|
-
} else {
|
|
665
|
-
resolve();
|
|
666
664
|
}
|
|
667
665
|
|
|
668
666
|
} else {
|
|
@@ -712,6 +710,14 @@ function deleteObject(objectStore, object) {
|
|
|
712
710
|
});
|
|
713
711
|
}
|
|
714
712
|
|
|
713
|
+
function cursorUpdate(cursor, update) {
|
|
714
|
+
return new Promise((resolve, reject) => {
|
|
715
|
+
const request = cursor.update(update)
|
|
716
|
+
request.onsuccess = () => resolve(request.source.value);
|
|
717
|
+
request.onerror = () => reject(request.error);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
|
|
715
721
|
|
|
716
722
|
function filter(objectStore, data, object, result) {
|
|
717
723
|
let isMatch = true;
|
|
@@ -781,7 +787,7 @@ function dotNotationToObjectUpdate(data, object = {}) {
|
|
|
781
787
|
let newObject = object
|
|
782
788
|
let oldObject = new Object(newObject)
|
|
783
789
|
let keys = key.replace(/\[(\d+)\]/g, '.$1').split('.');
|
|
784
|
-
|
|
790
|
+
let value = data[key]
|
|
785
791
|
if (keys[0].startsWith('$'))
|
|
786
792
|
var operator = keys.shift()
|
|
787
793
|
|
|
@@ -861,6 +867,8 @@ function createData(data, newData, type) {
|
|
|
861
867
|
if (data.$filter) {
|
|
862
868
|
if (data.$filter.sort)
|
|
863
869
|
data[type] = sortData(data[type], data.$filter.sort)
|
|
870
|
+
|
|
871
|
+
data.$filter.startingIndex = data.$filter.index
|
|
864
872
|
data.$filter.index += data[type].length
|
|
865
873
|
}
|
|
866
874
|
|