@toa.io/storages.mongodb 1.0.0-alpha.207 → 1.0.0-alpha.209
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 +6 -6
- package/src/storage.js +27 -4
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.209",
|
|
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/conveyor": "1.0.0-alpha.
|
|
23
|
-
"@toa.io/core": "1.0.0-alpha.
|
|
24
|
-
"@toa.io/generic": "1.0.0-alpha.
|
|
25
|
-
"@toa.io/pointer": "1.0.0-alpha.
|
|
22
|
+
"@toa.io/conveyor": "1.0.0-alpha.208",
|
|
23
|
+
"@toa.io/core": "1.0.0-alpha.208",
|
|
24
|
+
"@toa.io/generic": "1.0.0-alpha.208",
|
|
25
|
+
"@toa.io/pointer": "1.0.0-alpha.208",
|
|
26
26
|
"mongodb": "7.1.0",
|
|
27
27
|
"openspan": "1.0.0-alpha.173",
|
|
28
28
|
"saslprep": "1.0.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "56601872d17c8f154afae932e9516459b42e6703"
|
|
31
31
|
}
|
package/src/storage.js
CHANGED
|
@@ -107,6 +107,8 @@ class Storage extends Connector {
|
|
|
107
107
|
else
|
|
108
108
|
return await this.set(entity)
|
|
109
109
|
} catch (error) {
|
|
110
|
+
console.error('MongoDB error', error)
|
|
111
|
+
|
|
110
112
|
const retry = await retriable(error, attempt)
|
|
111
113
|
|
|
112
114
|
if (retry)
|
|
@@ -123,10 +125,29 @@ class Storage extends Connector {
|
|
|
123
125
|
const operations = entities.map((entity) => {
|
|
124
126
|
const record = to(entity)
|
|
125
127
|
|
|
126
|
-
if (entity._version === 1)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return {
|
|
128
|
+
if (entity._version === 1) {
|
|
129
|
+
const { _version, ...rest } = record
|
|
130
|
+
|
|
131
|
+
return { // upsert in required when document is deleted
|
|
132
|
+
updateOne: {
|
|
133
|
+
filter: { _id: entity.id },
|
|
134
|
+
update: {
|
|
135
|
+
$set: {
|
|
136
|
+
...rest,
|
|
137
|
+
_deleted: null
|
|
138
|
+
},
|
|
139
|
+
$inc: { _version: 1 },
|
|
140
|
+
},
|
|
141
|
+
upsert: true
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} else
|
|
145
|
+
return {
|
|
146
|
+
replaceOne: {
|
|
147
|
+
filter: { _id: entity.id, _version: entity._version - 1 },
|
|
148
|
+
replacement: record
|
|
149
|
+
}
|
|
150
|
+
}
|
|
130
151
|
})
|
|
131
152
|
|
|
132
153
|
const client = this.#client.instance.client
|
|
@@ -142,6 +163,8 @@ class Storage extends Connector {
|
|
|
142
163
|
|
|
143
164
|
return true
|
|
144
165
|
} catch (error) {
|
|
166
|
+
console.error('MongoDB error', error)
|
|
167
|
+
|
|
145
168
|
const retry = await retriable(error, attempt)
|
|
146
169
|
|
|
147
170
|
if (retry)
|