@cocreate/mongodb 1.10.2 → 1.10.4

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.10.4](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.10.3...v1.10.4) (2023-10-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * dbClient error handling ([256e9b9](https://github.com/CoCreate-app/CoCreate-mongodb/commit/256e9b975a26c6eea16174d99335bf66066a5f36))
7
+
8
+ ## [1.10.3](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.10.2...v1.10.3) (2023-10-25)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump dependencies ([699920c](https://github.com/CoCreate-app/CoCreate-mongodb/commit/699920c13213562158983f04ba401bd919c24628))
14
+
1
15
  ## [1.10.2](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.10.1...v1.10.2) (2023-10-14)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/mongodb",
3
- "version": "1.10.2",
3
+ "version": "1.10.4",
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",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "main": "./src/index.js",
47
47
  "dependencies": {
48
- "@cocreate/utils": "^1.25.0",
48
+ "@cocreate/utils": "^1.26.1",
49
49
  "mongodb": "^4.12.1"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -8,10 +8,12 @@ async function dbClient(data) {
8
8
  let client = clients.get(data.storageUrl)
9
9
  if (!client) {
10
10
  try {
11
- client = MongoClient.connect(data.storageUrl, { useNewUrlParser: true, useUnifiedTopology: true });
11
+ clients.set(data.storageUrl, client)
12
+ client = await MongoClient.connect(data.storageUrl, { useNewUrlParser: true, useUnifiedTopology: true });
12
13
  clients.set(data.storageUrl, client)
13
14
  } catch (error) {
14
- console.error(error)
15
+ console.error(`${data.organization_id}: storageName ${data.storageName} failed to connect to mongodb`)
16
+ errorHandler(data, error)
15
17
  return { status: false }
16
18
  }
17
19
  }
@@ -41,7 +43,8 @@ function database(action, data) {
41
43
 
42
44
  try {
43
45
  const client = await dbClient(data)
44
- if (!client) return
46
+ if (!client.status)
47
+ return data
45
48
  if (action == 'readDatabase') {
46
49
  const db = client.db().admin();
47
50
  // TODO: support if a database name is defined then return the database details and stats
@@ -94,7 +97,8 @@ function array(action, data) {
94
97
 
95
98
  try {
96
99
  const client = await dbClient(data)
97
- if (!client) return
100
+ if (!client.status)
101
+ return data
98
102
 
99
103
  if (data.request)
100
104
  data.array = data.request
@@ -239,7 +243,9 @@ function object(action, data) {
239
243
  return new Promise(async (resolve, reject) => {
240
244
  try {
241
245
  const client = await dbClient(data)
242
- if (!client) return
246
+ if (!client.status)
247
+ return data
248
+
243
249
  let dataTransferedIn = 0
244
250
  let dataTransferedOut = 0
245
251
  let type = 'object'
@@ -286,6 +292,10 @@ function object(action, data) {
286
292
  createUpdate(update, options, data, true)
287
293
 
288
294
  for (let i = 0; i < data[type].length; i++) {
295
+ delete data[type][i].$storage
296
+ delete data[type][i].$database
297
+ delete data[type][i].$array
298
+
289
299
  if (action !== 'createObject' && data[type][i].$filter) {
290
300
  isFilter = true
291
301
  reference['$filter'] = data[type][i].$filter