hypercore 11.0.17 → 11.0.18

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.
@@ -850,14 +850,21 @@ module.exports = class SessionState {
850
850
  return head
851
851
  }
852
852
 
853
- _moveToCore (core) {
853
+ _moveToCore (core, truncated, appended) {
854
854
  const head = this.core.sessionStates.pop()
855
855
  if (head !== this) this.core.sessionStates[(head.index = this.index)] = head
856
856
 
857
857
  this.core = core
858
858
  this.index = this.core.sessionStates.push(this) - 1
859
859
 
860
- for (let i = this.sessions.length - 1; i >= 0; i--) this.sessions[i].transferSession(this.core)
860
+ for (let i = this.sessions.length - 1; i >= 0; i--) {
861
+ const s = this.sessions[i]
862
+ const manifest = s.manifest
863
+ s.transferSession(this.core)
864
+ if (!manifest && s.manifest) s.emit('manifest')
865
+ if (truncated) s.emit('truncate', truncated.to, truncated.fork)
866
+ if (appended) s.emit('append')
867
+ }
861
868
  }
862
869
 
863
870
  async moveTo (core, length) {
@@ -872,6 +879,9 @@ module.exports = class SessionState {
872
879
 
873
880
  const treeLength = this.length
874
881
 
882
+ let truncated = null
883
+ let appended = false
884
+
875
885
  if (!this.isSnapshot()) {
876
886
  if (this.lingers === null) this.lingers = []
877
887
  this.lingers.push(this.storage)
@@ -900,10 +910,14 @@ module.exports = class SessionState {
900
910
  this.roots = await this.tree.getRoots(length)
901
911
 
902
912
  if (truncation) {
903
- const { dependency, tree } = truncation
913
+ const { dependency } = truncation
904
914
 
905
915
  if (dependency) this.storage.updateDependencyLength(dependency.length, true)
906
- this.ontruncate(tree, tree.length, treeLength, true)
916
+ truncated = { to: treeLength, fork }
917
+ }
918
+
919
+ if (this.length > treeLength) {
920
+ appended = true
907
921
  }
908
922
  }
909
923
 
@@ -913,7 +927,7 @@ module.exports = class SessionState {
913
927
  if (state.name === this.name) state._moveToCore(core.core)
914
928
  }
915
929
 
916
- this._moveToCore(core.core)
930
+ this._moveToCore(core.core, truncated, appended)
917
931
  } finally {
918
932
  this.mutex.unlock()
919
933
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "11.0.17",
3
+ "version": "11.0.18",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {