@cocreate/mongodb 1.17.3 → 1.17.5

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.17.5](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.4...v1.17.5) (2024-02-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * $storage,$database, etc. if does not exist set as empty array ([a7d1ae4](https://github.com/CoCreate-app/CoCreate-mongodb/commit/a7d1ae4a277ad2f136963b4e78b6c7ba3826c3ba))
7
+
8
+ ## [1.17.4](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.3...v1.17.4) (2024-02-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * added console.log to temporarily log data[type] that are not arrays ([7fc7e1a](https://github.com/CoCreate-app/CoCreate-mongodb/commit/7fc7e1a4b4e4477b462c48be187fe3b6d416721d))
14
+
1
15
  ## [1.17.3](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.2...v1.17.3) (2024-02-05)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.17.3",
3
+ "version": "1.17.5",
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
@@ -717,20 +717,32 @@ function createData(data, array, type, dataTransferedIn, dataTransferedOut) {
717
717
  let key = '_id'
718
718
  if (type !== 'object')
719
719
  key = 'name'
720
- for (let i = 0; i < array.length; i++) {
721
- const matchIndex = data[type].findIndex((item) => item[key] === array[i][key]);
722
- if (matchIndex !== -1) {
723
- data[type][matchIndex].$storage.push(array[i].$storage)
724
- delete array[i].$storage
725
- data[type][matchIndex].$database.push(array[i].$database)
726
- delete array[i].$database
727
- data[type][matchIndex].$array.push(array[i].$array)
728
- delete array[i].$array
729
-
730
- // TODO: compare dates and merge and and updates to keep all synced and up to date
731
- data[type][matchIndex] = { ...data[type][matchIndex], ...array[i] };
732
- } else
733
- data[type].push(array[i])
720
+
721
+ // TODO: handle case where data[type] is not an array
722
+ if (!Array.isArray(data[type]))
723
+ console.log('data[type] is not an array', type)
724
+ else {
725
+ for (let i = 0; i < array.length; i++) {
726
+ const matchIndex = data[type].findIndex((item) => item[key] === array[i][key]);
727
+ if (matchIndex !== -1) {
728
+ if (!data[type][matchIndex].$storage)
729
+ data[type][matchIndex].$storage = []
730
+ if (!data[type][matchIndex].$database)
731
+ data[type][matchIndex].$database = []
732
+ if (!data[type][matchIndex].$array)
733
+ data[type][matchIndex].$array = []
734
+ data[type][matchIndex].$storage.push(array[i].$storage)
735
+ delete array[i].$storage
736
+ data[type][matchIndex].$database.push(array[i].$database)
737
+ delete array[i].$database
738
+ data[type][matchIndex].$array.push(array[i].$array)
739
+ delete array[i].$array
740
+
741
+ // TODO: compare dates and merge and and updates to keep all synced and up to date
742
+ data[type][matchIndex] = { ...data[type][matchIndex], ...array[i] };
743
+ } else
744
+ data[type].push(array[i])
745
+ }
734
746
  }
735
747
 
736
748
  return data