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 +2 -0
- package/lib/write.js +13 -4
- package/package.json +1 -1
package/lib/context.js
CHANGED
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.
|
|
49
|
+
const root = await this.tree.bootstrap()
|
|
40
50
|
|
|
41
|
-
const length = this.
|
|
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,
|