@nxtedition/rocksdb 15.2.6 → 15.3.0

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/binding.cc CHANGED
@@ -1960,7 +1960,6 @@ NAPI_METHOD(batch_write) {
1960
1960
 
1961
1961
  rocksdb::WriteBatch* batch;
1962
1962
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[1], reinterpret_cast<void**>(&batch)));
1963
-
1964
1963
  bool sync = false;
1965
1964
  NAPI_STATUS_THROWS(GetProperty(env, argv[2], "sync", sync));
1966
1965
 
package/chained-batch.js CHANGED
@@ -1,12 +1,17 @@
1
1
  'use strict'
2
2
 
3
+ const { fromCallback } = require('catering')
3
4
  const { AbstractChainedBatch } = require('abstract-level')
4
- const binding = require('./binding')
5
5
  const ModuleError = require('module-error')
6
6
  const assert = require('node:assert')
7
7
 
8
+ const binding = require('./binding')
9
+
10
+ const kPromise = Symbol('promise')
8
11
  const kBatchContext = Symbol('batchContext')
9
12
  const kDbContext = Symbol('dbContext')
13
+ const kBusy = Symbol('busy')
14
+
10
15
  const EMPTY = {}
11
16
 
12
17
  class ChainedBatch extends AbstractChainedBatch {
@@ -15,10 +20,18 @@ class ChainedBatch extends AbstractChainedBatch {
15
20
 
16
21
  this[kDbContext] = context
17
22
  this[kBatchContext] = binding.batch_init()
23
+ this[kBusy] = false
24
+ }
25
+
26
+ get length () {
27
+ assert(this[kBatchContext])
28
+
29
+ return binding.batch_count(this[kBatchContext])
18
30
  }
19
31
 
20
32
  _put (key, value, options) {
21
33
  assert(this[kBatchContext])
34
+ assert(!this[kBusy])
22
35
 
23
36
  if (key === null || key === undefined) {
24
37
  throw new ModuleError('Key cannot be null or undefined', {
@@ -40,6 +53,7 @@ class ChainedBatch extends AbstractChainedBatch {
40
53
 
41
54
  _putLogData (blob) {
42
55
  assert(this[kBatchContext])
56
+ assert(!this[kBusy])
43
57
 
44
58
  if (blob === null || blob === undefined) {
45
59
  throw new ModuleError('Blob cannot be null or undefined', {
@@ -54,6 +68,7 @@ class ChainedBatch extends AbstractChainedBatch {
54
68
 
55
69
  _del (key, options) {
56
70
  assert(this[kBatchContext])
71
+ assert(!this[kBusy])
57
72
 
58
73
  if (key === null || key === undefined) {
59
74
  throw new ModuleError('Key cannot be null or undefined', {
@@ -68,24 +83,43 @@ class ChainedBatch extends AbstractChainedBatch {
68
83
 
69
84
  _clear () {
70
85
  assert(this[kBatchContext])
86
+ assert(!this[kBusy])
71
87
 
72
88
  binding.batch_clear(this[kBatchContext])
73
89
  }
74
90
 
75
91
  _write (options, callback) {
76
92
  assert(this[kBatchContext])
93
+ assert(!this[kBusy])
77
94
 
78
- binding.batch_write(this[kDbContext], this[kBatchContext], options ?? EMPTY, callback)
95
+ return this._writeAsync(options, callback)
79
96
  }
80
97
 
81
98
  _writeSync (options) {
82
99
  assert(this[kBatchContext])
100
+ assert(!this[kBusy])
83
101
 
84
102
  binding.batch_write_sync(this[kDbContext], this[kBatchContext], options ?? EMPTY)
85
103
  }
86
104
 
105
+ _writeAsync (options, callback) {
106
+ assert(this[kBatchContext])
107
+ assert(!this[kBusy])
108
+
109
+ callback = fromCallback(callback, kPromise)
110
+
111
+ this[kBusy] = true
112
+ binding.batch_write(this[kDbContext], this[kBatchContext], options ?? EMPTY, (err) => {
113
+ this[kBusy] = false
114
+ callback(err)
115
+ })
116
+
117
+ return callback[kPromise]
118
+ }
119
+
87
120
  _close (callback) {
88
121
  assert(this[kBatchContext])
122
+ assert(!this[kBusy])
89
123
 
90
124
  try {
91
125
  this._closeSync()
@@ -96,20 +130,16 @@ class ChainedBatch extends AbstractChainedBatch {
96
130
  }
97
131
 
98
132
  _closeSync () {
99
- if (this[kBatchContext]) {
100
- binding.batch_clear(this[kBatchContext])
101
- this[kBatchContext] = null
102
- }
103
- }
104
-
105
- get length () {
106
133
  assert(this[kBatchContext])
134
+ assert(!this[kBusy])
107
135
 
108
- return binding.batch_count(this[kBatchContext])
136
+ binding.batch_clear(this[kBatchContext])
137
+ this[kBatchContext] = null
109
138
  }
110
139
 
111
140
  _merge (key, value, options) {
112
141
  assert(this[kBatchContext])
142
+ assert(!this[kBusy])
113
143
 
114
144
  if (key === null || key === undefined) {
115
145
  throw new ModuleError('Key cannot be null or undefined', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "15.2.6",
3
+ "version": "15.3.0",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",