@toa.io/storages.mongodb 1.0.0-alpha.321 → 1.0.0-alpha.323

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,21 @@
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.323](https://github.com/toa-io/toa/compare/v1.0.0-alpha.322...v1.0.0-alpha.323) (2026-10-01)
7
+
8
+ ### Bug Fixes
9
+
10
+ * **storages.mongodb:** store the moments an assignment sets as dates ([240102d](https://github.com/toa-io/toa/commit/240102db5b218e0b0a3a7b097c77852e749e76ef))
11
+
12
+
13
+ # [1.0.0-alpha.322](https://github.com/toa-io/toa/compare/v1.0.0-alpha.321...v1.0.0-alpha.322) (2026-09-29)
14
+
15
+ **Note:** Version bump only for package @toa.io/storages.mongodb
16
+
17
+
18
+
19
+
20
+
6
21
  # [1.0.0-alpha.321](https://github.com/toa-io/toa/compare/v1.0.0-alpha.320...v1.0.0-alpha.321) (2026-09-28)
7
22
 
8
23
  ### Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/storages.mongodb",
3
- "version": "1.0.0-alpha.321",
3
+ "version": "1.0.0-alpha.323",
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.311",
24
- "@toa.io/core": "1.0.0-alpha.321",
25
- "@toa.io/definitions": "1.0.0-alpha.321",
24
+ "@toa.io/core": "1.0.0-alpha.323",
25
+ "@toa.io/definitions": "1.0.0-alpha.323",
26
26
  "@toa.io/generic": "1.0.0-alpha.311",
27
27
  "@toa.io/pointer": "1.0.0-alpha.311",
28
28
  "mongodb": "7.6.0",
29
- "openspan": "1.0.0-alpha.305"
29
+ "openspan": "1.0.0-alpha.323"
30
30
  },
31
- "gitHead": "fa850e861a0c748d7364ccf7c8a09ce26973fc04"
31
+ "gitHead": "1d31b234602c9eda959d80bdca79b983ebf541ea"
32
32
  }
package/src/record.js CHANGED
@@ -49,13 +49,18 @@ export function codec(properties) {
49
49
 
50
50
  const dates = read.map(([name]) => name)
51
51
 
52
- if (dates.length === 0) return { to, from, dates }
52
+ if (dates.length === 0) return { to, from, changes, dates }
53
+
54
+ const write = dates.map((name) => [name, date])
53
55
 
54
56
  return {
55
57
  dates,
56
58
 
57
59
  // one way in for both: `Date` takes the milliseconds and the ISO string alike
58
- to: (entity) => convert(to(entity), dates.map((name) => [name, date])),
60
+ to: (entity) => convert(to(entity), write),
61
+
62
+ // what an assignment sets, which is the same properties with no record around them
63
+ changes: (changeset) => convert({ ...changeset }, write),
59
64
 
60
65
  from: (record) => {
61
66
  const state = from(record)
@@ -66,7 +71,7 @@ export function codec(properties) {
66
71
  }
67
72
 
68
73
  /**
69
- * Writes into an object either `to` or `from` has just made, so nothing the caller holds is
74
+ * Writes into an object `to`, `from` or `changes` has just made, so nothing the caller holds is
70
75
  * touched.
71
76
  *
72
77
  * @private
@@ -86,6 +91,9 @@ function convert(record, casts) {
86
91
 
87
92
  const date = (value) => new Date(value)
88
93
 
94
+ /** A changeset of an entity that declares no moment is set as it is. */
95
+ const changes = (changeset) => changeset
96
+
89
97
  /*
90
98
  * What a record written before the property was declared a moment holds is what it was given,
91
99
  * and it is answered as it is: a collection is converted by a migration rather than by every
package/src/storage.js CHANGED
@@ -41,6 +41,7 @@ export class Storage extends Connector {
41
41
  /** how a record is written and read back, which depends on what the entity declares */
42
42
  #to
43
43
  #from
44
+ #changes
44
45
 
45
46
  /** properties held as BSON dates, so that a criterion against one is one too */
46
47
  #dates
@@ -51,10 +52,11 @@ export class Storage extends Connector {
51
52
  this.#client = client
52
53
  this.#entity = entity
53
54
 
54
- const { to, from, dates } = codec(entity?.properties)
55
+ const { to, from, changes, dates } = codec(entity?.properties)
55
56
 
56
57
  this.#to = to
57
58
  this.#from = from
59
+ this.#changes = changes
58
60
  this.#dates = dates
59
61
 
60
62
  this.depends(client)
@@ -419,7 +421,7 @@ export class Storage extends Connector {
419
421
  }
420
422
 
421
423
  const update = {
422
- $set: { ...changeset },
424
+ $set: this.#changes(changeset),
423
425
  $inc: { VERSION: 1 }
424
426
  }
425
427
 
@@ -135,4 +135,27 @@ describe('codec, epoch-millis', () => {
135
135
  it('should read a record written before the property was a date', () => {
136
136
  assert.strictEqual(codec(properties).from({ _id: '1', DELETED: millis }).DELETED, millis)
137
137
  })
138
+
139
+ it('should write the moments of a changeset as dates', () => {
140
+ const changes = codec(properties).changes({ DELETED: millis, VERSION: 2 })
141
+
142
+ assert.ok(changes.DELETED instanceof Date)
143
+ assert.strictEqual(changes.DELETED.getTime(), millis)
144
+ assert.strictEqual(changes.VERSION, 2, 'and leaves a plain integer alone')
145
+ assert.ok(!('_id' in changes), 'and names no record')
146
+ })
147
+
148
+ it('should not modify the changeset', () => {
149
+ const changeset = { DELETED: millis }
150
+
151
+ codec(properties).changes(changeset)
152
+
153
+ assert.strictEqual(changeset.DELETED, millis)
154
+ })
155
+
156
+ it('should leave a changeset of an entity that declares no moment as it is', () => {
157
+ const changeset = { VERSION: 2 }
158
+
159
+ assert.strictEqual(codec({ VERSION: { type: 'integer' } }).changes(changeset), changeset)
160
+ })
138
161
  })