@nxtedition/rocksdb 12.0.2 → 12.0.3

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/chained-batch.js CHANGED
@@ -4,6 +4,7 @@ const { AbstractChainedBatch } = require('abstract-level')
4
4
  const binding = require('./binding')
5
5
  const ModuleError = require('module-error')
6
6
  const { fromCallback } = require('catering')
7
+ const assert = require('node:assert')
7
8
 
8
9
  const kBatchContext = Symbol('batchContext')
9
10
  const kDbContext = Symbol('dbContext')
@@ -20,6 +21,8 @@ class ChainedBatch extends AbstractChainedBatch {
20
21
  }
21
22
 
22
23
  _put (key, value, options) {
24
+ assert(this[kBatchContext])
25
+
23
26
  if (key === null || key === undefined) {
24
27
  throw new ModuleError('Key cannot be null or undefined', {
25
28
  code: 'LEVEL_INVALID_KEY'
@@ -39,6 +42,8 @@ class ChainedBatch extends AbstractChainedBatch {
39
42
  }
40
43
 
41
44
  _del (key, options) {
45
+ assert(this[kBatchContext])
46
+
42
47
  if (key === null || key === undefined) {
43
48
  throw new ModuleError('Key cannot be null or undefined', {
44
49
  code: 'LEVEL_INVALID_KEY'
@@ -51,10 +56,14 @@ class ChainedBatch extends AbstractChainedBatch {
51
56
  }
52
57
 
53
58
  _clear () {
59
+ assert(this[kBatchContext])
60
+
54
61
  binding.batch_clear(this[kBatchContext])
55
62
  }
56
63
 
57
64
  _write (options, callback) {
65
+ assert(this[kBatchContext])
66
+
58
67
  callback = fromCallback(callback, kPromise)
59
68
 
60
69
  try {
@@ -68,19 +77,29 @@ class ChainedBatch extends AbstractChainedBatch {
68
77
  }
69
78
 
70
79
  _writeSync (options) {
80
+ assert(this[kBatchContext])
81
+
71
82
  binding.batch_write(this[kDbContext], this[kBatchContext], options ?? EMPTY)
72
83
  }
73
84
 
74
85
  _close (callback) {
86
+ assert(this[kBatchContext])
87
+
75
88
  binding.batch_clear(this[kBatchContext])
89
+ this[kBatchContext] = null
90
+
76
91
  process.nextTick(callback)
77
92
  }
78
93
 
79
94
  get length () {
95
+ assert(this[kBatchContext])
96
+
80
97
  return binding.batch_count(this[kBatchContext])
81
98
  }
82
99
 
83
100
  _merge (key, value, options) {
101
+ assert(this[kBatchContext])
102
+
84
103
  if (key === null || key === undefined) {
85
104
  throw new ModuleError('Key cannot be null or undefined', {
86
105
  code: 'LEVEL_INVALID_KEY'
@@ -111,6 +130,8 @@ class ChainedBatch extends AbstractChainedBatch {
111
130
  }
112
131
 
113
132
  toArray (options) {
133
+ assert(this[kBatchContext])
134
+
114
135
  return binding.batch_iterate(this[kDbContext], this[kBatchContext], {
115
136
  keys: true,
116
137
  values: true,
package/iterator.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { fromCallback } = require('catering')
4
4
  const { AbstractIterator } = require('abstract-level')
5
+ const assert = require('node:assert')
5
6
 
6
7
  const binding = require('./binding')
7
8
 
@@ -26,6 +27,8 @@ class Iterator extends AbstractIterator {
26
27
  }
27
28
 
28
29
  _seek (target) {
30
+ assert(this[kContext])
31
+
29
32
  if (target.length === 0) {
30
33
  throw new Error('cannot seek() to an empty target')
31
34
  }
@@ -39,6 +42,8 @@ class Iterator extends AbstractIterator {
39
42
  }
40
43
 
41
44
  _next (callback) {
45
+ assert(this[kContext])
46
+
42
47
  if (this[kPosition] < this[kCache].length) {
43
48
  const key = this[kCache][this[kPosition]++]
44
49
  const val = this[kCache][this[kPosition]++]
@@ -65,6 +70,8 @@ class Iterator extends AbstractIterator {
65
70
  }
66
71
 
67
72
  _nextv (size, options, callback) {
73
+ assert(this[kContext])
74
+
68
75
  callback = fromCallback(callback, kPromise)
69
76
 
70
77
  if (this[kFinished]) {
@@ -72,28 +79,28 @@ class Iterator extends AbstractIterator {
72
79
  } else {
73
80
  this[kFirst] = false
74
81
 
75
- setImmediate(() => {
76
- try {
77
- const { rows, finished } = binding.iterator_nextv(this[kContext], size)
82
+ try {
83
+ const { rows, finished } = binding.iterator_nextv(this[kContext], size)
78
84
 
79
- const entries = []
80
- for (let n = 0; n < rows.length; n += 2) {
81
- entries.push([rows[n + 0], rows[n + 1]])
82
- }
85
+ const entries = []
86
+ for (let n = 0; n < rows.length; n += 2) {
87
+ entries.push([rows[n + 0], rows[n + 1]])
88
+ }
83
89
 
84
- this[kFinished] = finished
90
+ this[kFinished] = finished
85
91
 
86
- callback(null, entries, finished)
87
- } catch (err) {
88
- callback(err)
89
- }
90
- })
92
+ process.nextTick(callback, null, entries, finished)
93
+ } catch (err) {
94
+ process.nextTick(callback, err)
95
+ }
91
96
  }
92
97
 
93
98
  return callback[kPromise]
94
99
  }
95
100
 
96
101
  _nextvSync (size, options) {
102
+ assert(this[kContext])
103
+
97
104
  if (this[kFinished]) {
98
105
  return { rows: [], finished: true }
99
106
  }
@@ -107,6 +114,8 @@ class Iterator extends AbstractIterator {
107
114
  }
108
115
 
109
116
  _close (callback) {
117
+ assert(this[kContext])
118
+
110
119
  try {
111
120
  this._closeSync()
112
121
  process.nextTick(callback)
@@ -116,8 +125,11 @@ class Iterator extends AbstractIterator {
116
125
  }
117
126
 
118
127
  _closeSync () {
128
+ assert(this[kContext])
129
+
119
130
  this[kCache] = kEmpty
120
131
  binding.iterator_close(this[kContext])
132
+ this[kContext] = null
121
133
  }
122
134
 
123
135
  _end (callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "12.0.2",
3
+ "version": "12.0.3",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",