@cocreate/mongodb 1.17.1 → 1.17.2

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,12 @@
1
+ ## [1.17.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.1...v1.17.2) (2024-01-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * error message ([0344407](https://github.com/CoCreate-app/CoCreate-mongodb/commit/03444076bbc9da8379d8d9a112170ff1c2d416f3))
7
+ * query.organization_id ([1bcbff7](https://github.com/CoCreate-app/CoCreate-mongodb/commit/1bcbff7c57df52aa984b16e1df800d9b3cb0a581))
8
+ * queryData ([e49ab52](https://github.com/CoCreate-app/CoCreate-mongodb/commit/e49ab526bfcd9897f7fb30f578cb142c9c5b0efd))
9
+
1
10
  ## [1.17.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.0...v1.17.1) (2024-01-18)
2
11
 
3
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.17.1",
3
+ "version": "1.17.2",
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
@@ -1,5 +1,5 @@
1
1
  const { MongoClient, ObjectId } = require('mongodb');
2
- const { dotNotationToObject, query, searchData, sortData, isValidDate } = require('@cocreate/utils')
2
+ const { dotNotationToObject, queryData, searchData, sortData, isValidDate } = require('@cocreate/utils')
3
3
  const clients = new Map()
4
4
  const organizations = {}
5
5
 
@@ -405,6 +405,10 @@ function object(method, data) {
405
405
  }
406
406
  } else if (isFilter) {
407
407
  try {
408
+ // TODO: index is 1 if indexeddb already returned an item interfering with query
409
+ // if (data.array === "keys")
410
+ // index = 0
411
+
408
412
  if (method === 'read')
409
413
  projection = { ...projections, ...projection }
410
414
 
@@ -432,7 +436,7 @@ function object(method, data) {
432
436
  let object = data[type].find(obj => obj._id && obj._id.toString() === document._id.toString())
433
437
  if (object) {
434
438
  if (object.$storage && object.modified && object.modified.on) {
435
- if (document && new Date(object.modified.on) > new Date(document.modified.on)) {
439
+ if (document && document.modified && new Date(object.modified.on) > new Date(document.modified.on)) {
436
440
  object = { ...document, ...object }
437
441
  createUpdate(update, options, object)
438
442
  document = await arrayObj.updateOne(query, update, options);
@@ -651,7 +655,7 @@ async function createFilter(data, arrayObj) {
651
655
  }
652
656
 
653
657
  if (data['organization_id'])
654
- query['organization_id'] = { $eq: data['organization_id'] }
658
+ query['organization_id'] = data['organization_id']
655
659
 
656
660
  return { query, sort, index, limit, count }
657
661
  }
@@ -738,19 +742,23 @@ function getBytes(data) {
738
742
  }
739
743
 
740
744
  function errorHandler(data, error, database, array) {
741
- if (typeof error == 'object')
742
- error['storage'] = 'mongodb'
743
- else
744
- error = { storage: data.storageName, message: error }
745
+ let errorMessage = typeof error === 'object' && error.message ? error.message : error;
746
+
747
+ let errorObject = {
748
+ message: errorMessage,
749
+ storage: 'mongodb'
750
+ };
745
751
 
746
752
  if (database)
747
- error['database'] = database
753
+ errorObject.database = database;
748
754
  if (array)
749
- error['array'] = array
750
- if (data.error)
751
- data.error.push(error)
752
- else
753
- data.error = [error]
755
+ errorObject.array = array;
756
+
757
+ if (Array.isArray(data.error)) {
758
+ data.error.push(errorObject);
759
+ } else {
760
+ data.error = [errorObject];
761
+ }
754
762
  }
755
763
 
756
764
  module.exports = { send }