@toa.io/storages.mongodb 1.0.0-alpha.11 → 1.0.0-alpha.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/storages.mongodb",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.13",
4
4
  "description": "Toa MongoDB Storage Connector",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,13 +19,13 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
- "@toa.io/console": "1.0.0-alpha.11",
23
- "@toa.io/conveyor": "1.0.0-alpha.11",
24
- "@toa.io/core": "1.0.0-alpha.11",
25
- "@toa.io/generic": "1.0.0-alpha.11",
26
- "@toa.io/pointer": "1.0.0-alpha.11",
22
+ "@toa.io/console": "1.0.0-alpha.13",
23
+ "@toa.io/conveyor": "1.0.0-alpha.13",
24
+ "@toa.io/core": "1.0.0-alpha.13",
25
+ "@toa.io/generic": "1.0.0-alpha.13",
26
+ "@toa.io/pointer": "1.0.0-alpha.13",
27
27
  "mongodb": "6.3.0",
28
28
  "saslprep": "1.0.3"
29
29
  },
30
- "gitHead": "e343ac81eef12957cfa5e520119b1276b8ec0ad2"
30
+ "gitHead": "f779cc4a98abe96e4e928b918f9521826403536b"
31
31
  }
package/src/client.js CHANGED
@@ -57,17 +57,17 @@ class Client extends Connector {
57
57
  */
58
58
  async open () {
59
59
  const urls = await this.resolveURLs()
60
+ const db = process.env.CONTEXT ?? 'toa-dev'
61
+ const collection = this.locator.lowercase
60
62
 
61
- this.key = getKey(urls)
63
+ this.key = getKey(db, urls)
62
64
 
63
65
  INSTANCES[this.key] ??= this.createInstance(urls)
64
66
 
65
67
  this.instance = await INSTANCES[this.key]
66
68
  this.instance.count++
67
69
 
68
- this.collection = this.instance.client
69
- .db(this.locator.namespace)
70
- .collection(this.locator.name)
70
+ this.collection = this.instance.client.db(db).collection(collection)
71
71
  }
72
72
 
73
73
  /**
@@ -118,8 +118,8 @@ class Client extends Connector {
118
118
  }
119
119
  }
120
120
 
121
- function getKey (urls) {
122
- return urls.sort().join(' ')
121
+ function getKey (db, urls) {
122
+ return db + ':' + urls.sort().join(' ')
123
123
  }
124
124
 
125
125
  const OPTIONS = {
package/src/storage.js CHANGED
@@ -75,14 +75,20 @@ class Storage extends Connector {
75
75
  }
76
76
  } catch (error) {
77
77
  if (error.code === ERR_DUPLICATE_KEY) {
78
- return new exceptions.DuplicateException(Object.keys(error.keyValue))
78
+ const keys = error.keyValue ? Object.keys(error.keyValue) : undefined
79
+
80
+ if (keys === undefined) {
81
+ console.error(error)
82
+ }
83
+
84
+ return new exceptions.DuplicateException(keys)
79
85
  } else {
80
86
  throw error
81
87
  }
82
88
  }
83
89
  }
84
90
 
85
- async upsert (query, changeset, insert) {
91
+ async upsert (query, changeset) {
86
92
  const {
87
93
  criteria,
88
94
  options
@@ -93,20 +99,6 @@ class Storage extends Connector {
93
99
  $inc: { _version: 1 }
94
100
  }
95
101
 
96
- if (insert !== undefined) {
97
- delete insert._version
98
-
99
- options.upsert = true
100
-
101
- if (criteria._id !== undefined) {
102
- insert._id = criteria._id
103
- } else {
104
- return null
105
- } // this shouldn't ever happen
106
-
107
- if (Object.keys(insert) > 0) update.$setOnInsert = insert
108
- }
109
-
110
102
  options.returnDocument = 'after'
111
103
 
112
104
  const result = await this.#connection.update(criteria, update, options)