rocksdb-native 3.3.0 → 3.3.1

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/CMakeLists.txt CHANGED
@@ -13,7 +13,7 @@ if(target MATCHES "win32")
13
13
  add_compile_options(/MT$<$<CONFIG:Debug>:d>)
14
14
  endif()
15
15
 
16
- fetch_package("github:holepunchto/librocksdb#2b388ab")
16
+ fetch_package("github:holepunchto/librocksdb#2adf4ff")
17
17
 
18
18
  add_bare_module(rocksdb_native_bare)
19
19
 
package/lib/batch.js CHANGED
@@ -20,6 +20,7 @@ class RocksDBBatch {
20
20
 
21
21
  this._request = null
22
22
  this._resolve = null
23
+ this._reject = null
23
24
 
24
25
  this._handle = null
25
26
  this._buffer = null
@@ -38,16 +39,20 @@ class RocksDBBatch {
38
39
  this._autoDestroy = autoDestroy
39
40
  }
40
41
 
41
- _onfinished() {
42
+ _onfinished(err) {
42
43
  const resolve = this._resolve
44
+ const reject = this._reject
43
45
 
44
46
  this._operations = []
45
47
  this._promises = []
46
48
  this._request = null
47
49
  this._resolve = null
50
+ this._reject = null
48
51
 
49
52
  if (this._autoDestroy === true) this.destroy()
50
- if (resolve !== null) resolve()
53
+
54
+ if (reject !== null && err) reject(err)
55
+ else if (resolve !== null) resolve()
51
56
  }
52
57
 
53
58
  _resize() {
@@ -96,8 +101,9 @@ class RocksDBBatch {
96
101
  if (this._request) throw new Error('Request in progress')
97
102
  if (this._destroyed) throw new Error('Batch is destroyed')
98
103
 
99
- this._request = new Promise((resolve) => {
104
+ this._request = new Promise((resolve, reject) => {
100
105
  this._resolve = resolve
106
+ this._reject = reject
101
107
  })
102
108
 
103
109
  this._flush()
@@ -166,21 +172,26 @@ exports.ReadBatch = class RocksDBReadBatch extends RocksDBBatch {
166
172
  }
167
173
 
168
174
  _onread(errs, values) {
175
+ let applied = true
176
+
169
177
  for (let i = 0, n = this._promises.length; i < n; i++) {
170
178
  const promise = this._promises[i]
171
179
  if (promise === null) continue
172
180
 
173
181
  const err = errs[i]
174
182
 
175
- if (err) promise.reject(new Error(err))
176
- else {
183
+ if (err) {
184
+ applied = false
185
+
186
+ promise.reject(new Error(err))
187
+ } else {
177
188
  promise.resolve(
178
189
  values[i] ? this._decodeValue(Buffer.from(values[i])) : null
179
190
  )
180
191
  }
181
192
  }
182
193
 
183
- this._onfinished()
194
+ this._onfinished(applied ? null : new Error('Batch was not applied'))
184
195
  }
185
196
 
186
197
  get(key) {
@@ -227,15 +238,22 @@ exports.WriteBatch = class RocksDBWriteBatch extends RocksDBBatch {
227
238
  }
228
239
 
229
240
  _onwrite(err) {
241
+ let applied = true
242
+
230
243
  for (let i = 0, n = this._promises.length; i < n; i++) {
231
244
  const promise = this._promises[i]
232
245
  if (promise === null) continue
233
246
 
234
- if (err) promise.reject(new Error(err))
235
- else promise.resolve()
247
+ if (err) {
248
+ applied = false
249
+
250
+ promise.reject(new Error(err))
251
+ } else {
252
+ promise.resolve()
253
+ }
236
254
  }
237
255
 
238
- this._onfinished()
256
+ this._onfinished(applied ? null : new Error('Batch was not applied'))
239
257
  }
240
258
 
241
259
  put(key, value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rocksdb-native",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "librocksdb bindings for JavaScript",
5
5
  "exports": {
6
6
  ".": "./index.js",