@toa.io/storages.mongodb 1.0.0-alpha.126 → 1.0.0-alpha.130

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.126",
3
+ "version": "1.0.0-alpha.130",
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",
@@ -27,5 +27,5 @@
27
27
  "openspan": "1.0.0-alpha.93",
28
28
  "saslprep": "1.0.3"
29
29
  },
30
- "gitHead": "5d350c594b9ad4e0c5956c5ffcb792306b9004ed"
30
+ "gitHead": "fe6810a087b7c7c88b4e194b99ce421fc21501ba"
31
31
  }
package/src/client.js CHANGED
@@ -51,6 +51,7 @@ class Client extends Connector {
51
51
  super()
52
52
 
53
53
  this.locator = locator
54
+ this.name = locator.lowercase
54
55
  }
55
56
 
56
57
  /**
@@ -62,7 +63,6 @@ class Client extends Connector {
62
63
  const urls = await this.resolveURLs()
63
64
  const dbname = this.resolveDB()
64
65
 
65
- this.name = this.locator.lowercase
66
66
  this.key = getKey(dbname, urls)
67
67
 
68
68
  INSTANCES[this.key] ??= this.createInstance(urls)
package/src/storage.js CHANGED
@@ -13,6 +13,8 @@ class Storage extends Connector {
13
13
  #collection
14
14
  #entity
15
15
 
16
+ #logs
17
+
16
18
  constructor (client, entity) {
17
19
  super()
18
20
 
@@ -20,6 +22,8 @@ class Storage extends Connector {
20
22
  this.#entity = entity
21
23
 
22
24
  this.depends(client)
25
+
26
+ this.#logs = console.fork({ collection: client.name })
23
27
  }
24
28
 
25
29
  get raw () {
@@ -149,7 +153,7 @@ class Storage extends Connector {
149
153
  options.upsert = true
150
154
  options.returnDocument = ReturnDocument.AFTER
151
155
 
152
- console.debug('Database query', { method: 'findOneAndUpdate', criteria, update, options })
156
+ this.#logs.debug('Database query', { method: 'findOneAndUpdate', criteria, update, options })
153
157
 
154
158
  const result = await this.#collection.findOneAndUpdate(criteria, update, options)
155
159
 
@@ -180,7 +184,7 @@ class Storage extends Connector {
180
184
  const sparse = this.checkFields(Object.keys(fields))
181
185
 
182
186
  await this.#collection.createIndex(fields, { name, sparse })
183
- .catch((e) => console.warn('Index creation failed', { name, fields, error: e }))
187
+ .catch((e) => this.#logs.warn('Index creation failed', { name, fields, error: e }))
184
188
 
185
189
  indexes.push(name)
186
190
  }
@@ -198,7 +202,7 @@ class Storage extends Connector {
198
202
  name = 'unique_' + name
199
203
 
200
204
  await this.#collection.createIndex(fields, { name, unique: true, sparse })
201
- .catch((e) => console.warn('Unique index creation failed', { name, fields, error: e }))
205
+ .catch((e) => this.#logs.warn('Unique index creation failed', { name, fields, error: e }))
202
206
 
203
207
  return name
204
208
  }
@@ -208,7 +212,7 @@ class Storage extends Connector {
208
212
  const obsolete = current.filter((name) => !desired.includes(name))
209
213
 
210
214
  if (obsolete.length > 0) {
211
- console.info('Removing obsolete indexes', { indexes: obsolete.join(', ') })
215
+ this.#logs.info('Removing obsolete indexes', { indexes: obsolete.join(', ') })
212
216
 
213
217
  await Promise.all(obsolete.map((name) => this.#collection.dropIndex(name)))
214
218
  }
@@ -236,7 +240,7 @@ class Storage extends Connector {
236
240
  }
237
241
 
238
242
  if (optional.length > 0) {
239
- console.info('Index fields are optional, creating sparse index', { fields: optional.join(', ') })
243
+ this.#logs.info('Index fields are optional, creating sparse index', { fields: optional })
240
244
 
241
245
  return true
242
246
  } else
@@ -244,8 +248,7 @@ class Storage extends Connector {
244
248
  }
245
249
 
246
250
  debug (method, attributes) {
247
- console.debug('Database query', {
248
- collection: this.#client.name,
251
+ this.#logs.debug('Database query', {
249
252
  method,
250
253
  ...attributes
251
254
  })