@toa.io/storages.mongodb 1.0.0-alpha.32 → 1.0.0-alpha.33
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 +7 -7
- package/src/collection.js +4 -2
- package/src/record.js +8 -20
- package/src/storage.js +10 -18
- package/test/record.test.js +0 -15
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.33",
|
|
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.
|
|
23
|
-
"@toa.io/conveyor": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
26
|
-
"@toa.io/pointer": "1.0.0-alpha.
|
|
22
|
+
"@toa.io/console": "1.0.0-alpha.33",
|
|
23
|
+
"@toa.io/conveyor": "1.0.0-alpha.33",
|
|
24
|
+
"@toa.io/core": "1.0.0-alpha.33",
|
|
25
|
+
"@toa.io/generic": "1.0.0-alpha.33",
|
|
26
|
+
"@toa.io/pointer": "1.0.0-alpha.33",
|
|
27
27
|
"mongodb": "6.3.0",
|
|
28
28
|
"saslprep": "1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "ef81cea49d8f8b3b248adaba62d4548bbeb39f80"
|
|
31
31
|
}
|
package/src/collection.js
CHANGED
|
@@ -25,9 +25,11 @@ class Collection extends Connector {
|
|
|
25
25
|
|
|
26
26
|
/** @hot */
|
|
27
27
|
async find (query, options) {
|
|
28
|
-
|
|
28
|
+
return this.#collection.find(query, options).toArray()
|
|
29
|
+
}
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
async stream (query, options, transform) {
|
|
32
|
+
return this.#collection.find(query, options).stream({ transform })
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/** @hot */
|
package/src/record.js
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @returns {toa.mongodb.Record}
|
|
6
|
-
*/
|
|
7
|
-
const to = (entity) => {
|
|
8
|
-
const {
|
|
9
|
-
id,
|
|
10
|
-
...rest
|
|
11
|
-
} = entity
|
|
3
|
+
function to (entity) {
|
|
4
|
+
const { id, ...rest } = entity
|
|
12
5
|
|
|
13
6
|
return /** @type {toa.mongodb.Record} */ { _id: id, ...rest }
|
|
14
7
|
}
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
const from = (record) => {
|
|
21
|
-
if (record === undefined || record === null) return null
|
|
9
|
+
function from (record) {
|
|
10
|
+
if (record === undefined || record === null)
|
|
11
|
+
return null
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...rest
|
|
26
|
-
} = record
|
|
13
|
+
record.id = record._id
|
|
14
|
+
delete record._id
|
|
27
15
|
|
|
28
|
-
return
|
|
16
|
+
return record
|
|
29
17
|
}
|
|
30
18
|
|
|
31
19
|
exports.to = to
|
package/src/storage.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
Connector,
|
|
5
|
-
exceptions
|
|
6
|
-
} = require('@toa.io/core')
|
|
3
|
+
const { Connector, exceptions } = require('@toa.io/core')
|
|
7
4
|
|
|
8
5
|
const { translate } = require('./translate')
|
|
9
|
-
const {
|
|
10
|
-
to,
|
|
11
|
-
from
|
|
12
|
-
} = require('./record')
|
|
6
|
+
const { to, from } = require('./record')
|
|
13
7
|
|
|
14
8
|
class Storage extends Connector {
|
|
15
9
|
#connection
|
|
@@ -29,27 +23,25 @@ class Storage extends Connector {
|
|
|
29
23
|
}
|
|
30
24
|
|
|
31
25
|
async get (query) {
|
|
32
|
-
const {
|
|
33
|
-
criteria,
|
|
34
|
-
options
|
|
35
|
-
} = translate(query)
|
|
36
|
-
|
|
26
|
+
const { criteria, options } = translate(query)
|
|
37
27
|
const record = await this.#connection.get(criteria, options)
|
|
38
28
|
|
|
39
29
|
return from(record)
|
|
40
30
|
}
|
|
41
31
|
|
|
42
32
|
async find (query) {
|
|
43
|
-
const {
|
|
44
|
-
criteria,
|
|
45
|
-
options
|
|
46
|
-
} = translate(query)
|
|
47
|
-
|
|
33
|
+
const { criteria, options } = translate(query)
|
|
48
34
|
const recordset = await this.#connection.find(criteria, options)
|
|
49
35
|
|
|
50
36
|
return recordset.map((item) => from(item))
|
|
51
37
|
}
|
|
52
38
|
|
|
39
|
+
async stream (query = undefined) {
|
|
40
|
+
const { criteria, options } = translate(query)
|
|
41
|
+
|
|
42
|
+
return await this.#connection.stream(criteria, options, from)
|
|
43
|
+
}
|
|
44
|
+
|
|
53
45
|
async add (entity) {
|
|
54
46
|
const record = to(entity)
|
|
55
47
|
const result = await this.#connection.add(record)
|
package/test/record.test.js
CHANGED
|
@@ -47,19 +47,4 @@ describe('from', () => {
|
|
|
47
47
|
_version: 0
|
|
48
48
|
})
|
|
49
49
|
})
|
|
50
|
-
|
|
51
|
-
it('should not modify argument', () => {
|
|
52
|
-
/** @type {toa.mongodb.Record} */
|
|
53
|
-
const record = {
|
|
54
|
-
_id: '1',
|
|
55
|
-
_version: 0
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
from(record)
|
|
59
|
-
|
|
60
|
-
expect(record).toStrictEqual({
|
|
61
|
-
_id: '1',
|
|
62
|
-
_version: 0
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
50
|
})
|