npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tree-tagged-hyperdrive

v0.2.0

Published

This is a hyperdrive with a hyperbee on top. Every node in the hyperbee refers to a version of the hyperdrive. It's only required to share one key, because the hyperdrive key is stored in the hyperbee metadata, and setup is automatically done by this modu

Downloads

1

Readme

Tree Tagged Hyperdrive

This is a hyperdrive with a hyperbee on top. Every node in the hyperbee refers to a version of the hyperdrive. It's only required to share one key, because the hyperdrive key is stored in the hyperbee metadata, and setup is automatically done by this module.

Example

In this example two tagged hyperdrives are created. The first one is piped into the second one, so they return the same data. The same file is inserted into the first hyperdrive three times, each time with different data. Each time the file is inserted, an entry in the tree with a different version tag is created. Then all versions greater than 1.0.0 are requested and the content of their hello.txt is printed.

const TreeTaggedHyperdrive = require('tree-tagged-hyperdrive')

const treeTaggedHyperdrive1 = new TreeTaggedHyperdrive()

start()

async function start () {
  await treeTaggedHyperdrive1.ready()
  
  const treeTaggedHyperdrive2 = new TreeTaggedHyperdrive(treeTaggedHyperdrive1.getKey())

  const stream = treeTaggedHyperdrive1.replicate(true, { live: true })
  stream.pipe(treeTaggedHyperdrive2.replicate(false, { live: true })).pipe(stream) 

  await treeTaggedHyperdrive2.ready()

  await new Promise((resolve,reject) => {
    treeTaggedHyperdrive1.drive.writeFile('/hello.txt', 'brave', async function (err) {
      await treeTaggedHyperdrive1.put('0.0.1')
      treeTaggedHyperdrive1.drive.writeFile('/hello.txt', 'new', async function (err) {
        await treeTaggedHyperdrive1.put('1.0.0')
        treeTaggedHyperdrive1.drive.writeFile('/hello.txt', 'world', async function (err) {
          await treeTaggedHyperdrive1.put('1.1.0')

          const rs = await treeTaggedHyperdrive2.tree.createReadStream({ gte: '1.0.0' })
          rs.on('data', async (chunk) => {
            console.log('I found a version matching that query.');
            const drive = treeTaggedHyperdrive2.drive.checkout(chunk.value.toString())
            await drive.ready()
            drive.readFile('hello.txt', function (err, data) {
              console.log('I found a version matching that query: ' + chunk.key.toString())
              console.log('hello.txt contains this: ' + data.toString())
              if(data.toString() == 'world') {
                resolve()
              }
            })
          });
        })
      })
    })
  })
}

API

const treeTaggedHyperdrive = new TreeTaggedHyperdrive([key], [opts])

Make a new tagged hyperdrive. key can be a reference to a hyperbee instance.

opts can be:

  {
    corestore: <custom corestore to use>
    userData: <data to add to the hyperbee metadata>
  }

await treeTaggedHyperdrive.ready()

Wait for initialization to be complete.

await treeTaggedHyperdrive.put(tag, <version>)

Add an entry to the tree, refering to a hyperdrive version. If no version is supplied, the current drive version will be used.

await treeTaggedHyperdrive.getVersionAtTag(tag)

Get the hyperdrive version stored at the supplied tag.

await treeTaggedHyperdrive.getDriveAtTag(tag)

Get a checkout of the hyperdrive at the version specified by the supplied tag.

treeTaggedHyperdrive.getKey()

Get the key of this tagged hyperdrive. Can be used for replication.

treeTaggedHyperdrive.replicate(isInitiator, opts)

Returns a stream for replication. opts are the same as for corestore replication.

treeTaggedHyperdrive.getDrive()

Get the hyperdrive.

treeTaggedHyperdrive.getTree()

Get the hyperbee.