hyperbee2 0.0.0 → 0.0.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/lib/context.js CHANGED
@@ -102,6 +102,8 @@ class CoreContext {
102
102
  }
103
103
 
104
104
  getContextByKey(key) {
105
+ if (b4a.equals(key, this.core.key)) return this
106
+
105
107
  const hex = b4a.toString(key, 'hex')
106
108
  if (this.other.has(hex)) return this.other.get(hex)
107
109
 
package/lib/write.js CHANGED
@@ -29,6 +29,16 @@ module.exports = class WriteBatch {
29
29
  this.length = 0
30
30
  }
31
31
 
32
+ _getContext(root) {
33
+ if (!this.key && !root) return this.tree.context
34
+ return this.key ? this.tree.context.getContextByKey(this.key) : root.context
35
+ }
36
+
37
+ _getLength(root) {
38
+ if (this.length > -1) return this.length
39
+ return root ? root.seq + 1 : 0
40
+ }
41
+
32
42
  async flush() {
33
43
  if (this.flushing) throw new Error('Already flushed')
34
44
  this.flushing = true
@@ -36,15 +46,14 @@ module.exports = class WriteBatch {
36
46
  const ops = this.ops
37
47
  this.ops = []
38
48
 
39
- await this.tree.ready()
49
+ const root = await this.tree.bootstrap()
40
50
 
41
- const length = this.length === -1 ? this.tree.core.length : this.length
51
+ const length = this._getLength(root)
52
+ const context = this._getContext(root)
42
53
 
43
54
  const changed = length === 0
44
55
  const seq = length === 0 ? 0 : length - 1
45
56
 
46
- const context = this.key ? this.tree.context.getContextByKey(this.key) : this.tree.context
47
-
48
57
  this.length = length
49
58
  this.root = new TreeNodePointer(
50
59
  context,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbee2",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "btree",
5
5
  "main": "index.js",
6
6
  "files": [