@cocreate/mongodb 1.17.5 → 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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.18.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.6...v1.18.0) (2024-04-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * handle date queries ([7d437f2](https://github.com/CoCreate-app/CoCreate-mongodb/commit/7d437f28a98b1c89066a7be3885cba137a524d65))
7
+
8
+ ## [1.17.6](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.5...v1.17.6) (2024-02-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * process key[] as $push ([5628edf](https://github.com/CoCreate-app/CoCreate-mongodb/commit/5628edf111e46901583fd0ac9fcd5c27687f4204))
14
+
1
15
  ## [1.17.5](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.4...v1.17.5) (2024-02-14)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.17.5",
3
+ "version": "1.18.0",
4
4
  "description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "mongodb",
package/src/index.js CHANGED
@@ -520,6 +520,8 @@ function createUpdate(update, options, data, isGlobal) {
520
520
  options.upsert = data.upsert
521
521
  if (data.$upsert)
522
522
  options.upsert = data.$upsert
523
+ if (data.$update)
524
+ delete data.$update
523
525
 
524
526
  Object.keys(data).forEach(key => {
525
527
  if (isGlobal && !key.startsWith('$') || key === '_id')
@@ -560,6 +562,8 @@ function createUpdate(update, options, data, isGlobal) {
560
562
  }
561
563
  if (!key.startsWith('$'))
562
564
  operator = '$push'
565
+ if (key.endsWith('[]'))
566
+ key = key.replace('[]', '');
563
567
  }
564
568
 
565
569
  let operators = ['$rename', '$inc', '$push', '$each', '$splice', '$unset', '$delete', '$slice', '$pop', '$shift', '$addToSet', '$pull', '$currentDate']
@@ -628,8 +632,43 @@ async function createFilter(data, arrayObj) {
628
632
  let query = {}, sort = {}, index = 0, limit = 0, count
629
633
 
630
634
  if (data.$filter) {
631
- if (data.$filter.query)
632
- query = data.$filter.query
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
+ }
633
672
 
634
673
  if (data.$filter.sort) {
635
674
  for (let i = 0; i < data.$filter.sort.length; i++) {