@toa.io/storages.mongodb 1.0.0-alpha.324 → 1.0.0-alpha.325
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 +7 -0
- package/package.json +3 -3
- package/src/streams.js +5 -2
- package/test/streams.test.js +60 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
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.325](https://github.com/toa-io/toa/compare/v1.0.0-alpha.324...v1.0.0-alpha.325) (2026-10-02)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **storages.mongodb:** kill the cursor of a stream's position whatever type its id comes as ([71c799e](https://github.com/toa-io/toa/commit/71c799ec3694a41cc32890d9e21bb42573b96395))
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
# [1.0.0-alpha.324](https://github.com/toa-io/toa/compare/v1.0.0-alpha.323...v1.0.0-alpha.324) (2026-10-02)
|
|
7
14
|
|
|
8
15
|
**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.
|
|
3
|
+
"version": "1.0.0-alpha.325",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Toa MongoDB Storage Connector",
|
|
6
6
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@toa.io/conveyor": "1.0.0-alpha.311",
|
|
24
24
|
"@toa.io/core": "1.0.0-alpha.323",
|
|
25
|
-
"@toa.io/definitions": "1.0.0-alpha.
|
|
25
|
+
"@toa.io/definitions": "1.0.0-alpha.325",
|
|
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
29
|
"openspan": "1.0.0-alpha.323"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "95bc03e65c65f02d536da6ed027cf4f78f5cec74"
|
|
32
32
|
}
|
package/src/streams.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import { Readable } from 'node:stream'
|
|
3
|
-
import { Timestamp } from 'mongodb'
|
|
3
|
+
import { Long, Timestamp } from 'mongodb'
|
|
4
4
|
import { exceptions, parts } from '@toa.io/core'
|
|
5
5
|
import { match } from './match.js'
|
|
6
6
|
|
|
@@ -106,7 +106,10 @@ export class Streams {
|
|
|
106
106
|
{ session }
|
|
107
107
|
)
|
|
108
108
|
|
|
109
|
-
const {
|
|
109
|
+
const { postBatchResumeToken } = reply.cursor
|
|
110
|
+
|
|
111
|
+
// the driver gives an id that fits a number as a number, and `killCursors` takes a long
|
|
112
|
+
const id = Long.fromValue(reply.cursor.id)
|
|
110
113
|
|
|
111
114
|
if (!id.isZero()) await db.command({ killCursors: name, cursors: [id] }, { session })
|
|
112
115
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { Long, Timestamp } from 'mongodb'
|
|
4
|
+
|
|
5
|
+
import { Streams } from '../src/streams.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A first read takes the position of a change stream, and kills the cursor that took it. The
|
|
9
|
+
* driver gives a cursor id that fits a number as a number, and one that does not as a `Long`.
|
|
10
|
+
*/
|
|
11
|
+
function streams(id) {
|
|
12
|
+
const killed = []
|
|
13
|
+
|
|
14
|
+
const db = {
|
|
15
|
+
command: async (command) => {
|
|
16
|
+
if ('killCursors' in command) {
|
|
17
|
+
killed.push(...command.cursors)
|
|
18
|
+
|
|
19
|
+
return {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { cursor: { id, postBatchResumeToken: { _data: '82' } } }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const session = { operationTime: new Timestamp(1n), endSession: async () => undefined }
|
|
27
|
+
const cursor = {
|
|
28
|
+
hasNext: async () => false,
|
|
29
|
+
close: async () => undefined,
|
|
30
|
+
[Symbol.asyncIterator]: async function* () {}
|
|
31
|
+
}
|
|
32
|
+
const collection = { s: { db }, collectionName: 'test', find: () => cursor }
|
|
33
|
+
const client = () => ({ startSession: () => session })
|
|
34
|
+
|
|
35
|
+
return { streams: new Streams(collection, client, (record) => record, true), killed }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
for (const [name, id] of [
|
|
39
|
+
['a number', 7],
|
|
40
|
+
['a Long', Long.fromString('9007199254740993')]
|
|
41
|
+
])
|
|
42
|
+
it(`should kill the cursor of the position, whose id is ${name}`, async () => {
|
|
43
|
+
const { streams: read, killed } = streams(id)
|
|
44
|
+
|
|
45
|
+
await read.stream({ criteria: {}, options: {} })
|
|
46
|
+
|
|
47
|
+
assert.deepEqual(
|
|
48
|
+
killed.map((one) => Long.fromValue(one).toString()),
|
|
49
|
+
[Long.fromValue(id).toString()]
|
|
50
|
+
)
|
|
51
|
+
assert.ok(killed.every((one) => one instanceof Long))
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should kill no cursor that is closed already', async () => {
|
|
55
|
+
const { streams: read, killed } = streams(0)
|
|
56
|
+
|
|
57
|
+
await read.stream({ criteria: {}, options: {} })
|
|
58
|
+
|
|
59
|
+
assert.deepEqual(killed, [])
|
|
60
|
+
})
|