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

hypermerge

v0.4.0

Published

why merge when you can HYPERMERGE

Downloads

18

Readme

Hypermerge

Hypermerge is a Javascript library for building p2p collaborative applications without any server infrastructure. It combines Automerge, a CRDT, with hypercore, a distributed append-only log.

Example Usage

See examples/chat/channel.js for example usage.

API

You can also view the generated API docs.

var hm = new Hypermerge([options])

Creates a new Hypermerge instance that manages a set of documents. All previously opened documents are automatically re-opened.

options:

{
  path: string, // directory where the documents should be stored
  immutableApi: false, // whether to use Automerge Immutable.js documents
  defaultMetadata: {} // default metadata that should be written for created documents. Can be set later with `hypermergeInstance.defaultMetadata = {}`
}

hm.joinSwarm([options])

Joins the network swarm for all documents managed by this Hypermerge instance. Must be called after 'ready' has been emitted. options are passed to discovery-swarm.

var doc = hm.create([metadata])

Creates a new document (and hypercore) tracked by the hypermerge instance. If an object is passed, it will be associated with the newly created document. Some metadata properties are assigned automatically by hypermerge:

docId // An id for this document. Forking a document creates a new docId.
groupId // An id for this group of documents. Forking a document keeps the groupId.

hm.open(docId)

Opens the document specified by docId. Will download the document over the network if hm.joinSwarm() was called. The document is opened asynchronously; listen for the 'document:ready' event to get the document when it has finished opening.

hm.update(doc)

Records any local changes made to the document (via Automerge.change).

var newDoc = hm.change(doc, changeFn)

Shorthand for hm.update(Automerge.change(doc, changeFn)).

var doc = hm.fork(parentId, [metadata])

Creates a new document based on the document referenced by parentId. The metadata of the new document will contain a parentId property.

var mergedDoc = hm.merge(destDocId, sourceDocId)

Merges changes from the document referenced by sourceDocId into the document referenced by destDocId. Returns the merged document.

The source and destination docs must have come from the same root document. e.g. The source doc was a .fork() of the destination doc, or visa-versa.

hm.find(docId)

Returns the document for the given docId. Throws if the document has not been opened yet.

hm.getId(doc)

Returns the docId for the given doc.

hm.metadatas(docId)

Returns the list of metadata objects corresponding to the list of actors that have edited this document.

hm.has(docId)

Returns true if docId has been opened.

hm.any([function])

Returns true if any docs satisfy the given function. If a function is not passed, returns true if any docs exist.

hm.isMissingDeps(docId)

Returns true if the document specified by docId is missing changes from other actors. They may still be downloading from the network.

Events

hm.on('ready', hm)

Emitted when all document metadata has been loaded from storage, and the hypermerge instance is ready for use. Documents will continue loading from storage and the network. Required before .create(), .open(), etc. can be used.

hm.on('document:ready', docId, doc)

Emitted when a document has been fully loaded.

hm.on('document:updated', docId, doc, prevDoc)

Emitted when a document has been updated via changes received over the network. Not emitted after local calls to .update() or .change().

hm.on('peer:joined', actorId, peer)

Emitted when a network peer has connected.

hm.on('peer:left', actorId, peer)

Emitted when a network peer has disconnected.