@cocreate/mongodb 1.17.6 → 1.18.1
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 +14 -0
- package/package.json +1 -1
- package/src/index.js +50 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.18.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.18.0...v1.18.1) (2024-06-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* handling of $storage, $database, and $array refrence ([788c27f](https://github.com/CoCreate-app/CoCreate-mongodb/commit/788c27f4bf1ab8f37aabeb0e7d18d7378385cc07))
|
|
7
|
+
|
|
8
|
+
# [1.18.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.6...v1.18.0) (2024-04-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* handle date queries ([7d437f2](https://github.com/CoCreate-app/CoCreate-mongodb/commit/7d437f28a98b1c89066a7be3885cba137a524d65))
|
|
14
|
+
|
|
1
15
|
## [1.17.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.5...v1.17.6) (2024-02-20)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -632,8 +632,43 @@ async function createFilter(data, arrayObj) {
|
|
|
632
632
|
let query = {}, sort = {}, index = 0, limit = 0, count
|
|
633
633
|
|
|
634
634
|
if (data.$filter) {
|
|
635
|
-
|
|
636
|
-
|
|
635
|
+
function convertIfDate(value) {
|
|
636
|
+
if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/)) {
|
|
637
|
+
return new Date(value);
|
|
638
|
+
}
|
|
639
|
+
return value;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (data.$filter.query) {
|
|
643
|
+
for (let key in data.$filter.query) {
|
|
644
|
+
if (Array.isArray(data.$filter.query[key])) {
|
|
645
|
+
// Handle $or operator with an array of conditions
|
|
646
|
+
query[key] = data.$filter.query[key].map(condition => {
|
|
647
|
+
let newCondition = {};
|
|
648
|
+
for (let subKey in condition) {
|
|
649
|
+
if (typeof condition[subKey] === 'object' && condition[subKey] !== null) {
|
|
650
|
+
newCondition[subKey] = {};
|
|
651
|
+
for (let subCondition in condition[subKey]) {
|
|
652
|
+
newCondition[subKey][subCondition] = convertIfDate(condition[subKey][subCondition]);
|
|
653
|
+
}
|
|
654
|
+
} else {
|
|
655
|
+
newCondition[subKey] = convertIfDate(condition[subKey]);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return newCondition;
|
|
659
|
+
});
|
|
660
|
+
} else if (typeof data.$filter.query[key] === 'object' && data.$filter.query[key] !== null) {
|
|
661
|
+
// Handle general object conditions
|
|
662
|
+
query[key] = {};
|
|
663
|
+
for (let condition in data.$filter.query[key]) {
|
|
664
|
+
query[key][condition] = convertIfDate(data.$filter.query[key][condition]);
|
|
665
|
+
}
|
|
666
|
+
} else {
|
|
667
|
+
// Handle direct values
|
|
668
|
+
query[key] = convertIfDate(data.$filter.query[key]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
637
672
|
|
|
638
673
|
if (data.$filter.sort) {
|
|
639
674
|
for (let i = 0; i < data.$filter.sort.length; i++) {
|
|
@@ -729,18 +764,19 @@ function createData(data, array, type, dataTransferedIn, dataTransferedOut) {
|
|
|
729
764
|
for (let i = 0; i < array.length; i++) {
|
|
730
765
|
const matchIndex = data[type].findIndex((item) => item[key] === array[i][key]);
|
|
731
766
|
if (matchIndex !== -1) {
|
|
732
|
-
|
|
733
|
-
data[type][matchIndex]
|
|
734
|
-
|
|
735
|
-
data[type][matchIndex]
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
767
|
+
for (let $type of ['$storage', '$database', '$array']) {
|
|
768
|
+
if (!data[type][matchIndex][$type])
|
|
769
|
+
data[type][matchIndex][$type] = []
|
|
770
|
+
if (!Array.isArray(data[type][matchIndex][$type])) {
|
|
771
|
+
data[type][matchIndex][$type] = [data[type][matchIndex][$type]]
|
|
772
|
+
if (!data[type][matchIndex][$type].includes(array[i][$type])) {
|
|
773
|
+
data[type][matchIndex][$type].push(array[i][$type])
|
|
774
|
+
}
|
|
775
|
+
} else {
|
|
776
|
+
data[type][matchIndex][$type].push(array[i][$type])
|
|
777
|
+
}
|
|
778
|
+
delete array[i][$type]
|
|
779
|
+
}
|
|
744
780
|
|
|
745
781
|
// TODO: compare dates and merge and and updates to keep all synced and up to date
|
|
746
782
|
data[type][matchIndex] = { ...data[type][matchIndex], ...array[i] };
|