autobee 1.0.9 → 1.0.10

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.
@@ -645,8 +645,33 @@ const encoding21 = {
645
645
  // @autobee/link
646
646
  const encoding22 = encoding0
647
647
 
648
- // @autobee/batch
648
+ // @autobee/external-batch
649
649
  const encoding23 = {
650
+ preencode(state, m) {
651
+ c.fixed32.preencode(state, m.key)
652
+ c.uint.preencode(state, m.start)
653
+ c.uint.preencode(state, m.length)
654
+ },
655
+ encode(state, m) {
656
+ c.fixed32.encode(state, m.key)
657
+ c.uint.encode(state, m.start)
658
+ c.uint.encode(state, m.length)
659
+ },
660
+ decode(state) {
661
+ const r0 = c.fixed32.decode(state)
662
+ const r1 = c.uint.decode(state)
663
+ const r2 = c.uint.decode(state)
664
+
665
+ return {
666
+ key: r0,
667
+ start: r1,
668
+ length: r2
669
+ }
670
+ }
671
+ }
672
+
673
+ // @autobee/batch
674
+ const encoding24 = {
650
675
  preencode(state, m) {
651
676
  c.uint.preencode(state, m.start)
652
677
  c.uint.preencode(state, m.end)
@@ -667,72 +692,72 @@ const encoding23 = {
667
692
  }
668
693
 
669
694
  // @autobee/views
670
- const encoding24 = {
695
+ const encoding25 = {
671
696
  preencode(state, m) {
672
- encoding22.preencode(state, m.system)
673
697
  c.uint.preencode(state, m.flushes)
698
+ encoding23.preencode(state, m.system)
674
699
  state.end++ // flags are fixed size
675
700
 
676
- if (m.view) encoding22.preencode(state, m.view)
701
+ if (m.view) encoding23.preencode(state, m.view)
677
702
  },
678
703
  encode(state, m) {
679
704
  const flags = m.view ? 1 : 0
680
705
 
681
- encoding22.encode(state, m.system)
682
706
  c.uint.encode(state, m.flushes)
707
+ encoding23.encode(state, m.system)
683
708
  c.uint8.encode(state, flags)
684
709
 
685
- if (m.view) encoding22.encode(state, m.view)
710
+ if (m.view) encoding23.encode(state, m.view)
686
711
  },
687
712
  decode(state) {
688
- const r0 = encoding22.decode(state)
689
- const r1 = c.uint.decode(state)
713
+ const r0 = c.uint.decode(state)
714
+ const r1 = encoding23.decode(state)
690
715
  const flags = c.uint8.decode(state)
691
716
 
692
717
  return {
693
- system: r0,
694
- flushes: r1,
695
- view: (flags & 1) !== 0 ? encoding22.decode(state) : null
718
+ flushes: r0,
719
+ system: r1,
720
+ view: (flags & 1) !== 0 ? encoding23.decode(state) : null
696
721
  }
697
722
  }
698
723
  }
699
724
 
700
725
  // @autobee/views (inline)
701
- const encoding24_inline = {
726
+ const encoding25_inline = {
702
727
  preencode(state, m) {
703
- encoding22.preencode(state, m.system)
704
728
  c.uint.preencode(state, m.flushes)
729
+ encoding23.preencode(state, m.system)
705
730
 
706
- if (m.view) encoding22.preencode(state, m.view)
731
+ if (m.view) encoding23.preencode(state, m.view)
707
732
  },
708
733
  encode(state, m) {
709
- encoding22.encode(state, m.system)
710
734
  c.uint.encode(state, m.flushes)
735
+ encoding23.encode(state, m.system)
711
736
 
712
- if (m.view) encoding22.encode(state, m.view)
737
+ if (m.view) encoding23.encode(state, m.view)
713
738
  },
714
739
  decode(state, inlining) {
715
- const r0 = encoding22.decode(state)
716
- const r1 = c.uint.decode(state)
740
+ const r0 = c.uint.decode(state)
741
+ const r1 = encoding23.decode(state)
717
742
  const flags = inlining
718
743
 
719
744
  return {
720
- system: r0,
721
- flushes: r1,
722
- view: (flags & 1) !== 0 ? encoding22.decode(state) : null
745
+ flushes: r0,
746
+ system: r1,
747
+ view: (flags & 1) !== 0 ? encoding23.decode(state) : null
723
748
  }
724
749
  }
725
750
  }
726
751
 
727
752
  // @autobee/oplog-message-v3
728
- const encoding25 = {
753
+ const encoding26 = {
729
754
  preencode(state, m) {
730
755
  c.uint.preencode(state, m.timestamp)
731
- encoding25_1.preencode(state, m.links)
756
+ encoding26_1.preencode(state, m.links)
732
757
  state.end++ // max flag is 16 so always one byte
733
758
 
734
- if (m.batch) encoding23.preencode(state, m.batch)
735
- if (m.views) encoding24_inline.preencode(state, m.views)
759
+ if (m.batch) encoding24.preencode(state, m.batch)
760
+ if (m.views) encoding25_inline.preencode(state, m.views)
736
761
  if (m.value) c.buffer.preencode(state, m.value)
737
762
  },
738
763
  encode(state, m) {
@@ -742,25 +767,25 @@ const encoding25 = {
742
767
  }
743
768
 
744
769
  c.uint.encode(state, m.timestamp)
745
- encoding25_1.encode(state, m.links)
770
+ encoding26_1.encode(state, m.links)
746
771
  c.uint.encode(state, flags)
747
772
 
748
- if (m.batch) encoding23.encode(state, m.batch)
749
- if (m.views) encoding24_inline.encode(state, m.views)
773
+ if (m.batch) encoding24.encode(state, m.batch)
774
+ if (m.views) encoding25_inline.encode(state, m.views)
750
775
  if (m.value) c.buffer.encode(state, m.value)
751
776
  },
752
777
  decode(state) {
753
778
  const v = c.uint.decode(state)
754
779
  const r0 = c.uint.decode(state)
755
- const r1 = encoding25_1.decode(state)
780
+ const r1 = encoding26_1.decode(state)
756
781
  const flags = c.uint.decode(state)
757
782
 
758
783
  return {
759
784
  version: v,
760
785
  timestamp: r0,
761
786
  links: r1,
762
- batch: (flags & 1) !== 0 ? encoding23.decode(state) : null,
763
- views: (flags & 2) !== 0 ? encoding24_inline.decode(state, flags >>> 2) : null,
787
+ batch: (flags & 1) !== 0 ? encoding24.decode(state) : null,
788
+ views: (flags & 2) !== 0 ? encoding25_inline.decode(state, flags >>> 2) : null,
764
789
  optimistic: (flags & 8) !== 0,
765
790
  value: (flags & 16) !== 0 ? c.buffer.decode(state) : null
766
791
  }
@@ -768,7 +793,7 @@ const encoding25 = {
768
793
  }
769
794
 
770
795
  // @autobee/oplog
771
- const encoding26 = {
796
+ const encoding27 = {
772
797
  preencode(state, m) {
773
798
  c.uint.preencode(state, m.version)
774
799
  switch (m.version) {
@@ -782,7 +807,7 @@ const encoding26 = {
782
807
  encoding14.preencode(state, m)
783
808
  break
784
809
  case 3:
785
- encoding25.preencode(state, m)
810
+ encoding26.preencode(state, m)
786
811
  break
787
812
  default:
788
813
  throw new Error('Unsupported version')
@@ -801,7 +826,7 @@ const encoding26 = {
801
826
  encoding14.encode(state, m)
802
827
  break
803
828
  case 3:
804
- encoding25.encode(state, m)
829
+ encoding26.encode(state, m)
805
830
  break
806
831
  default:
807
832
  throw new Error('Unsupported version')
@@ -825,7 +850,7 @@ const encoding26 = {
825
850
  return decoded
826
851
  }
827
852
  case 3: {
828
- const decoded = encoding25.decode(state)
853
+ const decoded = encoding26.decode(state)
829
854
  return decoded
830
855
  }
831
856
  default:
@@ -835,7 +860,7 @@ const encoding26 = {
835
860
  }
836
861
 
837
862
  // @autobee/manifest-data
838
- const encoding27 = {
863
+ const encoding28 = {
839
864
  preencode(state, m) {
840
865
  c.uint.preencode(state, m.version)
841
866
  state.end++ // max flag is 2 so always one byte
@@ -869,7 +894,7 @@ const encoding18_3 = c.array(encoding22)
869
894
  // @autobee/system-info-v3.indexers, deferred due to recusive use
870
895
  const encoding18_4 = encoding18_3
871
896
  // @autobee/oplog-message-v3.links, deferred due to recusive use
872
- const encoding25_1 = encoding18_3
897
+ const encoding26_1 = encoding18_3
873
898
 
874
899
  function setVersion(v) {
875
900
  version = v
@@ -940,16 +965,18 @@ function getEncoding(name) {
940
965
  return encoding21
941
966
  case '@autobee/link':
942
967
  return encoding22
943
- case '@autobee/batch':
968
+ case '@autobee/external-batch':
944
969
  return encoding23
945
- case '@autobee/views':
970
+ case '@autobee/batch':
946
971
  return encoding24
947
- case '@autobee/oplog-message-v3':
972
+ case '@autobee/views':
948
973
  return encoding25
949
- case '@autobee/oplog':
974
+ case '@autobee/oplog-message-v3':
950
975
  return encoding26
951
- case '@autobee/manifest-data':
976
+ case '@autobee/oplog':
952
977
  return encoding27
978
+ case '@autobee/manifest-data':
979
+ return encoding28
953
980
  default:
954
981
  throw new Error('Encoder not found ' + name)
955
982
  }
@@ -526,6 +526,32 @@
526
526
  }
527
527
  ]
528
528
  },
529
+ {
530
+ "name": "external-batch",
531
+ "namespace": "autobee",
532
+ "compact": true,
533
+ "flagsPosition": -1,
534
+ "fields": [
535
+ {
536
+ "name": "key",
537
+ "required": true,
538
+ "type": "fixed32",
539
+ "version": 1
540
+ },
541
+ {
542
+ "name": "start",
543
+ "required": true,
544
+ "type": "uint",
545
+ "version": 1
546
+ },
547
+ {
548
+ "name": "length",
549
+ "required": true,
550
+ "type": "uint",
551
+ "version": 1
552
+ }
553
+ ]
554
+ },
529
555
  {
530
556
  "name": "batch",
531
557
  "namespace": "autobee",
@@ -553,21 +579,21 @@
553
579
  "flagsPosition": 2,
554
580
  "fields": [
555
581
  {
556
- "name": "system",
582
+ "name": "flushes",
557
583
  "required": true,
558
- "type": "@autobee/link",
584
+ "type": "uint",
559
585
  "version": 1
560
586
  },
561
587
  {
562
- "name": "flushes",
588
+ "name": "system",
563
589
  "required": true,
564
- "type": "uint",
590
+ "type": "@autobee/external-batch",
565
591
  "version": 1
566
592
  },
567
593
  {
568
594
  "name": "view",
569
595
  "required": false,
570
- "type": "@autobee/link",
596
+ "type": "@autobee/external-batch",
571
597
  "version": 1
572
598
  }
573
599
  ]
package/index.js CHANGED
@@ -79,6 +79,11 @@ module.exports = class Autobee extends ReadyResource {
79
79
  this._workingBee = bee
80
80
  this._workingView = handlers.open ? handlers.open(this._workingBee, this) : this._workingBee
81
81
 
82
+ this._localSystemStart = 0
83
+ this._localSystemLength = 0
84
+ this._localViewStart = 0
85
+ this._localViewLength = 0
86
+
82
87
  this._appending = []
83
88
  this._draining = null
84
89
 
@@ -98,6 +103,7 @@ module.exports = class Autobee extends ReadyResource {
98
103
  this._interrupting = false
99
104
  this._onErrorBound = this._onError.bind(this)
100
105
  this._bumpSoonBound = this.bumpSoon.bind(this)
106
+ this._onGroupUpdateBound = this._onGroupUpdate.bind(this)
101
107
 
102
108
  this.wakeupCapability = null
103
109
  this._wakeup = new AutobeeWakeup(this, handlers)
@@ -137,6 +143,9 @@ module.exports = class Autobee extends ReadyResource {
137
143
  await this.bee.ready()
138
144
  await this._bootingState
139
145
 
146
+ this._localSystemStart = this.system.bee.context.local.length
147
+ this._localViewStart = this._workingBee.context.local.length
148
+
140
149
  this.bumpSoon()
141
150
  }
142
151
 
@@ -269,7 +278,8 @@ module.exports = class Autobee extends ReadyResource {
269
278
  }
270
279
 
271
280
  this._notifyHandler = this.store.notifyGroup(this.wakeupCapability.discoveryKey)
272
- this._notifyHandler.on('update', this._bumpSoonBound)
281
+ this._notifyHandler.on('update', this._onGroupUpdateBound)
282
+ await this._drainBootHints()
273
283
  }
274
284
 
275
285
  const system = result.system || EMPTY_HEAD
@@ -405,15 +415,37 @@ module.exports = class Autobee extends ReadyResource {
405
415
  }
406
416
  }
407
417
 
408
- async _flushWakeup() {
409
- const hints = this._wakeup.flush()
418
+ _onGroupUpdate({ key, length }) {
419
+ this._wakeup.hint({ key, length })
420
+ this.bumpSoon()
421
+ }
410
422
 
411
- if (this._notifyHandler) {
412
- for await (const key of this._notifyHandler.updates({ since: this.previousDrain })) {
413
- const hex = b4a.toString(key, 'hex')
414
- hints.set(hex, -1)
415
- }
423
+ async _drainBootHints() {
424
+ if (!this._notifyHandler) return
425
+
426
+ const keys = []
427
+ for await (const key of this._notifyHandler.updates({ since: this.previousDrain })) {
428
+ keys.push(key)
416
429
  }
430
+ if (!keys.length) return
431
+
432
+ // read the lengths straight from storage in one batch instead of opening cores
433
+ const discoveryKeys = keys.map((key) => crypto.discoveryKey(key))
434
+ const infos = await this.store.storage.getInfos(discoveryKeys, {
435
+ auth: false,
436
+ head: true,
437
+ hints: false
438
+ })
439
+
440
+ for (let i = 0; i < keys.length; i++) {
441
+ const info = infos[i]
442
+ const length = info && info.head ? info.head.length : 0
443
+ this._wakeup.hint({ key: keys[i], length })
444
+ }
445
+ }
446
+
447
+ async _flushWakeup() {
448
+ const hints = this._wakeup.flush()
417
449
 
418
450
  this.previousDrain = Date.now()
419
451
  this.queueWakeupFastForward(hints).catch(noop)
@@ -421,11 +453,7 @@ module.exports = class Autobee extends ReadyResource {
421
453
  for (const [hex, length] of hints) {
422
454
  const key = b4a.from(hex, 'hex')
423
455
  if (this.writers.has(hex)) continue
424
- if (length !== -1) {
425
- const info = await this.system.get(key)
426
- if (info && length <= info.length) continue // stale hint
427
- }
428
- await this.writers.wakeup(key, length === -1 ? 0 : length)
456
+ await this.writers.wakeup(key, length)
429
457
  }
430
458
  }
431
459
 
@@ -445,7 +473,8 @@ module.exports = class Autobee extends ReadyResource {
445
473
 
446
474
  if (buf === null) return null
447
475
 
448
- return encoding.decodeOplog(buf)
476
+ const oplog = encoding.decodeOplog(buf)
477
+ return oplog
449
478
  }
450
479
 
451
480
  _update(changes) {
@@ -664,6 +693,8 @@ module.exports = class Autobee extends ReadyResource {
664
693
  }
665
694
 
666
695
  async _applyBatch(batch, optimistic) {
696
+ const local = batch[0].core === this.local
697
+
667
698
  const userBatch = []
668
699
  for (const node of batch) {
669
700
  this.system.addNode(node)
@@ -680,6 +711,11 @@ module.exports = class Autobee extends ReadyResource {
680
711
 
681
712
  const changed = await this.system.flush(batch, this._workingBee)
682
713
 
714
+ if (local) {
715
+ this._localSystemLength = this.system.bee.context.local.length - this._localSystemStart
716
+ this._localViewLength = this._workingBee.context.local.length - this._localViewStart
717
+ }
718
+
683
719
  await this._storeBoot()
684
720
 
685
721
  for (const { key, added } of changed) {
@@ -742,8 +778,24 @@ module.exports = class Autobee extends ReadyResource {
742
778
  }
743
779
 
744
780
  async _flushLocal() {
745
- // analyze is worth the trade off adding the view here also (technically not needed)
746
- await this.writers.flushLocal(this._workingBee.head())
781
+ await this.writers.flushLocal({
782
+ flushes: this.system.flushes,
783
+ system: {
784
+ key: this.system.bee.context.local.key,
785
+ start: this._localSystemStart,
786
+ length: this._localSystemLength
787
+ },
788
+ view: {
789
+ key: this._workingBee.context.local.key,
790
+ start: this._localViewStart,
791
+ length: this._localViewLength
792
+ }
793
+ })
794
+
795
+ this._localSystemStart = this.system.bee.context.local.length
796
+ this._localSystemLength = 0
797
+ this._localViewStart = this._workingBee.context.local.length
798
+ this._localViewLength = 0
747
799
  }
748
800
 
749
801
  moveTo(head, tip) {
@@ -758,9 +810,11 @@ module.exports = class Autobee extends ReadyResource {
758
810
  }
759
811
 
760
812
  const promises = []
813
+ const heads = []
761
814
  for (const [hex, length] of hints) {
762
815
  if (length === 0) continue
763
816
  const key = b4a.from(hex, 'hex')
817
+ heads.push({ key, length })
764
818
  promises.push(this._getOplog(key, length))
765
819
  }
766
820
 
@@ -768,24 +822,30 @@ module.exports = class Autobee extends ReadyResource {
768
822
  if (this.fastForwarding || this.fastForwardTo) return false
769
823
 
770
824
  let best = null
825
+ let bestHead = null
771
826
  let bestFlushes = -1
772
827
 
773
- for (const msg of ops) {
828
+ for (let i = 0; i < ops.length; i++) {
829
+ const msg = ops[i]
774
830
  if (msg === null) continue
775
831
 
776
832
  if (msg.views && msg.views.flushes > bestFlushes) {
777
833
  bestFlushes = msg.views.flushes
778
834
  best = msg.views
835
+ bestHead = heads[i]
779
836
  }
780
837
  }
781
838
 
782
839
  if (best === null || bestFlushes - this.system.flushes < MIN_FF_GAP) return false
783
840
 
784
- const view = this.bee.checkout(best.view)
841
+ const view = this.bee.checkout({
842
+ key: best.view.key,
843
+ length: best.view.start + best.view.length
844
+ })
785
845
 
786
846
  let trusted = null
787
847
  try {
788
- trusted = await this._handlers.onwakeup(view, this)
848
+ trusted = await this._handlers.onwakeup(bestHead, view, this)
789
849
  if (!trusted || this.fastForwarding || this.fastForwardTo) return false
790
850
  } finally {
791
851
  view.close()
@@ -793,13 +853,19 @@ module.exports = class Autobee extends ReadyResource {
793
853
 
794
854
  const oplog = await this._getOplog(trusted.key, trusted.length)
795
855
 
796
- return this.moveTo(oplog.views.system, {
797
- system: best.system,
798
- verified: {
799
- node: trusted,
800
- flushes: oplog.views.flushes
856
+ return this.moveTo(
857
+ {
858
+ key: oplog.views.system.key,
859
+ length: oplog.views.system.start + oplog.views.system.length
860
+ },
861
+ {
862
+ system: { key: best.system.key, length: best.system.start + best.system.length },
863
+ verified: {
864
+ node: trusted,
865
+ flushes: oplog.views.flushes
866
+ }
801
867
  }
802
- })
868
+ )
803
869
  }
804
870
 
805
871
  async _runFastForward(ff) {
package/lib/writers.js CHANGED
@@ -75,8 +75,8 @@ class ActiveWriters {
75
75
  return this.localWriter.clear()
76
76
  }
77
77
 
78
- flushLocal(head) {
79
- return this.localWriter.flush(head)
78
+ flushLocal(views) {
79
+ return this.localWriter.flush(views)
80
80
  }
81
81
 
82
82
  async refresh() {
@@ -90,16 +90,16 @@ class ActiveWriters {
90
90
  }
91
91
 
92
92
  async updateLocalState() {
93
- const w = this.localWriter
94
- const bootstrapping = w.core.length === 0 && b4a.equals(this.auto.key, w.core.key)
95
- const info = await this.auto.system.get(this.auto.local.key)
96
- const writable = this.writable
93
+ await this.localWriter.update()
94
+ }
97
95
 
98
- w.weight = info ? info.weight : 0
99
- this.writable = info ? !info.isRemoved : bootstrapping
96
+ _updateLocalState() {
97
+ const w = this.localWriter
100
98
 
99
+ const writable = w.isAdded && !w.isRemoved
101
100
  if (writable === this.writable) return
102
101
 
102
+ this.writable = writable
103
103
  this.auto.emit(this.writable ? 'writable' : 'unwritable')
104
104
  this.auto.emit('update')
105
105
  }
@@ -178,6 +178,8 @@ class Writer {
178
178
  this.index = 0
179
179
  this.weight = 0
180
180
  this.pending = null
181
+ this.processed = 0
182
+ this.appendLength = this.core.length + 1
181
183
  this.waiting = null
182
184
  this.download = null
183
185
 
@@ -307,9 +309,12 @@ class Writer {
307
309
  if (!latest || !latest.views) return []
308
310
 
309
311
  // signedLength for autobase compat
312
+ const system = latest.views.system.start + latest.views.system.length
313
+ const view = latest.views.view.start + latest.views.view.length
314
+
310
315
  return [
311
- { ...latest.views.system, signedLength: latest.views.system.length },
312
- { ...latest.views.view, signedLength: latest.views.view.length }
316
+ { key: latest.views.system.key, length: system, signedLength: system },
317
+ { key: latest.views.view.key, length: view, signedLength: view }
313
318
  ]
314
319
  }
315
320
 
@@ -324,13 +329,17 @@ class Writer {
324
329
  const info = await this.system.get(this.core.key)
325
330
 
326
331
  if (!info) {
327
- this.isAdded = this.system.isGenesis()
332
+ this.isAdded = this.system.isGenesis() && b4a.equals(this.core.key, this.writers.auto.key)
328
333
  } else {
329
334
  this.isAdded = true
330
335
  this.isRemoved = info.isRemoved
331
336
  this.weight = info.weight
332
337
  }
333
338
 
339
+ if (this === this.writers.localWriter) {
340
+ this.writers._updateLocalState()
341
+ }
342
+
334
343
  return info ? info.length : 0
335
344
  }
336
345
 
@@ -359,6 +368,9 @@ class Writer {
359
368
  const block = await this.core.get(length++)
360
369
  const oplog = encoding.decodeOplog(block)
361
370
  const node = createNode(this.core, length, this.weight, oplog)
371
+
372
+ if (this.writable) node.optimistic = false
373
+
362
374
  const b = oplog.batch
363
375
 
364
376
  // auto correct some batch invariants
@@ -400,12 +412,18 @@ class Writer {
400
412
 
401
413
  // handle local writer
402
414
  if (this.core.writable && this.pending !== null) {
403
- for (let i = 0; i < this.pending.length; i++) {
415
+ let start = this.processed
416
+ this.processed = this.pending.length
417
+
418
+ for (let i = start; i < this.processed; i++) {
404
419
  const node = this.pending[i]
405
420
 
406
- node.batch = { start: i, end: this.pending.length - 1 - i }
421
+ if (node.length <= length) {
422
+ start++
423
+ continue
424
+ }
407
425
 
408
- if (node.length <= length) continue
426
+ node.batch = { start: i, end: this.pending.length - 1 - i }
409
427
 
410
428
  if (!this.writers.writable && !node.optimistic) {
411
429
  this.writers.clearLocal()
@@ -426,11 +444,14 @@ class Writer {
426
444
  }
427
445
 
428
446
  if (!(await this._isLinked(node))) return null
447
+ }
429
448
 
449
+ if (this.processed === this.pending.length) {
430
450
  this.removePending()
431
-
432
- return this.pending.slice(i)
433
451
  }
452
+
453
+ if (start === this.processed) return null
454
+ return this.pending.slice(start, this.processed)
434
455
  }
435
456
 
436
457
  return null
@@ -474,16 +495,11 @@ class Writer {
474
495
  links,
475
496
  batch,
476
497
  views: null,
477
- optimistic,
498
+ optimistic: optimistic && !this.writable,
478
499
  value
479
500
  }
480
501
 
481
- const node = createNode(
482
- this.core,
483
- this.core.length + this.pending.length + 1,
484
- this.weight,
485
- oplog
486
- )
502
+ const node = createNode(this.core, this.appendLength++, this.weight, oplog)
487
503
 
488
504
  this.pending.push(node)
489
505
  this.addPending()
@@ -492,21 +508,27 @@ class Writer {
492
508
  }
493
509
 
494
510
  clear() {
495
- this.pending = null
511
+ if (!this.pending) return
512
+
513
+ if (this.processed === this.pending.length) {
514
+ this.pending = null
515
+ } else {
516
+ this.pending = this.pending.slice(this.processed)
517
+ }
518
+
519
+ this.processed = 0
496
520
  }
497
521
 
498
- flush(view) {
522
+ flush(views) {
499
523
  if (this.pending === null) return Promise.resolve()
500
524
  const buffers = []
501
- const s = this.system.bee.head()
502
- const flushes = this.system.flushes
503
- this.pending[this.pending.length - 1].views = { system: s, flushes, view }
504
- for (let i = 0; i < this.pending.length; i++) {
525
+ this.pending[this.pending.length - 1].views = views
526
+ for (let i = 0; i < this.processed; i++) {
505
527
  const node = this.pending[i]
506
528
  node.batch = { start: i, end: this.pending.length - 1 - i }
507
529
  buffers.push(encoding.encodeOplog(node))
508
530
  }
509
- this.pending = null
531
+ this.clear()
510
532
  return this.core.append(buffers)
511
533
  }
512
534
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autobee",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Bee based autobase",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Holepunch Inc.",
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "autobee-encryption": "^0.1.2",
27
- "autobee-wakeup": "^1.0.5",
27
+ "autobee-wakeup": "^1.1.3",
28
28
  "b4a": "^1.8.0",
29
29
  "compact-encoding": "^2.18.0",
30
- "hyperbee2": "^2.8.0",
31
- "hypercore": "^11.33.0",
30
+ "hyperbee2": "^2.10.3",
31
+ "hypercore": "^11.33.2",
32
32
  "hypercore-id-encoding": "^1.3.0",
33
33
  "hyperschema": "^1.20.1",
34
34
  "ready-guard": "^1.0.0",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "brittle": "^3.19.1",
41
- "corestore": "^7.10.0",
41
+ "corestore": "^7.11.0",
42
42
  "hypercore-crypto": "^3.6.1",
43
43
  "lunte": "^1.6.0",
44
44
  "prettier": "^3.8.1",