@cocreate/indexeddb 1.21.1 → 1.22.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 +19 -0
- package/docs/index.html +0 -4
- package/package.json +1 -1
- package/src/index.js +1 -114
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.22.0](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.21.2...v1.22.0) (2024-02-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* createUpdate relocated to utils to be accessible by other modues ([af6a85e](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/af6a85e91c28d384ac14ebc97cec096c332e770f))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* update operators $addToSet and $pull ([effc837](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/effc8376e2896ad421026aeec9f8cb2c1284cdeb))
|
|
12
|
+
|
|
13
|
+
## [1.21.2](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.21.1...v1.21.2) (2024-02-05)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* Removed https://cdn.cocreate.app/latest/CoCreate.min.css ([8489475](https://github.com/CoCreate-app/CoCreate-indexeddb/commit/848947543c0770ce7402183b07902e7465d23775))
|
|
19
|
+
|
|
1
20
|
## [1.21.1](https://github.com/CoCreate-app/CoCreate-indexeddb/compare/v1.21.0...v1.21.1) (2024-01-17)
|
|
2
21
|
|
|
3
22
|
|
package/docs/index.html
CHANGED
|
@@ -19,10 +19,6 @@
|
|
|
19
19
|
<meta name="robots" content="index,follow" />
|
|
20
20
|
|
|
21
21
|
<!-- CoCreate CSS CDN -->
|
|
22
|
-
<link
|
|
23
|
-
rel="stylesheet"
|
|
24
|
-
href="https://cdn.cocreate.app/latest/CoCreate.min.css"
|
|
25
|
-
type="text/css" />
|
|
26
22
|
|
|
27
23
|
<link rel="manifest" href="/manifest.webmanifest" />
|
|
28
24
|
</head>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { ObjectId, dotNotationToObject, searchData, sortData, queryData,
|
|
25
|
+
import { ObjectId, dotNotationToObject, searchData, sortData, queryData, createUpdate, isEqualArray, isEqualObject } from '@cocreate/utils'
|
|
26
26
|
|
|
27
27
|
let indexedDbFunction
|
|
28
28
|
|
|
@@ -745,119 +745,6 @@ function getGlobalOperators(data, object = {}) {
|
|
|
745
745
|
return object
|
|
746
746
|
}
|
|
747
747
|
|
|
748
|
-
function createUpdate(update, data, globalOpertors) {
|
|
749
|
-
let operatorKeys = {}
|
|
750
|
-
if (globalOpertors)
|
|
751
|
-
operatorKeys = { ...globalOpertors }
|
|
752
|
-
|
|
753
|
-
Object.keys(data).forEach(key => {
|
|
754
|
-
if (key.startsWith('$')) {
|
|
755
|
-
if (!key.includes('.'))
|
|
756
|
-
for (let oldkey of Object.keys(data[key]))
|
|
757
|
-
operatorKeys[key + '.' + oldkey] = data[key][oldkey]
|
|
758
|
-
else
|
|
759
|
-
operatorKeys[key] = data[key]
|
|
760
|
-
} else if (typeof data[key] === 'string' && data[key].startsWith('$')) {
|
|
761
|
-
operatorKeys[data[key] + '.' + key] = data[key]
|
|
762
|
-
} else if (key.endsWith(']')) {
|
|
763
|
-
const regex = /^(.*(?:\[\d+\].*?)?)\[(.*?)\](?:\[\])?$/;
|
|
764
|
-
const match = key.match(regex);
|
|
765
|
-
if (match[2] === '')
|
|
766
|
-
operatorKeys['$push.' + match[1]] = data[key]
|
|
767
|
-
else {
|
|
768
|
-
let index = parseInt(match[2], 10);
|
|
769
|
-
if (index === NaN)
|
|
770
|
-
operatorKeys[match[2] + '.' + match[1]] = data[key]
|
|
771
|
-
else
|
|
772
|
-
operatorKeys[key] = data[key]
|
|
773
|
-
}
|
|
774
|
-
} else if (key.includes('.')) {
|
|
775
|
-
operatorKeys[key] = data[key]
|
|
776
|
-
} else if (data[key] === undefined) {
|
|
777
|
-
delete update[key]
|
|
778
|
-
} else
|
|
779
|
-
update[key] = data[key]
|
|
780
|
-
|
|
781
|
-
})
|
|
782
|
-
|
|
783
|
-
return dotNotationToObjectUpdate(operatorKeys, update)
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
function dotNotationToObjectUpdate(data, object = {}) {
|
|
787
|
-
try {
|
|
788
|
-
for (const key of Object.keys(data)) {
|
|
789
|
-
let newObject = object
|
|
790
|
-
let oldObject = new Object(newObject)
|
|
791
|
-
let keys = key.replace(/\[(\d+)\]/g, '.$1').split('.');
|
|
792
|
-
let value = data[key]
|
|
793
|
-
let operator
|
|
794
|
-
if (keys[0].startsWith('$'))
|
|
795
|
-
operator = keys.shift()
|
|
796
|
-
|
|
797
|
-
let length = keys.length - 1
|
|
798
|
-
for (let i = 0; i < keys.length; i++) {
|
|
799
|
-
if (/^\d+$/.test(keys[i]))
|
|
800
|
-
keys[i] = parseInt(keys[i]);
|
|
801
|
-
|
|
802
|
-
if (length == i) {
|
|
803
|
-
if (operator) {
|
|
804
|
-
let operators = ['$rename', '$inc', '$push', '$each', '$splice', '$unset', '$delete', '$slice', '$pop', '$shift', '$addToSet', '$pull']
|
|
805
|
-
if (!operators.includes(operator))
|
|
806
|
-
continue
|
|
807
|
-
if (operator === '$rename') {
|
|
808
|
-
newObject[value] = newObject[keys[i]]
|
|
809
|
-
delete newObject[keys[i]]
|
|
810
|
-
} else if (operator === '$delete' || operator === '$unset' || operator === '$slice') {
|
|
811
|
-
if (typeof keys[i] === 'number')
|
|
812
|
-
newObject.slice(keys[i], 1);
|
|
813
|
-
else
|
|
814
|
-
delete newObject[keys[i]]
|
|
815
|
-
} else if (operator === '$shift') {
|
|
816
|
-
newObject[keys[i]].shift();
|
|
817
|
-
} else if (operator === '$pop') {
|
|
818
|
-
newObject[keys[i]].pop();
|
|
819
|
-
} else if (operator === '$addToSet' || operator === '$pull') {
|
|
820
|
-
// find matching items and update or delete
|
|
821
|
-
key = arrayKey
|
|
822
|
-
updates[key] = data[originalKey]
|
|
823
|
-
} else if (operator === '$push' || operator === '$splice') {
|
|
824
|
-
if (typeof keys[i] === 'number' && newObject.length >= keys[i])
|
|
825
|
-
newObject.splice(keys[i], 0, value);
|
|
826
|
-
else if (newObject[keys[i]])
|
|
827
|
-
newObject[keys[i]].push(value);
|
|
828
|
-
else
|
|
829
|
-
newObject[keys[i]] = [value];
|
|
830
|
-
} else if (operator === '$each') {
|
|
831
|
-
if (!Array.isArray(value))
|
|
832
|
-
value = [value]
|
|
833
|
-
if (typeof keys[i] === 'number')
|
|
834
|
-
newObject.splice(keys[i], 0, ...value);
|
|
835
|
-
else
|
|
836
|
-
newObject[keys[i]].push(...value);
|
|
837
|
-
} else if (operator === '$inc') {
|
|
838
|
-
newObject[keys[i]] += value
|
|
839
|
-
}
|
|
840
|
-
} else if (value === undefined) {
|
|
841
|
-
if (typeof keys[i] === 'number')
|
|
842
|
-
newObject.slice(keys[i], 1);
|
|
843
|
-
else
|
|
844
|
-
delete newObject[keys[i]]
|
|
845
|
-
} else
|
|
846
|
-
newObject[keys[i]] = value;
|
|
847
|
-
} else {
|
|
848
|
-
newObject[keys[i]] = oldObject[keys[i]] || {};
|
|
849
|
-
newObject = newObject[keys[i]]
|
|
850
|
-
oldObject = oldObject[keys[i]]
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
return object
|
|
855
|
-
} catch (error) {
|
|
856
|
-
console.log("Error converting dot notation to object", error);
|
|
857
|
-
return false;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
748
|
function createData(data, newData, type) {
|
|
862
749
|
// data.request = data[type] || {}
|
|
863
750
|
if (data[type] && data[type][0] && data[type][0].isFilter === 'isEmptyObjectFilter') {
|