@cocreate/mongodb 1.17.0 → 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,19 @@
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
+
10
+ ## [1.17.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.17.0...v1.17.1) (2024-01-18)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * handle stroage if $storage string ([732a2b9](https://github.com/CoCreate-app/CoCreate-mongodb/commit/732a2b9e0ac6cb10225a202df204f046e6728733))
16
+
1
17
  # [1.17.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.16.1...v1.17.0) (2024-01-17)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.17.0",
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
 
@@ -294,6 +294,14 @@ function object(method, data) {
294
294
  let $storage = data[type][i].$storage || []
295
295
  let $database = data[type][i].$database || []
296
296
  let $array = data[type][i].$array || []
297
+
298
+ if (!Array.isArray($storage))
299
+ $storage = [data[type][i].$storage]
300
+ if (!Array.isArray($database))
301
+ $database = [data[type][i].$database]
302
+ if (!Array.isArray($array))
303
+ $array = [data[type][i].$array]
304
+
297
305
  $storage.push(data.storageName)
298
306
  $database.push(database)
299
307
  $array.push(array)
@@ -397,6 +405,10 @@ function object(method, data) {
397
405
  }
398
406
  } else if (isFilter) {
399
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
+
400
412
  if (method === 'read')
401
413
  projection = { ...projections, ...projection }
402
414
 
@@ -424,7 +436,7 @@ function object(method, data) {
424
436
  let object = data[type].find(obj => obj._id && obj._id.toString() === document._id.toString())
425
437
  if (object) {
426
438
  if (object.$storage && object.modified && object.modified.on) {
427
- 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)) {
428
440
  object = { ...document, ...object }
429
441
  createUpdate(update, options, object)
430
442
  document = await arrayObj.updateOne(query, update, options);
@@ -643,7 +655,7 @@ async function createFilter(data, arrayObj) {
643
655
  }
644
656
 
645
657
  if (data['organization_id'])
646
- query['organization_id'] = { $eq: data['organization_id'] }
658
+ query['organization_id'] = data['organization_id']
647
659
 
648
660
  return { query, sort, index, limit, count }
649
661
  }
@@ -730,19 +742,23 @@ function getBytes(data) {
730
742
  }
731
743
 
732
744
  function errorHandler(data, error, database, array) {
733
- if (typeof error == 'object')
734
- error['storage'] = 'mongodb'
735
- else
736
- 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
+ };
737
751
 
738
752
  if (database)
739
- error['database'] = database
753
+ errorObject.database = database;
740
754
  if (array)
741
- error['array'] = array
742
- if (data.error)
743
- data.error.push(error)
744
- else
745
- 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
+ }
746
762
  }
747
763
 
748
764
  module.exports = { send }