Ruulul / hyper-nostr

33 stars 9 forks source link

TypeError: Cannot read properties of undefined (reading 'bitfield') #11

Open benzmuircroft opened 10 months ago

benzmuircroft commented 10 months ago
npm i hyper-nostr
/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:108
    const bitfield = core.core.bitfield
                               ^

TypeError: Cannot read properties of undefined (reading 'bitfield')
    at TreeNode.preload (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:108:32)
    at new TreeNode (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:101:10)
    at BlockEntry.getTreeNode (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:297:12)
    at Batch.getRoot (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:674:52)
    at async Batch._get (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:751:16)
    at async Batch.get (/home/benz/Desktop/nostr/node_modules/hyperbee/index.js:738:14)
    at async Autodeebee.get (/home/benz/Desktop/nostr/node_modules/hyperdeebee/autodeebee.js:65:12)
    at async Collection.indexExists (/home/benz/Desktop/nostr/node_modules/hyperdeebee/index.js:244:20)
    at async Collection.createIndex (/home/benz/Desktop/nostr/node_modules/hyperdeebee/index.js:218:20)
    at async createDB (file:///home/benz/Desktop/nostr/node_modules/hyper-nostr/db.js:19:3)

For the code:

;(async function(){
  const SDK = await import("hyper-sdk");
  const createSwarm = (await import('hyper-nostr')).default;
  const { generatePrivateKey, getPublicKey, getEventHash, signEvent } = require('nostr-tools');
  const goodbye = require('graceful-goodbye');

  const yourStorageFolder = './missed-events';

  const sdk = await SDK.create({
    storage: yourStorageFolder,
    autoJoin: true
  });
  goodbye(_ => sdk.close());

  const bob = await createSwarm(sdk, 'missed-events'); // <--- error is here 
})();
benzmuircroft commented 10 months ago

It's because hyper-nostr package.json has dependency ?:

"hyperbee": "^2.8.0",

and the version that gets installed is further developed to use newest holepunch

"name": "hyperbee",
"version": "2.18.1",
benzmuircroft commented 10 months ago

in hyper-nostr/db.js I logged the db object

Collection {
  name: 'events',
  bee: Autodeebee {
    autobase: Autobase {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      localInput: Hypercore(
        id: fr8e8y9k54y61j7pxwf7sxj1mcen16dfzim4ynzuio4n1473zscy
        key: 290e8383eade81e927ad7d0bdb3d325b10297865bd57a00af3ac34296bb9bd98
        discoveryKey: f3443e41888334dd1d127483043cefc88ef82fff01038b80f13fff6311f5bcae
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 1
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      localOutput: Hypercore(
        id: 1kjhxtp31yyd54wh7zuipp868nj3yey6g81c5pwwmq5o5kygkt5o
        key: 9293c7c5b990003dea9cede756b4fe389390201e31e4cdb6945bb70da8065477
        discoveryKey: 51286fcfc94aba30b3cb3728370efabc53c66363c505b6f16e269b7f3c831e65
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 2
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      opened: false,
      closed: false,
      _closing: null,
      _inputs: [Array],
      _outputs: [],
      _inputsByKey: Map(0) {},
      _outputsByKey: Map(0) {},
      _keyCompressors: Map(0) {},
      _viewSessions: [Set],
      _readStreams: [],
      _batchId: 0,
      _lock: [Function],
      _eagerUpdate: true,
      _sparse: true,
      _loadingInputsCount: 0,
      _pendingUpdates: [],
      view: [Hyperbee],
      _onappend: [Function (anonymous)],
      _opening: [Promise],
      ready: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    opts: { sub: true },
    bee: Hyperbee {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      opening: null,
      closing: null,
      opened: false,
      closed: false,
      feed: [LinearizedCoreSession],
      core: [LinearizedCoreSession],
      keyEncoding: [Object],
      valueEncoding: [Object],
      extension: null,
      metadata: null,
      lock: [Function],
      sep: <Buffer 00>,
      readonly: false,
      prefix: <Buffer 65 76 65 6e 74 73 00>,
      alwaysDuplicate: true,
      _unprefixedKeyEncoding: [Object],
      _sub: true,
      _checkout: 0,
      _view: true,
      _onappendBound: null,
      _ontruncateBound: null,
      _watchers: null,
      _entryWatchers: null,
      _sessions: true,
      _batches: [],
      [Symbol(kCapture)]: false
    }
  },
  docs: Autodeebee {
    autobase: Autobase {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      localInput: Hypercore(
        id: fr8e8y9k54y61j7pxwf7sxj1mcen16dfzim4ynzuio4n1473zscy
        key: 290e8383eade81e927ad7d0bdb3d325b10297865bd57a00af3ac34296bb9bd98
        discoveryKey: f3443e41888334dd1d127483043cefc88ef82fff01038b80f13fff6311f5bcae
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 1
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      localOutput: Hypercore(
        id: 1kjhxtp31yyd54wh7zuipp868nj3yey6g81c5pwwmq5o5kygkt5o
        key: 9293c7c5b990003dea9cede756b4fe389390201e31e4cdb6945bb70da8065477
        discoveryKey: 51286fcfc94aba30b3cb3728370efabc53c66363c505b6f16e269b7f3c831e65
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 2
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      opened: false,
      closed: false,
      _closing: null,
      _inputs: [Array],
      _outputs: [],
      _inputsByKey: Map(0) {},
      _outputsByKey: Map(0) {},
      _keyCompressors: Map(0) {},
      _viewSessions: [Set],
      _readStreams: [],
      _batchId: 0,
      _lock: [Function],
      _eagerUpdate: true,
      _sparse: true,
      _loadingInputsCount: 0,
      _pendingUpdates: [],
      view: [Hyperbee],
      _onappend: [Function (anonymous)],
      _opening: [Promise],
      ready: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    opts: { sub: true },
    bee: Hyperbee {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      opening: null,
      closing: null,
      opened: false,
      closed: false,
      feed: [LinearizedCoreSession],
      core: [LinearizedCoreSession],
      keyEncoding: [Object],
      valueEncoding: [Object],
      extension: null,
      metadata: null,
      lock: [Function],
      sep: <Buffer 00>,
      readonly: false,
      prefix: <Buffer 65 76 65 6e 74 73 00 64 6f 63 00>,
      alwaysDuplicate: true,
      _unprefixedKeyEncoding: [Object],
      _sub: true,
      _checkout: 0,
      _view: true,
      _onappendBound: null,
      _ontruncateBound: null,
      _watchers: null,
      _entryWatchers: null,
      _sessions: true,
      _batches: [],
      [Symbol(kCapture)]: false
    }
  },
  idxs: Autodeebee {
    autobase: Autobase {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      localInput: Hypercore(
        id: fr8e8y9k54y61j7pxwf7sxj1mcen16dfzim4ynzuio4n1473zscy
        key: 290e8383eade81e927ad7d0bdb3d325b10297865bd57a00af3ac34296bb9bd98
        discoveryKey: f3443e41888334dd1d127483043cefc88ef82fff01038b80f13fff6311f5bcae
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 1
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      localOutput: Hypercore(
        id: 1kjhxtp31yyd54wh7zuipp868nj3yey6g81c5pwwmq5o5kygkt5o
        key: 9293c7c5b990003dea9cede756b4fe389390201e31e4cdb6945bb70da8065477
        discoveryKey: 51286fcfc94aba30b3cb3728370efabc53c66363c505b6f16e269b7f3c831e65
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 2
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      opened: false,
      closed: false,
      _closing: null,
      _inputs: [Array],
      _outputs: [],
      _inputsByKey: Map(0) {},
      _outputsByKey: Map(0) {},
      _keyCompressors: Map(0) {},
      _viewSessions: [Set],
      _readStreams: [],
      _batchId: 0,
      _lock: [Function],
      _eagerUpdate: true,
      _sparse: true,
      _loadingInputsCount: 0,
      _pendingUpdates: [],
      view: [Hyperbee],
      _onappend: [Function (anonymous)],
      _opening: [Promise],
      ready: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    opts: { sub: true },
    bee: Hyperbee {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      opening: null,
      closing: null,
      opened: false,
      closed: false,
      feed: [LinearizedCoreSession],
      core: [LinearizedCoreSession],
      keyEncoding: [Object],
      valueEncoding: [Object],
      extension: null,
      metadata: null,
      lock: [Function],
      sep: <Buffer 00>,
      readonly: false,
      prefix: <Buffer 65 76 65 6e 74 73 00 69 64 78 73 00>,
      alwaysDuplicate: true,
      _unprefixedKeyEncoding: [Object],
      _sub: true,
      _checkout: 0,
      _view: true,
      _onappendBound: null,
      _ontruncateBound: null,
      _watchers: null,
      _entryWatchers: null,
      _sessions: true,
      _batches: [],
      [Symbol(kCapture)]: false
    }
  },
  idx: Autodeebee {
    autobase: Autobase {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      localInput: Hypercore(
        id: fr8e8y9k54y61j7pxwf7sxj1mcen16dfzim4ynzuio4n1473zscy
        key: 290e8383eade81e927ad7d0bdb3d325b10297865bd57a00af3ac34296bb9bd98
        discoveryKey: f3443e41888334dd1d127483043cefc88ef82fff01038b80f13fff6311f5bcae
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 1
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      localOutput: Hypercore(
        id: 1kjhxtp31yyd54wh7zuipp868nj3yey6g81c5pwwmq5o5kygkt5o
        key: 9293c7c5b990003dea9cede756b4fe389390201e31e4cdb6945bb70da8065477
        discoveryKey: 51286fcfc94aba30b3cb3728370efabc53c66363c505b6f16e269b7f3c831e65
        opened: true
        closed: false
        snapshotted: false
        sparse: true
        writable: true
        length: 2
        fork: 0
        sessions: [ 2 ]
        activeRequests: [ 0 ]
        peers: [ 0 ]
      ),
      opened: false,
      closed: false,
      _closing: null,
      _inputs: [Array],
      _outputs: [],
      _inputsByKey: Map(0) {},
      _outputsByKey: Map(0) {},
      _keyCompressors: Map(0) {},
      _viewSessions: [Set],
      _readStreams: [],
      _batchId: 0,
      _lock: [Function],
      _eagerUpdate: true,
      _sparse: true,
      _loadingInputsCount: 0,
      _pendingUpdates: [],
      view: [Hyperbee],
      _onappend: [Function (anonymous)],
      _opening: [Promise],
      ready: [Function (anonymous)],
      [Symbol(kCapture)]: false
    },
    opts: { sub: true },
    bee: Hyperbee {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      opening: null,
      closing: null,
      opened: false,
      closed: false,
      feed: [LinearizedCoreSession],
      core: [LinearizedCoreSession],
      keyEncoding: [Object],
      valueEncoding: [Object],
      extension: null,
      metadata: null,
      lock: [Function],
      sep: <Buffer 00>,
      readonly: false,
      prefix: <Buffer 65 76 65 6e 74 73 00 69 64 78 00>,
      alwaysDuplicate: true,
      _unprefixedKeyEncoding: [Object],
      _sub: true,
      _checkout: 0,
      _view: true,
      _onappendBound: null,
      _ontruncateBound: null,
      _watchers: null,
      _entryWatchers: null,
      _sessions: true,
      _batches: [],
      [Symbol(kCapture)]: false
    }
  }
}
benzmuircroft commented 10 months ago

well on line 108 of hyperbee/index.js it looks for core.core.bitfield but core._core exists and it does not have a bitfield

benzmuircroft commented 10 months ago

Trying to track down what exactly happens when the db's first key collection is declared ....

TypeError: Cannot read properties of undefined (reading 'bitfield') at TreeNode.preload (/hyperbee/index.js:108:32) const bitfield = core.core.bitfield at new TreeNode (/hyperbee/index.js:101:10) this.preload() at BlockEntry.getTreeNode (/hyperbee/index.js:297:12) return new TreeNode(this, entry.keys, entry.children, offset) at Batch.getRoot (/hyperbee/index.js:674:52) return (await this.getBlock(this.version - 1)).getTreeNode(0) at async Batch._get (/hyperbee/index.js:751:16) let node = await this.getRoot(false) 🚨? at async Batch.get (/hyperbee/index.js:738:14) return await this._get(key, encoding) at async Autodeebee.get (/hyperdeebee/autodeebee.js:65:12) return await this.bee.get(key) at async Collection.indexExists (/hyperdeebee/index.js:244:20) await this.idxs.get(name) at async Collection.createIndex (/hyperdeebee/index.js:218:20) await this.indexExists(name) at async createDB (/hyper-nostr/db.js:19:3) await events.createIndex(['kind'])

benzmuircroft commented 10 months ago

I found a fork of the original hyperbeedee that was last updated 3 weeks ago

https://github.com/cayasso/hyperbeedeebee

benzmuircroft commented 10 months ago

WOW!! @Ruulul look at these new commits! https://github.com/cayasso/hyperbeedeebee/commit/53eaefe9f8cacdc4233f0ad2fb9e095076030bbe

benzmuircroft commented 10 months ago

It requires this https://www.npmjs.com/package/sub-encoder

made for hyperbee!

benzmuircroft commented 10 months ago

a legacy fix which forces older modules to be used