@toa.io/storages.mongodb 1.0.0-alpha.301 → 1.0.0-alpha.303

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
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.303](https://github.com/toa-io/toa/compare/v1.0.0-alpha.302...v1.0.0-alpha.303) (2026-09-12)
7
+
8
+ ### Features
9
+
10
+ * **metrics:** measure storage, stash, blob storages and fetch ([252298b](https://github.com/toa-io/toa/commit/252298bb9f34421694da4ee89742d62b47c39dfb))
11
+
12
+ ### Performance Improvements
13
+
14
+ * **storages.mongodb:** rename a record's _id to id in place ([4aeb2a1](https://github.com/toa-io/toa/commit/4aeb2a1d61f7f2b0ddab203b5887152e8917ef7f))
15
+
16
+
17
+ # [1.0.0-alpha.302](https://github.com/toa-io/toa/compare/v1.0.0-alpha.301...v1.0.0-alpha.302) (2026-09-11)
18
+
19
+ **Note:** Version bump only for package @toa.io/storages.mongodb
20
+
21
+
22
+
23
+
24
+
6
25
  # [1.0.0-alpha.301](https://github.com/toa-io/toa/compare/v1.0.0-alpha.300...v1.0.0-alpha.301) (2026-09-11)
7
26
 
8
27
  **Note:** Version bump only for package @toa.io/storages.mongodb
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/storages.mongodb",
3
- "version": "1.0.0-alpha.301",
3
+ "version": "1.0.0-alpha.303",
4
4
  "type": "module",
5
5
  "description": "Toa MongoDB Storage Connector",
6
6
  "author": "temich <tema.gurtovoy@gmail.com>",
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@toa.io/conveyor": "1.0.0-alpha.301",
24
- "@toa.io/core": "1.0.0-alpha.301",
25
- "@toa.io/definitions": "1.0.0-alpha.301",
24
+ "@toa.io/core": "1.0.0-alpha.303",
25
+ "@toa.io/definitions": "1.0.0-alpha.303",
26
26
  "@toa.io/generic": "1.0.0-alpha.301",
27
27
  "@toa.io/pointer": "1.0.0-alpha.301",
28
28
  "mongodb": "7.6.0",
29
- "openspan": "1.0.0-alpha.301"
29
+ "openspan": "1.0.0-alpha.303"
30
30
  },
31
- "gitHead": "cc49bc90efd35464b2ad7803246786c607a44685"
31
+ "gitHead": "b8e9dd89f6d49756944687a95dfc786f12947286"
32
32
  }
package/readme.md CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  ## Tracing
4
4
 
5
- Commands are recorded as `client` spans within the trace of the current invocation,
6
- using the [driver command monitoring events](https://www.mongodb.com/docs/drivers/node/current/monitoring/command-monitoring/).
5
+ Commands are recorded as `client` spans within the trace of the current invocation.
7
6
 
8
7
  Spans are named `{command} {collection}` and carry `db.*` attributes following the
9
8
  [OpenTelemetry semantic conventions](https://opentelemetry.io/docs/specs/semconv/database/mongodb/):
@@ -0,0 +1,39 @@
1
+ import { registry } from 'openspan'
2
+
3
+ /**
4
+ * What this storage measures. `provider` is which database it is, so that a deployment running more
5
+ * than one can be read a kind at a time. No database label: the database is the context, which
6
+ * every series already carries as its resource.
7
+ */
8
+ const meters = registry()
9
+
10
+ /** Prometheus' own ladder, in seconds: from five milliseconds to ten seconds. */
11
+ const DURATIONS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
12
+
13
+ const PROVIDER = 'mongodb'
14
+
15
+ const duration = meters.histogram(
16
+ 'toa.storage.query.duration',
17
+ { buckets: DURATIONS, unit: 's' },
18
+ { provider: null, collection: null, operation: null }
19
+ )
20
+
21
+ /**
22
+ * A compare-and-swap that lost. Whether it is retried or raised is the operation's to declare, and
23
+ * the retried one succeeds — so without this it is a duration that grew and nothing else.
24
+ */
25
+ const conflicts = meters.counter('toa.storage.conflicts', {
26
+ provider: null,
27
+ collection: null
28
+ })
29
+
30
+ export function query(collection, operation) {
31
+ return {
32
+ histogram: duration,
33
+ labels: { provider: PROVIDER, collection, operation }
34
+ }
35
+ }
36
+
37
+ export function conflicted(collection) {
38
+ conflicts.add(1, { provider: PROVIDER, collection })
39
+ }
package/src/record.js CHANGED
@@ -4,12 +4,18 @@ export function to(entity) {
4
4
  return /** @type {toa.mongodb.Record} */ { _id: id, ...rest }
5
5
  }
6
6
 
7
+ /**
8
+ * Renamed in the object the driver decoded, which is a new one for every document; an entity
9
+ * copies a state before an operation that writes changes it. A copy costs ten times the rename,
10
+ * and what it would keep is only `id` in front, which a reply does not promise.
11
+ */
7
12
  export function from(record) {
8
13
  if (record === undefined || record === null) return null
9
14
 
10
- const { _id, ...rest } = record
15
+ record.id = record._id
16
+ delete record._id
11
17
 
12
- return { id: _id, ...rest }
18
+ return record
13
19
  }
14
20
 
15
21
  /**
package/src/storage.js CHANGED
@@ -5,6 +5,7 @@ import { codec } from './record.js'
5
5
  import { Inbox } from './inbox.js'
6
6
  import { Outbox } from './outbox.js'
7
7
  import { Migrations } from './migrations.js'
8
+ import { conflicted, query } from './measurements.js'
8
9
  import { ReturnDocument } from 'mongodb'
9
10
 
10
11
  export class Storage extends Connector {
@@ -184,6 +185,9 @@ export class Storage extends Connector {
184
185
  this.#collection.findOneAndReplace(criteria, record, { session })
185
186
  )
186
187
 
188
+ // the version moved under this write: whoever asked either retries it or raises
189
+ if (result === null) conflicted(this.#collection.collectionName)
190
+
187
191
  return result !== null
188
192
  }
189
193
 
@@ -509,7 +513,8 @@ export class Storage extends Connector {
509
513
  'db.namespace': this.#collection.dbName,
510
514
  'db.operation.name': method,
511
515
  'db.collection.name': collection
512
- }
516
+ },
517
+ measure: query(collection, method)
513
518
  }
514
519
 
515
520
  this.#spans.set(method, options)